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

Force a run of the setup playbook after a db failover #18120

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
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