Skip to content

Commit

Permalink
convert ems#validate_remote_console_vmrc_support to supports
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Mar 23, 2023
1 parent 0aef0d0 commit 9d663a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
18 changes: 5 additions & 13 deletions app/models/manageiq/providers/vmware/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Vmware::InfraManager < InfraManager
supports :label_mapping
supports :metrics
supports :native_console
supports :vmrc_console do
"vCenter needs to be refreshed to determine remote console support." if api_version.blank? || hostname.blank? || uid_ems.blank?
end
supports :webmks_console

supports :provisioning
supports :smartstate_analysis
supports :streaming_refresh do
Expand Down Expand Up @@ -332,19 +337,6 @@ def remote_console_vmrc_acquire_ticket
ticket
end

def remote_console_vmrc_support_known?
!api_version.blank? && !hostname.blank? && !uid_ems.blank?
end

def validate_remote_console_vmrc_support
raise(MiqException::RemoteConsoleNotSupportedError, "vCenter needs to be refreshed to determine VMRC remote console support.") unless self.remote_console_vmrc_support_known?
true
end

def validate_remote_console_webmks_support
true
end

def after_update_authentication
super
stop_refresh_worker_queue_on_credential_change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def remote_console_vmrc_acquire_ticket(_userid = nil, _originating_server = nil)

def validate_remote_console_vmrc_support
validate_remote_console_acquire_ticket("vmrc")
ext_management_system.validate_remote_console_vmrc_support
validate_supports(ext_management_system.unsupported_reason(:vmrc_console))
true
end

Expand Down Expand Up @@ -87,7 +87,7 @@ def remote_console_webmks_acquire_ticket(userid, originating_server = nil)

def validate_remote_console_webmks_support
validate_remote_console_acquire_ticket("webmks")
ext_management_system.validate_remote_console_webmks_support
validate_supports(ext_management_system.unsupported_reason(:webmks_console))
true
end

Expand Down Expand Up @@ -144,6 +144,14 @@ def remote_console_vnc_acquire_ticket(userid, originating_server)

private

# @param unsupported_reason [Nil,String, Symbol]
# a symbol will lookup the unsupported reason
# otherwise, will raise an error if there is a reason to
def validate_supports(unsupported_reason)
unsupported_reason = unsupported_reason(unsupported_reason) if unsupported_reason.kind_of?(Symbol)
raise(MiqException::RemoteConsoleNotSupportedError, unsupported_reason) if unsupported_reason
end

# Method to generate the remote URI for the VMRC console
def build_vmrc_url(ticket)
url = URI::Generic.build(:scheme => "vmrc",
Expand Down
18 changes: 9 additions & 9 deletions spec/models/manageiq/providers/vmware/infra_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,50 +155,50 @@
end
end

context "#validate_remote_console_vmrc_support" do
context "#supports?(:vmrc_console)" do
before(:each) do
@ems = FactoryBot.create(:ems_vmware)
end

it "raise for missing/blank values" do
@ems.update(:api_version => "", :uid_ems => "2E1C1E82-BD83-4E54-9271-630C6DFAD4D1")
expect { @ems.validate_remote_console_vmrc_support }.to raise_error MiqException::RemoteConsoleNotSupportedError
expect(@ems.supports?(:vmrc_console)).to be_falsey
end
end

context "#remote_console_vmrc_support_known?" do
context "#supports?(:vmrc_console)" do
before(:each) do
@ems = FactoryBot.create(:ems_vmware)
end

it "true with nothing missing/blank" do
@ems.update(:api_version => "5.0", :uid_ems => "2E1C1E82-BD83-4E54-9271-630C6DFAD4D1")
expect(@ems.remote_console_vmrc_support_known?).to be_truthy
expect(@ems.supports?(:vmrc_console)).to be_truthy
end

it "false for blank hostname" do
@ems.update(:hostname => "", :api_version => "5.0", :uid_ems => "2E1C1E82-BD83-4E54-9271-630C6DFAD4D1")
expect(@ems.remote_console_vmrc_support_known?).not_to be_truthy
expect(@ems.supports?(:vmrc_console)).not_to be_truthy
end

it "false for missing api_version" do
@ems.update(:api_version => nil, :uid_ems => "2E1C1E82-BD83-4E54-9271-630C6DFAD4D1")
expect(@ems.remote_console_vmrc_support_known?).not_to be_truthy
expect(@ems.supports?(:vmrc_console)).not_to be_truthy
end

it "false for blank api_version" do
@ems.update(:api_version => "", :uid_ems => "2E1C1E82-BD83-4E54-9271-630C6DFAD4D1")
expect(@ems.remote_console_vmrc_support_known?).not_to be_truthy
expect(@ems.supports?(:vmrc_console)).not_to be_truthy
end

it "false for missing uid_ems" do
@ems.update(:api_version => "5.0", :uid_ems => nil)
expect(@ems.remote_console_vmrc_support_known?).not_to be_truthy
expect(@ems.supports?(:vmrc_console)).not_to be_truthy
end

it "false for blank uid_ems" do
@ems.update(:api_version => "5.0", :uid_ems => "")
expect(@ems.remote_console_vmrc_support_known?).not_to be_truthy
expect(@ems.supports?(:vmrc_console)).not_to be_truthy
end
end

Expand Down

0 comments on commit 9d663a6

Please sign in to comment.