Skip to content

Commit eb0dbd5

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix: Volume backup restore output"
2 parents 6ce1f77 + 03e2fdd commit eb0dbd5

File tree

5 files changed

+82
-24
lines changed

5 files changed

+82
-24
lines changed

openstackclient/tests/unit/volume/v2/test_volume_backup.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,28 @@ class TestBackupRestore(volume_fakes.TestVolume):
364364
attrs={'volume_id': volume.id},
365365
)
366366

367+
columns = (
368+
"id",
369+
"volume_id",
370+
"volume_name",
371+
)
372+
373+
data = (
374+
backup.id,
375+
volume.id,
376+
volume.name,
377+
)
378+
367379
def setUp(self):
368380
super().setUp()
369381

370382
self.volume_sdk_client.find_backup.return_value = self.backup
371383
self.volume_sdk_client.find_volume.return_value = self.volume
372-
self.volume_sdk_client.restore_backup.return_value = (
373-
volume_fakes.create_one_volume(
374-
{'id': self.volume['id']},
375-
)
376-
)
384+
self.volume_sdk_client.restore_backup.return_value = {
385+
'id': self.backup['id'],
386+
'volume_id': self.volume['id'],
387+
'volume_name': self.volume['name'],
388+
}
377389

378390
# Get the command object to mock
379391
self.cmd = volume_backup.RestoreVolumeBackup(self.app, None)
@@ -389,13 +401,15 @@ def test_backup_restore(self):
389401
]
390402
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
391403

392-
result = self.cmd.take_action(parsed_args)
404+
columns, data = self.cmd.take_action(parsed_args)
393405
self.volume_sdk_client.restore_backup.assert_called_with(
394406
self.backup.id,
395407
volume_id=None,
396408
name=None,
397409
)
398-
self.assertIsNotNone(result)
410+
411+
self.assertEqual(self.columns, columns)
412+
self.assertEqual(self.data, data)
399413

400414
def test_backup_restore_with_volume(self):
401415
self.volume_sdk_client.find_volume.side_effect = (
@@ -411,13 +425,15 @@ def test_backup_restore_with_volume(self):
411425
]
412426
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
413427

414-
result = self.cmd.take_action(parsed_args)
428+
columns, data = self.cmd.take_action(parsed_args)
415429
self.volume_sdk_client.restore_backup.assert_called_with(
416430
self.backup.id,
417431
volume_id=None,
418432
name=self.backup.volume_id,
419433
)
420-
self.assertIsNotNone(result)
434+
435+
self.assertEqual(self.columns, columns)
436+
self.assertEqual(self.data, data)
421437

422438
def test_backup_restore_with_volume_force(self):
423439
arglist = [
@@ -432,13 +448,15 @@ def test_backup_restore_with_volume_force(self):
432448
]
433449
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
434450

435-
result = self.cmd.take_action(parsed_args)
451+
columns, data = self.cmd.take_action(parsed_args)
436452
self.volume_sdk_client.restore_backup.assert_called_with(
437453
self.backup.id,
438454
volume_id=self.volume.id,
439455
name=None,
440456
)
441-
self.assertIsNotNone(result)
457+
458+
self.assertEqual(self.columns, columns)
459+
self.assertEqual(self.data, data)
442460

443461
def test_backup_restore_with_volume_existing(self):
444462
arglist = [

openstackclient/tests/unit/volume/v3/test_volume_backup.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,28 @@ class TestBackupRestore(volume_fakes.TestVolume):
462462
attrs={'volume_id': volume.id},
463463
)
464464

465+
columns = (
466+
"id",
467+
"volume_id",
468+
"volume_name",
469+
)
470+
471+
data = (
472+
backup.id,
473+
volume.id,
474+
volume.name,
475+
)
476+
465477
def setUp(self):
466478
super().setUp()
467479

468480
self.volume_sdk_client.find_backup.return_value = self.backup
469481
self.volume_sdk_client.find_volume.return_value = self.volume
470-
self.volume_sdk_client.restore_backup.return_value = (
471-
volume_fakes.create_one_volume(
472-
{'id': self.volume['id']},
473-
)
474-
)
482+
self.volume_sdk_client.restore_backup.return_value = {
483+
'id': self.backup['id'],
484+
'volume_id': self.volume['id'],
485+
'volume_name': self.volume['name'],
486+
}
475487

