Skip to content

Commit

Permalink
Merge pull request #16989 from carbonin/recheck_embedded_ansible_auth…
Browse files Browse the repository at this point in the history
…entication

Re-check the provider authentication if the API is responding
(cherry picked from commit 04aea3e)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1552783
  • Loading branch information
jrafanie authored and simaishi committed Mar 7, 2018
1 parent cfe0101 commit a2d7cf1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/embedded_ansible_worker/runner.rb
Expand Up @@ -23,6 +23,7 @@ def heartbeat

def do_work
embedded_ansible.start if !embedded_ansible.alive? && !embedded_ansible.running?
provider.authentication_check if embedded_ansible.alive? && !provider.authentication_status_ok?
end

def before_exit(*_)
Expand All @@ -37,7 +38,6 @@ def setup_ansible

def update_embedded_ansible_provider
server = MiqServer.my_server(true)
provider = ManageIQ::Providers::EmbeddedAnsible::Provider.first_or_initialize

provider.name = "Embedded Ansible"
provider.zone = server.zone
Expand Down Expand Up @@ -65,6 +65,10 @@ def message_sync_config(*_args); end

private

def provider
@provider ||= ManageIQ::Providers::EmbeddedAnsible::Provider.first_or_initialize
end

def provider_url
URI::Generic.build(provider_uri_hash).to_s
end
Expand Down
35 changes: 35 additions & 0 deletions spec/models/embedded_ansible_worker/runner_spec.rb
Expand Up @@ -128,5 +128,40 @@
end
end
end

context "#do_work" do
it "starts embedded ansible if it is not alive and not running" do
allow(embedded_ansible_instance).to receive(:alive?).and_return(false)
allow(embedded_ansible_instance).to receive(:running?).and_return(false)

expect(embedded_ansible_instance).to receive(:start)

runner.do_work
end

context "with a provider" do
let(:provider) { FactoryGirl.create(:provider_embedded_ansible, :with_authentication) }

it "runs an authentication check if embedded ansible is alive and the credentials are not valid" do
auth = provider.authentications.first
auth.status = "Error"
auth.save!

allow(embedded_ansible_instance).to receive(:alive?).and_return(true)
allow(runner).to receive(:provider).and_return(provider)
expect(provider).to receive(:authentication_check)

runner.do_work
end

it "doesn't run an authentication check if the credentials are valid" do
allow(embedded_ansible_instance).to receive(:alive?).and_return(true)
allow(runner).to receive(:provider).and_return(provider)
expect(provider).not_to receive(:authentication_check)

runner.do_work
end
end
end
end
end

0 comments on commit a2d7cf1

Please sign in to comment.