diff --git a/openstack/block_storage/v2/backup.py b/openstack/block_storage/v2/backup.py index 5fb7adf3b..aa68366b6 100644 --- a/openstack/block_storage/v2/backup.py +++ b/openstack/block_storage/v2/backup.py @@ -86,6 +86,8 @@ class Backup(resource.Resource): updated_at = resource.Body("updated_at") #: The UUID of the volume. volume_id = resource.Body("volume_id") + #: The name of the volume. + volume_name = resource.Body("volume_name") def create(self, session, prepend_key=True, base_path=None, **params): """Create a remote resource based on this instance. @@ -186,7 +188,7 @@ class Backup(resource.Resource): 'Either of `name` or `volume_id` must be specified.' ) response = session.post(url, json=body) - self._translate_response(response, has_body=False) + self._translate_response(response, resource_response_key='restore') return self def force_delete(self, session): diff --git a/openstack/block_storage/v3/backup.py b/openstack/block_storage/v3/backup.py index 9efcd3418..636a0d3f5 100644 --- a/openstack/block_storage/v3/backup.py +++ b/openstack/block_storage/v3/backup.py @@ -100,6 +100,8 @@ class Backup(resource.Resource): user_id = resource.Body('user_id') #: The UUID of the volume. volume_id = resource.Body("volume_id") + #: The name of the volume. + volume_name = resource.Body("volume_name") _max_microversion = "3.64" @@ -202,7 +204,7 @@ class Backup(resource.Resource): 'Either of `name` or `volume_id` must be specified.' ) response = session.post(url, json=body) - self._translate_response(response, has_body=False) + self._translate_response(response, resource_response_key='restore') return self def force_delete(self, session): diff --git a/openstack/tests/unit/block_storage/v2/test_backup.py b/openstack/tests/unit/block_storage/v2/test_backup.py index 600ed8855..20b1413a4 100644 --- a/openstack/tests/unit/block_storage/v2/test_backup.py +++ b/openstack/tests/unit/block_storage/v2/test_backup.py @@ -137,6 +137,18 @@ class TestBackup(base.TestCase): def test_restore(self): sot = backup.Backup(**BACKUP) + restore_response = mock.Mock() + restore_response.status_code = 202 + restore_response.json.return_value = { + "restore": { + "backup_id": "back", + "volume_id": "vol", + "volume_name": "name", + } + } + restore_response.headers = {} + self.sess.post.return_value = restore_response + self.assertEqual(sot, sot.restore(self.sess, 'vol', 'name')) url = f'backups/{FAKE_ID}/restore' @@ -146,6 +158,18 @@ class TestBackup(base.TestCase): def test_restore_name(self): sot = backup.Backup(**BACKUP) + restore_response = mock.Mock() + restore_response.status_code = 202 + restore_response.json.return_value = { + "restore": { + "backup_id": "back", + "volume_id": "vol", + "volume_name": "name", + } + } + restore_response.headers = {} + self.sess.post.return_value = restore_response + self.assertEqual(sot, sot.restore(self.sess, name='name')) url = f'backups/{FAKE_ID}/restore' @@ -155,6 +179,18 @@ class TestBackup(base.TestCase): def test_restore_vol_id(self): sot = backup.Backup(**BACKUP) + restore_response = mock.Mock() + restore_response.status_code = 202 + restore_response.json.return_value = { + "restore": { + "backup_id": "back", + "volume_id": "vol", + "volume_name": "name", + } + } + restore_response.headers = {} + self.sess.post.return_value = restore_response + self.assertEqual(sot, sot.restore(self.sess, volume_id='vol')) url = f'backups/{FAKE_ID}/restore' diff --git a/openstack/tests/unit/block_storage/v3/test_backup.py b/openstack/tests/unit/block_storage/v3/test_backup.py index 796cd05ae..ef68e88d4 100644 --- a/openstack/tests/unit/block_storage/v3/test_backup.py +++ b/openstack/tests/unit/block_storage/v3/test_backup.py @@ -150,6 +150,18 @@ class TestBackup(base.TestCase): def test_restore(self): sot = backup.Backup(**BACKUP) + restore_response = mock.Mock() + restore_response.status_code = 202 + restore_response.json.return_value = { + "restore": { + "backup_id": "back", + "volume_id": "vol", + "volume_name": "name", + } + } + restore_response.headers = {} + self.sess.post.return_value = restore_response + self.assertEqual(sot, sot.restore(self.sess, 'vol', 'name')) url = f'backups/{FAKE_ID}/restore' @@ -159,6 +171,18 @@ class TestBackup(base.TestCase): def test_restore_name(self): sot = backup.Backup(**BACKUP) + restore_response = mock.Mock() + restore_response.status_code = 202 + restore_response.json.return_value = { + "restore": { + "backup_id": "back", + "volume_id": "vol", + "volume_name": "name", + } + } + restore_response.headers = {} + self.sess.post.return_value = restore_response + self.assertEqual(sot, sot.restore(self.sess, name='name')) url = f'backups/{FAKE_ID}/restore' @@ -168,6 +192,18 @@ class TestBackup(base.TestCase): def test_restore_vol_id(self): sot = backup.Backup(**BACKUP) + restore_response = mock.Mock() + restore_response.status_code = 202 + restore_response.json.return_value = { + "restore": { + "backup_id": "back", + "volume_id": "vol", + "volume_name": "name", + } + } + restore_response.headers = {} + self.sess.post.return_value = restore_response + self.assertEqual(sot, sot.restore(self.sess, volume_id='vol')) url = f'backups/{FAKE_ID}/restore' diff --git a/releasenotes/notes/fix-restore-resp-4e0bf3a246f3dc59.yaml b/releasenotes/notes/fix-restore-resp-4e0bf3a246f3dc59.yaml new file mode 100644 index 000000000..884b93c4c --- /dev/null +++ b/releasenotes/notes/fix-restore-resp-4e0bf3a246f3dc59.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Previously the volume backup restore response only + returned ``id`` and now it also returns ``volume_id`` + and ``volume_name`` fields.