python-manilaclient 6.2.0__py3-none-any.whl → 6.4.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.
Files changed (33) hide show
  1. manilaclient/api_versions.py +1 -1
  2. manilaclient/common/constants.py +1 -0
  3. manilaclient/common/httpclient.py +120 -1
  4. manilaclient/osc/v2/resource_locks.py +2 -0
  5. manilaclient/osc/v2/share.py +29 -5
  6. manilaclient/osc/v2/share_network_subnets.py +5 -2
  7. manilaclient/osc/v2/share_networks.py +4 -3
  8. manilaclient/osc/v2/share_replicas.py +5 -2
  9. manilaclient/osc/v2/share_snapshots.py +5 -2
  10. manilaclient/tests/functional/osc/base.py +4 -0
  11. manilaclient/tests/functional/osc/test_share_snapshots.py +135 -0
  12. manilaclient/tests/unit/common/test_httpclient.py +222 -0
  13. manilaclient/tests/unit/fakes.py +3 -3
  14. manilaclient/tests/unit/osc/v2/fakes.py +1 -0
  15. manilaclient/tests/unit/osc/v2/test_resource_locks.py +38 -0
  16. manilaclient/tests/unit/osc/v2/test_share.py +44 -0
  17. manilaclient/tests/unit/osc/v2/test_share_networks.py +54 -2
  18. manilaclient/tests/unit/osc/v2/test_share_type.py +18 -0
  19. manilaclient/tests/unit/v2/fakes.py +21 -0
  20. manilaclient/tests/unit/v2/test_client.py +48 -79
  21. manilaclient/tests/unit/v2/test_share_export_locations.py +53 -0
  22. manilaclient/tests/unit/v2/test_shares.py +44 -4
  23. manilaclient/v2/client.py +50 -52
  24. manilaclient/v2/shares.py +39 -2
  25. {python_manilaclient-6.2.0.dist-info → python_manilaclient-6.4.0.dist-info}/METADATA +12 -19
  26. {python_manilaclient-6.2.0.dist-info → python_manilaclient-6.4.0.dist-info}/RECORD +32 -32
  27. {python_manilaclient-6.2.0.dist-info → python_manilaclient-6.4.0.dist-info}/WHEEL +1 -1
  28. {python_manilaclient-6.2.0.dist-info → python_manilaclient-6.4.0.dist-info}/licenses/AUTHORS +6 -0
  29. python_manilaclient-6.4.0.dist-info/pbr.json +1 -0
  30. python_manilaclient-6.2.0.dist-info/pbr.json +0 -1
  31. {python_manilaclient-6.2.0.dist-info → python_manilaclient-6.4.0.dist-info}/entry_points.txt +0 -0
  32. {python_manilaclient-6.2.0.dist-info → python_manilaclient-6.4.0.dist-info}/licenses/LICENSE +0 -0
  33. {python_manilaclient-6.2.0.dist-info → python_manilaclient-6.4.0.dist-info}/top_level.txt +0 -0
@@ -29,7 +29,7 @@ from manilaclient import utils
29
29
 
30
30
  LOG = logging.getLogger(__name__)
31
31
 
32
- MAX_VERSION = '2.96'
32
+ MAX_VERSION = '2.98'
33
33
  MIN_VERSION = '2.0'
34
34
  DEPRECATED_VERSION = '1.0'
35
35
  _VERSIONED_METHOD_MAP = {}
@@ -183,3 +183,4 @@ RESOURCE_LOCK_VERSION = '2.81'
183
183
  QOS_TYPE_VERSION = '2.94'
184
184
  SHARE_MIGRATION_GRADUATION_VERSION = '2.96'
