Merge "Expose version_between as a real function"

This commit is contained in:
Zuul 2018-05-17 21:06:53 +00:00 committed by Gerrit Code Review
commit db5aa8b3ae
3 changed files with 11 additions and 6 deletions

View File

@ -323,7 +323,7 @@ def version_to_string(version):
return ".".join(map(_str_or_latest, version)) return ".".join(map(_str_or_latest, version))
def _version_between(min_version, max_version, candidate): def version_between(min_version, max_version, candidate):
"""Determine whether a candidate version is within a specified range. """Determine whether a candidate version is within a specified range.
:param min_version: The minimum version that is acceptable. :param min_version: The minimum version that is acceptable.
@ -714,7 +714,7 @@ class Discover(object):
if _latest_soft_match(min_version, data['version']): if _latest_soft_match(min_version, data['version']):
return data return data
# Only validate version bounds if versions were specified # Only validate version bounds if versions were specified
if min_version and max_version and _version_between( if min_version and max_version and version_between(
min_version, max_version, data['version']): min_version, max_version, data['version']):
return data return data
@ -1235,7 +1235,7 @@ class EndpointData(object):
else: else:
# `is_between` means version bounds were specified *and* the URL # `is_between` means version bounds were specified *and* the URL
# version is between them. # version is between them.
is_between = min_version and max_version and _version_between( is_between = min_version and max_version and version_between(
min_version, max_version, url_version) min_version, max_version, url_version)
exact_match = (is_between and max_version and exact_match = (is_between and max_version and
max_version[0] == url_version[0]) max_version[0] == url_version[0])

View File

@ -395,14 +395,14 @@ class DiscoverUtils(utils.TestCase):
def test_version_between(self): def test_version_between(self):
def good(minver, maxver, cand): def good(minver, maxver, cand):
self.assertTrue(discover._version_between(minver, maxver, cand)) self.assertTrue(discover.version_between(minver, maxver, cand))
def bad(minver, maxver, cand): def bad(minver, maxver, cand):
self.assertFalse(discover._version_between(minver, maxver, cand)) self.assertFalse(discover.version_between(minver, maxver, cand))
def exc(excls, minver, maxver, cand): def exc(excls, minver, maxver, cand):
self.assertRaises(excls, self.assertRaises(excls,
discover._version_between, minver, maxver, cand) discover.version_between, minver, maxver, cand)
# candidate required # candidate required
exc(ValueError, (1, 0), (1, 0), None) exc(ValueError, (1, 0), (1, 0), None)

View File

@ -0,0 +1,5 @@
---
features:
- |
Exposed ``keystoneauth1.discover.version_between`` as a public function
that can be used to determine if a given version is within a range.