Skip to content

Commit

Permalink
Fix instance reconfigure button visibility
Browse files Browse the repository at this point in the history
The 'Reconfigure this Instance' toolbar button should only be visible
if the model supports the operation.

https://bugzilla.redhat.com/show_bug.cgi?id=1331052
  • Loading branch information
mzazrivec committed May 4, 2016
1 parent 78dc56c commit 1c6c0cd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/controllers/vm_cloud_controller.rb
Expand Up @@ -50,8 +50,8 @@ def resize_vm
@record = @sb[:action] = nil
replace_right_cell
when "submit"
valid, details = @record.validate_resize
if valid
validation = @record.validate_resize
if validation[:available]
begin
old_flavor = @record.flavor
@record.resize(flavor)
Expand All @@ -70,7 +70,7 @@ def resize_vm
add_flash(_("Unable to reconfigure %{instance} \"%{name}\": %{details}") % {
:instance => ui_lookup(:table => 'vm_cloud'),
:name => @record.name,
:details => details}, :error)
:details => validation[:message]}, :error)
end
params[:id] = @record.id.to_s # reset id in params for show
@record = nil
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/application_helper/button/instance_reconfigure.rb
@@ -0,0 +1,10 @@
class ApplicationHelper::Button::InstanceReconfigure < ApplicationHelper::Button::Basic
def calculate_properties
super
self[:title] = @record.is_available_now_error_message(:resize) if disabled?
end

def disabled?
!@record.is_available?(:resize)
end
end
Expand Up @@ -46,7 +46,8 @@ class ApplicationHelper::Toolbar::OpenstackVmCloudCenter < ApplicationHelper::To
:instance_resize,
'pficon pficon-edit fa-lg',
t = N_('Reconfigure this Instance'),
t),
t,
:klass => ApplicationHelper::Button::InstanceReconfigure),
button(
:vm_right_size,
'product product-custom-6 fa-lg',
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/application_helper/toolbar/x_vm_cloud_center.rb
Expand Up @@ -58,7 +58,8 @@ class ApplicationHelper::Toolbar::XVmCloudCenter < ApplicationHelper::Toolbar::B
:instance_resize,
'pficon pficon-edit fa-lg',
t = N_('Reconfigure this Instance'),
t)
t,
:klass => ApplicationHelper::Button::InstanceReconfigure)
]
),
])
Expand Down
4 changes: 4 additions & 0 deletions app/models/manageiq/providers/cloud_manager/vm.rb
Expand Up @@ -59,6 +59,10 @@ def validate_timeline
{:available => true, :message => nil}
end

def validate_resize
validate_unsupported(_("Resize"))
end

private

def raise_created_event
Expand Down
@@ -1,6 +1,9 @@
module ManageIQ::Providers::Openstack::CloudManager::Vm::Resize
def validate_resize
%w(ACTIVE SHUTOFF).include? raw_power_state
msg = validate_vm_control
return {:available => msg[0], :message => msg[1]} unless msg.nil?
return {:available => true, :message => nil} if %w(ACTIVE SHUTOFF).include?(raw_power_state)
{:available => false, :message => _("The Instance cannot be resized, current state has to be active or shutoff.")}
end

def raw_resize(new_flavor)
Expand Down
Expand Up @@ -134,7 +134,7 @@
it "initiate resize process" do
service = double
allow(ems).to receive(:connect).and_return(service)
expect(vm.validate_resize).to be true
expect(vm.validate_resize[:available]).to be_truthy
expect(vm.validate_resize_confirm).to be false
expect(service).to receive(:resize_server).with(vm.ems_ref, flavor.ems_ref)
vm.resize(flavor)
Expand All @@ -144,7 +144,7 @@
vm.raw_power_state = 'VERIFY_RESIZE'
service = double
allow(ems).to receive(:connect).and_return(service)
expect(vm.validate_resize).to be false
expect(vm.validate_resize[:available]).to be_falsey
expect(vm.validate_resize_confirm).to be true
expect(service).to receive(:confirm_resize_server).with(vm.ems_ref)
vm.resize_confirm
Expand All @@ -154,7 +154,7 @@
vm.raw_power_state = 'VERIFY_RESIZE'
service = double
allow(ems).to receive(:connect).and_return(service)
expect(vm.validate_resize).to be false
expect(vm.validate_resize[:available]).to be_falsey
expect(vm.validate_resize_revert).to be true
expect(service).to receive(:revert_resize_server).with(vm.ems_ref)
vm.resize_revert
Expand Down

0 comments on commit 1c6c0cd

Please sign in to comment.