185
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,114 @@ 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
+ kwargs.setdefault('connect_retries', 1)
67
+ self._logger = logging.getLogger(__name__)
68
+ super().__init__(**kwargs)
69
+
70
+ @staticmethod
71
+ def _get_base_url(url):
72
+ """Truncates url and returns base endpoint."""
73
+ service_endpoint = parse.urlparse(url)
74
+ service_endpoint_base_path = re.search(
75
+ r'(.+?)/v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)',
76
+ service_endpoint.path,
77
+ )
78
+ base_path = (
79
+ service_endpoint_base_path.group(1)
80
+ if service_endpoint_base_path
81
+ else ''
82
+ )
83
+ base_url = service_endpoint._replace(path=base_path)
84
+ return parse.urlunparse(base_url) + '/'
85
+
86
+ def request(self, url, method, **kwargs):
87
+ kwargs.setdefault('authenticated', True)
88
+ if self.default_headers:
89
+ # Per-request headers take precedence over the sticky defaults.
90
+ headers = dict(self.default_headers)
91
+ headers.update(kwargs.get('headers') or {})
92
+ kwargs['headers'] = headers
93
+ if self.http_log_debug:
94
+ kwargs.setdefault('logger', self._logger)
95
+ if self.timeout:
96
+ kwargs.setdefault('timeout', self.timeout)
97
+ raise_exc = kwargs.pop('raise_exc', True)
98
+ resp, body = super().request(url, method, raise_exc=False, **kwargs)
99
+ if raise_exc and resp.status_code >= 400:
100
+ raise exceptions.from_response(resp, method, url)
101
+ return resp, body
102
+
103
+ def _cs_request(self, url, method, **kwargs):
104
+ attempts = 0
105
+ timeout = 1
106
+ while True:
107
+ attempts += 1
108
+ try:
109
+ return self.request(url, method, **kwargs)
110
+ except (
111
+ exceptions.ClientException,
112
+ ks_exceptions.RetriableConnectionFailure,
113
+ ) as e:
114
+ # BadRequest is a ClientException subclass; keystoneauth
115
+ # raises RetriableConnectionFailure for transient network
116
+ # errors, which are not manila ClientExceptions.
117
+ if attempts > self.retries:
118
+ raise
119
+ self._logger.debug("Request error: %s", str(e))
120
+ self._logger.debug(
121
+ "Failed attempt(%(current)s of %(total)s), "
122
+ " retrying in %(sec)s seconds",
123
+ {'current': attempts, 'total': self.retries, 'sec': timeout},
124
+ )
125
+ sleep(timeout)
126
+ timeout *= 2
127
+
128
+ def get(self, url, **kwargs):
129
+ return self._cs_request(url, 'GET', **kwargs)
130
+
131
+ def post(self, url, **kwargs):
132
+ return self._cs_request(url, 'POST', **kwargs)
133
+
134
+ def put(self, url, **kwargs):
135
+ return self._cs_request(url, 'PUT', **kwargs)
136
+
137
+ def delete(self, url, **kwargs):
138
+ return self._cs_request(url, 'DELETE', **kwargs)
139
+
140
+ def get_with_base_url(self, url, **kwargs):
141
+ base_url = self._get_base_url(self.endpoint_override)
142
+ return self._cs_request(
143
+ base_url + url,
144
+ 'GET',
145
+ endpoint_override=base_url,
146
+ **kwargs,
147
+ )
148
+
149
+
39
150
  class HTTPClient:
