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

Run the setup playbook if we see that an upgrade has happened #15482

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
17 changes: 16 additions & 1 deletion lib/embedded_ansible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class EmbeddedAnsible
HTTP_PORT = 54_321
HTTPS_PORT = 54_322
WAIT_FOR_ANSIBLE_SLEEP = 1.second
TOWER_VERSION_FILE = "/var/lib/awx/.tower_version".freeze

def self.available?
return true if MiqEnvironment::Command.is_container?
Expand All @@ -36,6 +37,10 @@ def self.configured?
key.present? && key == File.read(SECRET_KEY_FILE)
end

def self.upgrade?
local_tower_version != tower_rpm_version
end

def self.alive?
return false unless configured? && running?
begin
Expand Down Expand Up @@ -87,7 +92,7 @@ def self.api_connection
end

def self.appliance_start
if configured?
if configured? && !upgrade?
services.each { |service| LinuxAdmin::Service.new(service).start.enable }
else
configure_secret_key
Expand Down Expand Up @@ -229,4 +234,14 @@ def self.database_connection
ActiveRecord::Base.connection
end
private_class_method :database_connection

def self.local_tower_version
File.read(TOWER_VERSION_FILE).strip
end
private_class_method :local_tower_version

def self.tower_rpm_version
LinuxAdmin::Rpm.info("ansible-tower-server")["version"]
end
private_class_method :tower_rpm_version
end
34 changes: 33 additions & 1 deletion spec/lib/embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,15 @@
end
end

describe ".start when configured" do
describe ".start when configured and not upgrading" do
let(:version_file) { Tempfile.new("tower_version") }

before do
version_file.write("3.1.3\n")
version_file.close
stub_const("EmbeddedAnsible::TOWER_VERSION_FILE", version_file.path)
expect(LinuxAdmin::Rpm).to receive(:info).with("ansible-tower-server").and_return("version" => "3.1.3")

stub_const("EmbeddedAnsible::WAIT_FOR_ANSIBLE_SLEEP", 0)

expect(EmbeddedAnsible).to receive(:configured?).and_return true
Expand Down Expand Up @@ -319,6 +326,31 @@
end
end

describe ".start when configured and upgrading" do
let(:version_file) { Tempfile.new("tower_version") }

before do
version_file.write("3.1.2\n")
version_file.close
stub_const("EmbeddedAnsible::TOWER_VERSION_FILE", version_file.path)
expect(LinuxAdmin::Rpm).to receive(:info).with("ansible-tower-server").and_return("version" => "3.1.3")

expect(described_class).to receive(:configured?).and_return(true)
expect(described_class).to receive(:configure_secret_key)
end

it "runs the setup playbook" do
expect(described_class).to receive(:alive?).and_return(true)
miq_database.set_ansible_admin_authentication(:password => "adminpassword")
miq_database.set_ansible_rabbitmq_authentication(:userid => "rabbituser", :password => "rabbitpassword")
miq_database.set_ansible_database_authentication(:userid => "databaseuser", :password => "databasepassword")

expect(AwesomeSpawn).to receive(:run!).with("ansible-tower-setup", anything)

described_class.start
end
end

describe ".start when not configured" do
before do
expect(described_class).to receive(:configured?).and_return(false)
Expand Down