Fix: Volume backup restore output
Currently the volume backup restore command returns with error even though the restore is initiated. This patch corrects the response received from SDK and processes it in a human readable form. Change-Id: I7f020631fbb39ceef8740775fd82686d90a6c703 Closes-Bug: #2063335 Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/931755
This commit is contained in:
		 Rajat Dhasmana
					Rajat Dhasmana
				
			
				
					committed by
					
						 Stephen Finucane
						Stephen Finucane
					
				
			
			
				
	
			
			
			 Stephen Finucane
						Stephen Finucane
					
				
			
						parent
						
							c74af3f01e
						
					
				
				
					commit
					03e2fdd162
				
			| @@ -364,16 +364,28 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         attrs={'volume_id': volume.id}, |         attrs={'volume_id': volume.id}, | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     columns = ( | ||||||
|  |         "id", | ||||||
|  |         "volume_id", | ||||||
|  |         "volume_name", | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  |     data = ( | ||||||
|  |         backup.id, | ||||||
|  |         volume.id, | ||||||
|  |         volume.name, | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         super().setUp() |         super().setUp() | ||||||
|  |  | ||||||
|         self.volume_sdk_client.find_backup.return_value = self.backup |         self.volume_sdk_client.find_backup.return_value = self.backup | ||||||
|         self.volume_sdk_client.find_volume.return_value = self.volume |         self.volume_sdk_client.find_volume.return_value = self.volume | ||||||
|         self.volume_sdk_client.restore_backup.return_value = ( |         self.volume_sdk_client.restore_backup.return_value = { | ||||||
|             volume_fakes.create_one_volume( |             'id': self.backup['id'], | ||||||
|                 {'id': self.volume['id']}, |             'volume_id': self.volume['id'], | ||||||
|             ) |             'volume_name': self.volume['name'], | ||||||
|         ) |         } | ||||||
|  |  | ||||||
|         # Get the command object to mock |         # Get the command object to mock | ||||||
|         self.cmd = volume_backup.RestoreVolumeBackup(self.app, None) |         self.cmd = volume_backup.RestoreVolumeBackup(self.app, None) | ||||||
| @@ -389,13 +401,15 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         ] |         ] | ||||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) |         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||||
|  |  | ||||||
|         result = self.cmd.take_action(parsed_args) |         columns, data = self.cmd.take_action(parsed_args) | ||||||
|         self.volume_sdk_client.restore_backup.assert_called_with( |         self.volume_sdk_client.restore_backup.assert_called_with( | ||||||
|             self.backup.id, |             self.backup.id, | ||||||
|             volume_id=None, |             volume_id=None, | ||||||
|             name=None, |             name=None, | ||||||
|         ) |         ) | ||||||
|         self.assertIsNotNone(result) |  | ||||||
|  |         self.assertEqual(self.columns, columns) | ||||||
|  |         self.assertEqual(self.data, data) | ||||||
|  |  | ||||||
|     def test_backup_restore_with_volume(self): |     def test_backup_restore_with_volume(self): | ||||||
|         self.volume_sdk_client.find_volume.side_effect = ( |         self.volume_sdk_client.find_volume.side_effect = ( | ||||||
| @@ -411,13 +425,15 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         ] |         ] | ||||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) |         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||||
|  |  | ||||||
|         result = self.cmd.take_action(parsed_args) |         columns, data = self.cmd.take_action(parsed_args) | ||||||
|         self.volume_sdk_client.restore_backup.assert_called_with( |         self.volume_sdk_client.restore_backup.assert_called_with( | ||||||
|             self.backup.id, |             self.backup.id, | ||||||
|             volume_id=None, |             volume_id=None, | ||||||
|             name=self.backup.volume_id, |             name=self.backup.volume_id, | ||||||
|         ) |         ) | ||||||
|         self.assertIsNotNone(result) |  | ||||||
|  |         self.assertEqual(self.columns, columns) | ||||||
|  |         self.assertEqual(self.data, data) | ||||||
|  |  | ||||||
|     def test_backup_restore_with_volume_force(self): |     def test_backup_restore_with_volume_force(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
| @@ -432,13 +448,15 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         ] |         ] | ||||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) |         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||||
|  |  | ||||||
|         result = self.cmd.take_action(parsed_args) |         columns, data = self.cmd.take_action(parsed_args) | ||||||
|         self.volume_sdk_client.restore_backup.assert_called_with( |         self.volume_sdk_client.restore_backup.assert_called_with( | ||||||
|             self.backup.id, |             self.backup.id, | ||||||
|             volume_id=self.volume.id, |             volume_id=self.volume.id, | ||||||
|             name=None, |             name=None, | ||||||
|         ) |         ) | ||||||
|         self.assertIsNotNone(result) |  | ||||||
|  |         self.assertEqual(self.columns, columns) | ||||||
|  |         self.assertEqual(self.data, data) | ||||||
|  |  | ||||||
|     def test_backup_restore_with_volume_existing(self): |     def test_backup_restore_with_volume_existing(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
|   | |||||||
| @@ -462,16 +462,28 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         attrs={'volume_id': volume.id}, |         attrs={'volume_id': volume.id}, | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     columns = ( | ||||||
|  |         "id", | ||||||
|  |         "volume_id", | ||||||
|  |         "volume_name", | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  |     data = ( | ||||||
|  |         backup.id, | ||||||
|  |         volume.id, | ||||||
|  |         volume.name, | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         super().setUp() |         super().setUp() | ||||||
|  |  | ||||||
|         self.volume_sdk_client.find_backup.return_value = self.backup |         self.volume_sdk_client.find_backup.return_value = self.backup | ||||||
|         self.volume_sdk_client.find_volume.return_value = self.volume |         self.volume_sdk_client.find_volume.return_value = self.volume | ||||||
|         self.volume_sdk_client.restore_backup.return_value = ( |         self.volume_sdk_client.restore_backup.return_value = { | ||||||
|             volume_fakes.create_one_volume( |             'id': self.backup['id'], | ||||||
|                 {'id': self.volume['id']}, |             'volume_id': self.volume['id'], | ||||||
|             ) |             'volume_name': self.volume['name'], | ||||||
|         ) |         } | ||||||
|  |  | ||||||
|         # Get the command object to mock |         # Get the command object to mock | ||||||
|         self.cmd = volume_backup.RestoreVolumeBackup(self.app, None) |         self.cmd = volume_backup.RestoreVolumeBackup(self.app, None) | ||||||
| @@ -487,13 +499,15 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         ] |         ] | ||||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) |         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||||
|  |  | ||||||
|         result = self.cmd.take_action(parsed_args) |         columns, data = self.cmd.take_action(parsed_args) | ||||||
|         self.volume_sdk_client.restore_backup.assert_called_with( |         self.volume_sdk_client.restore_backup.assert_called_with( | ||||||
|             self.backup.id, |             self.backup.id, | ||||||
|             volume_id=None, |             volume_id=None, | ||||||
|             name=None, |             name=None, | ||||||
|         ) |         ) | ||||||
|         self.assertIsNotNone(result) |  | ||||||
|  |         self.assertEqual(self.columns, columns) | ||||||
|  |         self.assertEqual(self.data, data) | ||||||
|  |  | ||||||
|     def test_backup_restore_with_volume(self): |     def test_backup_restore_with_volume(self): | ||||||
|         self.volume_sdk_client.find_volume.side_effect = ( |         self.volume_sdk_client.find_volume.side_effect = ( | ||||||
| @@ -509,13 +523,15 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         ] |         ] | ||||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) |         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||||
|  |  | ||||||
|         result = self.cmd.take_action(parsed_args) |         columns, data = self.cmd.take_action(parsed_args) | ||||||
|         self.volume_sdk_client.restore_backup.assert_called_with( |         self.volume_sdk_client.restore_backup.assert_called_with( | ||||||
|             self.backup.id, |             self.backup.id, | ||||||
|             volume_id=None, |             volume_id=None, | ||||||
|             name=self.backup.volume_id, |             name=self.backup.volume_id, | ||||||
|         ) |         ) | ||||||
|         self.assertIsNotNone(result) |  | ||||||
|  |         self.assertEqual(self.columns, columns) | ||||||
|  |         self.assertEqual(self.data, data) | ||||||
|  |  | ||||||
|     def test_backup_restore_with_volume_force(self): |     def test_backup_restore_with_volume_force(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
| @@ -530,13 +546,15 @@ class TestBackupRestore(volume_fakes.TestVolume): | |||||||
|         ] |         ] | ||||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) |         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||||
|  |  | ||||||
|         result = self.cmd.take_action(parsed_args) |         columns, data = self.cmd.take_action(parsed_args) | ||||||
|         self.volume_sdk_client.restore_backup.assert_called_with( |         self.volume_sdk_client.restore_backup.assert_called_with( | ||||||
|             self.backup.id, |             self.backup.id, | ||||||
|             volume_id=self.volume.id, |             volume_id=self.volume.id, | ||||||
|             name=None, |             name=None, | ||||||
|         ) |         ) | ||||||
|         self.assertIsNotNone(result) |  | ||||||
|  |         self.assertEqual(self.columns, columns) | ||||||
|  |         self.assertEqual(self.data, data) | ||||||
|  |  | ||||||
|     def test_backup_restore_with_volume_existing(self): |     def test_backup_restore_with_volume_existing(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
|   | |||||||
| @@ -359,6 +359,12 @@ class RestoreVolumeBackup(command.ShowOne): | |||||||
|             ignore_missing=False, |             ignore_missing=False, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |         columns = ( | ||||||
|  |             'id', | ||||||
|  |             'volume_id', | ||||||
|  |             'volume_name', | ||||||
|  |         ) | ||||||
|  |  | ||||||
|         volume_name = None |         volume_name = None | ||||||
|         volume_id = None |         volume_id = None | ||||||
|         try: |         try: | ||||||
| @@ -378,12 +384,15 @@ class RestoreVolumeBackup(command.ShowOne): | |||||||
|                 ) |                 ) | ||||||
|                 raise exceptions.CommandError(msg % parsed_args.volume) |                 raise exceptions.CommandError(msg % parsed_args.volume) | ||||||
|  |  | ||||||
|         return volume_client.restore_backup( |         restore = volume_client.restore_backup( | ||||||
|             backup.id, |             backup.id, | ||||||
|             volume_id=volume_id, |             volume_id=volume_id, | ||||||
|             name=volume_name, |             name=volume_name, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |         data = utils.get_dict_properties(restore, columns) | ||||||
|  |         return (columns, data) | ||||||
|  |  | ||||||
|  |  | ||||||
| class SetVolumeBackup(command.Command): | class SetVolumeBackup(command.Command): | ||||||
|     _description = _("Set volume backup properties") |     _description = _("Set volume backup properties") | ||||||
|   | |||||||
| @@ -412,6 +412,12 @@ class RestoreVolumeBackup(command.ShowOne): | |||||||
|     def take_action(self, parsed_args): |     def take_action(self, parsed_args): | ||||||
|         volume_client = self.app.client_manager.sdk_connection.volume |         volume_client = self.app.client_manager.sdk_connection.volume | ||||||
|  |  | ||||||
|  |         columns = ( | ||||||
|  |             'id', | ||||||
|  |             'volume_id', | ||||||
|  |             'volume_name', | ||||||
|  |         ) | ||||||
|  |  | ||||||
|         backup = volume_client.find_backup( |         backup = volume_client.find_backup( | ||||||
|             parsed_args.backup, |             parsed_args.backup, | ||||||
|             ignore_missing=False, |             ignore_missing=False, | ||||||
| @@ -436,12 +442,15 @@ class RestoreVolumeBackup(command.ShowOne): | |||||||
|                 ) |                 ) | ||||||
|                 raise exceptions.CommandError(msg % parsed_args.volume) |                 raise exceptions.CommandError(msg % parsed_args.volume) | ||||||
|  |  | ||||||
|         return volume_client.restore_backup( |         restore = volume_client.restore_backup( | ||||||
|             backup.id, |             backup.id, | ||||||
|             volume_id=volume_id, |             volume_id=volume_id, | ||||||
|             name=volume_name, |             name=volume_name, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |         data = utils.get_dict_properties(restore, columns) | ||||||
|  |         return (columns, data) | ||||||
|  |  | ||||||
|  |  | ||||||
| class SetVolumeBackup(command.Command): | class SetVolumeBackup(command.Command): | ||||||
|     _description = _("Set volume backup properties") |     _description = _("Set volume backup properties") | ||||||
|   | |||||||
| @@ -0,0 +1,4 @@ | |||||||
|  | --- | ||||||
|  | fixes: | ||||||
|  |   - | | ||||||
|  |     Fixed the output of ``volume backup restore`` command. | ||||||
		Reference in New Issue
	
	Block a user