Merge "Fix volume backup restore response"

This commit is contained in:
Zuul 2024-12-17 19:09:33 +00:00 committed by Gerrit Code Review
commit c058f63ad3
5 changed files with 84 additions and 2 deletions

View File

@ -86,6 +86,8 @@ class Backup(resource.Resource):
updated_at = resource.Body("updated_at") updated_at = resource.Body("updated_at")
#: The UUID of the volume. #: The UUID of the volume.
volume_id = resource.Body("volume_id") 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): def create(self, session, prepend_key=True, base_path=None, **params):
"""Create a remote resource based on this instance. """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.' 'Either of `name` or `volume_id` must be specified.'
) )
response = session.post(url, json=body) response = session.post(url, json=body)
self._translate_response(response, has_body=False) self._translate_response(response, resource_response_key='restore')
return self return self
def force_delete(self, session): def force_delete(self, session):

View File

@ -100,6 +100,8 @@ class Backup(resource.Resource):
user_id = resource.Body('user_id') user_id = resource.Body('user_id')
#: The UUID of the volume. #: The UUID of the volume.
volume_id = resource.Body("volume_id") volume_id = resource.Body("volume_id")
#: The name of the volume.
volume_name = resource.Body("volume_name")
_max_microversion = "3.64" _max_microversion = "3.64"
@ -202,7 +204,7 @@ class Backup(resource.Resource):
'Either of `name` or `volume_id` must be specified.' 'Either of `name` or `volume_id` must be specified.'
) )
response = session.post(url, json=body) response = session.post(url, json=body)
self._translate_response(response, has_body=False) self._translate_response(response, resource_response_key='restore')
return self return self
def force_delete(self, session): def force_delete(self, session):

View File

@ -137,6 +137,18 @@ class TestBackup(base.TestCase):
def test_restore(self): def test_restore(self):
sot = backup.Backup(**BACKUP) 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')) self.assertEqual(sot, sot.restore(self.sess, 'vol', 'name'))
url = f'backups/{FAKE_ID}/restore' url = f'backups/{FAKE_ID}/restore'
@ -146,6 +158,18 @@ class TestBackup(base.TestCase):
def test_restore_name(self): def test_restore_name(self):
sot = backup.Backup(**BACKUP) 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')) self.assertEqual(sot, sot.restore(self.sess, name='name'))
url = f'backups/{FAKE_ID}/restore' url = f'backups/{FAKE_ID}/restore'
@ -155,6 +179,18 @@ class TestBackup(base.TestCase):
def test_restore_vol_id(self): def test_restore_vol_id(self):
sot = backup.Backup(**BACKUP) 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')) self.assertEqual(sot, sot.restore(self.sess, volume_id='vol'))
url = f'backups/{FAKE_ID}/restore' url = f'backups/{FAKE_ID}/restore'

View File

@ -150,6 +150,18 @@ class TestBackup(base.TestCase):
def test_restore(self): def test_restore(self):
sot = backup.Backup(**BACKUP) 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')) self.assertEqual(sot, sot.restore(self.sess, 'vol', 'name'))
url = f'backups/{FAKE_ID}/restore' url = f'backups/{FAKE_ID}/restore'
@ -159,6 +171,18 @@ class TestBackup(base.TestCase):
def test_restore_name(self): def test_restore_name(self):
sot = backup.Backup(**BACKUP) 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')) self.assertEqual(sot, sot.restore(self.sess, name='name'))
url = f'backups/{FAKE_ID}/restore' url = f'backups/{FAKE_ID}/restore'
@ -168,6 +192,18 @@ class TestBackup(base.TestCase):
def test_restore_vol_id(self): def test_restore_vol_id(self):
sot = backup.Backup(**BACKUP) 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')) self.assertEqual(sot, sot.restore(self.sess, volume_id='vol'))
url = f'backups/{FAKE_ID}/restore' url = f'backups/{FAKE_ID}/restore'

View File

@ -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.