forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New class to for determining whether embedded ansible is installed, a…
…vailable and enabled. https://www.pivotaltracker.com/story/show/137134397
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |