From e2ed49ca9593d919eba0bb5cf936420db7d50cab Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 24 Oct 2017 17:11:58 -0400 Subject: [PATCH 1/3] Login with console authentication if available --- app/models/manageiq/providers/vmware/infra_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/vmware/infra_manager.rb b/app/models/manageiq/providers/vmware/infra_manager.rb index bdadbe420..0b629e91e 100644 --- a/app/models/manageiq/providers/vmware/infra_manager.rb +++ b/app/models/manageiq/providers/vmware/infra_manager.rb @@ -34,7 +34,7 @@ def self.description end def remote_console_vmrc_acquire_ticket - vim = connect + vim = connect(:auth_type => :console) ticket = vim.acquireCloneTicket # The ticket received is valid for 30 seconds, but we can't disconnect the From 1d7cf23fe0668630984e54a1fb814c89d0e447f8 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 30 Oct 2017 09:21:42 -0400 Subject: [PATCH 2/3] Add supported auth types to VMware::InfraManager --- app/models/manageiq/providers/vmware/infra_manager.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/manageiq/providers/vmware/infra_manager.rb b/app/models/manageiq/providers/vmware/infra_manager.rb index 0b629e91e..23861bfec 100644 --- a/app/models/manageiq/providers/vmware/infra_manager.rb +++ b/app/models/manageiq/providers/vmware/infra_manager.rb @@ -33,6 +33,14 @@ def self.description @description ||= "VMware vCenter".freeze end + def supported_auth_types + %w(default console) + end + + def supports_authentication?(authtype) + supported_auth_types.include?(authtype.to_s) + end + def remote_console_vmrc_acquire_ticket vim = connect(:auth_type => :console) ticket = vim.acquireCloneTicket From 6818be17678bf0e710c8f8c6c032c8cc047e09a3 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 1 Nov 2017 08:55:44 -0400 Subject: [PATCH 3/3] Add console spec test to fallback to default creds --- .../providers/vmware/infra_manager_spec.rb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/spec/models/manageiq/providers/vmware/infra_manager_spec.rb b/spec/models/manageiq/providers/vmware/infra_manager_spec.rb index 964952ac8..5f8de1c6f 100644 --- a/spec/models/manageiq/providers/vmware/infra_manager_spec.rb +++ b/spec/models/manageiq/providers/vmware/infra_manager_spec.rb @@ -81,6 +81,48 @@ end end + context "#remote_console_vmrc_acquire_ticket" do + let(:ems) do + _, _, zone = EvmSpecHelper.create_guid_miq_server_zone + FactoryGirl.create(:ems_vmware, :zone => zone) + end + + context "with console credentials" do + before do + ems.authentications << FactoryGirl.create(:authentication, :userid => "root", :password => "vmware") + ems.authentications << FactoryGirl.create(:authentication, :authtype => "console", :userid => "readonly", :password => "1234") + end + + it "uses the console credentials" do + require 'VMwareWebService/MiqVim' + + vim = mock_vim_broker_connection + + expect(MiqVim).to receive(:new).with(ems.hostname, "readonly", "1234").and_return(vim) + expect(vim).to receive(:acquireCloneTicket) + + ems.remote_console_vmrc_acquire_ticket + end + end + + context "without console credentials" do + before do + ems.authentications << FactoryGirl.create(:authentication, :userid => "root", :password => "vmware") + end + + it "uses the default credentials" do + require 'VMwareWebService/MiqVim' + + vim = mock_vim_broker_connection + + expect(MiqVim).to receive(:new).with(ems.hostname, "root", "vmware").and_return(vim) + expect(vim).to receive(:acquireCloneTicket) + + ems.remote_console_vmrc_acquire_ticket + end + end + end + context "handling changes that may require EventCatcher restart" do before(:each) do guid, server, zone = EvmSpecHelper.create_guid_miq_server_zone @@ -123,4 +165,12 @@ def assert_event_catcher_restart_queued expect(q[0].instance_id).to eq(@ems.id) expect(q[0].role).to eq("event") end + + def mock_vim_broker_connection + vim = double(vim) + allow(vim).to receive(:server).and_return(ems.hostname) + allow(vim).to receive(:isVirtualCenter?).and_return(true) + allow(vim).to receive(:apiVersion).and_return(6.0) + vim + end end