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
This commit is contained in:
Iury Gregory Melo Ferreira 2020-05-12 12:02:32 +02:00
parent 855986c024
commit ead9ecfcbc
16 changed files with 49 additions and 47 deletions

View File

@ -19,7 +19,7 @@
# concurrency models can cause undefined behavior and potentially API timeouts. # concurrency models can cause undefined behavior and potentially API timeouts.
import os import os
os.environ['EVENTLET_NO_GREENDNS'] = 'yes' # noqa E402 os.environ['EVENTLET_NO_GREENDNS'] = 'yes'
import eventlet import eventlet
@ -27,10 +27,11 @@ eventlet.monkey_patch(os=False)
# Monkey patch the original current_thread to use the up-to-date _active # Monkey patch the original current_thread to use the up-to-date _active
# global variable. See https://bugs.launchpad.net/bugs/1863021 and # global variable. See https://bugs.launchpad.net/bugs/1863021 and
# https://github.com/eventlet/eventlet/issues/592 # 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 __original_module_threading as orig_threading # noqa
import threading # noqa import threading # noqa
orig_threading.current_thread.__globals__['_active'] = threading._active 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') i18n.install('ironic')

View File

@ -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 ' LOG.warning('IPv6 is enabled and the DHCP driver appears set '
'to a plugin aside from "neutron". Node %(name)s ' 'to a plugin aside from "neutron". Node %(name)s '
'may not receive proper DHCPv6 provided ' '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 # NOTE(TheJulia): This was added for ISC DHCPd support, however it
# appears that isc support was never added to neutron and is likely # appears that isc support was never added to neutron and is likely
# a down stream driver. # a down stream driver.

View File

@ -28,7 +28,7 @@ import sys
import tempfile import tempfile
import eventlet import eventlet
eventlet.monkey_patch(os=False) # noqa E402 eventlet.monkey_patch(os=False)
import fixtures import fixtures
from ironic_lib import utils from ironic_lib import utils
from oslo_concurrency import processutils from oslo_concurrency import processutils

View File

@ -185,9 +185,9 @@ class TestListAllocations(test_api_base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, self.assertTrue(self.validate_link(link['href'], bookmark=bookmark,
headers=self.headers)) headers=self.headers))
def test_collection_links(self): def test_collection_links(self):

View File

