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

Check that the Embedded Ansible role is on #15045

Merged
merged 2 commits into from
May 10, 2017
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
10 changes: 10 additions & 0 deletions app/models/manageiq/providers/embedded_ansible/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
return super if role_enabled?
raise StandardError, 'Embedded ansible is disabled'
end

def self.role_enabled?
MiqServer.all.any? { |x| x.has_active_role?('embedded_ansible') }
end
private_class_method :role_enabled?
end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
describe ManageIQ::Providers::EmbeddedAnsible::Provider do
subject { FactoryGirl.create(:provider_embedded_ansible) }

let(:miq_server) { FactoryGirl.create(:miq_server) }

before do
EvmSpecHelper.assign_embedded_ansible_role(miq_server)
end

it_behaves_like 'ansible provider'

context "DefaultAnsibleObjects concern" do
Expand Down Expand Up @@ -35,5 +41,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
6 changes: 6 additions & 0 deletions spec/support/evm_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down