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

Login with console authentication if available #125

Merged
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: 9 additions & 1 deletion app/models/manageiq/providers/vmware/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,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