40
151
  """HTTP Client class used by multiple clients.
41
152
 
@@ -203,6 +314,13 @@ class HTTPClient:
203
314
  def delete(self, url, **kwargs):
204
315
  return self._cs_request(url, 'DELETE', **kwargs)
205
316
 
317
+ @staticmethod
318
+ def _safe_header(name, value):
319
+ if name.lower() in ('x-auth-token',):
320
+ token_hash = hashlib.sha256(value.encode('utf-8')).hexdigest()
321
+ value = '{SHA256}' + token_hash
322
+ return value
323
+
206
324
  def log_request(self, method, url, headers, data=None):
207
325
  if not self.http_log_debug:
208
326
  return
@@ -210,7 +328,8 @@ class HTTPClient:
210
328
  string_parts = ['curl -i', f' -X {method}', f' {url}']
211
329
 
212
330
  for element in headers:
213
- header = f' -H "{element}: {headers[element]}"'
331
+ value = self._safe_header(element, headers[element])
332
+ header = f' -H "{element}: {value}"'
214
333
  string_parts.append(header)
215
334
 
216
335
  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>',
@@ -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': format_columns.DictColumn(
810
- data.pop('metadata', {})
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': format_columns.DictColumn(
1343
- data.pop('metadata', {})
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': format_columns.DictColumn(
292
- data.pop('metadata', {})
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
- ss.pop('metadata', {})
253
- ),
252
+ 'properties': format_columns.DictColumn(metadata)
253
+ if parsed_args.formatter == 'table'
254
+ else metadata,
254
255
  },
255
256
  )
256
257
 
@@ -360,10 +360,13 @@ class ShowShareReplica(command.ShowOne):
360
360
  )
361
361
  # Special mapping for columns to make the output easier to read:
362
362
  # 'metadata' --> 'properties'
363
+ metadata = replica._info.pop('metadata', {})
363
364
  replica._info.update(
364
365
  {
365
- 'properties': format_columns.DictColumn(
366
- replica._info.pop('metadata', {})
366
+ 'properties': (
367
+ format_columns.DictColumn(metadata)
368
+ if parsed_args.formatter == 'table'
369
+ else metadata
367
370
  ),
368
371
  },
369
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': format_columns.DictColumn(
222
- data.pop('metadata', {})
222
+ 'properties': (
223
+ format_columns.DictColumn(metadata)
224
+ if parsed_args.formatter == 'table'
225
+ else metadata
223
226
  ),
224
227
  },
225
228
  )
@@ -349,6 +349,7 @@ class OSCClientTestBase(base.ClientTestBase):
349
349
  share,
350
350
  name=None,
351
351
  description=None,
352
+ properties=None,
352
353
  wait=True,
353
354
  force=None,
354
355
  add_cleanup=True,
@@ -360,6 +361,9 @@ class OSCClientTestBase(base.ClientTestBase):
360
361
 
361
362
  if description:
362
363
  cmd += f' --description {description}'
364
+ if properties:
365
+ for key, value in properties.items():
366
+ cmd += f' --property {key}={value}'
363
367
  if wait:
364
368
  cmd += ' --wait'
365
369
  if force:
@@ -13,6 +13,8 @@
13
13
  import json
14
14
 
15
15
  from manilaclient.tests.functional.osc import base
16
+ from tempest.lib.common.utils import data_utils
17
+ from tempest.lib import exceptions as tempest_exceptions
16
18
 
17
19
 
18
20
  class ShareSnapshotCLITest(base.OSCClientTestBase):
@@ -229,3 +231,136 @@ class ShareSnapshotCLITest(base.OSCClientTestBase):
229
231
  self.openstack,
230
232
  f'share snapshot delete {snapshot["id"]} --force --wait',
231
233
  )
234
+
235
+ def test_share_snapshot_create_with_metadata(self):
236
+ share = self.create_share()
237
+
238
+ snapshot_name = data_utils.rand_name("snapshot")
239
+
240
+ snapshot = self.create_snapshot(
241
+ share["id"],
242
+ name=snapshot_name,
243
+ properties={
244
+ "key1": "value1",
245
+ "key2": "value2",
246
+ },
247
+ )
248
+
249
+ self.assertEqual(share["id"], snapshot["share_id"])
250
+ self.assertEqual(snapshot_name, snapshot["name"])
251
+
252
+ show_result = self.dict_result(
253
+ 'share snapshot', f'show {snapshot["id"]}'
254
+ )
255
+
256
+ self.assertNotIn(show_result['properties'], [{}, "", None])
257
+
258
+ self.assertEqual(
259
+ "key1='value1', key2='value2'", show_result['properties']
260
+ )
261
+
262
+ def test_share_snapshot_show_metadata(self):
263
+ share = self.create_share()
264
+
265
+ snapshot_name = data_utils.rand_name("snapshot")
266
+
267
+ snapshot = self.create_snapshot(
268
+ share["id"],
269
+ name=snapshot_name,
270
+ )
271
+
272
+ self.dict_result(
273
+ 'share snapshot set',
274
+ f'{snapshot["id"]} --property key1=value1 --property key2=value2',
275
+ )
276
+
277
+ show_result = self.dict_result(
278
+ 'share snapshot show', f'{snapshot["id"]}'
279
+ )
280
+
281
+ self.assertEqual(snapshot["id"], show_result["id"])
282
+ self.assertEqual(snapshot_name, show_result["name"])
283
+
284
+ self.assertNotIn(show_result['properties'], [{}, "", None])
285
+
286
+ show_properties = dict(
287
+ item.split('=') for item in show_result['properties'].split(', ')
288
+ )
289
+
290
+ self.assertIn('key1', show_properties)
291
+ self.assertIn('key2', show_properties)
292
+ self.assertEqual("'value1'", show_properties['key1'])
293
+ self.assertEqual("'value2'", show_properties['key2'])
294
+
295
+ self.assertRaises(
296
+ tempest_exceptions.CommandFailed,
297
+ self.dict_result,
298
+ 'share snapshot show',
299
+ '00000000-0000-0000-0000-000000000000',
300
+ )
301
+
302
+ def test_share_snapshot_set_metadata(self):
303
+ share = self.create_share()
304
+
305
+ snapshot_name = data_utils.rand_name("snapshot")
306
+
307
+ snapshot = self.create_snapshot(
308
+ share["id"], name=snapshot_name, add_cleanup=True
309
+ )
310
+
311
+ self.dict_result(
312
+ 'share snapshot set',
313
+ f'{snapshot["id"]} --property key1=value1 --property key2=value2',
314
+ )
315
+
316
+ show_result = self.dict_result(
317
+ 'share snapshot show', f'{snapshot["id"]}'
318
+ )
319
+
320
+ self.assertNotIn(show_result['properties'], [{}, "", None])
321
+ show_properties = dict(
322
+ item.split('=') for item in show_result['properties'].split(', ')
323
+ )
324
+ self.assertIn('key1', show_properties)
325
+ self.assertIn('key2', show_properties)
326
+ self.assertEqual("'value1'", show_properties['key1'])
327
+ self.assertEqual("'value2'", show_properties['key2'])
328
+
329
+ self.assertRaises(
330
+ tempest_exceptions.CommandFailed,
331
+ self.openstack,
332
+ f'share snapshot set {snapshot["id"]} --property xyzzy',
333
+ )
334
+
335
+ def test_share_snapshot_unset_metadata(self):
336
+ share = self.create_share()
337
+
338
+ snapshot_name = data_utils.rand_name("snapshot")
339
+
340
+ snapshot = self.create_snapshot(
341
+ share["id"],
342
+ name=snapshot_name,
343
+ )
344
+
345
+ self.dict_result(
346
+ 'share snapshot set',
347
+ f'{snapshot["id"]} --property key1=value1 --property key2=value2',
348
+ )
349
+
350
+ self.assertRaises(
351
+ tempest_exceptions.CommandFailed,
352
+ self.dict_result,
353
+ 'share snapshot unset',
354
+ f'{snapshot["id"]} --property invalid_key',
355
+ )
356
+
357
+ self.dict_result(
358
+ 'share snapshot unset',
359
+ f'{snapshot["id"]} --property key1 --property key2',
360
+ )
361
+
362
+ show_result = self.dict_result(
363
+ 'share snapshot show', f'{snapshot["id"]}'
364
+ )
365
+
366
+ self.assertIn(show_result['properties'], [{}, "", None])