Bump hacking to 3.0.0

The new version enables a lot of standard flake8 checks, so a few
fixes are required. W503 is disabled as it conflicts with W504
and the latter seems to be preferred nowadays.

Change-Id: I7c66f18be46af73a47919deef1f38c1f1d3cc741
This commit is contained in:
Dmitry Tantsur 2020-03-30 11:17:16 +02:00
parent b7cb687b5e
commit 9be0a750a9
10 changed files with 56 additions and 53 deletions

View File

@ -444,10 +444,10 @@ def from_response(response, method, url):
if isinstance(body, dict):
error = body.get(list(body)[0])
if isinstance(error, dict):
kwargs["message"] = (error.get("message") or
error.get("faultstring"))
kwargs["details"] = (error.get("details") or
str(body))
kwargs["message"] = (error.get("message")
or error.get("faultstring"))
kwargs["details"] = (error.get("details")
or str(body))
elif content_type.startswith("text/"):
kwargs["details"] = getattr(response, 'text', '')
@ -458,8 +458,8 @@ def from_response(response, method, url):
if response.status_code >= http_client.INTERNAL_SERVER_ERROR:
cls = HttpServerError
# 4XX status codes are client request errors
elif (http_client.BAD_REQUEST <= response.status_code <
http_client.INTERNAL_SERVER_ERROR):
elif (http_client.BAD_REQUEST <= response.status_code
< http_client.INTERNAL_SERVER_ERROR):
cls = HTTPClientError
else:
cls = HttpError

View File

@ -104,9 +104,9 @@ class VersionNegotiationMixin(object):
:param resp: The response object from http request
"""
def _query_server(conn):
if (self.os_ironic_api_version and
not isinstance(self.os_ironic_api_version, list) and
self.os_ironic_api_version != 'latest'):
if (self.os_ironic_api_version
and not isinstance(self.os_ironic_api_version, list)
and self.os_ironic_api_version != 'latest'):
base_version = ("/v%s" %
str(self.os_ironic_api_version).split('.')[0])
else:
@ -119,8 +119,8 @@ class VersionNegotiationMixin(object):
version_overridden = False
if (resp and hasattr(resp, 'request') and
hasattr(resp.request, 'headers')):
if (resp and hasattr(resp, 'request')
and hasattr(resp.request, 'headers')):
orig_hdr = resp.request.headers
# Get the version of the client's last request and fallback
# to the default for things like unit tests to not cause
@ -129,8 +129,8 @@ class VersionNegotiationMixin(object):
self.os_ironic_api_version)
else:
req_api_ver = self.os_ironic_api_version
if (resp and req_api_ver != self.os_ironic_api_version and
self.api_version_select_state == 'negotiated'):
if (resp and req_api_ver != self.os_ironic_api_version
and self.api_version_select_state == 'negotiated'):
# If we have a non-standard api version on the request,
# but we think we've negotiated, then the call was overridden.
# We should report the error with the called version
@ -173,10 +173,10 @@ class VersionNegotiationMixin(object):
# be supported by the requested version.
# 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
not self._must_negotiate_version()) or
(self.api_version_select_state == 'negotiated' and
version_overridden)):
if ((self.api_version_select_state == 'user'
and not self._must_negotiate_version())
or (self.api_version_select_state == 'negotiated'
and version_overridden)):
raise exc.UnsupportedVersion(textwrap.fill(
_("Requested API version %(req)s is not supported by the "
"server, client, or the requested operation is not "
@ -263,9 +263,10 @@ class VersionNegotiationMixin(object):
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)))
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)
@ -398,8 +399,8 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter):
body = resp.content
content_type = resp.headers.get('content-type', None)
status = resp.status_code
if (status in (http_client.NO_CONTENT, http_client.RESET_CONTENT) or
content_type is None):
if (status in (http_client.NO_CONTENT, http_client.RESET_CONTENT)
or content_type is None):
return resp, list()
if 'application/json' in content_type:
try:

View File

@ -16,31 +16,32 @@ from ironicclient.common.apiclient.exceptions import * # noqa
# NOTE(akurilin): This alias is left here since v.0.1.3 to support backwards
# compatibility.
InvalidEndpoint = EndpointException
CommunicationError = ConnectionRefused
HTTPBadRequest = BadRequest
HTTPInternalServerError = InternalServerError
HTTPNotFound = NotFound
HTTPServiceUnavailable = ServiceUnavailable
InvalidEndpoint = exceptions.EndpointException
CommunicationError = exceptions.ConnectionRefused
HTTPBadRequest = exceptions.BadRequest
HTTPInternalServerError = exceptions.InternalServerError
HTTPNotFound = exceptions.NotFound
HTTPServiceUnavailable = exceptions.ServiceUnavailable
class AmbiguousAuthSystem(ClientException):
class AmbiguousAuthSystem(exceptions.ClientException):
"""Could not obtain token and endpoint using provided credentials."""
pass
# Alias for backwards compatibility
AmbigiousAuthSystem = AmbiguousAuthSystem
class InvalidAttribute(ClientException):
class InvalidAttribute(exceptions.ClientException):
pass
class StateTransitionFailed(ClientException):
class StateTransitionFailed(exceptions.ClientException):
"""Failed to reach a requested provision state."""
class StateTransitionTimeout(ClientException):
class StateTransitionTimeout(exceptions.ClientException):
"""Timed out while waiting for a requested provision state."""

View File

@ -55,7 +55,7 @@ class FakeResource(object):
setattr(self, k, v)
def __repr__(self):
reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and
k != 'manager')
reprkeys = sorted(k for k in self.__dict__.keys()
if k[0] != '_' and k != 'manager')
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
return "<%s %s>" % (self.__class__.__name__, info)

View File

@ -367,7 +367,8 @@ fake_responses = {
{},
{"connectors": [CONNECTOR]},
),
}, '/v1/nodes/%s/volume/targets' % NODE1['uuid']:
},
'/v1/nodes/%s/volume/targets' % NODE1['uuid']:
{
'GET': (
{},

View File

@ -711,8 +711,8 @@ class NodeManager(base.CreateManager):
return
# Note that if expected_state == 'error' we still succeed
if (node.provision_state == 'error' or
node.provision_state.endswith(' failed')):
if (node.provision_state == 'error'
or node.provision_state.endswith(' failed')):
raise exc.StateTransitionFailed(
_('Node %(node)s failed to reach state %(state)s. '
'It\'s in state %(actual)s, and has error: %(error)s') %

View File

@ -21,7 +21,7 @@ fasteners==0.7.0
fixtures==3.0.0
flake8==2.5.5
future==0.16.0
hacking==1.0.0
hacking==3.0.0
idna==2.6
imagesize==0.7.1
iso8601==0.1.11

View File

@ -1,7 +1,7 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
hacking>=1.0.0,<1.1.0 # Apache-2.0
hacking>=3.0.0,<3.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
doc8>=0.6.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD

View File

@ -72,7 +72,7 @@ commands =
make -C doc/build/pdf
[flake8]
ignore =
ignore = W503
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools
# [H106] Don't put vim configuration in source files.
# [H203] Use assertIs(Not)None to check for None.