python-manilaclient 6.1.0__py3-none-any.whl → 6.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- manilaclient/api_versions.py +1 -1
- manilaclient/common/constants.py +3 -0
- manilaclient/common/httpclient.py +119 -1
- manilaclient/osc/v2/resource_locks.py +2 -0
- manilaclient/osc/v2/share.py +29 -5
- manilaclient/osc/v2/share_network_subnets.py +5 -2
- manilaclient/osc/v2/share_networks.py +4 -3
- manilaclient/osc/v2/share_replicas.py +18 -2
- manilaclient/osc/v2/share_snapshots.py +5 -2
- manilaclient/tests/unit/common/test_httpclient.py +218 -0
- manilaclient/tests/unit/osc/v2/fakes.py +2 -1
- manilaclient/tests/unit/osc/v2/test_resource_locks.py +38 -0
- manilaclient/tests/unit/osc/v2/test_share.py +44 -0
- manilaclient/tests/unit/osc/v2/test_share_networks.py +54 -2
- manilaclient/tests/unit/osc/v2/test_share_replicas.py +41 -0
- manilaclient/tests/unit/osc/v2/test_share_type.py +18 -0
- manilaclient/tests/unit/v2/fakes.py +21 -0
- manilaclient/tests/unit/v2/test_client.py +48 -79
- manilaclient/tests/unit/v2/test_share_export_locations.py +53 -0
- manilaclient/tests/unit/v2/test_shares.py +44 -4
- manilaclient/v2/client.py +50 -52
- manilaclient/v2/shares.py +138 -6
- {python_manilaclient-6.1.0.dist-info → python_manilaclient-6.3.0.dist-info}/METADATA +6 -6
- {python_manilaclient-6.1.0.dist-info → python_manilaclient-6.3.0.dist-info}/RECORD +30 -30
- {python_manilaclient-6.1.0.dist-info → python_manilaclient-6.3.0.dist-info}/WHEEL +1 -1
- {python_manilaclient-6.1.0.dist-info → python_manilaclient-6.3.0.dist-info}/licenses/AUTHORS +4 -0
- python_manilaclient-6.3.0.dist-info/pbr.json +1 -0
- python_manilaclient-6.1.0.dist-info/pbr.json +0 -1
- {python_manilaclient-6.1.0.dist-info → python_manilaclient-6.3.0.dist-info}/entry_points.txt +0 -0
- {python_manilaclient-6.1.0.dist-info → python_manilaclient-6.3.0.dist-info}/licenses/LICENSE +0 -0
- {python_manilaclient-6.1.0.dist-info → python_manilaclient-6.3.0.dist-info}/top_level.txt +0 -0
manilaclient/api_versions.py
CHANGED
manilaclient/common/constants.py
CHANGED
|
@@ -181,3 +181,6 @@ REPLICA_PRE_GRADUATION_VERSION = '2.55'
|
|
|
181
181
|
SHARE_TRANSFER_VERSION = '2.77'
|
|
182
182
|
RESOURCE_LOCK_VERSION = '2.81'
|
|
183
183
|
QOS_TYPE_VERSION = '2.94'
|
|
184
|
+
SHARE_MIGRATION_GRADUATION_VERSION = '2.96'
|
|
185
|
+
SHARE_MIGRATION_PRE_GRADUATION_VERSION = '2.95'
|
|
186
|
+
SHARE_MIGRATION_PROGRESS_GET_VERSION = '2.98'
|
|
@@ -17,9 +17,12 @@
|
|
|
17
17
|
# limitations under the License.
|
|
18
18
|
|
|
19
19
|
import copy
|
|
20
|
+
import hashlib
|
|
20
21
|
import logging
|
|
21
22
|
from urllib import parse
|
|
22
23
|
|
|
24
|
+
from keystoneauth1 import adapter
|
|
25
|
+
from keystoneauth1 import exceptions as ks_exceptions
|
|
23
26
|
from oslo_serialization import jsonutils
|
|
24
27
|
from oslo_utils import importutils
|
|
25
28
|
from oslo_utils import strutils
|
|
@@ -36,6 +39,113 @@ except ImportError:
|
|
|
36
39
|
pass
|
|
37
40
|
|
|
38
41
|
|
|
42
|
+
class SessionClient(adapter.LegacyJsonAdapter):
|
|
43
|
+
"""HTTP client based on keystoneauth1 session.
|
|
44
|
+
|
|
45
|
+
Uses the keystoneauth1 session for making API requests, which
|
|
46
|
+
provides automatic token management, renewal, and safe logging
|
|
47
|
+
(token redaction).
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
api_version,
|
|
53
|
+
retries=0,
|
|
54
|
+
http_log_debug=False,
|
|
55
|
+
timeout=None,
|
|
56
|
+
**kwargs,
|
|
57
|
+
):
|
|
58
|
+
self.retries = int(retries or 0)
|
|
59
|
+
self.http_log_debug = http_log_debug
|
|
60
|
+
self.timeout = timeout
|
|
61
|
+
# NOTE: default_headers is merged into every request. It exists for
|
|
62
|
+
# compatibility with callers (e.g. the experimental_api decorator)
|
|
63
|
+
# that toggle sticky headers such as the experimental API header.
|
|
64
|
+
self.default_headers = {}
|
|
65
|
+
kwargs['default_microversion'] = api_version.get_string()
|
|
66
|
+
self._logger = logging.getLogger(__name__)
|
|
67
|
+
super().__init__(**kwargs)
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def _get_base_url(url):
|
|
71
|
+
"""Truncates url and returns base endpoint."""
|
|
72
|
+
service_endpoint = parse.urlparse(url)
|
|
73
|
+
service_endpoint_base_path = re.search(
|
|
74
|
+
r'(.+?)/v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)',
|
|
75
|
+
service_endpoint.path,
|
|
76
|
+
)
|
|
77
|
+
base_path = (
|
|
78
|
+
service_endpoint_base_path.group(1)
|
|
79
|
+
if service_endpoint_base_path
|
|
80
|
+
else ''
|
|
81
|
+
)
|
|
82
|
+
base_url = service_endpoint._replace(path=base_path)
|
|
83
|
+
return parse.urlunparse(base_url) + '/'
|
|
84
|
+
|
|
85
|
+
def request(self, url, method, **kwargs):
|
|
86
|
+
kwargs.setdefault('authenticated', True)
|
|
87
|
+
if self.default_headers:
|
|
88
|
+
# Per-request headers take precedence over the sticky defaults.
|
|
89
|
+
headers = dict(self.default_headers)
|
|
90
|
+
headers.update(kwargs.get('headers') or {})
|
|
91
|
+
kwargs['headers'] = headers
|
|
92
|
+
if self.http_log_debug:
|
|
93
|
+
kwargs.setdefault('logger', self._logger)
|
|
94
|
+
if self.timeout:
|
|
95
|
+
kwargs.setdefault('timeout', self.timeout)
|
|
96
|
+
raise_exc = kwargs.pop('raise_exc', True)
|
|
97
|
+
resp, body = super().request(url, method, raise_exc=False, **kwargs)
|
|
98
|
+
if raise_exc and resp.status_code >= 400:
|
|
99
|
+
raise exceptions.from_response(resp, method, url)
|
|
100
|
+
return resp, body
|
|
101
|
+
|
|
102
|
+
def _cs_request(self, url, method, **kwargs):
|
|
103
|
+
attempts = 0
|
|
104
|
+
timeout = 1
|
|
105
|
+
while True:
|
|
106
|
+
attempts += 1
|
|
107
|
+
try:
|
|
108
|
+
return self.request(url, method, **kwargs)
|
|
109
|
+
except (
|
|
110
|
+
exceptions.ClientException,
|
|
111
|
+
ks_exceptions.RetriableConnectionFailure,
|
|
112
|
+
) as e:
|
|
113
|
+
# BadRequest is a ClientException subclass; keystoneauth
|
|
114
|
+
# raises RetriableConnectionFailure for transient network
|
|
115
|
+
# errors, which are not manila ClientExceptions.
|
|
116
|
+
if attempts > self.retries:
|
|
117
|
+
raise
|
|
118
|
+
self._logger.debug("Request error: %s", str(e))
|
|
119
|
+
self._logger.debug(
|
|
120
|
+
"Failed attempt(%(current)s of %(total)s), "
|
|
121
|
+
" retrying in %(sec)s seconds",
|
|
122
|
+
{'current': attempts, 'total': self.retries, 'sec': timeout},
|
|
123
|
+
)
|
|
124
|
+
sleep(timeout)
|
|
125
|
+
timeout *= 2
|
|
126
|
+
|
|
127
|
+
def get(self, url, **kwargs):
|
|
128
|
+
return self._cs_request(url, 'GET', **kwargs)
|
|
129
|
+
|
|
130
|
+
def post(self, url, **kwargs):
|
|
131
|
+
return self._cs_request(url, 'POST', **kwargs)
|
|
132
|
+
|
|
133
|
+
def put(self, url, **kwargs):
|
|
134
|
+
return self._cs_request(url, 'PUT', **kwargs)
|
|
135
|
+
|
|
136
|
+
def delete(self, url, **kwargs):
|
|
137
|
+
return self._cs_request(url, 'DELETE', **kwargs)
|
|
138
|
+
|
|
139
|
+
def get_with_base_url(self, url, **kwargs):
|
|
140
|
+
base_url = self._get_base_url(self.endpoint_override)
|
|
141
|
+
return self._cs_request(
|
|
142
|
+
base_url + url,
|
|
143
|
+
'GET',
|
|
144
|
+
endpoint_override=base_url,
|
|
145
|
+
**kwargs,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
39
149
|
class HTTPClient:
|
|
40
150
|
"""HTTP Client class used by multiple clients.
|
|
41
151
|
|
|
@@ -203,6 +313,13 @@ class HTTPClient:
|
|
|
203
313
|
def delete(self, url, **kwargs):
|
|
204
314
|
return self._cs_request(url, 'DELETE', **kwargs)
|
|
205
315
|
|
|
316
|
+
@staticmethod
|
|
317
|
+
def _safe_header(name, value):
|
|
318
|
+
if name.lower() in ('x-auth-token',):
|
|
319
|
+
token_hash = hashlib.sha256(value.encode('utf-8')).hexdigest()
|
|
320
|
+
value = '{SHA256}' + token_hash
|
|
321
|
+
return value
|
|
322
|
+
|
|
206
323
|
def log_request(self, method, url, headers, data=None):
|
|
207
324
|
if not self.http_log_debug:
|
|
208
325
|
return
|
|
@@ -210,7 +327,8 @@ class HTTPClient:
|
|
|
210
327
|
string_parts = ['curl -i', f' -X {method}', f' {url}']
|
|
211
328
|
|
|
212
329
|
for element in headers:
|
|
213
|
-
|
|
330
|
+
value = self._safe_header(element, headers[element])
|
|
331
|
+
header = f' -H "{element}: {value}"'
|
|
214
332
|
string_parts.append(header)
|
|
215
333
|
|
|
216
334
|
if data:
|
|
@@ -162,6 +162,7 @@ class ListResourceLock(command.Lister):
|
|
|
162
162
|
"combine with --all-projects (Admin only)."
|
|
163
163
|
),
|
|
164
164
|
)
|
|
165
|
+
identity_common.add_project_domain_option_to_parser(parser)
|
|
165
166
|
parser.add_argument(
|
|
166
167
|
'--user',
|
|
167
168
|
default=None,
|
|
@@ -171,6 +172,7 @@ class ListResourceLock(command.Lister):
|
|
|
171
172
|
"(Admin only)."
|
|
172
173
|
),
|
|
173
174
|
)
|
|
175
|
+
identity_common.add_user_domain_option_to_parser(parser)
|
|
174
176
|
parser.add_argument(
|
|
175
177
|
'--id',
|
|
176
178
|
metavar='<id>',
|
manilaclient/osc/v2/share.py
CHANGED
|
@@ -164,7 +164,9 @@ class CreateShare(command.ShowOne):
|
|
|
164
164
|
help=_(
|
|
165
165
|
'The share type to create the share with. If not '
|
|
166
166
|
'specified, unless creating from a snapshot, the default '
|
|
167
|
-
'share type will be used.'
|
|
167
|
+
'share type will be used. Note that share creation will '
|
|
168
|
+
'fail if no share type is specified and no default share '
|
|
169
|
+
'type is configured by the administrator.'
|
|
168
170
|
),
|
|
169
171
|
)
|
|
170
172
|
parser.add_argument(
|
|
@@ -617,6 +619,14 @@ class ListShare(command.Lister):
|
|
|
617
619
|
'Available for microversion >= 2.90'
|
|
618
620
|
),
|
|
619
621
|
)
|
|
622
|
+
parser.add_argument(
|
|
623
|
+
'--availability-zone',
|
|
624
|
+
metavar="<availability_zone>",
|
|
625
|
+
help=_(
|
|
626
|
+
'Filter shares by their availability zone. '
|
|
627
|
+
'Available for microversion >= 2.97'
|
|
628
|
+
),
|
|
629
|
+
)
|
|
620
630
|
|
|
621
631
|
return parser
|
|
622
632
|
|
|
@@ -742,6 +752,14 @@ class ListShare(command.Lister):
|
|
|
742
752
|
"available with manila API version >= 2.90"
|
|
743
753
|
)
|
|
744
754
|
|
|
755
|
+
if share_client.api_version >= api_versions.APIVersion('2.97'):
|
|
756
|
+
search_opts['availability_zone'] = parsed_args.availability_zone
|
|
757
|
+
elif getattr(parsed_args, 'availability_zone'):
|
|
758
|
+
raise exceptions.CommandError(
|
|
759
|
+
"Filtering shares by availability zone is only "
|
|
760
|
+
"available with manila API version >= 2.97"
|
|
761
|
+
)
|
|
762
|
+
|
|
745
763
|
# NOTE(vkmc) We implemented sorting and filtering in manilaclient
|
|
746
764
|
# but we will use the one provided by osc
|
|
747
765
|
if share_client.api_version >= api_versions.APIVersion("2.36"):
|
|
@@ -804,10 +822,13 @@ class ShowShare(command.ShowOne):
|
|
|
804
822
|
data['export_locations'] = export_locations
|
|
805
823
|
# Special mapping for columns to make the output easier to read:
|
|
806
824
|
# 'metadata' --> 'properties'
|
|
825
|
+
metadata = data.pop('metadata', {})
|
|
807
826
|
data.update(
|
|
808
827
|
{
|
|
809
|
-
'properties':
|
|
810
|
-
|
|
828
|
+
'properties': (
|
|
829
|
+
format_columns.DictColumn(metadata)
|
|
830
|
+
if parsed_args.formatter == 'table'
|
|
831
|
+
else metadata
|
|
811
832
|
),
|
|
812
833
|
},
|
|
813
834
|
)
|
|
@@ -1337,10 +1358,13 @@ class ShareExportLocationShow(command.ShowOne):
|
|
|
1337
1358
|
share=share, export_location=parsed_args.export_location
|
|
1338
1359
|
)
|
|
1339
1360
|
data = export_location._info
|
|
1361
|
+
metadata = data.pop('metadata', {})
|
|
1340
1362
|
data.update(
|
|
1341
1363
|
{
|
|
1342
|
-
'properties':
|
|
1343
|
-
|
|
1364
|
+
'properties': (
|
|
1365
|
+
format_columns.DictColumn(metadata)
|
|
1366
|
+
if parsed_args.formatter == 'table'
|
|
1367
|
+
else metadata
|
|
1344
1368
|
),
|
|
1345
1369
|
},
|
|
1346
1370
|
)
|
|
@@ -286,10 +286,13 @@ class ShowShareNetworkSubnet(command.ShowOne):
|
|
|
286
286
|
|
|
287
287
|
# Special mapping for columns to make the output easier to read:
|
|
288
288
|
# 'metadata' --> 'properties'
|
|
289
|
+
metadata = data.pop('metadata', {})
|
|
289
290
|
data.update(
|
|
290
291
|
{
|
|
291
|
-
'properties':
|
|
292
|
-
|
|
292
|
+
'properties': (
|
|
293
|
+
format_columns.DictColumn(metadata)
|
|
294
|
+
if parsed_args.formatter == 'table'
|
|
295
|
+
else metadata
|
|
293
296
|
),
|
|
294
297
|
},
|
|
295
298
|
)
|
|
@@ -246,11 +246,12 @@ class ShowShareNetwork(command.ShowOne):
|
|
|
246
246
|
# Special mapping for columns to make the output easier to read:
|
|
247
247
|
# 'metadata' --> 'properties'
|
|
248
248
|
for ss in data['share_network_subnets']:
|
|
249
|
+
metadata = ss.pop('metadata', {})
|
|
249
250
|
ss.update(
|
|
250
251
|
{
|
|
251
|
-
'properties': format_columns.DictColumn(
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
'properties': format_columns.DictColumn(metadata)
|
|
253
|
+
if parsed_args.formatter == 'table'
|
|
254
|
+
else metadata,
|
|
254
255
|
},
|
|
255
256
|
)
|
|
256
257
|
|
|
@@ -297,6 +297,19 @@ class ListShareReplica(command.Lister):
|
|
|
297
297
|
'availability_zone',
|
|
298
298
|
'updated_at',
|
|
299
299
|
]
|
|
300
|
+
|
|
301
|
+
if share_client.api_version >= api_versions.APIVersion("2.95"):
|
|
302
|
+
for replica in replicas:
|
|
303
|
+
replica._info.update(
|
|
304
|
+
{
|
|
305
|
+
'properties': format_columns.DictColumn(
|
|
306
|
+
replica._info.pop('metadata', {})
|
|
307
|
+
),
|
|
308
|
+
},
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
columns += ['properties']
|
|
312
|
+
|
|
300
313
|
column_headers = utils.format_column_headers(columns)
|
|
301
314
|
data = (
|
|
302
315
|
osc_utils.get_dict_properties(replica._info, columns)
|
|
@@ -347,10 +360,13 @@ class ShowShareReplica(command.ShowOne):
|
|
|
347
360
|
)
|
|
348
361
|
# Special mapping for columns to make the output easier to read:
|
|
349
362
|
# 'metadata' --> 'properties'
|
|
363
|
+
metadata = replica._info.pop('metadata', {})
|
|
350
364
|
replica._info.update(
|
|
351
365
|
{
|
|
352
|
-
'properties':
|
|
353
|
-
|
|
366
|
+
'properties': (
|
|
367
|
+
format_columns.DictColumn(metadata)
|
|
368
|
+
if parsed_args.formatter == 'table'
|
|
369
|
+
else metadata
|
|
354
370
|
),
|
|
355
371
|
},
|
|
356
372
|
)
|
|
@@ -216,10 +216,13 @@ class ShowShareSnapshot(command.ShowOne):
|
|
|
216
216
|
data['export_locations'] = locations
|
|
217
217
|
# Special mapping for columns to make the output easier to read:
|
|
218
218
|
# 'metadata' --> 'properties'
|
|
219
|
+
metadata = data.pop('metadata', {})
|
|
219
220
|
data.update(
|
|
220
221
|
{
|
|
221
|
-
'properties':
|
|
222
|
-
|
|
222
|
+
'properties': (
|
|
223
|
+
format_columns.DictColumn(metadata)
|
|
224
|
+
if parsed_args.formatter == 'table'
|
|
225
|
+
else metadata
|
|
223
226
|
),
|
|
224
227
|
},
|
|
225
228
|
)
|
|
@@ -10,13 +10,18 @@
|
|
|
10
10
|
# License for the specific language governing permissions and limitations
|
|
11
11
|
# under the License.
|
|
12
12
|
|
|
13
|
+
import hashlib
|
|
13
14
|
import re
|
|
14
15
|
from unittest import mock
|
|
15
16
|
|
|
16
17
|
import ddt
|
|
18
|
+
from keystoneauth1 import exceptions as ks_exceptions
|
|
19
|
+
from keystoneauth1 import session as ks_session
|
|
20
|
+
from oslo_serialization import jsonutils
|
|
17
21
|
import requests
|
|
18
22
|
|
|
19
23
|
import manilaclient
|
|
24
|
+
from manilaclient.common import constants
|
|
20
25
|
from manilaclient.common import httpclient
|
|
21
26
|
from manilaclient import exceptions
|
|
22
27
|
from manilaclient.tests.unit import utils
|
|
@@ -104,6 +109,7 @@ class ClientTest(utils.TestCase):
|
|
|
104
109
|
super().setUp()
|
|
105
110
|
self.max_version = manilaclient.API_MAX_VERSION
|
|
106
111
|
self.max_version_str = self.max_version.get_string()
|
|
112
|
+
self.mock_object(httpclient, 'sleep')
|
|
107
113
|
|
|
108
114
|
@ddt.data(
|
|
109
115
|
"http://manila.example.com/v2/b2d18606-2673-4965-885a-4f5a8b955b9b",
|
|
@@ -260,3 +266,215 @@ class ClientTest(utils.TestCase):
|
|
|
260
266
|
)
|
|
261
267
|
|
|
262
268
|
test_post_call()
|
|
269
|
+
|
|
270
|
+
def test_log_request_redacts_token(self):
|
|
271
|
+
cl = get_authed_client()
|
|
272
|
+
token = "token"
|
|
273
|
+
token_hash = hashlib.sha256(token.encode('utf-8')).hexdigest()
|
|
274
|
+
|
|
275
|
+
with mock.patch.object(cl._logger, 'debug') as mock_debug:
|
|
276
|
+
cl.log_request(
|
|
277
|
+
'GET', 'http://example.com/hi', {'X-Auth-Token': token}, None
|
|
278
|
+
)
|
|
279
|
+
logged = mock_debug.call_args[0][1]
|
|
280
|
+
self.assertNotIn(token_hash[:8], token[:8])
|
|
281
|
+
self.assertNotIn(f'"X-Auth-Token: {token}"', logged)
|
|
282
|
+
self.assertIn(f'"X-Auth-Token: {{SHA256}}{token_hash}"', logged)
|
|
283
|
+
|
|
284
|
+
def test_safe_header_non_sensitive(self):
|
|
285
|
+
value = httpclient.HTTPClient._safe_header(
|
|
286
|
+
'Content-Type', 'application/json'
|
|
287
|
+
)
|
|
288
|
+
self.assertEqual('application/json', value)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
@ddt.ddt
|
|
292
|
+
class SessionClientTest(utils.TestCase):
|
|
293
|
+
def setUp(self):
|
|
294
|
+
super().setUp()
|
|
295
|
+
self.max_version = manilaclient.API_MAX_VERSION
|
|
296
|
+
self.endpoint = 'http://192.0.2.10/share/v2/fake_project'
|
|
297
|
+
|
|
298
|
+
def _fake_response(self, status_code=200, text='{"hi": "there"}'):
|
|
299
|
+
resp = mock.Mock()
|
|
300
|
+
resp.status_code = status_code
|
|
301
|
+
resp.text = text
|
|
302
|
+
resp.headers = {}
|
|
303
|
+
resp.json.return_value = jsonutils.loads(text) if text else None
|
|
304
|
+
return resp
|
|
305
|
+
|
|
306
|
+
def _get_client(
|
|
307
|
+
self, retries=0, http_log_debug=False, timeout=None, response=None
|
|
308
|
+
):
|
|
309
|
+
# Build a SessionClient backed by a real keystoneauth Session whose
|
|
310
|
+
# transport-level request() is mocked, so the real adapter code path
|
|
311
|
+
# (URL handling, body->json mapping, microversion) is exercised.
|
|
312
|
+
session = ks_session.Session()
|
|
313
|
+
self.session_request = mock.Mock(
|
|
314
|
+
return_value=response or self._fake_response()
|
|
315
|
+
)
|
|
316
|
+
session.request = self.session_request
|
|
317
|
+
return httpclient.SessionClient(
|
|
318
|
+
session=session,
|
|
319
|
+
auth=mock.Mock(),
|
|
320
|
+
interface='public',
|
|
321
|
+
service_type='sharev2',
|
|
322
|
+
api_version=self.max_version,
|
|
323
|
+
user_agent=fake_user_agent,
|
|
324
|
+
endpoint_override=self.endpoint,
|
|
325
|
+
retries=retries,
|
|
326
|
+
http_log_debug=http_log_debug,
|
|
327
|
+
timeout=timeout,
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
def test_init_sets_default_microversion_and_headers(self):
|
|
331
|
+
cl = self._get_client()
|
|
332
|
+
self.assertEqual({}, cl.default_headers)
|
|
333
|
+
self.assertEqual(
|
|
334
|
+
self.max_version.get_string(), cl.default_microversion
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
def test_get_returns_parsed_body(self):
|
|
338
|
+
cl = self._get_client()
|
|
339
|
+
|
|
340
|
+
resp, body = cl.get('/shares')
|
|
341
|
+
|
|
342
|
+
self.assertEqual({'hi': 'there'}, body)
|
|
343
|
+
args, kwargs = self.session_request.call_args
|
|
344
|
+
self.assertEqual('GET', args[1])
|
|
345
|
+
self.assertTrue(kwargs['authenticated'])
|
|
346
|
+
|
|
347
|
+
def test_post_maps_body_to_json(self):
|
|
348
|
+
cl = self._get_client(
|
|
349
|
+
response=self._fake_response(
|
|
350
|
+
status_code=202, text='{"share": {"id": "x"}}'
|
|
351
|
+
)
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
resp, body = cl.post('/shares', body={'share': {'name': 'test'}})
|
|
355
|
+
|
|
356
|
+
self.assertEqual({'share': {'id': 'x'}}, body)
|
|
357
|
+
args, kwargs = self.session_request.call_args
|
|
358
|
+
self.assertEqual('POST', args[1])
|
|
359
|
+
# LegacyJsonAdapter maps the legacy ``body`` kwarg onto ``json``.
|
|
360
|
+
self.assertEqual({'share': {'name': 'test'}}, kwargs['json'])
|
|
361
|
+
|
|
362
|
+
@ddt.data('put', 'delete')
|
|
363
|
+
def test_put_and_delete_dispatch(self, method):
|
|
364
|
+
cl = self._get_client(
|
|
365
|
+
response=self._fake_response(status_code=202, text='')
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
getattr(cl, method)('/shares/1')
|
|
369
|
+
|
|
370
|
+
args, kwargs = self.session_request.call_args
|
|
371
|
+
self.assertEqual(method.upper(), args[1])
|
|
372
|
+
|
|
373
|
+
def test_request_raises_manila_exception_on_error_status(self):
|
|
374
|
+
cl = self._get_client(
|
|
375
|
+
response=self._fake_response(
|
|
376
|
+
status_code=400,
|
|
377
|
+
text='{"badRequest": {"message": "nope"}}',
|
|
378
|
+
)
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
self.assertRaises(exceptions.BadRequest, cl.get, '/shares')
|
|
382
|
+
|
|
383
|
+
def test_default_headers_are_merged_into_requests(self):
|
|
384
|
+
# Regression test: the experimental_api decorator toggles a sticky
|
|
385
|
+
# header via client.default_headers; it must reach the wire.
|
|
386
|
+
cl = self._get_client()
|
|
387
|
+
cl.default_headers[constants.EXPERIMENTAL_HTTP_HEADER] = 'true'
|
|
388
|
+
|
|
389
|
+
cl.get('/shares')
|
|
390
|
+
|
|
391
|
+
args, kwargs = self.session_request.call_args
|
|
392
|
+
self.assertEqual(
|
|
393
|
+
'true', kwargs['headers'][constants.EXPERIMENTAL_HTTP_HEADER]
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
def test_per_request_headers_override_default_headers(self):
|
|
397
|
+
cl = self._get_client()
|
|
398
|
+
cl.default_headers['X-Test'] = 'default'
|
|
399
|
+
|
|
400
|
+
cl.get('/shares', headers={'X-Test': 'override'})
|
|
401
|
+
|
|
402
|
+
args, kwargs = self.session_request.call_args
|
|
403
|
+
self.assertEqual('override', kwargs['headers']['X-Test'])
|
|
404
|
+
|
|
405
|
+
@ddt.data(
|
|
406
|
+
(
|
|
407
|
+
'http://192.0.2.10/share/v2/fake_project',
|
|
408
|
+
'http://192.0.2.10/share/',
|
|
409
|
+
),
|
|
410
|
+
('http://192.0.2.10/share/v2.22/', 'http://192.0.2.10/share/'),
|
|
411
|
+
('http://192.0.2.10:8786/v2/fake', 'http://192.0.2.10:8786/'),
|
|
412
|
+
('http://192.0.2.10/share/v1', 'http://192.0.2.10/share/'),
|
|
413
|
+
)
|
|
414
|
+
@ddt.unpack
|
|
415
|
+
def test_get_base_url(self, endpoint, expected):
|
|
416
|
+
self.assertEqual(
|
|
417
|
+
expected, httpclient.SessionClient._get_base_url(endpoint)
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
def test_get_with_base_url_strips_version_path(self):
|
|
421
|
+
cl = self._get_client()
|
|
422
|
+
|
|
423
|
+
cl.get_with_base_url('')
|
|
424
|
+
|
|
425
|
+
args, kwargs = self.session_request.call_args
|
|
426
|
+
self.assertEqual('http://192.0.2.10/share/', args[0])
|
|
427
|
+
self.assertEqual('GET', args[1])
|
|
428
|
+
|
|
429
|
+
@mock.patch.object(httpclient, 'sleep', mock.Mock())
|
|
430
|
+
def test_cs_request_retries_client_exception(self):
|
|
431
|
+
cl = self._get_client(retries=1)
|
|
432
|
+
ok = (mock.Mock(status_code=200), {'hi': 'there'})
|
|
433
|
+
with mock.patch.object(
|
|
434
|
+
cl,
|
|
435
|
+
'request',
|
|
436
|
+
side_effect=[exceptions.ClientException('boom'), ok],
|
|
437
|
+
) as mock_request:
|
|
438
|
+
resp, body = cl.get('/shares')
|
|
439
|
+
|
|
440
|
+
self.assertEqual({'hi': 'there'}, body)
|
|
441
|
+
self.assertEqual(2, mock_request.call_count)
|
|
442
|
+
|
|
443
|
+
@mock.patch.object(httpclient, 'sleep', mock.Mock())
|
|
444
|
+
def test_cs_request_retries_connection_failure(self):
|
|
445
|
+
# Regression test: transient keystoneauth connection failures are
|
|
446
|
+
# not manila ClientExceptions and must still be retried.
|
|
447
|
+
cl = self._get_client(retries=1)
|
|
448
|
+
ok = (mock.Mock(status_code=200), {'hi': 'there'})
|
|
449
|
+
with mock.patch.object(
|
|
450
|
+
cl,
|
|
451
|
+
'request',
|
|
452
|
+
side_effect=[ks_exceptions.ConnectTimeout(), ok],
|
|
453
|
+
) as mock_request:
|
|
454
|
+
resp, body = cl.get('/shares')
|
|
455
|
+
|
|
456
|
+
self.assertEqual({'hi': 'there'}, body)
|
|
457
|
+
self.assertEqual(2, mock_request.call_count)
|
|
458
|
+
|
|
459
|
+
@mock.patch.object(httpclient, 'sleep', mock.Mock())
|
|
460
|
+
def test_cs_request_raises_after_retry_limit(self):
|
|
461
|
+
cl = self._get_client(retries=1)
|
|
462
|
+
with mock.patch.object(
|
|
463
|
+
cl,
|
|
464
|
+
'request',
|
|
465
|
+
side_effect=exceptions.ClientException('boom'),
|
|
466
|
+
) as mock_request:
|
|
467
|
+
self.assertRaises(exceptions.ClientException, cl.get, '/shares')
|
|
468
|
+
|
|
469
|
+
self.assertEqual(2, mock_request.call_count)
|
|
470
|
+
|
|
471
|
+
def test_cs_request_no_retry_by_default(self):
|
|
472
|
+
cl = self._get_client(retries=0)
|
|
473
|
+
with mock.patch.object(
|
|
474
|
+
cl,
|
|
475
|
+
'request',
|
|
476
|
+
side_effect=exceptions.BadRequest('boom'),
|
|
477
|
+
) as mock_request:
|
|
478
|
+
self.assertRaises(exceptions.BadRequest, cl.get, '/shares')
|
|
479
|
+
|
|
480
|
+
self.assertEqual(1, mock_request.call_count)
|
|
@@ -75,7 +75,7 @@ class TestShare(osc_utils.TestCommand):
|
|
|
75
75
|
endpoint=osc_fakes.AUTH_URL, token=osc_fakes.AUTH_TOKEN
|
|
76
76
|
)
|
|
77
77
|
|
|
78
|
-
self.app.client_manager.identity = identity_fakes.
|
|
78
|
+
self.app.client_manager.identity = identity_fakes.FakeIdentityClient(
|
|
79
79
|
endpoint=osc_fakes.AUTH_URL, token=osc_fakes.AUTH_TOKEN
|
|
80
80
|
)
|
|
81
81
|
|
|
@@ -1184,6 +1184,7 @@ class FakeShareNetwork:
|
|
|
1184
1184
|
"network_type": "vlan",
|
|
1185
1185
|
"mtu": "1500",
|
|
1186
1186
|
"gateway": "10.0.0.1",
|
|
1187
|
+
"metadata": {"key": "value"},
|
|
1187
1188
|
},
|
|
1188
1189
|
],
|
|
1189
1190
|
}
|
|
@@ -261,6 +261,44 @@ class TestResourceLockList(TestResourceLock):
|
|
|
261
261
|
expected_data = [sorted(v) for v in self.values]
|
|
262
262
|
self.assertEqual(actual_data, expected_data)
|
|
263
263
|
|
|
264
|
+
@mock.patch.object(osc_resource_locks.identity_common, 'find_project')
|
|
265
|
+
def test_share_lock_list_project(self, mock_find_project):
|
|
266
|
+
project = mock.Mock(id='project-id')
|
|
267
|
+
mock_find_project.return_value = project
|
|
268
|
+
arglist = ['--project', 'project-name']
|
|
269
|
+
verifylist = [
|
|
270
|
+
('project', 'project-name'),
|
|
271
|
+
('project_domain', None),
|
|
272
|
+
]
|
|
273
|
+
|
|
274
|
+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
275
|
+
|
|
276
|
+
self.cmd.take_action(parsed_args)
|
|
277
|
+
|
|
278
|
+
mock_find_project.assert_called_once_with(
|
|
279
|
+
self.app.client_manager.identity, 'project-name', None
|
|
280
|
+
)
|
|
281
|
+
search_opts = self.locks_mock.list.call_args.kwargs['search_opts']
|
|
282
|
+
self.assertTrue(search_opts['all_projects'])
|
|
283
|
+
self.assertEqual(project.id, search_opts['project_id'])
|
|
284
|
+
|
|
285
|
+
@mock.patch.object(osc_resource_locks.identity_common, 'find_user')
|
|
286
|
+
def test_share_lock_list_user(self, mock_find_user):
|
|
287
|
+
user = mock.Mock(id='user-id')
|
|
288
|
+
mock_find_user.return_value = user
|
|
289
|
+
arglist = ['--user', 'user-name']
|
|
290
|
+
verifylist = [('user', 'user-name'), ('user_domain', None)]
|
|
291
|
+
|
|
292
|
+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
293
|
+
|
|
294
|
+
self.cmd.take_action(parsed_args)
|
|
295
|
+
|
|
296
|
+
mock_find_user.assert_called_once_with(
|
|
297
|
+
self.app.client_manager.identity, 'user-name', None
|
|
298
|
+
)
|
|
299
|
+
search_opts = self.locks_mock.list.call_args.kwargs['search_opts']
|
|
300
|
+
self.assertEqual(user.id, search_opts['user_id'])
|
|
301
|
+
|
|
264
302
|
|
|
265
303
|
class TestResourceLockSet(TestResourceLock):
|
|
266
304
|
def setUp(self):
|