From 9e45781eaba457afc90650c13306c309b907f77a Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 15 May 2018 11:41:45 -0500 Subject: [PATCH] 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 --- keystoneauth1/discover.py | 6 +++--- keystoneauth1/tests/unit/test_discovery.py | 6 +++--- releasenotes/notes/version-between-b4b0bcf4cecfb9e4.yaml | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/version-between-b4b0bcf4cecfb9e4.yaml diff --git a/keystoneauth1/discover.py b/keystoneauth1/discover.py index a2d584c1..8fe84816 100644 --- a/keystoneauth1/discover.py +++ b/keystoneauth1/discover.py @@ -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]) diff --git a/keystoneauth1/tests/unit/test_discovery.py b/keystoneauth1/tests/unit/test_discovery.py index 53e63948..15490cf3 100644 --- a/keystoneauth1/tests/unit/test_discovery.py +++ b/keystoneauth1/tests/unit/test_discovery.py @@ -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) diff --git a/releasenotes/notes/version-between-b4b0bcf4cecfb9e4.yaml b/releasenotes/notes/version-between-b4b0bcf4cecfb9e4.yaml new file mode 100644 index 00000000..36620d55 --- /dev/null +++ b/releasenotes/notes/version-between-b4b0bcf4cecfb9e4.yaml @@ -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.