Skip to content

Commit

Permalink
convert console_supported? to supports?
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Mar 8, 2023
1 parent 1d12179 commit 50aeec2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class ManageIQ::Providers::Ovirt::InfraManager::Vm
module RemoteConsole
def console_supported?(type)
return true if type.upcase == 'NATIVE'

%w[SPICE VNC].include?(type.upcase) && html5_console_enabled?
extend ActiveSupport::Concern

included do
supports :native_console
# NOTE: this says that these are supported IF html_console is enabled
supports(:html5_console) { _("Html5 console is disabled by default, check settings to enable it") unless html5_console_enabled? }
supports(:console) { unsupported_reason(:html5_console) }
supports(:spice_console) { unsupported_reason(:html5_console) }
supports(:vnc_console) { unsupported_reason(:html5_console) }
end

def validate_remote_console_acquire_ticket(protocol, options = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,54 @@
expect(queue_messages.first.args).to be_empty
end

context '#console_supported?' do
context '#supports?(:console)' do
it 'html5 disabled in settings' do
::Settings.ems.ems_ovirt.consoles.html5_enabled = false
stub_html5_enable(false)

expect(vm.console_supported?('spice')).to be false
expect(vm.console_supported?('vnc')).to be false
expect(vm.console_supported?('native')).to be true
expect(vm.supports?(:spice_console)).to be false
expect(vm.supports?(:vnc_console)).to be false
expect(vm.supports?(:html5_console)).to be false
expect(vm.supports?(:console)).to be false
expect(vm.supports?(:native_console)).to be true
end

it 'html5 enabled in settings' do
::Settings.ems.ems_ovirt.consoles.html5_enabled = true
stub_html5_enable(true)

expect(vm.console_supported?('spice')).to be true
expect(vm.console_supported?('vnc')).to be true
expect(vm.console_supported?('native')).to be true
expect(vm.supports?(:spice_console)).to be true
expect(vm.supports?(:vnc_console)).to be true
expect(vm.supports?(:native_console)).to be true
expect(vm.supports?(:html5_console)).to be true
expect(vm.supports?(:console)).to be true
end
end

context '#validate_remote_console_acquire_ticket' do
it 'no errors for html5 console enabled' do
::Settings.ems.ems_ovirt.consoles.html5_enabled = true
stub_html5_enable(true)

expect { vm.validate_remote_console_acquire_ticket('html5') }.not_to raise_error
end

context 'errors' do
it 'html5 disabled by default in settings' do
::Settings.ems.ems_ovirt.consoles.html5_enabled = false
stub_html5_enable(false)

expect { vm.validate_remote_console_acquire_ticket('html5') }
.to raise_error(MiqException::RemoteConsoleNotSupportedError,
/Html5 console is disabled by default/)
end

it 'vm with no ems' do
::Settings.ems.ems_ovirt.consoles.html5_enabled = true
stub_html5_enable(true)
vm.update_attribute(:ext_management_system, nil)

expect { vm.validate_remote_console_acquire_ticket('html5') }
.to raise_error(MiqException::RemoteConsoleNotSupportedError, /registered with a management system/)
end

it 'vm not running' do
::Settings.ems.ems_ovirt.consoles.html5_enabled = true
stub_html5_enable(true)
vm.update_attribute(:raw_power_state, 'poweredOff')

expect { vm.validate_remote_console_acquire_ticket('html5') }
Expand Down Expand Up @@ -143,4 +147,11 @@
end
end
end

private

# @param value [Boolean] whether html5 is enabled
def stub_html5_enable(value)
stub_settings_merge(:ems => {:ems_ovirt => {:consoles => {:html5_enabled => value}}})
end
end

0 comments on commit 50aeec2

Please sign in to comment.