Skip to content

Commit

Permalink
Fixes #7884 - Display Fog errors on vm operation
Browse files Browse the repository at this point in the history
  • Loading branch information
dLobatog committed Oct 9, 2014
1 parent fb4e6a3 commit b04c9fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/controllers/compute_resources_vms_controller.rb
Expand Up @@ -109,14 +109,18 @@ def find_vm
end

def run_vm_action(action)
if (@vm.send(action) rescue false)
if @vm.send(action)
@vm.reload
notice _("%{vm} is now %{vm_state}") % {:vm => @vm, :vm_state => @vm.state.capitalize}
redirect_to compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => @vm.identity)
else
error _("failed to %{action} %{vm}") % {:action => _(action), :vm => @vm}
redirect_to :back
end
# This should only rescue Fog::Errors, but Fog returns all kinds of errors...
rescue => e
error _("Error - %{message}") % { :message => _(e.message) }
redirect_to :back
end

end
13 changes: 12 additions & 1 deletion test/functional/compute_resources_vms_controller_test.rb
Expand Up @@ -160,7 +160,7 @@ def test_should_create_vm(name = "new_test")
get :power, {:format => "json", :id => @test_vm.uuid, :compute_resource_id => @compute_resource.to_param}, set_session_user
assert_redirected_to compute_resource_vm_path(:compute_resource_id => @compute_resource.to_param, :id => @test_vm.identity)
get_test_vm
assert !@test_vm.ready?
refute @test_vm.ready?

# Swith it back on for next tests
get :power, {:format => "json", :id => @test_vm.uuid, :compute_resource_id => @compute_resource.to_param}, set_session_user
Expand All @@ -169,6 +169,17 @@ def test_should_create_vm(name = "new_test")
assert @test_vm.ready?
end

test 'errors coming from the vm should be displayed' do
setup_user 'power'

get_test_vm
@test_vm.class.any_instance.expects(:stop).raises(Fog::Errors::Error.new('Power error'))
@request.env['HTTP_REFERER'] = compute_resource_vm_path(:compute_resource_id => @compute_resource.to_param,
:id => @test_vm.identity)
get :power, {:format => 'json', :id => @test_vm.uuid, :compute_resource_id => @compute_resource.to_param}, set_session_user
assert_match /Power error/, flash[:error]
assert_redirected_to @request.env['HTTP_REFERER']
end

def get_test_vm
@compute_resource.vms.index {|vm| vm.name == "test" and @test_vm = vm}
Expand Down

0 comments on commit b04c9fb

Please sign in to comment.