Merge "Minor changes to version negotiation logic"
This commit is contained in:
@@ -140,8 +140,7 @@ class VersionNegotiationMixin(object):
|
||||
# TODO(TheJulia): We should break this method into several parts,
|
||||
# such as a sanity check/error method.
|
||||
if (self.api_version_select_state == 'user' and
|
||||
self.os_ironic_api_version != 'latest' and
|
||||
not isinstance(self.os_ironic_api_version, list)):
|
||||
not self._must_negotiate_version()):
|
||||
raise exc.UnsupportedVersion(textwrap.fill(
|
||||
_("Requested API version %(req)s is not supported by the "
|
||||
"server, client, or the requested operation is not "
|
||||
@@ -226,6 +225,10 @@ class VersionNegotiationMixin(object):
|
||||
# NOTE(jlvillal): Declared for unit testing purposes
|
||||
raise NotImplementedError()
|
||||
|
||||
def _must_negotiate_version(self):
|
||||
return (self.api_version_select_state == 'user' and
|
||||
(self.os_ironic_api_version == 'latest' or
|
||||
isinstance(self.os_ironic_api_version, list)))
|
||||
|
||||
_RETRY_EXCEPTIONS = (exc.Conflict, exc.ServiceUnavailable,
|
||||
exc.ConnectionRefused, kexc.RetriableConnectionFailure)
|
||||
@@ -370,10 +373,7 @@ class HTTPClient(VersionNegotiationMixin):
|
||||
"""
|
||||
# NOTE(TheJulia): self.os_ironic_api_version is reset in
|
||||
# the self.negotiate_version() call if negotiation occurs.
|
||||
if (self.os_ironic_api_version and
|
||||
self.api_version_select_state == 'user' and
|
||||
(self.os_ironic_api_version == 'latest' or
|
||||
isinstance(self.os_ironic_api_version, list))):
|
||||
if self.os_ironic_api_version and self._must_negotiate_version():
|
||||
self.negotiate_version(self.session, None)
|
||||
|
||||
# Copy the kwargs so we can reuse the original in case of redirects
|
||||
@@ -586,10 +586,7 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter):
|
||||
|
||||
# NOTE(TheJulia): self.os_ironic_api_version is reset in
|
||||
# the self.negotiate_version() call if negotiation occurs.
|
||||
if (self.os_ironic_api_version and
|
||||
self.api_version_select_state == 'user' and
|
||||
(self.os_ironic_api_version == 'latest' or
|
||||
isinstance(self.os_ironic_api_version, list))):
|
||||
if self.os_ironic_api_version and self._must_negotiate_version():
|
||||
self.negotiate_version(self.session, None)
|
||||
|
||||
kwargs.setdefault('user_agent', USER_AGENT)
|
||||
|
||||
@@ -231,7 +231,7 @@ class VersionNegotiationMixinTest(utils.BaseTestCase):
|
||||
def test_negotiate_version_server_user_list(
|
||||
self, mock_pvh, mock_msr, mock_save_data):
|
||||
# have to retry with simple get
|
||||
mock_pvh.side_effect = iter([(None, None), ('1.1', '1.26')])
|
||||
mock_pvh.side_effect = [(None, None), ('1.1', '1.26')]
|
||||
mock_conn = mock.MagicMock()
|
||||
self.test_object.api_version_select_state = 'user'
|
||||
self.test_object.os_ironic_api_version = ['1.1', '1.6', '1.25',
|
||||
|
||||
@@ -49,7 +49,7 @@ class Client(object):
|
||||
if kwargs['os_ironic_api_version'] == 'latest':
|
||||
raise ValueError(
|
||||
"Invalid configuration defined. "
|
||||
"The os_ironic_api_versioncan not be set "
|
||||
"The os_ironic_api_version can not be set "
|
||||
"to 'latest' while allow_api_version_downgrade "
|
||||
"is set.")
|
||||
# NOTE(dtantsur): here we allow the HTTP client to negotiate a
|
||||
|
||||
Reference in New Issue
Block a user