|
16 | 16 | from unittest import mock |
17 | 17 | from unittest.mock import call |
18 | 18 |
|
| 19 | +from cinderclient import api_versions |
19 | 20 | from osc_lib.cli import format_columns |
20 | 21 | from osc_lib import exceptions |
21 | 22 | from osc_lib import utils |
@@ -47,6 +48,9 @@ def setUp(self): |
47 | 48 | self.snapshots_mock = self.app.client_manager.volume.volume_snapshots |
48 | 49 | self.snapshots_mock.reset_mock() |
49 | 50 |
|
| 51 | + self.backups_mock = self.app.client_manager.volume.backups |
| 52 | + self.backups_mock.reset_mock() |
| 53 | + |
50 | 54 | self.types_mock = self.app.client_manager.volume.volume_types |
51 | 55 | self.types_mock.reset_mock() |
52 | 56 |
|
@@ -129,6 +133,7 @@ def test_volume_create_min_options(self): |
129 | 133 | source_volid=None, |
130 | 134 | consistencygroup_id=None, |
131 | 135 | scheduler_hints=None, |
| 136 | + backup_id=None, |
132 | 137 | ) |
133 | 138 |
|
134 | 139 | self.assertEqual(self.columns, columns) |
@@ -174,6 +179,7 @@ def test_volume_create_options(self): |
174 | 179 | source_volid=None, |
175 | 180 | consistencygroup_id=consistency_group.id, |
176 | 181 | scheduler_hints={'k': 'v'}, |
| 182 | + backup_id=None, |
177 | 183 | ) |
178 | 184 |
|
179 | 185 | self.assertEqual(self.columns, columns) |
@@ -210,6 +216,7 @@ def test_volume_create_properties(self): |
210 | 216 | source_volid=None, |
211 | 217 | consistencygroup_id=None, |
212 | 218 | scheduler_hints=None, |
| 219 | + backup_id=None, |
213 | 220 | ) |
214 | 221 |
|
215 | 222 | self.assertEqual(self.columns, columns) |
@@ -248,6 +255,7 @@ def test_volume_create_image_id(self): |
248 | 255 | source_volid=None, |
249 | 256 | consistencygroup_id=None, |
250 | 257 | scheduler_hints=None, |
| 258 | + backup_id=None, |
251 | 259 | ) |
252 | 260 |
|
253 | 261 | self.assertEqual(self.columns, columns) |
@@ -286,6 +294,7 @@ def test_volume_create_image_name(self): |
286 | 294 | source_volid=None, |
287 | 295 | consistencygroup_id=None, |
288 | 296 | scheduler_hints=None, |
| 297 | + backup_id=None, |
289 | 298 | ) |
290 | 299 |
|
291 | 300 | self.assertEqual(self.columns, columns) |
@@ -323,11 +332,72 @@ def test_volume_create_with_snapshot(self): |
323 | 332 | source_volid=None, |
324 | 333 | consistencygroup_id=None, |
325 | 334 | scheduler_hints=None, |
| 335 | + backup_id=None, |
| 336 | + ) |
| 337 | + |
| 338 | + self.assertEqual(self.columns, columns) |
| 339 | + self.assertCountEqual(self.datalist, data) |
| 340 | + |
| 341 | + def test_volume_create_with_backup(self): |
| 342 | + backup = volume_fakes.create_one_backup() |
| 343 | + self.new_volume.backup_id = backup.id |
| 344 | + arglist = [ |
| 345 | + '--backup', self.new_volume.backup_id, |
| 346 | + self.new_volume.name, |
| 347 | + ] |
| 348 | + verifylist = [ |
| 349 | + ('backup', self.new_volume.backup_id), |
| 350 | + ('name', self.new_volume.name), |
| 351 | + ] |
| 352 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 353 | + |
| 354 | + self.backups_mock.get.return_value = backup |
| 355 | + |
| 356 | + self.app.client_manager.volume.api_version = \ |
| 357 | + api_versions.APIVersion('3.47') |
| 358 | + |
| 359 | + # In base command class ShowOne in cliff, abstract method take_action() |
| 360 | + # returns a two-part tuple with a tuple of column names and a tuple of |
| 361 | + # data to be shown. |
| 362 | + columns, data = self.cmd.take_action(parsed_args) |
| 363 | + |
| 364 | + self.volumes_mock.create.assert_called_once_with( |
| 365 | + size=backup.size, |
| 366 | + snapshot_id=None, |
| 367 | + name=self.new_volume.name, |
| 368 | + description=None, |
| 369 | + volume_type=None, |
| 370 | + availability_zone=None, |
| 371 | + metadata=None, |
| 372 | + imageRef=None, |
| 373 | + source_volid=None, |
| 374 | + consistencygroup_id=None, |
| 375 | + scheduler_hints=None, |
| 376 | + backup_id=backup.id, |
326 | 377 | ) |
327 | 378 |
|
328 | 379 | self.assertEqual(self.columns, columns) |
329 | 380 | self.assertCountEqual(self.datalist, data) |
330 | 381 |
|
| 382 | + def test_volume_create_with_backup_pre_347(self): |
| 383 | + backup = volume_fakes.create_one_backup() |
| 384 | + self.new_volume.backup_id = backup.id |
| 385 | + arglist = [ |
| 386 | + '--backup', self.new_volume.backup_id, |
| 387 | + self.new_volume.name, |
| 388 | + ] |
| 389 | + verifylist = [ |
| 390 | + ('backup', self.new_volume.backup_id), |
| 391 | + ('name', self.new_volume.name), |
| 392 | + ] |
| 393 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 394 | + |
| 395 | + self.backups_mock.get.return_value = backup |
| 396 | + |
| 397 | + exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, |
| 398 | + parsed_args) |
| 399 | + self.assertIn("--os-volume-api-version 3.47 or greater", str(exc)) |
| 400 | + |
331 | 401 | def test_volume_create_with_bootable_and_readonly(self): |
332 | 402 | arglist = [ |
333 | 403 | '--bootable', |
@@ -361,6 +431,7 @@ def test_volume_create_with_bootable_and_readonly(self): |
361 | 431 | source_volid=None, |
362 | 432 | consistencygroup_id=None, |
363 | 433 | scheduler_hints=None, |
| 434 | + backup_id=None, |
364 | 435 | ) |
365 | 436 |
|
366 | 437 | self.assertEqual(self.columns, columns) |
@@ -403,6 +474,7 @@ def test_volume_create_with_nonbootable_and_readwrite(self): |
403 | 474 | source_volid=None, |
404 | 475 | consistencygroup_id=None, |
405 | 476 | scheduler_hints=None, |
| 477 | + backup_id=None, |
406 | 478 | ) |
407 | 479 |
|
408 | 480 | self.assertEqual(self.columns, columns) |
@@ -454,6 +526,7 @@ def test_volume_create_with_bootable_and_readonly_fail( |
454 | 526 | source_volid=None, |
455 | 527 | consistencygroup_id=None, |
456 | 528 | scheduler_hints=None, |
| 529 | + backup_id=None, |
457 | 530 | ) |
458 | 531 |
|
459 | 532 | self.assertEqual(2, mock_error.call_count) |
|
0 commit comments