1919
2020from openstackclient .compute .v2 import server_volume
2121from openstackclient .tests .unit .compute .v2 import fakes as compute_fakes
22+ from openstackclient .tests .unit .volume .v2 import fakes as volume_fakes
2223
2324
2425class TestServerVolume (compute_fakes .TestComputev2 ):
2526
2627 def setUp (self ):
2728 super ().setUp ()
2829
29- # Get a shortcut to the compute client ServerManager Mock
30- self .servers_mock = self .app .client_manager .compute .servers
31- self .servers_mock .reset_mock ()
32-
33- # Get a shortcut to the compute client VolumeManager mock
34- self .servers_volumes_mock = self .app .client_manager .compute .volumes
35- self .servers_volumes_mock .reset_mock ()
36-
3730 self .app .client_manager .sdk_connection = mock .Mock ()
3831 self .app .client_manager .sdk_connection .compute = mock .Mock ()
39- self .sdk_client = self .app .client_manager .sdk_connection .compute
32+ self .app .client_manager .sdk_connection .volume = mock .Mock ()
33+ self .compute_client = self .app .client_manager .sdk_connection .compute
34+ self .volume_client = self .app .client_manager .sdk_connection .volume
4035
4136
4237class TestServerVolumeList (TestServerVolume ):
@@ -47,8 +42,8 @@ def setUp(self):
4742 self .server = compute_fakes .FakeServer .create_one_sdk_server ()
4843 self .volume_attachments = compute_fakes .create_volume_attachments ()
4944
50- self .sdk_client .find_server .return_value = self .server
51- self .sdk_client .volume_attachments .return_value = (
45+ self .compute_client .find_server .return_value = self .server
46+ self .compute_client .volume_attachments .return_value = (
5247 self .volume_attachments )
5348
5449 # Get the command object to test
@@ -88,7 +83,9 @@ def test_server_volume_list(self, sm_mock):
8883 ),
8984 tuple (data ),
9085 )
91- self .sdk_client .volume_attachments .assert_called_once_with (self .server )
86+ self .compute_client .volume_attachments .assert_called_once_with (
87+ self .server ,
88+ )
9289
9390 @mock .patch .object (sdk_utils , 'supports_microversion' )
9491 def test_server_volume_list_with_tags (self , sm_mock ):
@@ -126,7 +123,9 @@ def test_server_volume_list_with_tags(self, sm_mock):
126123 ),
127124 tuple (data ),
128125 )
129- self .sdk_client .volume_attachments .assert_called_once_with (self .server )
126+ self .compute_client .volume_attachments .assert_called_once_with (
127+ self .server ,
128+ )
130129
131130 @mock .patch .object (sdk_utils , 'supports_microversion' )
132131 def test_server_volume_list_with_delete_on_attachment (self , sm_mock ):
@@ -169,7 +168,9 @@ def test_server_volume_list_with_delete_on_attachment(self, sm_mock):
169168 ),
170169 tuple (data ),
171170 )
172- self .sdk_client .volume_attachments .assert_called_once_with (self .server )
171+ self .compute_client .volume_attachments .assert_called_once_with (
172+ self .server ,
173+ )
173174
174175 @mock .patch .object (sdk_utils , 'supports_microversion' )
175176 def test_server_volume_list_with_attachment_ids (self , sm_mock ):
@@ -217,123 +218,139 @@ def test_server_volume_list_with_attachment_ids(self, sm_mock):
217218 ),
218219 tuple (data ),
219220 )
220- self .sdk_client .volume_attachments .assert_called_once_with (self .server )
221+ self .compute_client .volume_attachments .assert_called_once_with (
222+ self .server ,
223+ )
221224
222225
223226class TestServerVolumeUpdate (TestServerVolume ):
224227
225228 def setUp (self ):
226229 super ().setUp ()
227230
228- self .server = compute_fakes .FakeServer .create_one_server ()
229- self .servers_mock .get .return_value = self .server
231+ self .server = compute_fakes .FakeServer .create_one_sdk_server ()
232+ self .compute_client .find_server .return_value = self .server
233+
234+ self .volume = volume_fakes .create_one_sdk_volume ()
235+ self .volume_client .find_volume .return_value = self .volume
230236
231237 # Get the command object to test
232238 self .cmd = server_volume .UpdateServerVolume (self .app , None )
233239
234240 def test_server_volume_update (self ):
235-
236241 arglist = [
237242 self .server .id ,
238- 'foo' ,
243+ self . volume . id ,
239244 ]
240245 verifylist = [
241246 ('server' , self .server .id ),
242- ('volume' , 'foo' ),
247+ ('volume' , self . volume . id ),
243248 ('delete_on_termination' , None ),
244249 ]
245250 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
246251
247252 result = self .cmd .take_action (parsed_args )
248253
249254 # This is a no-op
250- self .servers_volumes_mock . update_server_volume .assert_not_called ()
255+ self .compute_client . update_volume_attachment .assert_not_called ()
251256 self .assertIsNone (result )
252257
253- def test_server_volume_update_with_delete_on_termination ( self ):
254- self . app . client_manager . compute . api_version = \
255- api_versions . APIVersion ( '2.85' )
258+ @ mock . patch . object ( sdk_utils , 'supports_microversion' )
259+ def test_server_volume_update_with_delete_on_termination ( self , sm_mock ):
260+ sm_mock . return_value = True
256261
257262 arglist = [
258263 self .server .id ,
259- 'foo' ,
264+ self . volume . id ,
260265 '--delete-on-termination' ,
261266 ]
262267 verifylist = [
263268 ('server' , self .server .id ),
264- ('volume' , 'foo' ),
269+ ('volume' , self . volume . id ),
265270 ('delete_on_termination' , True ),
266271 ]
267272 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
268273
269274 result = self .cmd .take_action (parsed_args )
270275
271- self .servers_volumes_mock .update_server_volume .assert_called_once_with (
272- self .server .id , 'foo' , 'foo' ,
273- delete_on_termination = True )
276+ self .compute_client .update_volume_attachment .assert_called_once_with (
277+ self .server ,
278+ self .volume ,
279+ delete_on_termination = True ,
280+ )
274281 self .assertIsNone (result )
275282
276- def test_server_volume_update_with_preserve_on_termination ( self ):
277- self . app . client_manager . compute . api_version = \
278- api_versions . APIVersion ( '2.85' )
283+ @ mock . patch . object ( sdk_utils , 'supports_microversion' )
284+ def test_server_volume_update_with_preserve_on_termination ( self , sm_mock ):
285+ sm_mock . return_value = True
279286
280287 arglist = [
281288 self .server .id ,
282- 'foo' ,
289+ self . volume . id ,
283290 '--preserve-on-termination' ,
284291 ]
285292 verifylist = [
286293 ('server' , self .server .id ),
287- ('volume' , 'foo' ),
294+ ('volume' , self . volume . id ),
288295 ('delete_on_termination' , False ),
289296 ]
290297 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
291298
292299 result = self .cmd .take_action (parsed_args )
293300
294- self .servers_volumes_mock .update_server_volume .assert_called_once_with (
295- self .server .id , 'foo' , 'foo' ,
296- delete_on_termination = False )
301+ self .compute_client .update_volume_attachment .assert_called_once_with (
302+ self .server ,
303+ self .volume ,
304+ delete_on_termination = False
305+ )
297306 self .assertIsNone (result )
298307
299- def test_server_volume_update_with_delete_on_termination_pre_v285 (self ):
300- self .app .client_manager .compute .api_version = \
301- api_versions .APIVersion ('2.84' )
308+ @mock .patch .object (sdk_utils , 'supports_microversion' )
309+ def test_server_volume_update_with_delete_on_termination_pre_v285 (
310+ self , sm_mock ,
311+ ):
312+ sm_mock .return_value = False
302313
303314 arglist = [
304315 self .server .id ,
305- 'foo' ,
316+ self . volume . id ,
306317 '--delete-on-termination' ,
307318 ]
308319 verifylist = [
309320 ('server' , self .server .id ),
310- ('volume' , 'foo' ),
321+ ('volume' , self . volume . id ),
311322 ('delete_on_termination' , True ),
312323 ]
313324 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
314325
315326 self .assertRaises (
316327 exceptions .CommandError ,
317328 self .cmd .take_action ,
318- parsed_args )
329+ parsed_args ,
330+ )
331+ self .compute_client .update_volume_attachment .assert_not_called ()
319332
320- def test_server_volume_update_with_preserve_on_termination_pre_v285 (self ):
321- self .app .client_manager .compute .api_version = \
322- api_versions .APIVersion ('2.84' )
333+ @mock .patch .object (sdk_utils , 'supports_microversion' )
334+ def test_server_volume_update_with_preserve_on_termination_pre_v285 (
335+ self , sm_mock ,
336+ ):
337+ sm_mock .return_value = False
323338
324339 arglist = [
325340 self .server .id ,
326- 'foo' ,
341+ self . volume . id ,
327342 '--preserve-on-termination' ,
328343 ]
329344 verifylist = [
330345 ('server' , self .server .id ),
331- ('volume' , 'foo' ),
346+ ('volume' , self . volume . id ),
332347 ('delete_on_termination' , False ),
333348 ]
334349 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
335350
336351 self .assertRaises (
337352 exceptions .CommandError ,
338353 self .cmd .take_action ,
339- parsed_args )
354+ parsed_args ,
355+ )
356+ self .compute_client .update_volume_attachment .assert_not_called ()
0 commit comments