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): if isinstance(body, dict):
error = body.get(list(body)[0]) error = body.get(list(body)[0])
if isinstance(error, dict): if isinstance(error, dict):
kwargs["message"] = (error.get("message") or kwargs["message"] = (error.get("message")
error.get("faultstring")) or error.get("faultstring"))
kwargs["details"] = (error.get("details") or kwargs["details"] = (error.get("details")
str(body)) or str(body))
elif content_type.startswith("text/"): elif content_type.startswith("text/"):
kwargs["details"] = getattr(response, '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: if response.status_code >= http_client.INTERNAL_SERVER_ERROR:
cls = HttpServerError cls = HttpServerError
# 4XX status codes are client request errors # 4XX status codes are client request errors
elif (http_client.BAD_REQUEST <= response.status_code < elif (http_client.BAD_REQUEST <= response.status_code
http_client.INTERNAL_SERVER_ERROR): < http_client.INTERNAL_SERVER_ERROR):
cls = HTTPClientError cls = HTTPClientError
else: else:
cls = HttpError cls = HttpError

View File

@ -104,9 +104,9 @@ class VersionNegotiationMixin(object):
:param resp: The response object from http request :param resp: The response object from http request
""" """
def _query_server(conn): def _query_server(conn):
if (self.os_ironic_api_version and if (self.os_ironic_api_version
not isinstance(self.os_ironic_api_version, list) and and not isinstance(self.os_ironic_api_version, list)
self.os_ironic_api_version != 'latest'): and self.os_ironic_api_version != 'latest'):
base_version = ("/v%s" % base_version = ("/v%s" %
str(self.os_ironic_api_version).split('.')[0]) str(self.os_ironic_api_version).split('.')[0])
else: else:
@ -119,8 +119,8 @@ class VersionNegotiationMixin(object):
version_overridden = False version_overridden = False
if (resp and hasattr(resp, 'request') and if (resp and hasattr(resp, 'request')
hasattr(resp.request, 'headers')): and hasattr(resp.request, 'headers')):
orig_hdr = resp.request.headers orig_hdr = resp.request.headers
# Get the version of the client's last request and fallback # Get the version of the client's last request and fallback
# to the default for things like unit tests to not cause # to the default for things like unit tests to not cause
@ -129,8 +129,8 @@ class VersionNegotiationMixin(object):
self.os_ironic_api_version) self.os_ironic_api_version)
else: else:
req_api_ver = self.os_ironic_api_version req_api_ver = self.os_ironic_api_version
if (resp and req_api_ver != self.os_ironic_api_version and if (resp and req_api_ver != self.os_ironic_api_version
self.api_version_select_state == 'negotiated'): and self.api_version_select_state == 'negotiated'):
# If we have a non-standard api version on the request, # If we have a non-standard api version on the request,
# but we think we've negotiated, then the call was overridden. # but we think we've negotiated, then the call was overridden.
# We should report the error with the called version # We should report the error with the called version
@ -173,10 +173,10 @@ class VersionNegotiationMixin(object):
# be supported by the requested version. # be supported by the requested version.
# TODO(TheJulia): We should break this method into several parts, # TODO(TheJulia): We should break this method into several parts,
# such as a sanity check/error method. # such as a sanity check/error method.
if ((self.api_version_select_state == 'user' and if ((self.api_version_select_state == 'user'
not self._must_negotiate_version()) or and not self._must_negotiate_version())
(self.api_version_select_state == 'negotiated' and or (self.api_version_select_state == 'negotiated'
version_overridden)): and version_overridden)):
raise exc.UnsupportedVersion(textwrap.fill( raise exc.UnsupportedVersion(textwrap.fill(
_("Requested API version %(req)s is not supported by the " _("Requested API version %(req)s is not supported by the "
"server, client, or the requested operation is not " "server, client, or the requested operation is not "
@ -263,9 +263,10 @@ class VersionNegotiationMixin(object):
raise NotImplementedError() raise NotImplementedError()
def _must_negotiate_version(self): def _must_negotiate_version(self):
return (self.api_version_select_state == 'user' and return (self.api_version_select_state == 'user'
(self.os_ironic_api_version == 'latest' or and (self.os_ironic_api_version == 'latest'
isinstance(self.os_ironic_api_version, list))) or isinstance(self.os_ironic_api_version, list)))
_RETRY_EXCEPTIONS = (exc.Conflict, exc.ServiceUnavailable, _RETRY_EXCEPTIONS = (exc.Conflict, exc.ServiceUnavailable,
exc.ConnectionRefused, kexc.RetriableConnectionFailure) exc.ConnectionRefused, kexc.RetriableConnectionFailure)
@ -398,8 +399,8 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter):
body = resp.content body = resp.content
content_type = resp.headers.get('content-type', None) content_type = resp.headers.get('content-type', None)
status = resp.status_code status = resp.status_code
if (status in (http_client.NO_CONTENT, http_client.RESET_CONTENT) or if (status in (http_client.NO_CONTENT, http_client.RESET_CONTENT)
content_type is None): or content_type is None):
return resp, list() return resp, list()
if 'application/json' in content_type: if 'application/json' in content_type:
try: 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 # NOTE(akurilin): This alias is left here since v.0.1.3 to support backwards
# compatibility. # compatibility.
InvalidEndpoint = EndpointException InvalidEndpoint = exceptions.EndpointException
CommunicationError = ConnectionRefused CommunicationError = exceptions.ConnectionRefused
HTTPBadRequest = BadRequest HTTPBadRequest = exceptions.BadRequest
HTTPInternalServerError = InternalServerError HTTPInternalServerError = exceptions.InternalServerError
HTTPNotFound = NotFound HTTPNotFound = exceptions.NotFound
HTTPServiceUnavailable = ServiceUnavailable HTTPServiceUnavailable = exceptions.ServiceUnavailable
class AmbiguousAuthSystem(ClientException): class AmbiguousAuthSystem(exceptions.ClientException):
"""Could not obtain token and endpoint using provided credentials.""" """Could not obtain token and endpoint using provided credentials."""
pass pass
# Alias for backwards compatibility # Alias for backwards compatibility
AmbigiousAuthSystem = AmbiguousAuthSystem AmbigiousAuthSystem = AmbiguousAuthSystem
class InvalidAttribute(ClientException): class InvalidAttribute(exceptions.ClientException):
pass pass
class StateTransitionFailed(ClientException): class StateTransitionFailed(exceptions.ClientException):
"""Failed to reach a requested provision state.""" """Failed to reach a requested provision state."""
class StateTransitionTimeout(ClientException): class StateTransitionTimeout(exceptions.ClientException):
"""Timed out while waiting for a requested provision state.""" """Timed out while waiting for a requested provision state."""

View File

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

View File

@ -172,7 +172,7 @@ class DriverManagerTest(testtools.TestCase):
'driver_name': 'driver_name', 'driver_name': 'driver_name',
'method': 'method', 'method': 'method',
'args': vendor_passthru_args 'args': vendor_passthru_args
} }
final_path = 'driver_name/vendor_passthru/method' final_path = 'driver_name/vendor_passthru/method'
for http_method in ('POST', 'PUT', 'PATCH'): for http_method in ('POST', 'PUT', 'PATCH'):
@ -189,7 +189,7 @@ class DriverManagerTest(testtools.TestCase):
'driver_name': 'driver_name', 'driver_name': 'driver_name',
'method': 'method', 'method': 'method',
'http_method': 'GET', 'http_method': 'GET',
} }
final_path = 'driver_name/vendor_passthru/method' final_path = 'driver_name/vendor_passthru/method'
self.mgr.vendor_passthru(**kwargs) self.mgr.vendor_passthru(**kwargs)
@ -201,7 +201,7 @@ class DriverManagerTest(testtools.TestCase):
'driver_name': 'driver_name', 'driver_name': 'driver_name',
'method': 'method', 'method': 'method',
'http_method': 'DELETE', 'http_method': 'DELETE',
} }
final_path = 'driver_name/vendor_passthru/method' final_path = 'driver_name/vendor_passthru/method'
self.mgr.vendor_passthru(**kwargs) self.mgr.vendor_passthru(**kwargs)
@ -213,7 +213,7 @@ class DriverManagerTest(testtools.TestCase):
'driver_name': 'driver_name', 'driver_name': 'driver_name',
'method': 'method', 'method': 'method',
'http_method': 'UNKNOWN', 'http_method': 'UNKNOWN',
} }
self.assertRaises(exc.InvalidAttribute, self.mgr.vendor_passthru, self.assertRaises(exc.InvalidAttribute, self.mgr.vendor_passthru,
**kwargs) **kwargs)

