Skip to content

Commit

Permalink
New class to for determining whether embedded ansible is installed, a…
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanzillo committed Jan 10, 2017
1 parent 939ddfc commit 2cf595c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/embedded_ansible.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class EmbeddedAnsible
APPLIANCE_ANSIBLE_DIRECTORY = "/opt/ansible-installer".freeze
ANSIBLE_ROLE = "embedded_ansible".freeze

def self.available?
installed?
end

def self.enabled?
MiqServer.my_server(true).has_active_role?(ANSIBLE_ROLE)
end

def self.running?
# TODO
false
end

def self.installed?
path = ENV["APPLIANCE_ANSIBLE_DIRECTORY"] || APPLIANCE_ANSIBLE_DIRECTORY
Dir.exist?(File.expand_path(path.to_s))
end
private_class_method :installed?
end
27 changes: 27 additions & 0 deletions spec/lib/embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe EmbeddedAnsible do
before do
ENV["APPLIANCE_ANSIBLE_DIRECTORY"] = nil
end

context ".available?" do
it "returns true when installed in the default location" do
allow(Dir).to receive(:exist?).with("/opt/ansible-installer").and_return(true)

expect(described_class.available?).to be_truthy
end

it "returns true when installed in the custom location in env var" do
ENV["APPLIANCE_ANSIBLE_DIRECTORY"] = "/tmp"
allow(Dir).to receive(:exist?).with("/tmp").and_return(true)
allow(Dir).to receive(:exist?).with("/opt/ansible-installer").and_return(false)

expect(described_class.available?).to be_truthy
end

it "returns false when not installed" do
allow(Dir).to receive(:exist?).with("/opt/ansible-installer").and_return(false)

expect(described_class.available?).to be_falsey
end
end
end

0 comments on commit 2cf595c

Please sign in to comment.