Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter embedded ansible for rpm builds #14637

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/embedded_ansible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
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
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
Expand All @@ -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?
Expand Down Expand Up @@ -85,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|
Expand Down
49 changes: 27 additions & 22 deletions spec/lib/embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, vim

}
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
Expand Down Expand Up @@ -88,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

Expand Down Expand Up @@ -231,7 +236,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")
Expand All @@ -258,7 +263,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")