Skip to content

Commit

Permalink
convert console_supported? to supports?
Browse files Browse the repository at this point in the history
- moving all supports into provider classes
- moving :console from vm_or_template to vm/operations with the rest of them.
- explicitly stating html5_console and console
- native_console had half in supports and half in console_supported. so less of a change

- dropping console_supported?
  • Loading branch information
kbrock committed Mar 8, 2023
1 parent 0667484 commit 4a4f57d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 61 deletions.
19 changes: 7 additions & 12 deletions app/models/vm/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ module Vm::Operations
include_concern 'Lifecycle'

included do
supports :html5_console do
consup = %w[vnc webmks spice].any? { |type| send(:console_supported?, type) }
_("The web-based HTML5 Console is not supported") unless consup
end

supports :vmrc_console do
_("VMRC Console not supported") unless console_supported?('VMRC')
end

supports :native_console do
_("VM NATIVE Console not supported") unless console_supported?('NATIVE')
end
supports_not :console
supports_not :html5_console
supports_not :native_console
supports_not :spice_console
supports_not :vmrc_console
supports_not :vnc_console
supports_not :webmks_console

supports :launch_html5_console do
_("The web-based HTML5 Console is not available because the VM is not powered on") unless power_state == 'on'
Expand Down
6 changes: 0 additions & 6 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1608,10 +1608,6 @@ def add_ems_event(event_type, event_message, event_timestamp)
EmsEvent.add(ems_id, event)
end

def console_supported?(_type)
false
end

# Stop certain charts from showing unless the subclass allows
def non_generic_charts_available?
false
Expand Down Expand Up @@ -1670,8 +1666,6 @@ def tenant_identity
user
end

supports(:console) { N_("Console not supported") unless console_supported?('spice') || console_supported?('vnc') }

def child_resources
children
end
Expand Down
43 changes: 0 additions & 43 deletions spec/models/vm/operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,6 @@
end
end

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)

expect(@vm.supports?(:vmrc_console)).to be_falsey
expect(@vm.unsupported_reason(:vmrc_console)).to include('VMRC Console not supported')
end

it 'supports it if all conditions are met' do
allow(@vm).to receive(:console_supported?).with('VMRC').and_return(true)

expect(@vm.supports?(:vmrc_console)).to be_truthy
end
end

describe '#supports?(:html5_console)' do
it 'supports it if all conditions are met' do
allow(@vm).to receive(:console_supported?).and_return(true)
expect(@vm.supports?(:html5_console)).to be_truthy
end

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

describe '#supports?(:native_console)' do
it 'returns false if type is not supported' do
allow(@vm).to receive(:console_supported?).with('NATIVE').and_return(false)

expect(@vm.supports?(:native_console)).to be_falsey
expect(@vm.unsupported_reason(:native_console)).to include('NATIVE Console not supported')
end

it 'supports it if all conditions are met' do
allow(@vm).to receive(:console_supported?).with('NATIVE').and_return(true)

expect(@vm.supports?(:native_console)).to be_truthy
end
end

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)
Expand Down

0 comments on commit 4a4f57d

Please sign in to comment.