44
55from mock import Mock
66from nose .tools import raises
7+ from parameterized import parameterized_class
78
89import oca
910import 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+ ])
1217class 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
0 commit comments