Skip to content

Commit

Permalink
Merge pull request #18120 from carbonin/recover_embedded_ansible_afte…
Browse files Browse the repository at this point in the history
…r_failover

Force a run of the setup playbook after a db failover

(cherry picked from commit e5cc6fc)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1543340
  • Loading branch information
bdunne authored and simaishi committed Nov 5, 2018
1 parent 77db974 commit e0f7546
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/embedded_ansible/appliance_embedded_ansible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def initialize
end

def start
if configured? && !upgrade?
update_proxy_settings
services.each { |service| LinuxAdmin::Service.new(service).start.enable }
else
if run_setup_script?
configure_secret_key
run_setup_script(EXCLUDE_TAGS)
else
update_proxy_settings
services.each { |service| LinuxAdmin::Service.new(service).start.enable }
end

5.times do
Expand Down Expand Up @@ -99,6 +99,10 @@ def playbook_repo_path

private

def run_setup_script?
force_setup_run? || !configured? || upgrade?
end

def upgrade?
local_tower_version != tower_rpm_version
end
Expand Down Expand Up @@ -126,6 +130,7 @@ def run_setup_script(exclude_tags)
AwesomeSpawn.run!(SETUP_SCRIPT, :params => params)
end
write_setup_complete_file
remove_force_setup_marker_file
rescue AwesomeSpawn::CommandResultError => e
_log.error("EmbeddedAnsible setup script failed with: #{e.message}")
miq_database.ansible_secret_key = nil
Expand Down Expand Up @@ -213,4 +218,16 @@ def setup_completed?
def setup_complete_file
Rails.root.join("tmp", "embedded_ansible_setup_complete")
end

def remove_force_setup_marker_file
FileUtils.rm_f(force_setup_run_marker_file)
end

def force_setup_run?
File.exist?(force_setup_run_marker_file)
end

def force_setup_run_marker_file
Rails.root.join("tmp", "embedded_ansible_force_setup_run")
end
end
1 change: 1 addition & 0 deletions lib/evm_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def self.configure_rails_handler(monitor)
ActiveRecord::Base.establish_connection(Rails.application.config.database_configuration[Rails.env])

raise_server_event("db_failover_executed")
FileUtils.touch(Rails.root.join("tmp", "embedded_ansible_force_setup_run"))
LinuxAdmin::Service.new("evmserverd").restart
end

Expand Down
18 changes: 18 additions & 0 deletions spec/lib/embedded_ansible/appliance_embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@
end
end

describe "#start with the force setup run marker file" do
it "runs the setup playbook" do
file = Rails.root.join("tmp", "embedded_ansible_force_setup_run")
FileUtils.touch(file)

expect(subject).to receive(:configure_secret_key)
expect(subject).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)

subject.start
FileUtils.rm_f(file)
end
end

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

0 comments on commit e0f7546

Please sign in to comment.