diff --git a/app/models/mixins/supports_feature_mixin.rb b/app/models/mixins/supports_feature_mixin.rb index 24296514eb55..4fb0f52c2632 100644 --- a/app/models/mixins/supports_feature_mixin.rb +++ b/app/models/mixins/supports_feature_mixin.rb @@ -89,15 +89,11 @@ module SupportsFeatureMixin :discovery => 'Discovery of Managers for a Provider', :evacuate => 'Evacuation', :cockpit_console => 'Cockpit Console', - :vnc_console => 'VNC Console', - :mks_console => 'MKS Console', + :html5_console => 'HTML5 Console', :vmrc_console => 'VMRC Console', - :spice_console => 'Spice Console', :launch_cockpit => 'Launch Cockpit UI', - :launch_vnc_console => 'Launch VNC Console', + :launch_html5_console => 'Launch HTML5 Console', :launch_vmrc_console => 'Launch VMRC Console', - :launch_mks_console => 'Launch WebMKS Console', - :launch_spice_console => 'Launch Spice Console', :admin_ui => 'Open Admin UI for a Provider', :live_migrate => 'Live Migration', :migrate => 'Migration', diff --git a/app/models/vm.rb b/app/models/vm.rb index 58477b5f25b7..0103c18c78c2 100644 --- a/app/models/vm.rb +++ b/app/models/vm.rb @@ -111,10 +111,8 @@ def remote_console_url=(url, user_id) def supported_consoles { - :spice => spice_support, - :vnc => vnc_support, + :html5 => html5_support, :vmrc => vmrc_support, - :webmks => webmks_support, :cockpit => cockpit_support } end @@ -125,38 +123,22 @@ def self.display_name(number = 1) private - def vnc_support + def html5_support { - :visible => supports_vnc_console?, - :enabled => supports_launch_vnc_console?, - :message => unsupported_reason(:launch_vnc_console) - } - end - - def webmks_support - { - :visible => supports_mks_console?, - :enabled => supports_launch_mks_console?, - :message => unsupported_reason(:launch_mks_console) + :visible => supports_html5_console?, + :enabled => supports_launch_html5_console?, + :message => unsupported_reason(:launch_html5_console) } end def vmrc_support { - :visible => supports_vnc_console?, + :visible => supports_vmrc_console?, :enabled => supports_launch_vmrc_console?, :message => unsupported_reason(:launch_vmrc_console) } end - def spice_support - { - :visible => supports_spice_console?, - :enabled => supports_launch_spice_console?, - :message => unsupported_reason(:launch_spice_console) - } - end - def cockpit_support { :visible => supports_cockpit_console?, diff --git a/app/models/vm/operations.rb b/app/models/vm/operations.rb index 286ab675d79f..4350adacdef1 100644 --- a/app/models/vm/operations.rb +++ b/app/models/vm/operations.rb @@ -9,38 +9,17 @@ module Vm::Operations include_concern 'Lifecycle' included do - supports :vnc_console do - message = "VNC Console not supported" - if vendor == 'vmware' - unsupported_reason_add(:vnc_console, message) unless ext_management_system.present? && console_supported?('VNC') - elsif !console_supported?('VNC') - unsupported_reason_add(:vnc_console, message) - end - end - - supports :mks_console do - message = "WebMKS Console not supported" - if vendor != 'vmware' - unsupported_reason_add(:mks_console, message) - elsif console_supported?('WEBMKS') && !console_supported?('WebMKS') - unsupported_reason_add(:mks_console, message) - end + supports :html5_console do + consup = %w[vnc webmks spice].any? { |type| send(:console_supported?, type) } + unsupported_reason_add(:html5_console, (_"The web-based HTML5 Console is not supported")) unless consup end supports :vmrc_console do - unsupported_reason_add(:vmrc_console, "VMRC Console not supported") unless console_supported?('VMRC') + unsupported_reason_add(:vmrc_console, _("VMRC Console not supported")) unless console_supported?('VMRC') end - supports :spice_console do - unsupported_reason_add(:spice_console, "Spice Console not supported") unless console_supports_type?('SPICE') - end - - supports :launch_vnc_console do - if vendor == 'vmware' && ext_management_system.try(:api_version).to_f >= 6.5 - unsupported_reason_add(:launch_vnc_console, _('VNC consoles are unsupported on VMware ESXi 6.5 and later.')) - elsif power_state != 'on' - unsupported_reason_add(:launch_vnc_console, _('The web-based VNC console is not available because the VM is not powered on')) - end + supports :launch_html5_console do + unsupported_reason_add(:launch_html5_console, _("The web-based HTML5 Console is not available because the VM is not powered on")) unless power_state == 'on' end supports :launch_vmrc_console do @@ -50,20 +29,6 @@ module Vm::Operations unsupported_reason_add(:launch_vmrc_console, _('VM VMRC Console error: %{error}') % {:error => err}) end end - - supports :launch_mks_console do - if power_state != 'on' - unsupported_reason_add(:launch_mks_console, _('The web-based WebMKS console is not available because the VM is not powered on')) - elsif !Rails.root.join('public', 'webmks').exist? - unsupported_reason_add(:launch_mks_console, _("The web-based WebMKS console is not available because the required libraries aren't installed")) - end - end - - supports :launch_spice_console do - if power_state != 'on' - unsupported_reason_add(:launch_spice_console, _('The web-based spice console is not available because the VM is not powered on')) - end - end end def cockpit_url diff --git a/spec/models/vm/operations_spec.rb b/spec/models/vm/operations_spec.rb index 41f57d6d95e6..b795fb6d5052 100644 --- a/spec/models/vm/operations_spec.rb +++ b/spec/models/vm/operations_spec.rb @@ -60,117 +60,7 @@ end end - context '#supports_vnc_console?' do - it 'does not support it for vmware vms if it is not the specified console type in settings' do - allow(@vm).to receive(:vendor).and_return('vmware') - allow(@vm).to receive(:console_supported?).with('VNC').and_return(false) - - expect(@vm.supports_vnc_console?).to be_falsey - expect(@vm.unsupported_reason(:vnc_console)).to include('VNC Console not supported') - end - - it 'adds unsupported reason for non-vmware vms and unsupported types' do - allow(@vm).to receive(:vendor).and_return('amazon') - allow(@vm).to receive(:console_supported?).with('VNC').and_return(false) - - expect(@vm.supports_vnc_console?).to be_falsey - expect(@vm.unsupported_reason(:vnc_console)).to include('VNC Console not supported') - end - - it 'supports it if all conditions are met' do - server = double - allow(Settings).to receive(:server).and_return(server) - - expect(@vm.supports_vnc_console?).to be_truthy - end - end - - context '#supports_mks_console?' do - it 'is not supported if the console type is not supported' do - allow(@vm).to receive(:power_state).and_return('on') - - expect(@vm.supports_mks_console?).to be_falsey - expect(@vm.unsupported_reason(:mks_console)).to include('WebMKS Console not supported') - end - - it 'supports it if all conditions are met' do - allow(@vm).to receive(:console_supported?).with('WEBMKS').and_return(true) - allow(@vm).to receive(:console_supported?).with('WebMKS').and_return(true) - - expect(@vm.supports_mks_console?).to be_truthy - end - end - - context '#supports_launch_vnc_console?' do - before do - @ems_double = double - allow(@vm).to receive(:ext_management_system).and_return(@ems_double) - end - - it 'returns the correct error message if the vm vendor is vmware and it does not have an ext_management_system' do - allow(@vm).to receive(:ext_management_system).and_return(nil) - allow(@vm).to receive(:power_state).and_return('off') - - expect(@vm.supports_launch_vnc_console?).to be_falsey - expect(@vm.unsupported_reason(:launch_vnc_console)).to include('the VM is not powered on') - end - - it 'does not support if vendor is vmware and api version is >= 6.5' do - allow(@ems_double).to receive(:api_version).and_return('6.5') - allow(@vm).to receive(:vendor).and_return('vmware') - - expect(@vm.supports_launch_vnc_console?).to be_falsey - expect(@vm.unsupported_reason(:launch_vnc_console)).to include('unsupported on VMware ESXi 6.5 and later') - end - - it 'does not support if vm is not powered on' do - allow(@ems_double).to receive(:api_version).and_return('6.4') - allow(@vm).to receive(:power_state).and_return('off') - - expect(@vm.supports_launch_vnc_console?).to be_falsey - expect(@vm.unsupported_reason(:launch_vnc_console)).to include('the VM is not powered on') - end - - it 'supports it if all conditions are met' do - allow(@vm).to receive(:power_state).and_return('on') - allow(@vm).to receive(:vendor).and_return('vmware') - allow(@ems_double).to receive(:api_version).and_return('6.4') - - expect(@vm.supports_launch_vnc_console?).to be_truthy - end - end - - context '#supports_launch_mks_console?' do - before do - root, @join = double, double - allow(Rails).to receive(:root).and_return(root) - allow(root).to receive(:join).with('public', 'webmks').and_return(@join) - end - - it 'is not supported if the vm is not powered on' do - allow(@vm).to receive(:power_state).and_return('off') - - expect(@vm.supports_launch_mks_console?).to be_falsey - expect(@vm.unsupported_reason(:launch_mks_console)).to include('the VM is not powered on') - end - - it 'is not supported if the required libraries are not installed' do - allow(@join).to receive(:exist?).and_return(false) - allow(@vm).to receive(:power_state).and_return('on') - - expect(@vm.supports_launch_mks_console?).to be_falsey - expect(@vm.unsupported_reason(:launch_mks_console)).to include("the required libraries aren't installed") - end - - it 'supports it if all conditions are met' do - allow(@join).to receive(:exist?).and_return(true) - allow(@vm).to receive(:power_state).and_return('on') - - expect(@vm.supports_launch_mks_console?).to be_truthy - end - end - - context '#supports_vmrc_console?' do + describe '#supports_vmrc_console?' do it 'returns false if type is not supported' do allow(@vm).to receive(:console_supported?).with('VMRC').and_return(false) @@ -185,22 +75,20 @@ end end - context '#supports_spice_console?' do - it 'returns false if type is not supported' do - allow(@vm).to receive(:console_supported?).with('SPICE').and_return(false) - - expect(@vm.supports_spice_console?).to be_falsey - expect(@vm.unsupported_reason(:spice_console)).to include('Spice Console not supported') - end - + describe '#supports_html5_console?' do it 'supports it if all conditions are met' do - allow(@vm).to receive(:console_supported?).with('SPICE').and_return(true) + allow(@vm).to receive(:console_supported?).and_return(true) + expect(@vm.supports_html5_console?).to be_truthy + end - expect(@vm.supports_spice_console?).to be_truthy + it 'returns false if type is not supported' do + allow(@vm).to receive(:console_supported?).and_return(false) + expect(@vm.supports_html5_console?).to be_falsey + expect(@vm.unsupported_reason(:html5_console)).to include('HTML5 Console is not supported') end end - context '#supports_launch_vmrc_console?' do + describe '#supports_launch_vmrc_console?' do it 'does not support it if validate_remote_console_vmrc_support raises an error' do allow(@vm).to receive(:validate_remote_console_vmrc_support).and_raise(StandardError) @@ -215,18 +103,18 @@ end end - context '#supports_launch_spice_console?' do + describe '#supports_launch_html5_console?' do it 'does not support it if vm is not powered on' do allow(@vm).to receive(:power_state).and_return('off') - expect(@vm.supports_launch_spice_console?).to be_falsey - expect(@vm.unsupported_reason(:launch_spice_console)).to include('the VM is not powered on') + expect(@vm.supports_launch_html5_console?).to be_falsey + expect(@vm.unsupported_reason(:launch_html5_console)).to include('the VM is not powered on') end it 'supports it if all conditions are met' do allow(@vm).to receive(:power_state).and_return('on') - expect(@vm.supports_launch_spice_console?).to be_truthy + expect(@vm.supports_launch_html5_console?).to be_truthy end end end diff --git a/spec/models/vm_spec.rb b/spec/models/vm_spec.rb index d90ebdb595a5..081b1a66591b 100644 --- a/spec/models/vm_spec.rb +++ b/spec/models/vm_spec.rb @@ -307,7 +307,7 @@ context "#supported_consoles" do it 'returns all of the console types' do vm = FactoryBot.create(:vm) - expect(vm.supported_consoles.keys).to match_array([:spice, :vnc, :vmrc, :webmks, :cockpit]) + expect(vm.supported_consoles.keys).to match_array([:html5, :vmrc, :cockpit]) end end end