Expose version_between as a real function

We expose version_to_string and version_match but not version_between.
openstacksdk would really like to use version_between too for matching
microversion suitability. Turn it in to a public function.

Change-Id: I710f9e1441f4caeb9bd9830f9d4a3398a71249ec
This commit is contained in:
Monty Taylor 2018-05-15 11:41:45 -05:00
parent 0bebdaf0f9
commit 9e45781eab
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
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))
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.
:param min_version: The minimum version that is acceptable.
@ -714,7 +714,7 @@ class Discover(object):
if _latest_soft_match(min_version, data['version']):
return data
# 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']):
return data
@ -1235,7 +1235,7 @@ class EndpointData(object):
else:
# `is_between` means version bounds were specified *and* the URL
# 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)
exact_match = (is_between and max_version and
max_version[0] == url_version[0])

View File

@ -395,14 +395,14 @@ class DiscoverUtils(utils.TestCase):
def test_version_between(self):
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):
self.assertFalse(discover._version_between(minver, maxver, cand))
self.assertFalse(discover.version_between(minver, maxver, cand))
def exc(excls, minver, maxver, cand):
self.assertRaises(excls,
discover._version_between, minver, maxver, cand)
discover.version_between, minver, maxver, cand)
# candidate required
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.