Skip to content

Commit

Permalink
Merge pull request #206 from sasoc/completely-stop-or-suspend-vm
Browse files Browse the repository at this point in the history
Completely stop/suspend VM, not just partially
(cherry picked from commit 30e5ad2)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1553389
  • Loading branch information
agrare authored and simaishi committed Mar 8, 2018
1 parent 1a31805 commit 47d3dc1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Expand Up @@ -9,12 +9,18 @@ def raw_start
end

def raw_stop
with_provider_object(&:power_off)
with_provider_connection do |service|
response = service.post_undeploy_vapp(ems_ref, :UndeployPowerAction => 'powerOff')
service.process_task(response.body)
end
update_attributes!(:raw_power_state => "off")
end

def raw_suspend
with_provider_object(&:suspend)
with_provider_connection do |service|
response = service.post_undeploy_vapp(ems_ref, :UndeployPowerAction => 'suspend')
service.process_task(response.body)
end
update_attributes!(:raw_power_state => "suspended")
end

Expand Down
29 changes: 29 additions & 0 deletions spec/models/manageiq/providers/vmware/cloud_manager/vm_spec.rb
Expand Up @@ -55,4 +55,33 @@
vm.raw_destroy
end
end

describe 'power operations' do
before(:each) do
allow(ems).to receive(:with_provider_connection).and_yield(connection)
end

let(:ems) { FactoryGirl.create(:ems_vmware_cloud) }
let(:vm) { FactoryGirl.create(:vm_vcloud, :ext_management_system => ems, :ems_ref => 'id') }
let(:connection) { double('connection') }
let(:response) { double('response', :body => nil) }

context '.raw_stop' do
it 'stops the virtual machine' do
expect(connection).to receive(:post_undeploy_vapp).with('id', :UndeployPowerAction => 'powerOff').and_return(response)
expect(connection).to receive(:process_task)

vm.raw_stop
end
end

context '.raw_suspend' do
it 'suspends the virtual machine' do
expect(connection).to receive(:post_undeploy_vapp).with('id', :UndeployPowerAction => 'suspend').and_return(response)
expect(connection).to receive(:process_task)

vm.raw_suspend
end
end
end
end

0 comments on commit 47d3dc1

Please sign in to comment.