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

convert console_supported? to supports? #635

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Loading