From 27dc7f85949836e9f774be4a37a913e22314f409 Mon Sep 17 00:00:00 2001 From: Drew Bomhof Date: Tue, 9 May 2017 15:20:49 -0400 Subject: [PATCH 1/2] Check the Embedded Ansible role is on 1. Raise an error if an attempt at raw_connect is made if the role is not enabled 2. Continue on as normal with the connect if the role is enabled https://bugzilla.redhat.com/show_bug.cgi?id=1448186 --- .../providers/embedded_ansible/provider.rb | 10 ++++++++++ .../embedded_ansible/provider_spec.rb | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/models/manageiq/providers/embedded_ansible/provider.rb b/app/models/manageiq/providers/embedded_ansible/provider.rb index 224d411cb39..cf598b653ea 100644 --- a/app/models/manageiq/providers/embedded_ansible/provider.rb +++ b/app/models/manageiq/providers/embedded_ansible/provider.rb @@ -8,4 +8,14 @@ class ManageIQ::Providers::EmbeddedAnsible::Provider < ::Provider :class_name => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager", :dependent => :destroy, :autosave => true + + def self.raw_connect(base_url, username, password, verify_ssl) + raise StandardError, 'Embedded ansible is disabled' unless role_enabled? + super + end + + def self.role_enabled? + MiqServer.all.any? { |x| x.has_active_role?('embedded_ansible') } + end + private_class_method :role_enabled? end diff --git a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb index 28ce91ffcbe..8b120fb674e 100644 --- a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb @@ -1,6 +1,14 @@ describe ManageIQ::Providers::EmbeddedAnsible::Provider do subject { FactoryGirl.create(:provider_embedded_ansible) } + let(:miq_server) { FactoryGirl.create(:miq_server) } + + before do + FactoryGirl.create(:server_role, :name => 'embedded_ansible', :max_concurrent => 0) + server_role = miq_server.assign_role('embedded_ansible') + miq_server.assigned_server_roles.where(:server_role_id => server_role.id).first.update_attributes(:active => true) + end + it_behaves_like 'ansible provider' context "DefaultAnsibleObjects concern" do @@ -35,5 +43,16 @@ end end end + + context "Embedded Ansible role" do + it "disabled #raw_connect" do + miq_server.active_roles.delete_all + expect { described_class.raw_connect('a', 'b', 'c', 'd') }.to raise_exception(StandardError, 'Embedded ansible is disabled') + end + + it "enabled #raw_connect" do + expect(described_class.raw_connect('a', 'b', 'c', 'd')).to be_truthy + end + end end end From 6b99c98811f1723fc0424ca7dd0dc81ee45d3b64 Mon Sep 17 00:00:00 2001 From: Drew Bomhof Date: Wed, 10 May 2017 14:05:07 -0400 Subject: [PATCH 2/2] Modify specs to set the embedded role https://bugzilla.redhat.com/show_bug.cgi?id=1448186 --- app/models/manageiq/providers/embedded_ansible/provider.rb | 4 ++-- .../automation_manager/configuration_script_spec.rb | 4 ++++ .../embedded_ansible/automation_manager/credential_spec.rb | 4 ++++ .../refresher_configuration_script_source_spec.rb | 4 ++++ .../embedded_ansible/automation_manager/refresher_spec.rb | 4 ++++ .../automation_manager/refresher_v2_spec.rb | 4 ++++ .../manageiq/providers/embedded_ansible/provider_spec.rb | 4 +--- spec/support/evm_spec_helper.rb | 6 ++++++ 8 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/models/manageiq/providers/embedded_ansible/provider.rb b/app/models/manageiq/providers/embedded_ansible/provider.rb index cf598b653ea..6a4e5e21965 100644 --- a/app/models/manageiq/providers/embedded_ansible/provider.rb +++ b/app/models/manageiq/providers/embedded_ansible/provider.rb @@ -10,8 +10,8 @@ class ManageIQ::Providers::EmbeddedAnsible::Provider < ::Provider :autosave => true def self.raw_connect(base_url, username, password, verify_ssl) - raise StandardError, 'Embedded ansible is disabled' unless role_enabled? - super + return super if role_enabled? + raise StandardError, 'Embedded ansible is disabled' end def self.role_enabled? diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb index fdd27b4f545..054e93236c6 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb @@ -3,5 +3,9 @@ let(:manager_with_authentication) { provider_with_authentication.managers.first } let(:manager_with_configuration_scripts) { FactoryGirl.create(:embedded_automation_manager_ansible, :provider, :configuration_script) } + before do + EvmSpecHelper.assign_embedded_ansible_role + end + it_behaves_like 'ansible configuration_script' end diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb index d6842806b85..8e07f709b4e 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb @@ -3,5 +3,9 @@ FactoryGirl.create(:provider_embedded_ansible, :with_authentication, :default_organization => 1).managers.first end + before do + EvmSpecHelper.assign_embedded_ansible_role + end + it_behaves_like 'ansible credential' end diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_configuration_script_source_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_configuration_script_source_spec.rb index 23542bc2bba..b2fd15a48b4 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_configuration_script_source_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_configuration_script_source_spec.rb @@ -1,4 +1,8 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Refresher do + before do + EvmSpecHelper.assign_embedded_ansible_role + end + it_behaves_like 'refresh configuration_script_source', :provider_embedded_ansible, described_class.parent, diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_spec.rb index 6bc7a30c8c1..fc3fedead8a 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_spec.rb @@ -1,4 +1,8 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Refresher do + before do + EvmSpecHelper.assign_embedded_ansible_role + end + it_behaves_like 'ansible refresher', :provider_embedded_ansible, described_class.parent, diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_v2_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_v2_spec.rb index 48cefd7dc5e..02fcd719233 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_v2_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/refresher_v2_spec.rb @@ -1,4 +1,8 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Refresher do + before do + EvmSpecHelper.assign_embedded_ansible_role + end + it_behaves_like 'ansible refresher_v2', :provider_embedded_ansible, described_class.parent, diff --git a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb index 8b120fb674e..4a66a4abd97 100644 --- a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb @@ -4,9 +4,7 @@ let(:miq_server) { FactoryGirl.create(:miq_server) } before do - FactoryGirl.create(:server_role, :name => 'embedded_ansible', :max_concurrent => 0) - server_role = miq_server.assign_role('embedded_ansible') - miq_server.assigned_server_roles.where(:server_role_id => server_role.id).first.update_attributes(:active => true) + EvmSpecHelper.assign_embedded_ansible_role(miq_server) end it_behaves_like 'ansible provider' diff --git a/spec/support/evm_spec_helper.rb b/spec/support/evm_spec_helper.rb index b44e72caf75..d9867a0589d 100644 --- a/spec/support/evm_spec_helper.rb +++ b/spec/support/evm_spec_helper.rb @@ -21,6 +21,12 @@ def self.vmware_nested_folders(ems) end end + def self.assign_embedded_ansible_role(miq_server = nil) + miq_server ||= local_miq_server + FactoryGirl.create(:server_role, :name => 'embedded_ansible', :max_concurrent => 0) + miq_server.assign_role('embedded_ansible').update_attributes(:active => true) + end + # Clear all EVM caches def self.clear_caches @settings_loaded = Vmdb::Settings.last_loaded