Browse Source

Merge "Fixed minor review comments and updated docs"

Jenkins 1 year ago
parent
commit
353b926042

+ 53
- 3
doc/source/using-sessions.rst View File

@@ -375,14 +375,64 @@ the ``microversion`` parameter of the `request` method on the
375 375
 to pass the appropriate header to the service informing the service of the
376 376
 microversion the user wants.
377 377
 
378
+.. code-block:: python
379
+
380
+    resp = session.get('/volumes',
381
+                       microversion='3.15',
382
+                       endpoint_filter={'service_type': 'volume',
383
+                                        'interface': 'public',
384
+                                        'min_version': '3',
385
+                                        'max_version': 'latest'})
386
+
378 387
 If the user is using a :class:`keystoneauth1.adapter.Adapter`, the
379 388
 `service_type`, which is a part of the data sent in the microversion header,
380 389
 will be taken from the Adapter's `service_type`.
381 390
 
391
+.. code-block:: python
392
+
393
+    adapter = keystoneauth1.adapter.Adapter(
394
+        session=session,
395
+        service_type='compute',
396
+        interface='public',
397
+        min_version='2.1')
398
+    response = adapter.get('/servers', microversion='2.38')
399
+
400
+The user can also provide a ``default_microversion`` parameter to the Adapter
401
+constructor which will be used on all requests where an explicit microversion
402
+is not requested.
403
+
404
+.. code-block:: python
405
+
406
+    adapter = keystoneauth1.adapter.Adapter(
407
+        session=session,
408
+        service_type='compute',
409
+        interface='public',
410
+        min_version='2.1',
411
+        default_microversion='2.38')
412
+    response = adapter.get('/servers')
413
+
382 414
 If the user is using a :class:`keystoneauth1.session.Session`, the
383
-`service_type` will be taken from the `service_type` in `endpoint_filter`
384
-or alternately from the parameter `microversion_service_type` in case there
385
-is no `service_type` in `endpoint_filter` for some reason.
415
+`service_type` will be taken from the `service_type` in `endpoint_filter`.
416
+
417
+If the `service_type` is the incorrect value to use for the microversion header
418
+for the service in question, the parameter `microversion_service_type` can be
419
+given. For instance, although keystoneauth already knows about Cinder, the
420
+`service_type` for Cinder is ``block-storage`` but the microversion header
421
+expects ``volume``.
422
+
423
+.. code-block:: python
424
+
425
+    # Interactions with cinder do not need to explicitly override the
426
+    # microversion_service_type - it is only being used as an example for the
427
+    # use of the parameter.
428
+    resp = session.get('/volumes',
429
+                       microversion='3.15',
430
+                       microversion_service_type='volume',
431
+                       endpoint_filter={'service_type': 'block-storage',
432
+                                        'interface': 'public',
433
+                                        'min_version': '3',
434
+                                        'max_version': 'latest'})
435
+
386 436
 
387 437
 .. _API-WG Specs: http://specs.openstack.org/openstack/api-wg/
388 438
 .. _Consuming the Catalog: http://specs.openstack.org/openstack/api-wg/guidelines/consuming-catalog.html

+ 9
- 13
keystoneauth1/session.py View File

@@ -449,7 +449,7 @@ class Session(object):
449 449
                     " service_type information is available. Either provide a"
450 450
                     " service_type in endpoint_filter or pass"
451 451
                     " microversion_service_type as an argument.".format(
452
-                        microversion=discover.version_to_string(microversion)))
452
+                        microversion=microversion))
453 453
 
454 454
         # TODO(mordred) cinder uses volume in its microversion header. This
455 455
         # logic should be handled in the future by os-service-types but for
@@ -457,17 +457,13 @@ class Session(object):
457 457
         if (service_type.startswith('volume')
458 458
                 or service_type == 'block-storage'):
459 459
             service_type = 'volume'
460
-        # TODO(mordred) Fix this as part of the service-types generalized
461
-        # fix. Ironic does not yet support the new version header
462
-        if service_type != 'baremetal':
463
-            headers.setdefault('OpenStack-API-Version',
464
-                               '{service_type} {microversion}'.format(
465
-                                   service_type=service_type,
466
-                                   microversion=microversion))
460
+        headers.setdefault('OpenStack-API-Version',
461
+                           '{service_type} {microversion}'.format(
462
+                               service_type=service_type,
463
+                               microversion=microversion))
467 464
         header_names = _mv_legacy_headers_for_service(service_type)
468 465
         for h in header_names:
469 466
             headers.setdefault(h, microversion)
470
-        return headers
471 467
 
472 468
     @positional()
473 469
     def request(self, url, method, json=None, original_ip=None,
@@ -551,10 +547,10 @@ class Session(object):
551 547
         :param str microversion_service_type: The service_type to be sent in
552 548
                        the microversion header, if a microversion is given.
553 549
                        Defaults to the value of service_type from
554
-                       endpoint_filter if one exists. If endpoint_filter
555
-                       does not have a service_type, microversion is given and
556
-                       microversion_service_type is not provided, an exception
557
-                       will be raised.
550
+                       endpoint_filter if one exists. If endpoint_filter is not
551
+                       provided or does not have a service_type, microversion
552
+                       is given and microversion_service_type is not provided,
553
+                       an exception will be raised.
558 554
         :param kwargs: any other parameter that can be passed to
559 555
                        :meth:`requests.Session.request` (such as `headers`).
560 556
                        Except:

+ 3
- 1
keystoneauth1/tests/unit/test_session.py View File

@@ -144,8 +144,9 @@ class SessionTests(utils.TestCase):
144 144
         headers = {}
145 145
         client_session.Session._set_microversion_headers(
146 146
             headers, '2.30', 'baremetal', None)
147
+        self.assertEqual(headers['OpenStack-API-Version'], 'baremetal 2.30')
147 148
         self.assertEqual(headers['X-OpenStack-Ironic-API-Version'], '2.30')
148
-        self.assertEqual(len(headers.keys()), 1)
149
+        self.assertEqual(len(headers.keys()), 2)
149 150
 
150 151
         # volumev2 service-type - volume microversion
151 152
         headers = {}
@@ -209,6 +210,7 @@ class SessionTests(utils.TestCase):
209 210
 
210 211
         self.assertTrue(resp.ok)
211 212
         self.assertRequestHeaderEqual('OpenStack-API-Version', 'compute 2.30')
213
+        self.assertRequestHeaderEqual('X-OpenStack-Nova-API-Version', '2.30')
212 214
 
213 215
     def test_user_agent(self):
214 216
         session = client_session.Session()

+ 6
- 0
releasenotes/notes/microversion-header-support-901acd820a21d788.yaml View File

@@ -0,0 +1,6 @@
1
+---
2
+features:
3
+  - Added support for specifying a microversion to use on
4
+    a given REST request. The microversion can be specified
5
+    on session request calls and a default can be set on
6
+    Adapter construction.

Loading…
Cancel
Save