diff --git a/app/models/vm/operations.rb b/app/models/vm/operations.rb index 6e006e798f9..57e5025b74b 100644 --- a/app/models/vm/operations.rb +++ b/app/models/vm/operations.rb @@ -36,7 +36,7 @@ module Vm::Operations end supports :launch_vnc_console do - if vendor == 'vmware' && ext_management_system.api_version.to_f >= 6.5 + 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')) diff --git a/spec/models/vm/operations_spec.rb b/spec/models/vm/operations_spec.rb index 3d8b45035a2..6bc2526cb8e 100644 --- a/spec/models/vm/operations_spec.rb +++ b/spec/models/vm/operations_spec.rb @@ -108,6 +108,14 @@ 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')