476488
# Get the command object to mock
477489
self.cmd = volume_backup.RestoreVolumeBackup(self.app, None)
@@ -487,13 +499,15 @@ def test_backup_restore(self):
487499
]
488500
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
489501

490-
result = self.cmd.take_action(parsed_args)
502+
columns, data = self.cmd.take_action(parsed_args)
491503
self.volume_sdk_client.restore_backup.assert_called_with(
492504
self.backup.id,
493505
volume_id=None,
494506
name=None,
495507
)
496-
self.assertIsNotNone(result)
508+
509+
self.assertEqual(self.columns, columns)
510+
self.assertEqual(self.data, data)
497511

498512
def test_backup_restore_with_volume(self):
499513
self.volume_sdk_client.find_volume.side_effect = (
@@ -509,13 +523,15 @@ def test_backup_restore_with_volume(self):
509523
]
510524
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
511525

512-
result = self.cmd.take_action(parsed_args)
526+
columns, data = self.cmd.take_action(parsed_args)
513527
self.volume_sdk_client.restore_backup.assert_called_with(
514528
self.backup.id,
515529
volume_id=None,
516530
name=self.backup.volume_id,
517531
)
518-
self.assertIsNotNone(result)
532+
533+
self.assertEqual(self.columns, columns)
534+
self.assertEqual(self.data, data)
519535

520536
def test_backup_restore_with_volume_force(self):
521537
arglist = [
@@ -530,13 +546,15 @@ def test_backup_restore_with_volume_force(self):
530546
]
531547
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
532548

533-
result = self.cmd.take_action(parsed_args)
549+
columns, data = self.cmd.take_action(parsed_args)
534550
self.volume_sdk_client.restore_backup.assert_called_with(
535551
self.backup.id,
536552
volume_id=self.volume.id,
537553
name=None,
538554
)
539-
self.assertIsNotNone(result)
555+
556+
self.assertEqual(self.columns, columns)
557+
self.assertEqual(self.data, data)
540558

541559
def test_backup_restore_with_volume_existing(self):
542560
arglist = [

openstackclient/volume/v2/volume_backup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ def take_action(self, parsed_args):
359359
ignore_missing=False,
360360
)
361361

362+
columns = (
363+
'id',
364+
'volume_id',
365+
'volume_name',
366+
)
367+
362368
volume_name = None
363369
volume_id = None
364370
try:
@@ -378,12 +384,15 @@ def take_action(self, parsed_args):
378384
)
379385
raise exceptions.CommandError(msg % parsed_args.volume)
380386

381-
return volume_client.restore_backup(
387+
restore = volume_client.restore_backup(
382388
backup.id,
383389
volume_id=volume_id,
384390
name=volume_name,
385391
)
386392

393+
data = utils.get_dict_properties(restore, columns)
394+
return (columns, data)
395+
387396

388397
class SetVolumeBackup(command.Command):
389398
_description = _("Set volume backup properties")

openstackclient/volume/v3/volume_backup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ def get_parser(self, prog_name):
412412
def take_action(self, parsed_args):
413413
volume_client = self.app.client_manager.sdk_connection.volume
414414

415+
columns = (
416+
'id',
417+
'volume_id',
418+
'volume_name',
419+
)
420+
415421
backup = volume_client.find_backup(
416422
parsed_args.backup,
417423
ignore_missing=False,
@@ -436,12 +442,15 @@ def take_action(self, parsed_args):
436442
)
437443
raise exceptions.CommandError(msg % parsed_args.volume)
438444

439-
return volume_client.restore_backup(
445+
restore = volume_client.restore_backup(
440446
backup.id,
441447
volume_id=volume_id,
442448
name=volume_name,
443449
)
444450

451+
data = utils.get_dict_properties(restore, columns)
452+
return (columns, data)
453+
445454

446455
class SetVolumeBackup(command.Command):
447456
_description = _("Set volume backup properties")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed the output of ``volume backup restore`` command.

0 commit comments

Comments
 (0)