Skip to content

Commit

Permalink
Get rid of power methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Lantero committed Feb 10, 2017
1 parent c4d19f1 commit 8925082
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 46 deletions.
11 changes: 0 additions & 11 deletions test/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import socket
import unittest

from pyVmomi import vim

from vcdriver.exceptions import (
NoObjectFound,
DownloadError,
Expand Down Expand Up @@ -87,15 +85,6 @@ def test_idempotent_methods(self):
vm.destroy()
self.assertIsNone(vm.__getattribute__('_vm_object'))

def test_power_methods(self):
for vm in self.all_vms:
vm.create()
vm.power_off()
with self.assertRaises(vim.fault.InvalidPowerState):
vm.power_off()
vm.power_on()
vm.power_on()

def test_context_manager(self):
for vm in self.all_vms:
with self.assertRaises(NoObjectFound):
Expand Down
16 changes: 0 additions & 16 deletions test/unit/test_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,6 @@ def test_virtual_machine_find(
self.assertIsNotNone(vm.__getattribute__('_vm_object'))
self.assertEqual(get_vcenter_object_by_name.call_count, 1)

@mock.patch('vcdriver.vm.connection')
@mock.patch('vcdriver.vm.wait_for_vcenter_task')
def test_virtual_machine_single_vcenter_task_methods(
self, wait_for_vcenter_task, connection
):
vm = VirtualMachine()
vm_object_mock = mock.MagicMock()
methods = [vm.power_on, vm.power_off]
for method in methods:
method()
method()
vm.__setattr__('_vm_object', vm_object_mock)
method()
vm.__setattr__('_vm_object', None)
self.assertEqual(wait_for_vcenter_task.call_count, len(methods))

@mock.patch('vcdriver.vm.connection')
def test_virtual_machine_ip(self, connection):
vm = VirtualMachine()
Expand Down
24 changes: 5 additions & 19 deletions vcdriver/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ def destroy(self):
""" Destroy the virtual machine and set the vm object to None """
if self._vm_object:
try:
self.power_off()
wait_for_vcenter_task(
self._vm_object.PowerOffVM_Task(),
'Power off virtual machine "{}"'.format(self.name),
self.timeout
)
except vim.fault.InvalidPowerState:
pass
wait_for_vcenter_task(
Expand All @@ -145,24 +149,6 @@ def ip(self):
validate_ip(ip)
return ip

def power_on(self):
""" Power on machine """
if self._vm_object:
wait_for_vcenter_task(
self._vm_object.PowerOnVM_Task(),
'Power on virtual machine "{}"'.format(self.name),
self.timeout
)

def power_off(self):
""" Power off machine (Machine must be on) """
if self._vm_object:
wait_for_vcenter_task(
self._vm_object.PowerOffVM_Task(),
'Power off virtual machine "{}"'.format(self.name),
self.timeout
)

def ssh(self, command, use_sudo=False):
"""
Executes a shell command through ssh
Expand Down

0 comments on commit 8925082

Please sign in to comment.