diff --git a/ironicclient/common/http.py b/ironicclient/common/http.py index 2a62a46c3..b785725a2 100644 --- a/ironicclient/common/http.py +++ b/ironicclient/common/http.py @@ -139,7 +139,7 @@ class VersionNegotiationMixin(object): negotiated_ver = str(min(StrictVersion(self.os_ironic_api_version), StrictVersion(max_ver))) - if negotiated_ver < min_ver: + if StrictVersion(negotiated_ver) < StrictVersion(min_ver): negotiated_ver = min_ver # server handles microversions, but doesn't support # the requested version, so try a negotiated version diff --git a/ironicclient/tests/unit/common/test_http.py b/ironicclient/tests/unit/common/test_http.py index 0da706aae..3ac02699e 100644 --- a/ironicclient/tests/unit/common/test_http.py +++ b/ironicclient/tests/unit/common/test_http.py @@ -183,6 +183,23 @@ class VersionNegotiationMixinTest(utils.BaseTestCase): self.assertEqual(1, mock_pvh.call_count) self.assertEqual(0, mock_save_data.call_count) + @mock.patch.object(filecache, 'save_data', autospec=True) + @mock.patch.object(http.VersionNegotiationMixin, '_parse_version_headers', + autospec=True) + def test_negotiate_version_strict_version_comparison(self, mock_pvh, + mock_save_data): + # Test version comparison with StrictVersion + max_ver = '1.10' + mock_pvh.return_value = ('1.2', max_ver) + mock_conn = mock.MagicMock() + self.test_object.os_ironic_api_version = '1.10' + result = self.test_object.negotiate_version(mock_conn, self.response) + self.assertEqual(max_ver, result) + self.assertEqual(1, mock_pvh.call_count) + host, port = http.get_server(self.test_object.endpoint) + mock_save_data.assert_called_once_with(host=host, port=port, + data=max_ver) + def test_get_server(self): host = 'ironic-host' port = '6385'