From 50aeec207feacecfb8580a0975b60b7724f5916f Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Tue, 7 Mar 2023 18:10:25 -0500 Subject: [PATCH] convert console_supported? to supports? --- .../ovirt/infra_manager/vm/remote_console.rb | 13 +++++-- .../infra_manager/vm/remote_console_spec.rb | 37 ++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/app/models/manageiq/providers/ovirt/infra_manager/vm/remote_console.rb b/app/models/manageiq/providers/ovirt/infra_manager/vm/remote_console.rb index 6180bbb4..8a09fd15 100644 --- a/app/models/manageiq/providers/ovirt/infra_manager/vm/remote_console.rb +++ b/app/models/manageiq/providers/ovirt/infra_manager/vm/remote_console.rb @@ -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 = {}) diff --git a/spec/models/manageiq/providers/ovirt/infra_manager/vm/remote_console_spec.rb b/spec/models/manageiq/providers/ovirt/infra_manager/vm/remote_console_spec.rb index 84adea99..7066768a 100644 --- a/spec/models/manageiq/providers/ovirt/infra_manager/vm/remote_console_spec.rb +++ b/spec/models/manageiq/providers/ovirt/infra_manager/vm/remote_console_spec.rb @@ -13,34 +13,38 @@ 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, @@ -48,7 +52,7 @@ 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') } @@ -56,7 +60,7 @@ 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') } @@ -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