blob: 2728c67d908da283e738d8426a0f23157326a861 [file] [log] [blame]
Giulio Fidente74b08ad2014-01-18 04:02:51 +01001# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Matthew Treinish21905512015-07-13 10:33:35 -040016from oslo_serialization import jsonutils as json
ravikumar-venkatesan18c1d0e2015-03-18 11:28:37 +000017
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080018from tempest.lib.common import rest_client
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050019from tempest.lib import exceptions as lib_exc
Giulio Fidente74b08ad2014-01-18 04:02:51 +010020
21
David Paterson9eabc332016-09-20 06:53:47 -070022class BackupsClient(rest_client.RestClient):
23 """Volume V1 Backups client"""
24 api_version = "v1"
Giulio Fidente74b08ad2014-01-18 04:02:51 +010025
Ghanshyam4a9e3032015-12-10 17:50:54 +090026 def create_backup(self, **kwargs):
zhuflb9255a52016-06-24 10:29:43 +080027 """Creates a backup of volume.
28
29 Available params: see http://developer.openstack.org/
30 api-ref-blockstorage-v2.html#createBackup
31 """
Ghanshyam4a9e3032015-12-10 17:50:54 +090032 post_body = json.dumps({'backup': kwargs})
Giulio Fidente74b08ad2014-01-18 04:02:51 +010033 resp, body = self.post('backups', post_body)
34 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000035 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080036 return rest_client.ResponseBody(resp, body)
Giulio Fidente74b08ad2014-01-18 04:02:51 +010037
Ghanshyam4a9e3032015-12-10 17:50:54 +090038 def restore_backup(self, backup_id, **kwargs):
zhuflb9255a52016-06-24 10:29:43 +080039 """Restore volume from backup.
40
41 Available params: see http://developer.openstack.org/
42 api-ref-blockstorage-v2.html#restoreBackup
43 """
Ghanshyam4a9e3032015-12-10 17:50:54 +090044 post_body = json.dumps({'restore': kwargs})
Giulio Fidente74b08ad2014-01-18 04:02:51 +010045 resp, body = self.post('backups/%s/restore' % (backup_id), post_body)
46 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000047 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080048 return rest_client.ResponseBody(resp, body)
Giulio Fidente74b08ad2014-01-18 04:02:51 +010049
50 def delete_backup(self, backup_id):
51 """Delete a backup of volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080052 resp, body = self.delete('backups/%s' % backup_id)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000053 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080054 return rest_client.ResponseBody(resp, body)
Giulio Fidente74b08ad2014-01-18 04:02:51 +010055
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000056 def show_backup(self, backup_id):
Giulio Fidente74b08ad2014-01-18 04:02:51 +010057 """Returns the details of a single backup."""
guo yunxian6cdf0562016-08-17 16:21:52 +080058 url = "backups/%s" % backup_id
Giulio Fidente74b08ad2014-01-18 04:02:51 +010059 resp, body = self.get(url)
60 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000061 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080062 return rest_client.ResponseBody(resp, body)
Giulio Fidente74b08ad2014-01-18 04:02:51 +010063
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000064 def list_backups(self, detail=False):
raiesmh08f04da342014-02-28 17:14:43 +053065 """Information for all the tenant's backups."""
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000066 url = "backups"
67 if detail:
68 url += "/detail"
raiesmh08f04da342014-02-28 17:14:43 +053069 resp, body = self.get(url)
70 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000071 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080072 return rest_client.ResponseBody(resp, body)
raiesmh08f04da342014-02-28 17:14:43 +053073
ravikumar-venkatesan18c1d0e2015-03-18 11:28:37 +000074 def export_backup(self, backup_id):
75 """Export backup metadata record."""
76 url = "backups/%s/export_record" % backup_id
77 resp, body = self.get(url)
78 body = json.loads(body)
79 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080080 return rest_client.ResponseBody(resp, body)
ravikumar-venkatesan18c1d0e2015-03-18 11:28:37 +000081
Ghanshyam4a9e3032015-12-10 17:50:54 +090082 def import_backup(self, **kwargs):
ravikumar-venkatesan18c1d0e2015-03-18 11:28:37 +000083 """Import backup metadata record."""
Ghanshyam4a9e3032015-12-10 17:50:54 +090084 post_body = json.dumps({'backup-record': kwargs})
ravikumar-venkatesan18c1d0e2015-03-18 11:28:37 +000085 resp, body = self.post("backups/import_record", post_body)
86 body = json.loads(body)
87 self.expected_success(201, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080088 return rest_client.ResponseBody(resp, body)
ravikumar-venkatesan18c1d0e2015-03-18 11:28:37 +000089
bkopilov19fc5fd2016-07-06 12:02:18 +030090 def reset_backup_status(self, backup_id, status):
91 """Reset the specified backup's status."""
92 post_body = json.dumps({'os-reset_status': {"status": status}})
93 resp, body = self.post('backups/%s/action' % backup_id, post_body)
94 self.expected_success(202, resp.status)
95 return rest_client.ResponseBody(resp, body)
96
Ken'ichi Ohmichi153b3d92016-08-03 14:35:46 -070097 def is_resource_deleted(self, id):
98 try:
99 self.show_backup(id)
100 except lib_exc.NotFound:
101 return True
102 return False