@ -190,9 +190,10 @@ class TestListChassis(test_api_base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) self.assertTrue(self.validate_link(link['href'],
bookmark=bookmark))
if public_url is not None: if public_url is not None:
expected = [{'href': '%s/v1/chassis/%s' % (public_url, uuid), expected = [{'href': '%s/v1/chassis/%s' % (public_url, uuid),

View File

@ -156,9 +156,9 @@ class TestListConductors(test_api_base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn('rocky.rocks', data['links'][0]['href']) self.assertIn('rocky.rocks', data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, self.assertTrue(self.validate_link(link['href'], bookmark=bookmark,
headers=headers)) headers=headers))
if public_url is not None: if public_url is not None:

View File

@ -216,9 +216,9 @@ class TestListDeployTemplates(BaseDeployTemplatesAPITest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, self.assertTrue(self.validate_link(link['href'], bookmark=bookmark,
headers=self.headers)) headers=self.headers))
def test_collection_links(self): def test_collection_links(self):

View File

@ -270,9 +270,10 @@ class TestListDrivers(base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(self.hw1, data['links'][0]['href']) self.assertIn(self.hw1, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) self.assertTrue(self.validate_link(link['href'],
bookmark=bookmark))
if public_url is not None: if public_url is not None:
expected = [{'href': '%s/v1/drivers/%s' % (public_url, self.hw1), expected = [{'href': '%s/v1/drivers/%s' % (public_url, self.hw1),

View File

@ -1103,9 +1103,10 @@ class TestListNodes(test_api_base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) self.assertTrue(self.validate_link(link['href'],
bookmark=bookmark))
if public_url is not None: if public_url is not None:
expected = [{'href': '%s/v1/nodes/%s' % (public_url, uuid), expected = [{'href': '%s/v1/nodes/%s' % (public_url, uuid),

View File

@ -664,9 +664,10 @@ class TestListPorts(test_api_base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark)) self.assertTrue(self.validate_link(link['href'],
bookmark=bookmark))
if public_url is not None: if public_url is not None:
expected = [{'href': '%s/v1/ports/%s' % (public_url, uuid), expected = [{'href': '%s/v1/ports/%s' % (public_url, uuid),

View File

@ -288,9 +288,9 @@ class TestListPortgroups(test_api_base.BaseApiTest):
self.assertIn('ports', data) self.assertIn('ports', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, self.assertTrue(self.validate_link(link['href'], bookmark=bookmark,
headers=self.headers)) headers=self.headers))
def test_collection_links(self): def test_collection_links(self):

View File

@ -25,9 +25,9 @@ class TestGetVolume(test_api_base.BaseApiTest):
def _test_links(self, data, key, headers): def _test_links(self, data, key, headers):
self.assertIn(key, data) self.assertIn(key, data)
self.assertEqual(2, len(data[key])) self.assertEqual(2, len(data[key]))
for l in data[key]: for link in data[key]:
bookmark = (l['rel'] == 'bookmark') bookmark = (link['rel'] == 'bookmark')
self.assertTrue(self.validate_link(l['href'], self.assertTrue(self.validate_link(link['href'],
bookmark=bookmark, bookmark=bookmark,
headers=headers)) headers=headers))

View File

@ -233,9 +233,9 @@ class TestListVolumeConnectors(test_api_base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, self.assertTrue(self.validate_link(link['href'], bookmark=bookmark,
headers=self.headers)) headers=self.headers))
def test_collection_links(self): def test_collection_links(self):

View File

@ -223,9 +223,9 @@ class TestListVolumeTargets(test_api_base.BaseApiTest):
self.assertIn('links', data) self.assertIn('links', data)
self.assertEqual(2, len(data['links'])) self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href']) self.assertIn(uuid, data['links'][0]['href'])
for l in data['links']: for link in data['links']:
bookmark = l['rel'] == 'bookmark' bookmark = link['rel'] == 'bookmark'
self.assertTrue(self.validate_link(l['href'], bookmark=bookmark, self.assertTrue(self.validate_link(link['href'], bookmark=bookmark,
headers=self.headers)) headers=self.headers))
def test_collection_links(self): def test_collection_links(self):

View File

@ -29,10 +29,7 @@ class BlockExecuteTestCase(base.TestCase):
subprocess.check_output, utils.execute) subprocess.check_output, utils.execute)
for function_name in execute_functions: for function_name in execute_functions:
exc = self.assertRaises( exc = self.assertRaises(Exception, function_name, ["echo", "%s" % function_name]) # noqa
Exception,
function_name,
["echo", "%s" % function_name]) # noqa
# Have to use 'noqa' as we are raising plain Exception and we will # Have to use 'noqa' as we are raising plain Exception and we will
# get H202 error in 'pep8' check. # 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 # still get an exception for a child. So in this case
# ironic_lib.utils.execute() calls processutils.execute(). Make sure an # ironic_lib.utils.execute() calls processutils.execute(). Make sure an
# exception is raised even though we mocked processutils.execute() # exception is raised even though we mocked processutils.execute()
exc = self.assertRaises( exc = self.assertRaises(Exception, utils.execute, "ls") # noqa
Exception,
utils.execute,
"ls") # noqa
# Have to use 'noqa' as we are raising plain Exception and we will get # Have to use 'noqa' as we are raising plain Exception and we will get
# H202 error in 'pep8' check. # H202 error in 'pep8' check.

View File

@ -109,8 +109,10 @@ deps =
commands = {posargs} commands = {posargs}
[flake8] [flake8]
# [E129] visually indented line with same indent as next logical line
# [E741] ambiguous variable name
# [W503] Line break before binary operator. # [W503] Line break before binary operator.
ignore = E129,W503 ignore = E129,E741,W503
filename = *.py,app.wsgi filename = *.py,app.wsgi
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build
import-order-style = pep8 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 # 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. # the various modules. This can be done in batches changing the filters.
per-file-ignores = per-file-ignores =
ironic/cmd/__init__.py:E402
ironic/tests/base.py:E402
ironic/tests/unit/api/*:H210 ironic/tests/unit/api/*:H210
ironic/tests/unit/conductor/*:H210 ironic/tests/unit/conductor/*:H210
ironic/tests/unit/common/*:H210 ironic/tests/unit/common/*:H210
@ -163,4 +167,3 @@ deps =
[testenv:bandit] [testenv:bandit]
deps = -r{toxinidir}/test-requirements.txt deps = -r{toxinidir}/test-requirements.txt
commands = bandit -r ironic -x tests -n5 -ll -c tools/bandit.yml commands = bandit -r ironic -x tests -n5 -ll -c tools/bandit.yml