Skip to content

Commit a591ad1

Browse files
H.Eckertsysradium
authored andcommitted
Expose new API actions and update test suite accordingly; bump egg version to '4.15.2'
1 parent da0fe24 commit a591ad1

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

oca/tests/test_virtualmachine.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
from mock import Mock
66
from nose.tools import raises
7+
from parameterized import parameterized_class
78

89
import oca
910
import oca.pool
1011

11-
12+
@parameterized_class([
13+
{'one_version': '4.10.0'},
14+
{'one_version': '5.4.0'},
15+
{'one_version': '6.0.0'},
16+
])
1217
class TestVirtualMachine(unittest.TestCase):
1318
def setUp(self):
1419
self.client = oca.Client('test:test')
20+
self.client.call = Mock(return_value=self.one_version)
21+
self.client.call.reset_mock()
1522
self.xml = open(os.path.join(os.path.dirname(oca.__file__),
1623
'tests/fixtures/vm.xml')).read()
1724

@@ -64,38 +71,43 @@ def test_allocate(self):
6471
assert oca.VirtualMachine.allocate(self.client, '<VM></VM>') == 3
6572

6673
def test_deploy(self):
67-
self.client.call = Mock(return_value='')
6874
vm = oca.VirtualMachine(self.xml, self.client)
75+
self.client.call = Mock(return_value='')
6976
vm.deploy(3)
7077
self.client.call.assert_called_once_with('vm.deploy', '6', 3)
7178

7279
def test_migrate(self):
73-
self.client.call = Mock(return_value='')
7480
vm = oca.VirtualMachine(self.xml, self.client)
81+
self.client.call = Mock(return_value='')
7582
vm.migrate(3)
7683
self.client.call.assert_called_once_with('vm.migrate', '6', 3, False)
7784

7885
def test_live_migrate(self):
79-
self.client.call = Mock(return_value='')
8086
vm = oca.VirtualMachine(self.xml, self.client)
87+
self.client.call = Mock(return_value='')
8188
vm.live_migrate(3)
8289
self.client.call.assert_called_once_with('vm.migrate', '6', 3, True)
8390

8491
def test_save_disk(self):
85-
self.client.call = Mock(return_value='')
8692
vm = oca.VirtualMachine(self.xml, self.client)
93+
self.client.call = Mock(return_value='')
8794
vm.save_disk(1, 2)
8895
self.client.call.assert_called_once_with('vm.savedisk', '6', 1, 2)
8996

9097
def test_actions(self):
91-
oca.client = oca.Client('test:test')
9298
vm = oca.VirtualMachine(self.xml, self.client)
9399
for action in ['shutdown', 'shutdown_hard', 'poweroff', 'poweroff_hard',
94100
'hold', 'release', 'stop', 'cancel', 'suspend', 'resume',
95-
'reboot', 'finalize', 'delete', 'resched', 'unresched']:
101+
'reboot', 'finalize', 'delete', 'resched', 'unresched',
102+
'terminate', 'terminate_hard']:
96103
self.client.call = Mock(return_value='')
97104
getattr(vm, action)()
98-
if action in ('shutdown_hard', 'poweroff_hard', 'undeploy_hard'):
105+
if self.one_version >= '5':
106+
if action in ('shutdown', 'shutdown_hard'):
107+
action = action.replace("shutdown", "terminate")
108+
elif action in ('terminate', 'terminate_hard'):
109+
action = action.replace("terminate", "shutdown")
110+
if action in ('shutdown_hard', 'terminate_hard', 'poweroff_hard', 'undeploy_hard'):
99111
action = action.replace("_", "-")
100112
self.client.call.assert_called_once_with('vm.action', action, '6')
101113

@@ -120,8 +132,8 @@ def test_lcm_states(self):
120132
assert vm.short_lcm_state == lcm
121133

122134
def test_resubmit(self):
123-
self.client.call = Mock(return_value='')
124135
vm = oca.VirtualMachine(self.xml, self.client)
136+
self.client.call = Mock(return_value='')
125137
vm.resubmit()
126138
self.client.call.assert_called_once_with('vm.action', 'resubmit', '6')
127139

oca/vm.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ def allocate(client, template):
175175
return vm_id
176176

177177
def __init__(self, xml, client):
178+
if client.one_version is None:
179+
client.version()
178180
super(VirtualMachine, self).__init__(xml, client)
179181
self.id = self['ID'] if self['ID'] else None
180182

@@ -229,13 +231,31 @@ def shutdown(self):
229231
"""
230232
Shutdowns an already deployed VM
231233
"""
232-
self._action('shutdown')
234+
self.terminate()
233235

234236
def shutdown_hard(self):
235237
"""
236238
Shutdown hard an already deployed VM
237239
"""
238-
self._action('shutdown-hard')
240+
self.terminate_hard()
241+
242+
def terminate(self):
243+
"""
244+
Terminates an already deployed VM
245+
"""
246+
if self.client.one_version >= '5':
247+
self._action('terminate')
248+
else:
249+
self._action('shutdown')
250+
251+
def terminate_hard(self):
252+
"""
253+
Terminates an already deployed VM forcefully
254+
"""
255+
if self.client.one_version >= '5':
256+
self._action('terminate-hard')
257+
else:
258+
self._action('shutdown-hard')
239259

240260
def poweroff(self):
241261
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import sys
66

7-
__version__ = '4.15.1'
7+
__version__ = '4.15.2'
88

99

1010
# borrowed from Pylons project

0 commit comments

Comments
 (0)