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

RHV Native viewer #19675

Merged
merged 1 commit into from
Jan 13, 2020
Merged
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
2 changes: 2 additions & 0 deletions app/models/mixins/supports_feature_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ module SupportsFeatureMixin
:cockpit_console => 'Cockpit Console',
:html5_console => 'HTML5 Console',
:vmrc_console => 'VMRC Console',
:native_console => 'Native Console',
:launch_cockpit => 'Launch Cockpit UI',
:launch_html5_console => 'Launch HTML5 Console',
:launch_vmrc_console => 'Launch VMRC Console',
:launch_native_console => 'Launch Native Console',
:admin_ui => 'Open Admin UI for a Provider',
:live_migrate => 'Live Migration',
:warm_migrate => 'Warm Migration',
Expand Down
16 changes: 15 additions & 1 deletion app/models/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def validate_remote_console_vmrc_support
_("VMRC remote console is not supported on %{vendor}.") % {:vendor => vendor})
end

def validate_native_console_support
raise(MiqException::RemoteConsoleNotSupportedError,
_("NATIVE remote console is not supported on %{vendor}.") % {:vendor => vendor})
end

def add_to_service(service)
service.add_resource!(self)
end
Expand Down Expand Up @@ -115,7 +120,8 @@ def supported_consoles
{
:html5 => html5_support,
:vmrc => vmrc_support,
:cockpit => cockpit_support
:cockpit => cockpit_support,
:native => native_support
}
end

Expand Down Expand Up @@ -148,4 +154,12 @@ def cockpit_support
:message => unsupported_reason(:launch_cockpit)
}
end

def native_support
{
:visible => supports_native_console?,
:enabled => supports_launch_native_console?,
:message => unsupported_reason(:launch_native_console)
}
end
end
10 changes: 10 additions & 0 deletions app/models/vm/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module Vm::Operations
unsupported_reason_add(:vmrc_console, _("VMRC Console not supported")) unless console_supported?('VMRC')
end

supports :native_console do
unsupported_reason_add(:native_console, _("VM NATIVE Console not supported")) unless console_supported?('NATIVE')
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
Expand All @@ -29,6 +33,12 @@ module Vm::Operations
unsupported_reason_add(:launch_vmrc_console, _('VM VMRC Console error: %{error}') % {:error => err})
end
end

supports :launch_native_console do
validate_native_console_support
rescue StandardError => err
unsupported_reason_add(:launch_native_console, _('VM NATIVE Console error: %{error}') % {:error => err})
end
end

def cockpit_url
Expand Down
4 changes: 4 additions & 0 deletions db/fixtures/miq_product_features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5438,6 +5438,10 @@
:description: Open the Cockpit console for VMs
:feature_type: control
:identifier: cockpit_console
- :name: Native Console
:description: Open the Native console for VMs
:feature_type: control
:identifier: vm_native_console
- :name: Edit Tags
:description: Edit VM Tags
:feature_type: control
Expand Down
1 change: 1 addition & 0 deletions db/fixtures/miq_user_roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
- vm_html5_console
- vm_vmrc_console
- cockpit_console
- vm_native_console
- vm_perf
- vm_policy_sim
- vm_show
Expand Down
30 changes: 30 additions & 0 deletions spec/models/vm/operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@
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 Expand Up @@ -117,4 +132,19 @@
expect(@vm.supports_launch_html5_console?).to be_truthy
end
end

describe '#supports_launch_native_console?' do
it 'does not support it if validate_native_console_support raises an error' do
allow(@vm).to receive(:validate_native_console_support).and_raise(StandardError)

expect(@vm.supports_launch_native_console?).to be_falsey
expect(@vm.unsupported_reason(:launch_native_console)).to include('VM NATIVE Console error:')
end

it 'supports it if all conditions are met' do
allow(@vm).to receive(:validate_native_console_support)

expect(@vm.supports_launch_native_console?).to be_truthy
end
end
end
7 changes: 6 additions & 1 deletion spec/models/vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
expect { vm.validate_remote_console_vmrc_support }.to raise_error MiqException::RemoteConsoleNotSupportedError
end

it "#validate_native_console_support must be overridden" do
vm = FactoryBot.create(:vm_vmware, :vendor => 'vmware')
expect { vm.validate_native_console_support }.to raise_error MiqException::RemoteConsoleNotSupportedError
end

context ".find_all_by_mac_address_and_hostname_and_ipaddress" do
before do
@hardware1 = FactoryBot.create(:hardware)
Expand Down Expand Up @@ -309,7 +314,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([:html5, :vmrc, :cockpit])
expect(vm.supported_consoles.keys).to match_array([:html5, :vmrc, :cockpit, :native])
end
end
end