Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 1 | # 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 Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 16 | from oslo_serialization import jsonutils as json |
ravikumar-venkatesan | 18c1d0e | 2015-03-18 11:28:37 +0000 | [diff] [blame] | 17 | |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 18 | from tempest.lib.common import rest_client |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 19 | from tempest.lib import exceptions as lib_exc |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 20 | |
| 21 | |
David Paterson | 9eabc33 | 2016-09-20 06:53:47 -0700 | [diff] [blame] | 22 | class BackupsClient(rest_client.RestClient): |
| 23 | """Volume V1 Backups client""" |
| 24 | api_version = "v1" |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 25 | |
Ghanshyam | 4a9e303 | 2015-12-10 17:50:54 +0900 | [diff] [blame] | 26 | def create_backup(self, **kwargs): |
zhufl | b9255a5 | 2016-06-24 10:29:43 +0800 | [diff] [blame] | 27 | """Creates a backup of volume. |
| 28 | |
| 29 | Available params: see http://developer.openstack.org/ |
| 30 | api-ref-blockstorage-v2.html#createBackup |
| 31 | """ |
Ghanshyam | 4a9e303 | 2015-12-10 17:50:54 +0900 | [diff] [blame] | 32 | post_body = json.dumps({'backup': kwargs}) |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 33 | resp, body = self.post('backups', post_body) |
| 34 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 35 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 36 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 37 | |
Ghanshyam | 4a9e303 | 2015-12-10 17:50:54 +0900 | [diff] [blame] | 38 | def restore_backup(self, backup_id, **kwargs): |
zhufl | b9255a5 | 2016-06-24 10:29:43 +0800 | [diff] [blame] | 39 | """Restore volume from backup. |
| 40 | |
| 41 | Available params: see http://developer.openstack.org/ |
| 42 | api-ref-blockstorage-v2.html#restoreBackup |
| 43 | """ |
Ghanshyam | 4a9e303 | 2015-12-10 17:50:54 +0900 | [diff] [blame] | 44 | post_body = json.dumps({'restore': kwargs}) |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 45 | resp, body = self.post('backups/%s/restore' % (backup_id), post_body) |
| 46 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 47 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 48 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 49 | |
| 50 | def delete_backup(self, backup_id): |
| 51 | """Delete a backup of volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 52 | resp, body = self.delete('backups/%s' % backup_id) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 53 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 54 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 55 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 56 | def show_backup(self, backup_id): |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 57 | """Returns the details of a single backup.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 58 | url = "backups/%s" % backup_id |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 59 | resp, body = self.get(url) |
| 60 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 61 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 62 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 63 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 64 | def list_backups(self, detail=False): |
raiesmh08 | f04da34 | 2014-02-28 17:14:43 +0530 | [diff] [blame] | 65 | """Information for all the tenant's backups.""" |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 66 | url = "backups" |
| 67 | if detail: |
| 68 | url += "/detail" |
raiesmh08 | f04da34 | 2014-02-28 17:14:43 +0530 | [diff] [blame] | 69 | resp, body = self.get(url) |
| 70 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 71 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 72 | return rest_client.ResponseBody(resp, body) |
raiesmh08 | f04da34 | 2014-02-28 17:14:43 +0530 | [diff] [blame] | 73 | |
ravikumar-venkatesan | 18c1d0e | 2015-03-18 11:28:37 +0000 | [diff] [blame] | 74 | 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 Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 80 | return rest_client.ResponseBody(resp, body) |
ravikumar-venkatesan | 18c1d0e | 2015-03-18 11:28:37 +0000 | [diff] [blame] | 81 | |
Ghanshyam | 4a9e303 | 2015-12-10 17:50:54 +0900 | [diff] [blame] | 82 | def import_backup(self, **kwargs): |
ravikumar-venkatesan | 18c1d0e | 2015-03-18 11:28:37 +0000 | [diff] [blame] | 83 | """Import backup metadata record.""" |
Ghanshyam | 4a9e303 | 2015-12-10 17:50:54 +0900 | [diff] [blame] | 84 | post_body = json.dumps({'backup-record': kwargs}) |
ravikumar-venkatesan | 18c1d0e | 2015-03-18 11:28:37 +0000 | [diff] [blame] | 85 | resp, body = self.post("backups/import_record", post_body) |
| 86 | body = json.loads(body) |
| 87 | self.expected_success(201, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 88 | return rest_client.ResponseBody(resp, body) |
ravikumar-venkatesan | 18c1d0e | 2015-03-18 11:28:37 +0000 | [diff] [blame] | 89 | |
bkopilov | 19fc5fd | 2016-07-06 12:02:18 +0300 | [diff] [blame] | 90 | 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 Ohmichi | 153b3d9 | 2016-08-03 14:35:46 -0700 | [diff] [blame] | 97 | def is_resource_deleted(self, id): |
| 98 | try: |
| 99 | self.show_backup(id) |
| 100 | except lib_exc.NotFound: |
| 101 | return True |
| 102 | return False |