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

[V2V] Have ConversionHost explicitly search authentications for auth type #18748

Merged
merged 4 commits into from
May 11, 2019
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
4 changes: 2 additions & 2 deletions app/models/conversion_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def resource_supports_conversion_host
# with the resource using the 'ssh_keypair' auth type, and finally 'default'.
#
def find_credentials(auth_type = 'v2v')
authentication = authentication_type(auth_type)
authentication = authentications.detect { |a| a.authtype == auth_type }

if authentication.blank?
res = resource.respond_to?(:authentication_type) ? resource : resource.ext_management_system
Expand Down Expand Up @@ -307,7 +307,7 @@ def miq_ssh_util_args_manageiq_providers_openstack_cloudmanager_vm
# +extra_vars+ option should be a hash of key/value pairs which, if present,
# will be passed to the '-e' flag.
#
def ansible_playbook(playbook, extra_vars = {}, miq_task_id = nil, auth_type = nil)
def ansible_playbook(playbook, extra_vars = {}, miq_task_id = nil, auth_type = 'v2v')
task = MiqTask.find(miq_task_id) if miq_task_id.present?

host = hostname || ipaddress
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
status { "SomeMockedStatus" }
end

factory :authentication_v2v, :parent => :authentication_ssh_keypair do
authtype { "v2v" }
end

factory :authentication_redhat_metric, :parent => :authentication do
authtype { "metrics" }
end
Expand Down
48 changes: 42 additions & 6 deletions spec/models/conversion_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,53 @@

context "authentication associations" do
let(:vm) { FactoryBot.create(:vm_openstack) }
let(:ems) { FactoryBot.create(:ems_redhat, :zone => FactoryBot.create(:zone), :api_version => '4.2.4') }
let(:host) { FactoryBot.create(:host_redhat, :ext_management_system => ems) }

let(:conversion_host_vm) { FactoryBot.create(:conversion_host, :resource => vm) }
let(:auth_authkey) { FactoryBot.create(:authentication_ssh_keypair, :resource => conversion_host_vm) }
let(:conversion_host_host) { FactoryBot.create(:conversion_host, :resource => host) }

let(:auth_keypair) { FactoryBot.create(:authentication_ssh_keypair, :resource => conversion_host_vm) }
let(:auth_v2v) { FactoryBot.create(:authentication_v2v, :resource => conversion_host_host) }

it "finds associated authentications" do
expect(conversion_host_vm.authentications).to contain_exactly(auth_authkey)
it "finds associated ssh_keypair authentications" do
expect(conversion_host_vm.authentications).to contain_exactly(auth_keypair)
end

it "finds associated v2v authentications" do
expect(conversion_host_host.authentications).to contain_exactly(auth_v2v)
end

it "allows a resource to add an authentication" do
auth_authkey2 = FactoryBot.create(:authentication_ssh_keypair)
conversion_host_vm.authentications << auth_authkey2
expect(conversion_host_vm.authentications).to contain_exactly(auth_authkey, auth_authkey2)
auth_keypair2 = FactoryBot.create(:authentication_ssh_keypair)
conversion_host_vm.authentications << auth_keypair2
expect(conversion_host_vm.authentications).to contain_exactly(auth_keypair, auth_keypair2)
end
end

context "find_credentials" do
let(:auth_v2v) { FactoryBot.create(:authentication_v2v, :resource => conversion_host_vm) }
let(:ems_redhat) { FactoryBot.create(:ems_redhat, :zone => FactoryBot.create(:zone), :api_version => '4.2.4') }
let(:ems_openstack) { FactoryBot.create(:ems_openstack, :zone => FactoryBot.create(:zone)) }
let(:auth_default) { FactoryBot.create(:authentication) }
let(:auth_v2v) { FactoryBot.create(:authentication_v2v) }

let(:host) { FactoryBot.create(:host_redhat, :ext_management_system => ems_redhat) }
let(:vm) { FactoryBot.create(:vm_openstack, :ext_management_system => ems_openstack) }

let(:conversion_host_vm) { FactoryBot.create(:conversion_host, :resource => vm) }
let(:conversion_host_host) { FactoryBot.create(:conversion_host, :resource => host) }

it "finds the v2v credentials as expected when associated directly with the conversion host" do
conversion_host_vm.authentications << auth_v2v
expect(conversion_host_vm.send(:find_credentials)).to eq(auth_v2v)
end

it "finds the credentials associated with the resource if credentials cannot be found for the conversion host" do
vm.ext_management_system.authentications << auth_default
host.authentications << auth_default
expect(conversion_host_vm.send(:find_credentials)).to eq(auth_default)
expect(conversion_host_host.send(:find_credentials)).to eq(auth_default)
end
end

Expand Down