blob: d89aa5d9386ed57aa46b7f82dc941c665291c2aa [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
dwalleck5d734432012-10-04 01:11:47 -05002# 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 Treinish96e9e882014-06-09 18:37:19 -040016from xml.etree import ElementTree as etree
dwalleck5d734432012-10-04 01:11:47 -050017
Matthew Treinish21905512015-07-13 10:33:35 -040018from oslo_serialization import jsonutils as json
Matthew Treinish89128142015-04-23 10:44:30 -040019from six.moves.urllib import parse as urllib
20
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +000021from tempest.common import service_client
Matthew Treinish684d8992014-01-30 16:27:40 +000022
dwalleck5d734432012-10-04 01:11:47 -050023
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +000024class AccountClient(service_client.ServiceClient):
dwalleck5d734432012-10-04 01:11:47 -050025
Daisuke Morita499bba32013-11-28 18:44:49 +090026 def create_account(self, data=None,
27 params=None,
Ghanshyam2a180b82014-06-16 13:54:22 +090028 metadata=None,
29 remove_metadata=None,
Daisuke Morita499bba32013-11-28 18:44:49 +090030 metadata_prefix='X-Account-Meta-',
31 remove_metadata_prefix='X-Remove-Account-Meta-'):
32 """Create an account."""
Ghanshyam2a180b82014-06-16 13:54:22 +090033 if metadata is None:
34 metadata = {}
35 if remove_metadata is None:
36 remove_metadata = {}
Daisuke Morita499bba32013-11-28 18:44:49 +090037 url = ''
38 if params:
39 url += '?%s' % urllib.urlencode(params)
40
41 headers = {}
42 for key in metadata:
43 headers[metadata_prefix + key] = metadata[key]
44 for key in remove_metadata:
45 headers[remove_metadata_prefix + key] = remove_metadata[key]
46
47 resp, body = self.put(url, data, headers)
JordanPa84dde32014-11-14 15:47:42 +010048 self.expected_success(200, resp.status)
Daisuke Morita499bba32013-11-28 18:44:49 +090049 return resp, body
50
51 def delete_account(self, data=None, params=None):
52 """Delete an account."""
53 url = ''
54 if params:
Daisuke Morita499bba32013-11-28 18:44:49 +090055 url = '?%s%s' % (url, urllib.urlencode(params))
56
vponomaryov67b58fe2014-02-06 19:05:41 +020057 resp, body = self.delete(url, headers={}, body=data)
JordanPa84dde32014-11-14 15:47:42 +010058 self.expected_success(200, resp.status)
Daisuke Morita499bba32013-11-28 18:44:49 +090059 return resp, body
60
dwalleck5d734432012-10-04 01:11:47 -050061 def list_account_metadata(self):
62 """
63 HEAD on the storage URL
64 Returns all account metadata headers
65 """
Chmouel Boudjnahdcf40ea2014-01-06 18:35:34 -080066 resp, body = self.head('')
JordanPa84dde32014-11-14 15:47:42 +010067 self.expected_success(204, resp.status)
dwalleck5d734432012-10-04 01:11:47 -050068 return resp, body
69
70 def create_account_metadata(self, metadata,
Daisuke Moritae3f6ed32014-08-25 11:34:21 +090071 metadata_prefix='X-Account-Meta-',
72 data=None, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -050073 """Creates an account metadata entry."""
dwalleck5d734432012-10-04 01:11:47 -050074 headers = {}
Daisuke Moritae3f6ed32014-08-25 11:34:21 +090075 if metadata:
76 for key in metadata:
77 headers[metadata_prefix + key] = metadata[key]
dwalleck5d734432012-10-04 01:11:47 -050078
Daisuke Moritae3f6ed32014-08-25 11:34:21 +090079 url = ''
80 if params:
81 url = '?%s%s' % (url, urllib.urlencode(params))
82
83 resp, body = self.post(url, headers=headers, body=data)
JordanPa84dde32014-11-14 15:47:42 +010084 self.expected_success([200, 204], resp.status)
dwalleck5d734432012-10-04 01:11:47 -050085 return resp, body
86
Larisa Ustalov6c3c7802012-11-05 12:25:19 +020087 def delete_account_metadata(self, metadata,
88 metadata_prefix='X-Remove-Account-Meta-'):
89 """
90 Deletes an account metadata entry.
91 """
92
Chmouel Boudjnahdcf40ea2014-01-06 18:35:34 -080093 headers = {}
Larisa Ustalov6c3c7802012-11-05 12:25:19 +020094 for item in metadata:
Daisuke Morita83441282014-01-14 18:56:17 +090095 headers[metadata_prefix + item] = metadata[item]
96 resp, body = self.post('', headers=headers, body=None)
JordanPa84dde32014-11-14 15:47:42 +010097 self.expected_success(204, resp.status)
Daisuke Morita83441282014-01-14 18:56:17 +090098 return resp, body
99
100 def create_and_delete_account_metadata(
101 self,
102 create_metadata=None,
103 delete_metadata=None,
104 create_metadata_prefix='X-Account-Meta-',
105 delete_metadata_prefix='X-Remove-Account-Meta-'):
106 """
107 Creates and deletes an account metadata entry.
108 """
109 headers = {}
110 for key in create_metadata:
111 headers[create_metadata_prefix + key] = create_metadata[key]
112 for key in delete_metadata:
113 headers[delete_metadata_prefix + key] = delete_metadata[key]
114
Larisa Ustalov6c3c7802012-11-05 12:25:19 +0200115 resp, body = self.post('', headers=headers, body=None)
JordanPa84dde32014-11-14 15:47:42 +0100116 self.expected_success(204, resp.status)
Larisa Ustalov6c3c7802012-11-05 12:25:19 +0200117 return resp, body
118
dwalleck5d734432012-10-04 01:11:47 -0500119 def list_account_containers(self, params=None):
120 """
121 GET on the (base) storage URL
Chmouel Boudjnahdcf40ea2014-01-06 18:35:34 -0800122 Given valid X-Auth-Token, returns a list of all containers for the
123 account.
dwalleck5d734432012-10-04 01:11:47 -0500124
125 Optional Arguments:
126 limit=[integer value N]
127 Limits the number of results to at most N values
128 DEFAULT: 10,000
129
130 marker=[string value X]
131 Given string value X, return object names greater in value
132 than the specified marker.
133 DEFAULT: No Marker
134
135 format=[string value, either 'json' or 'xml']
136 Specify either json or xml to return the respective serialized
137 response.
138 DEFAULT: Python-List returned in response body
139 """
Daisuke Morita83441282014-01-14 18:56:17 +0900140 url = '?%s' % urllib.urlencode(params) if params else ''
dwalleck5d734432012-10-04 01:11:47 -0500141
Daisuke Morita83441282014-01-14 18:56:17 +0900142 resp, body = self.get(url, headers={})
Daisuke Morita499bba32013-11-28 18:44:49 +0900143 if params and params.get('format') == 'json':
144 body = json.loads(body)
Daisuke Morita83441282014-01-14 18:56:17 +0900145 elif params and params.get('format') == 'xml':
146 body = etree.fromstring(body)
147 else:
148 body = body.strip().splitlines()
JordanPa84dde32014-11-14 15:47:42 +0100149 self.expected_success([200, 204], resp.status)
dwalleck5d734432012-10-04 01:11:47 -0500150 return resp, body
harika-vakadi2daed0a2013-01-01 20:51:39 +0530151
Joe H. Rahme9e07bf02014-01-13 18:58:02 +0100152 def list_extensions(self):
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000153 self.skip_path()
Daisuke Morita83441282014-01-14 18:56:17 +0900154 try:
155 resp, body = self.get('info')
156 finally:
157 self.reset_path()
Joe H. Rahme9e07bf02014-01-13 18:58:02 +0100158 body = json.loads(body)
JordanPa84dde32014-11-14 15:47:42 +0100159 self.expected_success(200, resp.status)
Joe H. Rahme9e07bf02014-01-13 18:58:02 +0100160 return resp, body