Browse Source

Merge "Protect against endpoint_data not existing"

Zuul 8 months ago
parent
commit
58ac4c059a
2 changed files with 26 additions and 1 deletions
  1. 3
    1
      keystoneauth1/plugin.py
  2. 23
    0
      keystoneauth1/tests/unit/test_discovery.py

+ 3
- 1
keystoneauth1/plugin.py View File

@@ -149,7 +149,9 @@ class BaseAuthPlugin(object):
149 149
         endpoint_data = self.get_endpoint_data(
150 150
             session, endpoint_override=endpoint_override,
151 151
             discover_versions=False, **kwargs)
152
-        return endpoint_data.api_version
152
+        if endpoint_data:
153
+            return endpoint_data.api_version
154
+        return None
153 155
 
154 156
     def get_endpoint(self, session, **kwargs):
155 157
         """Return an endpoint for the client.

+ 23
- 0
keystoneauth1/tests/unit/test_discovery.py View File

@@ -560,6 +560,29 @@ class VersionDataTests(utils.TestCase):
560 560
 
561 561
         self.assertTrue(mock.called_once)
562 562
 
563
+    def test_version_data_legacy_ironic_no_override(self):
564
+        """Validate detection of legacy Ironic microversion ranges."""
565
+        ironic_url = 'https://bare-metal.example.com/v1/'
566
+        self.requests_mock.get(
567
+            ironic_url, status_code=200,
568
+            json={
569
+                'id': 'v1',
570
+                'links': [{
571
+                    "href": ironic_url,
572
+                    "rel": "self"}]},
573
+            headers={
574
+                'X-OpenStack-Ironic-API-Minimum-Version': '1.3',
575
+                'X-OpenStack-Ironic-API-Maximum-Version': '1.21',
576
+            })
577
+
578
+        plugin = noauth.NoAuth()
579
+        a = adapter.Adapter(
580
+            self.session,
581
+            auth=plugin,
582
+            service_type='baremetal')
583
+
584
+        self.assertIsNone(a.get_api_major_version())
585
+
563 586
     def test_version_data_ironic_microversions(self):
564 587
         """Validate detection of Ironic microversion ranges."""
565 588
         ironic_url = 'https://bare-metal.example.com/v1/'

Loading…
Cancel
Save