Skip to content

Commit

Permalink
Merge pull request #15313 from carbonin/handle_setup_playbook_failure…
Browse files Browse the repository at this point in the history
…_better

Handle setup playbook failure better
(cherry picked from commit 388a40c)

https://bugzilla.redhat.com/show_bug.cgi?id=1460803
https://bugzilla.redhat.com/show_bug.cgi?id=1460805
  • Loading branch information
jrafanie authored and simaishi committed Jun 12, 2017
1 parent ca3d55a commit 76ab38e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/embedded_ansible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def self.running?
end

def self.configured?
return false unless File.exist?(SECRET_KEY_FILE)
key = miq_database.ansible_secret_key
key.present? && key == File.read(SECRET_KEY_FILE)
end
Expand Down Expand Up @@ -98,6 +99,10 @@ def self.run_setup_script(exclude_tags)
}
AwesomeSpawn.run!(SETUP_SCRIPT, :params => params)
end
rescue AwesomeSpawn::CommandResultError => e
_log.error("EmbeddedAnsible setup script failed with: #{e.message}")
miq_database.ansible_secret_key = nil
raise
end
private_class_method :run_setup_script

Expand Down
18 changes: 17 additions & 1 deletion spec/lib/embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@

expect(described_class.configured?).to be false
end

it "returns false when the file doesn't exist and there is a value in the database" do
key_file.unlink
miq_database.ansible_secret_key = "password"
expect(described_class.configured?).to be false
end
end

describe ".configure_secret_key (private)" do
Expand All @@ -256,10 +262,10 @@
before do
expect(described_class).to receive(:configured?).and_return(false)
expect(described_class).to receive(:configure_secret_key)
expect(described_class).to receive(:alive?).and_return(true)
end

it "generates new passwords with no passwords set" do
expect(described_class).to receive(:alive?).and_return(true)
expect(described_class).to receive(:generate_database_authentication).and_return(double(:userid => "awx", :password => "databasepassword"))
expect(AwesomeSpawn).to receive(:run!) do |script_path, options|
params = options[:params]
Expand All @@ -284,6 +290,7 @@
end

it "uses the existing passwords when they are set in the database" 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")
Expand All @@ -306,6 +313,15 @@

described_class.start
end

it "removes the secret key from the database when setup fails" do
miq_database.ansible_secret_key = "supersecretkey"
expect(described_class).to receive(:generate_database_authentication).and_return(double(:userid => "awx", :password => "databasepassword"))

expect(AwesomeSpawn).to receive(:run!).and_raise(AwesomeSpawn::CommandResultError.new("error", 1))
expect { described_class.start }.to raise_error(AwesomeSpawn::CommandResultError)
expect(miq_database.reload.ansible_secret_key).not_to be_present
end
end

describe ".generate_database_authentication (private)" do
Expand Down

0 comments on commit 76ab38e

Please sign in to comment.