View File

@ -367,7 +367,8 @@ fake_responses = {
{}, {},
{"connectors": [CONNECTOR]}, {"connectors": [CONNECTOR]},
), ),
}, '/v1/nodes/%s/volume/targets' % NODE1['uuid']: },
'/v1/nodes/%s/volume/targets' % NODE1['uuid']:
{ {
'GET': ( 'GET': (
{}, {},
@ -1594,7 +1595,7 @@ class NodeManagerTest(testtools.TestCase):
'node_id': 'node_uuid', 'node_id': 'node_uuid',
'method': 'method', 'method': 'method',
'args': vendor_passthru_args 'args': vendor_passthru_args
} }
final_path = 'node_uuid/vendor_passthru/method' final_path = 'node_uuid/vendor_passthru/method'
for http_method in ('POST', 'PUT', 'PATCH'): for http_method in ('POST', 'PUT', 'PATCH'):
@ -1611,7 +1612,7 @@ class NodeManagerTest(testtools.TestCase):
'node_id': 'node_uuid', 'node_id': 'node_uuid',
'method': 'method', 'method': 'method',
'http_method': 'GET', 'http_method': 'GET',
} }
final_path = 'node_uuid/vendor_passthru/method' final_path = 'node_uuid/vendor_passthru/method'
self.mgr.vendor_passthru(**kwargs) self.mgr.vendor_passthru(**kwargs)
@ -1623,7 +1624,7 @@ class NodeManagerTest(testtools.TestCase):
'node_id': 'node_uuid', 'node_id': 'node_uuid',
'method': 'method', 'method': 'method',
'http_method': 'DELETE', 'http_method': 'DELETE',
} }
final_path = 'node_uuid/vendor_passthru/method' final_path = 'node_uuid/vendor_passthru/method'
self.mgr.vendor_passthru(**kwargs) self.mgr.vendor_passthru(**kwargs)
@ -1635,7 +1636,7 @@ class NodeManagerTest(testtools.TestCase):
'node_id': 'node_uuid', 'node_id': 'node_uuid',
'method': 'method', 'method': 'method',
'http_method': 'UNKNOWN', 'http_method': 'UNKNOWN',
} }
self.assertRaises(exc.InvalidAttribute, self.mgr.vendor_passthru, self.assertRaises(exc.InvalidAttribute, self.mgr.vendor_passthru,
**kwargs) **kwargs)
@ -1643,7 +1644,7 @@ class NodeManagerTest(testtools.TestCase):
def test_vif_list(self, _list_mock): def test_vif_list(self, _list_mock):
kwargs = { kwargs = {
'node_ident': NODE1['uuid'], 'node_ident': NODE1['uuid'],
} }
final_path = '/v1/nodes/%s/vifs' % NODE1['uuid'] final_path = '/v1/nodes/%s/vifs' % NODE1['uuid']
self.mgr.vif_list(**kwargs) self.mgr.vif_list(**kwargs)
@ -1654,7 +1655,7 @@ class NodeManagerTest(testtools.TestCase):
kwargs = { kwargs = {
'node_ident': NODE1['uuid'], 'node_ident': NODE1['uuid'],
'vif_id': 'vif_id', 'vif_id': 'vif_id',
} }
final_path = '%s/vifs' % NODE1['uuid'] final_path = '%s/vifs' % NODE1['uuid']
self.mgr.vif_attach(**kwargs) self.mgr.vif_attach(**kwargs)
@ -1667,7 +1668,7 @@ class NodeManagerTest(testtools.TestCase):
'node_ident': NODE1['uuid'], 'node_ident': NODE1['uuid'],
'vif_id': 'vif_id', 'vif_id': 'vif_id',
'foo': 'bar', 'foo': 'bar',
} }
final_path = '%s/vifs' % NODE1['uuid'] final_path = '%s/vifs' % NODE1['uuid']
self.mgr.vif_attach(**kwargs) self.mgr.vif_attach(**kwargs)
@ -1682,7 +1683,7 @@ class NodeManagerTest(testtools.TestCase):
'node_ident': NODE1['uuid'], 'node_ident': NODE1['uuid'],
'vif_id': 'vif_id', 'vif_id': 'vif_id',
'id': 'bar', 'id': 'bar',
} }
self.assertRaises( self.assertRaises(
exc.InvalidAttribute, exc.InvalidAttribute,
self.mgr.vif_attach, **kwargs) self.mgr.vif_attach, **kwargs)
@ -1692,7 +1693,7 @@ class NodeManagerTest(testtools.TestCase):
kwargs = { kwargs = {
'node_ident': NODE1['uuid'], 'node_ident': NODE1['uuid'],
'vif_id': 'vif_id', 'vif_id': 'vif_id',
} }
final_path = '%s/vifs/vif_id' % NODE1['uuid'] final_path = '%s/vifs/vif_id' % NODE1['uuid']
self.mgr.vif_detach(**kwargs) self.mgr.vif_detach(**kwargs)

View File

@ -711,8 +711,8 @@ class NodeManager(base.CreateManager):
return return
# Note that if expected_state == 'error' we still succeed # Note that if expected_state == 'error' we still succeed
if (node.provision_state == 'error' or if (node.provision_state == 'error'
node.provision_state.endswith(' failed')): or node.provision_state.endswith(' failed')):
raise exc.StateTransitionFailed( raise exc.StateTransitionFailed(
_('Node %(node)s failed to reach state %(state)s. ' _('Node %(node)s failed to reach state %(state)s. '
'It\'s in state %(actual)s, and has error: %(error)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 fixtures==3.0.0
flake8==2.5.5 flake8==2.5.5
future==0.16.0 future==0.16.0
hacking==1.0.0 hacking==3.0.0
idna==2.6 idna==2.6
imagesize==0.7.1 imagesize==0.7.1
iso8601==0.1.11 iso8601==0.1.11

View File

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

View File

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