Correct discover_version response

The discover_version function was ignoring the max microversion
supported by the client.  This patch corrects its behavior to return
the most recent API version, if any, supported by both the client
and the server it is communicating with.

Closes-bug: #1826286
Change-Id: If22b72452065080b24cb1b899c5a5a88b809e986
This commit is contained in:
Brian Rosmaita 2019-04-24 21:34:28 -04:00
parent 8d6a89f502
commit 9976975342
3 changed files with 36 additions and 9 deletions

View File

@ -275,19 +275,32 @@ def discover_version(client, requested_version):
server_start_version, server_end_version = _get_server_version_range(
client)
valid_version = requested_version
if not server_start_version and not server_end_version:
msg = ("Server does not support microversions. Changing server "
"version to %(min_version)s.")
LOG.debug(msg, {"min_version": DEPRECATED_VERSION})
valid_version = APIVersion(DEPRECATED_VERSION)
else:
valid_version = _validate_requested_version(
requested_version,
server_start_version,
server_end_version)
return APIVersion(DEPRECATED_VERSION)
_validate_server_version(server_start_version, server_end_version)
# get the highest version the server can handle relative to the
# requested version
valid_version = _validate_requested_version(
requested_version,
server_start_version,
server_end_version)
# see if we need to downgrade for the client
client_max = APIVersion(MAX_VERSION)
if client_max < valid_version:
msg = _("Requested version %(requested_version)s is "
"not supported. Downgrading requested version "
"to %(actual_version)s.")
LOG.debug(msg, {
"requested_version": requested_version,
"actual_version": client_max})
valid_version = client_max
_validate_server_version(server_start_version, server_end_version)
return valid_version

View File

@ -216,7 +216,12 @@ class DiscoverVersionTestCase(utils.TestCase):
("3.1", "3.3", "3.4", "3.7", "3.3", True), # Server too new
("3.9", "3.10", "3.0", "3.3", "3.10", True), # Server too old
("3.3", "3.9", "3.7", "3.17", "3.9", False), # Requested < server
("3.5", "3.8", "3.0", "3.7", "3.8", False, "3.7"), # downgraded
# downgraded because of server:
("3.5", "3.8", "3.0", "3.7", "3.8", False, "3.7"),
# downgraded because of client:
("3.5", "3.8", "3.0", "3.9", "3.9", False, "3.8"),
# downgraded because of both:
("3.5", "3.7", "3.0", "3.8", "3.9", False, "3.7"),
("3.5", "3.5", "3.0", "3.5", "3.5", False), # Server & client same
("3.5", "3.5", "3.0", "3.5", "3.5", False, "2.0", []), # Pre-micro
("3.1", "3.11", "3.4", "3.7", "3.7", False), # Requested in range

View File

@ -0,0 +1,9 @@
---
fixes:
- |
The ``discover_version`` function in the ``cinderclient.api_versions``
module was documented to return the most recent API version supported
by both the client and the target Block Storage API endpoint, but it
was not taking into account the highest API version supported by the
client. Its behavior has been corrected in this release.
[Bug `1826286 <https://bugs.launchpad.net/bugs/1826286>`_]