From 9984f387c73030e343736961830e7ebe32fb9190 Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Tue, 4 Apr 2017 15:26:24 -0400 Subject: [PATCH 1/3] Check for rpms rather than a path in EmbeddedAnsible.avaliable? --- lib/embedded_ansible.rb | 7 +++--- spec/lib/embedded_ansible_spec.rb | 36 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/embedded_ansible.rb b/lib/embedded_ansible.rb index 53a047e065f..edb8855de46 100644 --- a/lib/embedded_ansible.rb +++ b/lib/embedded_ansible.rb @@ -4,7 +4,6 @@ require "ansible_tower_client" class EmbeddedAnsible - APPLIANCE_ANSIBLE_DIRECTORY = "/opt/ansible-installer".freeze ANSIBLE_ROLE = "embedded_ansible".freeze SETUP_SCRIPT = "#{APPLIANCE_ANSIBLE_DIRECTORY}/setup.sh".freeze SECRET_KEY_FILE = "/etc/tower/SECRET_KEY".freeze @@ -15,8 +14,10 @@ class EmbeddedAnsible WAIT_FOR_ANSIBLE_SLEEP = 1.second def self.available? - path = ENV["APPLIANCE_ANSIBLE_DIRECTORY"] || APPLIANCE_ANSIBLE_DIRECTORY - Dir.exist?(File.expand_path(path.to_s)) + return false unless MiqEnvironment::Command.is_appliance? + + required_rpms = Set["ansible-tower-server", "ansible-tower-setup"] + required_rpms.subset?(LinuxAdmin::Rpm.list_installed.keys.to_set) end def self.enabled? diff --git a/spec/lib/embedded_ansible_spec.rb b/spec/lib/embedded_ansible_spec.rb index d811907403c..8f0d8d960cc 100644 --- a/spec/lib/embedded_ansible_spec.rb +++ b/spec/lib/embedded_ansible_spec.rb @@ -2,28 +2,32 @@ require "awesome_spawn" 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) + context "in an appliance" do + before do + allow(MiqEnvironment::Command).to receive(:is_appliance?).and_return(true) + end - expect(described_class.available?).to be_truthy - end + it "returns true when installed in the default location" do + installed_rpms = { + "ansible-tower-server" => "1.0.1", + "ansible-tower-setup" => "1.2.3", + "vim" => "13.5.1" + } + expect(LinuxAdmin::Rpm).to receive(:list_installed).and_return(installed_rpms) - 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 - expect(described_class.available?).to be_truthy - end + it "returns false when not installed" do + expect(LinuxAdmin::Rpm).to receive(:list_installed).and_return("vim" => "13.5.1") - 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 + it "returns false outside of an appliance" do + allow(MiqEnvironment::Command).to receive(:is_appliance?).and_return(false) expect(described_class.available?).to be_falsey end end From d87f08a90886744117d78b4cb8e2ea2f40a7b4c9 Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Tue, 4 Apr 2017 15:27:43 -0400 Subject: [PATCH 2/3] Update the setup script to use the new wrapper rather than setup.sh This wrapper script is provided in /usr/bin by the rpm rather than installed in a path by us manually. --- lib/embedded_ansible.rb | 2 +- spec/lib/embedded_ansible_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/embedded_ansible.rb b/lib/embedded_ansible.rb index edb8855de46..5348925428e 100644 --- a/lib/embedded_ansible.rb +++ b/lib/embedded_ansible.rb @@ -5,7 +5,7 @@ class EmbeddedAnsible ANSIBLE_ROLE = "embedded_ansible".freeze - SETUP_SCRIPT = "#{APPLIANCE_ANSIBLE_DIRECTORY}/setup.sh".freeze + SETUP_SCRIPT = "ansible-tower-setup".freeze SECRET_KEY_FILE = "/etc/tower/SECRET_KEY".freeze CONFIGURE_EXCLUDE_TAGS = "packages,migrations,firewall,supervisor".freeze START_EXCLUDE_TAGS = "packages,migrations,firewall".freeze diff --git a/spec/lib/embedded_ansible_spec.rb b/spec/lib/embedded_ansible_spec.rb index 8f0d8d960cc..6bdeefd5142 100644 --- a/spec/lib/embedded_ansible_spec.rb +++ b/spec/lib/embedded_ansible_spec.rb @@ -235,7 +235,7 @@ params = options[:params] inventory_file_contents = File.read(params[:inventory=]) - expect(script_path).to eq("/opt/ansible-installer/setup.sh") + expect(script_path).to eq("ansible-tower-setup") expect(params["--"]).to be_nil expect(params[:extra_vars=]).to eq(extra_vars) expect(params[:skip_tags=]).to eq("packages,migrations,firewall,supervisor") @@ -262,7 +262,7 @@ params = options[:params] inventory_file_contents = File.read(params[:inventory=]) - expect(script_path).to eq("/opt/ansible-installer/setup.sh") + expect(script_path).to eq("ansible-tower-setup") expect(params["--"]).to be_nil expect(params[:extra_vars=]).to eq(extra_vars) expect(params[:skip_tags=]).to eq("packages,migrations,firewall,supervisor") @@ -293,7 +293,7 @@ params = options[:params] inventory_file_contents = File.read(params[:inventory=]) - expect(script_path).to eq("/opt/ansible-installer/setup.sh") + expect(script_path).to eq("ansible-tower-setup") expect(params["--"]).to be_nil expect(params[:extra_vars=]).to eq(extra_vars) expect(params[:skip_tags=]).to eq("packages,migrations,firewall") From e47eafb0a02e19323ed29f2849f64dd2f8511328 Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Tue, 4 Apr 2017 15:31:21 -0400 Subject: [PATCH 3/3] Don't try to set up the UI files at setup time This extra variable tells the setup script that it shouldn't attempt to set up the various files needed to run the tower UI. --- lib/embedded_ansible.rb | 7 ++++--- spec/lib/embedded_ansible_spec.rb | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/embedded_ansible.rb b/lib/embedded_ansible.rb index 5348925428e..1df27e1deb4 100644 --- a/lib/embedded_ansible.rb +++ b/lib/embedded_ansible.rb @@ -86,9 +86,10 @@ def self.api_connection def self.run_setup_script(exclude_tags) json_extra_vars = { - :minimum_var_space => 0, - :http_port => HTTP_PORT, - :https_port => HTTPS_PORT + :minimum_var_space => 0, + :http_port => HTTP_PORT, + :https_port => HTTPS_PORT, + :tower_package_name => "ansible-tower-server" }.to_json with_inventory_file do |inventory_file_path| diff --git a/spec/lib/embedded_ansible_spec.rb b/spec/lib/embedded_ansible_spec.rb index 6bdeefd5142..743d9000de3 100644 --- a/spec/lib/embedded_ansible_spec.rb +++ b/spec/lib/embedded_ansible_spec.rb @@ -92,9 +92,10 @@ let(:miq_database) { MiqDatabase.first } let(:extra_vars) do { - :minimum_var_space => 0, - :http_port => described_class::HTTP_PORT, - :https_port => described_class::HTTPS_PORT + :minimum_var_space => 0, + :http_port => described_class::HTTP_PORT, + :https_port => described_class::HTTPS_PORT, + :tower_package_name => "ansible-tower-server" }.to_json end