Fix version negotiation
When the python client catch a 406 (Not Acceptable) error talking to an older version of the Ironic server the client will try to negotiate and fall back to the minimum supported version. Before the code was determining the minimum version by using the builtin min() method with strings but the result doesn't always come correct by doing it, e.g: In [1]: min('1.10', '1.6') Out[1]: '1.10' In [2]: min('1.9', '1.6') Out[2]: '1.6' This patch fix this problem with the version negotiation. Closes-Bug: #1475308 Change-Id: I2c756288d9590d1d18574a787601681b235fb57d
This commit is contained in:
parent
00a67148ce
commit
c3d38c921e
ironicclient
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
from distutils.version import StrictVersion
|
||||
import functools
|
||||
import json
|
||||
import logging
|
||||
@ -126,7 +127,8 @@ class VersionNegotiationMixin(object):
|
||||
% {'req': self.os_ironic_api_version,
|
||||
'min': min_ver, 'max': max_ver}))
|
||||
|
||||
negotiated_ver = min(self.os_ironic_api_version, max_ver)
|
||||
negotiated_ver = str(min(StrictVersion(self.os_ironic_api_version),
|
||||
StrictVersion(max_ver)))
|
||||
if negotiated_ver < min_ver:
|
||||
negotiated_ver = min_ver
|
||||
# server handles microversions, but doesn't support
|
||||
|
@ -116,7 +116,7 @@ class VersionNegotiationMixinTest(utils.BaseTestCase):
|
||||
autospec=True)
|
||||
def test_negotiate_version_server_newer(self, mock_pvh, mock_save_data):
|
||||
# Test newer server and older client
|
||||
mock_pvh.return_value = ('1.1', '99.99')
|
||||
mock_pvh.return_value = ('1.1', '1.10')
|
||||
mock_conn = mock.MagicMock()
|
||||
result = self.test_object.negotiate_version(mock_conn, self.response)
|
||||
self.assertEqual('1.6', result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user