Merge "Expose version status in EndpointData"

This commit is contained in:
Zuul 2018-04-25 16:40:07 +00:00 committed by Gerrit Code Review
commit 33ccb19557
3 changed files with 46 additions and 2 deletions

View File

@ -129,6 +129,26 @@ def get_version_data(session, url, authenticated=None):
'returned: %s' % err_text) '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): def normalize_version_number(version):
"""Turn a version representation into a tuple. """Turn a version representation into a tuple.
@ -459,6 +479,8 @@ class Discover(object):
endpoint. May be None. endpoint. May be None.
:max_microversion: The maximum microversion supported by the :max_microversion: The maximum microversion supported by the
endpoint. May be None. 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 :raw_status str: The status as provided by the server
:rtype: list(dict) :rtype: list(dict)
""" """
@ -525,6 +547,7 @@ class Discover(object):
'max_microversion': max_microversion, 'max_microversion': max_microversion,
'next_min_version': next_min_version, 'next_min_version': next_min_version,
'not_before': not_before, 'not_before': not_before,
'status': normalize_status(v['status']),
'raw_status': v['status']}) 'raw_status': v['status']})
versions.sort(key=lambda v: v['version'], reverse=reverse) versions.sort(key=lambda v: v['version'], reverse=reverse)
@ -688,7 +711,8 @@ class EndpointData(object):
min_microversion=None, min_microversion=None,
max_microversion=None, max_microversion=None,
next_min_version=None, next_min_version=None,
not_before=None): not_before=None,
status=None):
self.catalog_url = catalog_url self.catalog_url = catalog_url
self.service_url = service_url self.service_url = service_url
self.service_type = service_type self.service_type = service_type
@ -703,6 +727,7 @@ class EndpointData(object):
self.max_microversion = max_microversion self.max_microversion = max_microversion
self.next_min_version = next_min_version self.next_min_version = next_min_version
self.not_before = not_before self.not_before = not_before
self.status = status
self._saved_project_id = None self._saved_project_id = None
self._catalog_matches_version = False self._catalog_matches_version = False
self._catalog_matches_exactly = False self._catalog_matches_exactly = False
@ -727,7 +752,9 @@ class EndpointData(object):
min_microversion=self.min_microversion, min_microversion=self.min_microversion,
max_microversion=self.max_microversion, max_microversion=self.max_microversion,
next_min_version=self.next_min_version, 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 # Save cached discovery object - but we don't want to
# actually provide a constructor argument # actually provide a constructor argument
new_data._disc = self._disc new_data._disc = self._disc
@ -900,6 +927,7 @@ class EndpointData(object):
self.next_min_version = discovered_data['next_min_version'] self.next_min_version = discovered_data['next_min_version']
self.not_before = discovered_data['not_before'] self.not_before = discovered_data['not_before']
self.api_version = discovered_data['version'] self.api_version = discovered_data['version']
self.status = discovered_data['status']
# TODO(mordred): these next two things should be done by Discover # TODO(mordred): these next two things should be done by Discover
# in versioned_data_for. # in versioned_data_for.

View File

@ -497,6 +497,7 @@ class VersionDataTests(utils.TestCase):
for v in clean_data: for v in clean_data:
self.assertEqual(v['version'], (3, 0)) self.assertEqual(v['version'], (3, 0))
self.assertEqual(v['status'], 'CURRENT')
self.assertEqual(v['raw_status'], 'stable') self.assertEqual(v['raw_status'], 'stable')
self.assertEqual(v['url'], V3_URL) self.assertEqual(v['url'], V3_URL)
@ -536,6 +537,7 @@ class VersionDataTests(utils.TestCase):
'collection': None, 'collection': None,
'version': (2, 2), 'version': (2, 2),
'url': V3_URL, 'url': V3_URL,
'status': 'CURRENT',
'raw_status': 'CURRENT', 'raw_status': 'CURRENT',
}, },
**versions_out **versions_out
@ -808,6 +810,7 @@ class VersionDataTests(utils.TestCase):
'not_before': None, 'not_before': None,
'version': (1, 0), 'version': (1, 0),
'url': v1_url, 'url': v1_url,
'status': 'CURRENT',
'raw_status': 'CURRENT', 'raw_status': 'CURRENT',
}, },
{ {
@ -818,6 +821,7 @@ class VersionDataTests(utils.TestCase):
'not_before': None, 'not_before': None,
'version': (2, 0), 'version': (2, 0),
'url': v2_url, 'url': v2_url,
'status': 'CURRENT',
'raw_status': 'CURRENT', 'raw_status': 'CURRENT',
}, },
{ {
@ -828,6 +832,7 @@ class VersionDataTests(utils.TestCase):
'not_before': u'2019-12-31', 'not_before': u'2019-12-31',
'version': (3, 0), 'version': (3, 0),
'url': v3_url, 'url': v3_url,
'status': 'CURRENT',
'raw_status': 'CURRENT', 'raw_status': 'CURRENT',
}, },
]) ])
@ -893,6 +898,7 @@ class VersionDataTests(utils.TestCase):
'not_before': None, 'not_before': None,
'version': (1, 0), 'version': (1, 0),
'url': v1_url, 'url': v1_url,
'status': 'SUPPORTED',
'raw_status': 'SUPPORTED', 'raw_status': 'SUPPORTED',
}, },
{ {
@ -903,6 +909,7 @@ class VersionDataTests(utils.TestCase):
'not_before': None, 'not_before': None,
'version': (1, 1), 'version': (1, 1),
'url': v1_url, 'url': v1_url,
'status': 'CURRENT',
'raw_status': 'CURRENT', 'raw_status': 'CURRENT',
}, },
{ {
@ -913,6 +920,7 @@ class VersionDataTests(utils.TestCase):
'not_before': None, 'not_before': None,
'version': (2, 0), 'version': (2, 0),
'url': v2_url, 'url': v2_url,
'status': 'SUPPORTED',
'raw_status': 'SUPPORTED', 'raw_status': 'SUPPORTED',
}, },
{ {
@ -923,6 +931,7 @@ class VersionDataTests(utils.TestCase):
'not_before': None, 'not_before': None,
'version': (2, 1), 'version': (2, 1),
'url': v2_url, 'url': v2_url,
'status': 'SUPPORTED',
'raw_status': 'SUPPORTED', 'raw_status': 'SUPPORTED',
}, },
{ {
@ -933,6 +942,7 @@ class VersionDataTests(utils.TestCase):
'not_before': None, 'not_before': None,
'version': (2, 2), 'version': (2, 2),
'url': v2_url, 'url': v2_url,
'status': 'CURRENT',
'raw_status': 'CURRENT', 'raw_status': 'CURRENT',
}, },
]) ])

View File

@ -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.