Skip to content

Commit

Permalink
Merge pull request #15482 from carbonin/run_the_setup_playbook_for_to…
Browse files Browse the repository at this point in the history
…wer_upgrades

Run the setup playbook if we see that an upgrade has happened
  • Loading branch information
gtanzillo committed Jun 30, 2017
2 parents 7cc16bb + 72320a3 commit d418207
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
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

0 comments on commit d418207

Please sign in to comment.