From 43c6e378f944227068ed815d84c124d6a7cc9d08 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 5 Apr 2018 11:05:26 -0500 Subject: [PATCH] Expose version status in EndpointData We collect the status when doing discovery, but it's not exposed anywhere to the use when they look at the EndpointData for an endpoint. Add a function to normalize the statuses and then add normalized status to the EndpointData object. Change-Id: Icf855d7892335b093c1083cd0106946d8911010d --- keystoneauth1/discover.py | 32 +++++++++++++++++-- keystoneauth1/tests/unit/test_discovery.py | 10 ++++++ ...pose-endpoint-status-6195a6b76d8a8de8.yaml | 6 ++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/expose-endpoint-status-6195a6b76d8a8de8.yaml diff --git a/keystoneauth1/discover.py b/keystoneauth1/discover.py index 4cc1bf12..222602d7 100644 --- a/keystoneauth1/discover.py +++ b/keystoneauth1/discover.py @@ -129,6 +129,26 @@ def get_version_data(session, url, authenticated=None): 'returned: %s' % err_text) +def normalize_status(raw_status): + """Turn a status into a canonical status value. + + If the status from the version discovery document does not match one + of the known values, it will be set to 'UNKNOWN'. + + :param str raw_status: Status value from a discovery document. + + :returns: A canonicalized version of the status. Valid values + are CURRENT, SUPPORTED, DEPRECATED, EXPERIMENTAL and UNKNOWN + :rtype: str + """ + status = raw_status.upper() + if status == 'STABLE': + status = 'CURRENT' + if status not in ('CURRENT', 'SUPPORTED', 'DEPRECATED', 'EXPERIMENTAL'): + status = 'UNKNOWN' + return status + + def normalize_version_number(version): """Turn a version representation into a tuple. @@ -459,6 +479,8 @@ class Discover(object): endpoint. May be None. :max_microversion: The maximum microversion supported by the endpoint. May be None. + :status str: A canonicalized version of the status. Valid values + are CURRENT, SUPPORTED, DEPRECATED and EXPERIMENTAL :raw_status str: The status as provided by the server :rtype: list(dict) """ @@ -525,6 +547,7 @@ class Discover(object): 'max_microversion': max_microversion, 'next_min_version': next_min_version, 'not_before': not_before, + 'status': normalize_status(v['status']), 'raw_status': v['status']}) versions.sort(key=lambda v: v['version'], reverse=reverse) @@ -688,7 +711,8 @@ class EndpointData(object): min_microversion=None, max_microversion=None, next_min_version=None, - not_before=None): + not_before=None, + status=None): self.catalog_url = catalog_url self.service_url = service_url self.service_type = service_type @@ -703,6 +727,7 @@ class EndpointData(object): self.max_microversion = max_microversion self.next_min_version = next_min_version self.not_before = not_before + self.status = status self._saved_project_id = None self._catalog_matches_version = False self._catalog_matches_exactly = False @@ -727,7 +752,9 @@ class EndpointData(object): min_microversion=self.min_microversion, max_microversion=self.max_microversion, next_min_version=self.next_min_version, - not_before=self.not_before) + not_before=self.not_before, + status=self.status, + ) # Save cached discovery object - but we don't want to # actually provide a constructor argument new_data._disc = self._disc @@ -900,6 +927,7 @@ class EndpointData(object): self.next_min_version = discovered_data['next_min_version'] self.not_before = discovered_data['not_before'] self.api_version = discovered_data['version'] + self.status = discovered_data['status'] # TODO(mordred): these next two things should be done by Discover # in versioned_data_for. diff --git a/keystoneauth1/tests/unit/test_discovery.py b/keystoneauth1/tests/unit/test_discovery.py index 949746dc..23326f7f 100644 --- a/keystoneauth1/tests/unit/test_discovery.py +++ b/keystoneauth1/tests/unit/test_discovery.py @@ -497,6 +497,7 @@ class VersionDataTests(utils.TestCase): for v in clean_data: self.assertEqual(v['version'], (3, 0)) + self.assertEqual(v['status'], 'CURRENT') self.assertEqual(v['raw_status'], 'stable') self.assertEqual(v['url'], V3_URL) @@ -536,6 +537,7 @@ class VersionDataTests(utils.TestCase): 'collection': None, 'version': (2, 2), 'url': V3_URL, + 'status': 'CURRENT', 'raw_status': 'CURRENT', }, **versions_out @@ -808,6 +810,7 @@ class VersionDataTests(utils.TestCase): 'not_before': None, 'version': (1, 0), 'url': v1_url, + 'status': 'CURRENT', 'raw_status': 'CURRENT', }, { @@ -818,6 +821,7 @@ class VersionDataTests(utils.TestCase): 'not_before': None, 'version': (2, 0), 'url': v2_url, + 'status': 'CURRENT', 'raw_status': 'CURRENT', }, { @@ -828,6 +832,7 @@ class VersionDataTests(utils.TestCase): 'not_before': u'2019-12-31', 'version': (3, 0), 'url': v3_url, + 'status': 'CURRENT', 'raw_status': 'CURRENT', }, ]) @@ -893,6 +898,7 @@ class VersionDataTests(utils.TestCase): 'not_before': None, 'version': (1, 0), 'url': v1_url, + 'status': 'SUPPORTED', 'raw_status': 'SUPPORTED', }, { @@ -903,6 +909,7 @@ class VersionDataTests(utils.TestCase): 'not_before': None, 'version': (1, 1), 'url': v1_url, + 'status': 'CURRENT', 'raw_status': 'CURRENT', }, { @@ -913,6 +920,7 @@ class VersionDataTests(utils.TestCase): 'not_before': None, 'version': (2, 0), 'url': v2_url, + 'status': 'SUPPORTED', 'raw_status': 'SUPPORTED', }, { @@ -923,6 +931,7 @@ class VersionDataTests(utils.TestCase): 'not_before': None, 'version': (2, 1), 'url': v2_url, + 'status': 'SUPPORTED', 'raw_status': 'SUPPORTED', }, { @@ -933,6 +942,7 @@ class VersionDataTests(utils.TestCase): 'not_before': None, 'version': (2, 2), 'url': v2_url, + 'status': 'CURRENT', 'raw_status': 'CURRENT', }, ]) diff --git a/releasenotes/notes/expose-endpoint-status-6195a6b76d8a8de8.yaml b/releasenotes/notes/expose-endpoint-status-6195a6b76d8a8de8.yaml new file mode 100644 index 00000000..f625c772 --- /dev/null +++ b/releasenotes/notes/expose-endpoint-status-6195a6b76d8a8de8.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Added a 'status' field to the `EndpointData` object which contains a + canonicalized version of the information in the status field of discovery + documents.