Skip to content

Commit

Permalink
Merge pull request #15487 from carbonin/run_setup_playbook_upgrade_fine
Browse files Browse the repository at this point in the history
[FINE] Run setup playbook on ansible rpm upgrade
  • Loading branch information
simaishi authored Jun 30, 2017
2 parents 4db1274 + 43f3b26 commit 7182ec0
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 false unless MiqEnvironment::Command.is_appliance?
Expand All @@ -33,6 +34,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 All @@ -44,7 +49,7 @@ def self.alive?
end

def self.start
if configured?
if configured? && !upgrade?
services.each { |service| LinuxAdmin::Service.new(service).start.enable }
else
configure_secret_key
Expand Down Expand Up @@ -194,4 +199,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 @@ -87,8 +87,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 @@ -258,6 +265,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 7182ec0

Please sign in to comment.