From ead9ecfcbca02281cbb311c51575a41628d98b78 Mon Sep 17 00:00:00 2001 From: Iury Gregory Melo Ferreira Date: Tue, 12 May 2020 12:02:32 +0200 Subject: [PATCH] Fix pep8 This patch fixes the issues that pep8 is showing in our CI. Flake8 changes in tox.ini: -Added ironic/tests/base.py and ironic/cmd/__init__.py to per-file-ignores to ignore E402. -Added E741 to ignore. Change-Id: Icf92aa186fb4b2be0d59736a56260d01a5c3279a --- ironic/cmd/__init__.py | 5 +++-- ironic/common/pxe_utils.py | 2 +- ironic/tests/base.py | 2 +- .../tests/unit/api/controllers/v1/test_allocation.py | 6 +++--- ironic/tests/unit/api/controllers/v1/test_chassis.py | 7 ++++--- ironic/tests/unit/api/controllers/v1/test_conductor.py | 6 +++--- .../unit/api/controllers/v1/test_deploy_template.py | 6 +++--- ironic/tests/unit/api/controllers/v1/test_driver.py | 7 ++++--- ironic/tests/unit/api/controllers/v1/test_node.py | 7 ++++--- ironic/tests/unit/api/controllers/v1/test_port.py | 7 ++++--- ironic/tests/unit/api/controllers/v1/test_portgroup.py | 6 +++--- ironic/tests/unit/api/controllers/v1/test_volume.py | 6 +++--- .../unit/api/controllers/v1/test_volume_connector.py | 6 +++--- .../unit/api/controllers/v1/test_volume_target.py | 6 +++--- ironic/tests/unit/test_base.py | 10 ++-------- tox.ini | 7 +++++-- 16 files changed, 49 insertions(+), 47 deletions(-) diff --git a/ironic/cmd/__init__.py b/ironic/cmd/__init__.py index bd47b11ac7..403f918d99 100644 --- a/ironic/cmd/__init__.py +++ b/ironic/cmd/__init__.py @@ -19,7 +19,7 @@ # concurrency models can cause undefined behavior and potentially API timeouts. import os -os.environ['EVENTLET_NO_GREENDNS'] = 'yes' # noqa E402 +os.environ['EVENTLET_NO_GREENDNS'] = 'yes' import eventlet @@ -27,10 +27,11 @@ eventlet.monkey_patch(os=False) # Monkey patch the original current_thread to use the up-to-date _active # global variable. See https://bugs.launchpad.net/bugs/1863021 and # https://github.com/eventlet/eventlet/issues/592 +# all the noqa below are for I202 due to 'import eventlet' above import __original_module_threading as orig_threading # noqa import threading # noqa orig_threading.current_thread.__globals__['_active'] = threading._active -from ironic.common import i18n # noqa for I202 due to 'import eventlet' above +from ironic.common import i18n # noqa i18n.install('ironic') diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py index 4e49bcc786..87c9cfab28 100644 --- a/ironic/common/pxe_utils.py +++ b/ironic/common/pxe_utils.py @@ -480,7 +480,7 @@ def dhcp_options_for_instance(task, ipxe_enabled=False, url_boot=False, LOG.warning('IPv6 is enabled and the DHCP driver appears set ' 'to a plugin aside from "neutron". Node %(name)s ' 'may not receive proper DHCPv6 provided ' - 'boot parameters.'.format(name=task.node.uuid)) + 'boot parameters.', {'name': task.node.uuid}) # NOTE(TheJulia): This was added for ISC DHCPd support, however it # appears that isc support was never added to neutron and is likely # a down stream driver. diff --git a/ironic/tests/base.py b/ironic/tests/base.py index dabcb7ba4c..e7537efbdd 100644 --- a/ironic/tests/base.py +++ b/ironic/tests/base.py @@ -28,7 +28,7 @@ import sys import tempfile import eventlet -eventlet.monkey_patch(os=False) # noqa E402 +eventlet.monkey_patch(os=False) import fixtures from ironic_lib import utils from oslo_concurrency import processutils diff --git a/ironic/tests/unit/api/controllers/v1/test_allocation.py b/ironic/tests/unit/api/controllers/v1/test_allocation.py index 8f28a3d67c..32da8eec0b 100644 --- a/ironic/tests/unit/api/controllers/v1/test_allocation.py +++ b/ironic/tests/unit/api/controllers/v1/test_allocation.py @@ -185,9 +185,9 @@ class TestListAllocations(test_api_base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], bookmark=bookmark, headers=self.headers)) def test_collection_links(self): diff --git a/ironic/tests/unit/api/controllers/v1/test_chassis.py b/ironic/tests/unit/api/controllers/v1/test_chassis.py index 61c542c735..955b18b576 100644 --- a/ironic/tests/unit/api/controllers/v1/test_chassis.py +++ b/ironic/tests/unit/api/controllers/v1/test_chassis.py @@ -190,9 +190,10 @@ class TestListChassis(test_api_base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], + bookmark=bookmark)) if public_url is not None: expected = [{'href': '%s/v1/chassis/%s' % (public_url, uuid), diff --git a/ironic/tests/unit/api/controllers/v1/test_conductor.py b/ironic/tests/unit/api/controllers/v1/test_conductor.py index 8a96a2faff..d57440c4d4 100644 --- a/ironic/tests/unit/api/controllers/v1/test_conductor.py +++ b/ironic/tests/unit/api/controllers/v1/test_conductor.py @@ -156,9 +156,9 @@ class TestListConductors(test_api_base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn('rocky.rocks', data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], bookmark=bookmark, headers=headers)) if public_url is not None: diff --git a/ironic/tests/unit/api/controllers/v1/test_deploy_template.py b/ironic/tests/unit/api/controllers/v1/test_deploy_template.py index 6d7dfcb35d..7b104f160a 100644 --- a/ironic/tests/unit/api/controllers/v1/test_deploy_template.py +++ b/ironic/tests/unit/api/controllers/v1/test_deploy_template.py @@ -216,9 +216,9 @@ class TestListDeployTemplates(BaseDeployTemplatesAPITest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], bookmark=bookmark, headers=self.headers)) def test_collection_links(self): diff --git a/ironic/tests/unit/api/controllers/v1/test_driver.py b/ironic/tests/unit/api/controllers/v1/test_driver.py index 965c390f0c..bd4bb92cc9 100644 --- a/ironic/tests/unit/api/controllers/v1/test_driver.py +++ b/ironic/tests/unit/api/controllers/v1/test_driver.py @@ -270,9 +270,10 @@ class TestListDrivers(base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(self.hw1, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], + bookmark=bookmark)) if public_url is not None: expected = [{'href': '%s/v1/drivers/%s' % (public_url, self.hw1), diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index 421175c10e..fa10846c9d 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -1103,9 +1103,10 @@ class TestListNodes(test_api_base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], + bookmark=bookmark)) if public_url is not None: expected = [{'href': '%s/v1/nodes/%s' % (public_url, uuid), diff --git a/ironic/tests/unit/api/controllers/v1/test_port.py b/ironic/tests/unit/api/controllers/v1/test_port.py index 4b67bce73a..81e5abcded 100644 --- a/ironic/tests/unit/api/controllers/v1/test_port.py +++ b/ironic/tests/unit/api/controllers/v1/test_port.py @@ -664,9 +664,10 @@ class TestListPorts(test_api_base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], + bookmark=bookmark)) if public_url is not None: expected = [{'href': '%s/v1/ports/%s' % (public_url, uuid), diff --git a/ironic/tests/unit/api/controllers/v1/test_portgroup.py b/ironic/tests/unit/api/controllers/v1/test_portgroup.py index ec761edae8..5a4b640a2d 100644 --- a/ironic/tests/unit/api/controllers/v1/test_portgroup.py +++ b/ironic/tests/unit/api/controllers/v1/test_portgroup.py @@ -288,9 +288,9 @@ class TestListPortgroups(test_api_base.BaseApiTest): self.assertIn('ports', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], bookmark=bookmark, headers=self.headers)) def test_collection_links(self): diff --git a/ironic/tests/unit/api/controllers/v1/test_volume.py b/ironic/tests/unit/api/controllers/v1/test_volume.py index 9bc50d52a5..bca3263757 100644 --- a/ironic/tests/unit/api/controllers/v1/test_volume.py +++ b/ironic/tests/unit/api/controllers/v1/test_volume.py @@ -25,9 +25,9 @@ class TestGetVolume(test_api_base.BaseApiTest): def _test_links(self, data, key, headers): self.assertIn(key, data) self.assertEqual(2, len(data[key])) - for l in data[key]: - bookmark = (l['rel'] == 'bookmark') - self.assertTrue(self.validate_link(l['href'], + for link in data[key]: + bookmark = (link['rel'] == 'bookmark') + self.assertTrue(self.validate_link(link['href'], bookmark=bookmark, headers=headers)) diff --git a/ironic/tests/unit/api/controllers/v1/test_volume_connector.py b/ironic/tests/unit/api/controllers/v1/test_volume_connector.py index a80cf93cc1..dbd930297c 100644 --- a/ironic/tests/unit/api/controllers/v1/test_volume_connector.py +++ b/ironic/tests/unit/api/controllers/v1/test_volume_connector.py @@ -233,9 +233,9 @@ class TestListVolumeConnectors(test_api_base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], bookmark=bookmark, headers=self.headers)) def test_collection_links(self): diff --git a/ironic/tests/unit/api/controllers/v1/test_volume_target.py b/ironic/tests/unit/api/controllers/v1/test_volume_target.py index d724ddffe2..dd0b25bafd 100644 --- a/ironic/tests/unit/api/controllers/v1/test_volume_target.py +++ b/ironic/tests/unit/api/controllers/v1/test_volume_target.py @@ -223,9 +223,9 @@ class TestListVolumeTargets(test_api_base.BaseApiTest): self.assertIn('links', data) self.assertEqual(2, len(data['links'])) self.assertIn(uuid, data['links'][0]['href']) - for l in data['links']: - bookmark = l['rel'] == 'bookmark' - self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, + for link in data['links']: + bookmark = link['rel'] == 'bookmark' + self.assertTrue(self.validate_link(link['href'], bookmark=bookmark, headers=self.headers)) def test_collection_links(self): diff --git a/ironic/tests/unit/test_base.py b/ironic/tests/unit/test_base.py index 28eeb69922..922e25e759 100644 --- a/ironic/tests/unit/test_base.py +++ b/ironic/tests/unit/test_base.py @@ -29,10 +29,7 @@ class BlockExecuteTestCase(base.TestCase): subprocess.check_output, utils.execute) for function_name in execute_functions: - exc = self.assertRaises( - Exception, - function_name, - ["echo", "%s" % function_name]) # noqa + exc = self.assertRaises(Exception, function_name, ["echo", "%s" % function_name]) # noqa # Have to use 'noqa' as we are raising plain Exception and we will # get H202 error in 'pep8' check. @@ -58,10 +55,7 @@ class BlockExecuteTestCase(base.TestCase): # still get an exception for a child. So in this case # ironic_lib.utils.execute() calls processutils.execute(). Make sure an # exception is raised even though we mocked processutils.execute() - exc = self.assertRaises( - Exception, - utils.execute, - "ls") # noqa + exc = self.assertRaises(Exception, utils.execute, "ls") # noqa # Have to use 'noqa' as we are raising plain Exception and we will get # H202 error in 'pep8' check. diff --git a/tox.ini b/tox.ini index 21a331f6e8..6a77071b4e 100644 --- a/tox.ini +++ b/tox.ini @@ -109,8 +109,10 @@ deps = commands = {posargs} [flake8] +# [E129] visually indented line with same indent as next logical line +# [E741] ambiguous variable name # [W503] Line break before binary operator. -ignore = E129,W503 +ignore = E129,E741,W503 filename = *.py,app.wsgi exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build import-order-style = pep8 @@ -126,6 +128,8 @@ enable-extensions=H106,H203,H204,H205,H210,H904 # TODO(rpittau) remove the ignores below when we're ready to apply H210 to # the various modules. This can be done in batches changing the filters. per-file-ignores = + ironic/cmd/__init__.py:E402 + ironic/tests/base.py:E402 ironic/tests/unit/api/*:H210 ironic/tests/unit/conductor/*:H210 ironic/tests/unit/common/*:H210 @@ -163,4 +167,3 @@ deps = [testenv:bandit] deps = -r{toxinidir}/test-requirements.txt commands = bandit -r ironic -x tests -n5 -ll -c tools/bandit.yml -