Skip to content

Commit

Permalink
Merge pull request #125 from agrare/add_option_for_console_authentica…
Browse files Browse the repository at this point in the history
…tion

Login with console authentication if available
(cherry picked from commit f8943a1)
  • Loading branch information
blomquisg authored and simaishi committed Nov 9, 2017
1 parent 83de3f7 commit c341956
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/manageiq/providers/vmware/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ 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
vim = connect(:auth_type => :console)
ticket = vim.acquireCloneTicket

# The ticket received is valid for 30 seconds, but we can't disconnect the
Expand Down
50 changes: 50 additions & 0 deletions spec/models/manageiq/providers/vmware/infra_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit c341956

Please sign in to comment.