Resolve pep8 E402 errors and no longer ignore E402

Fix the pep8 E402 (Module level import not at top of file) errors.

For the Alembic files move the definitions of 'revision' and
'down_revision' below the imports. This is now done in Alembic [1]

For other files fix as needed by moving the imports or lines before
the imports.

In a few cases add a "# noqa E402" to whitelist the issue.

[1] dc2aae0374

Change-Id: I48c96d5da0cb747b3ca3fceea9b4ffa85a9ebe22
This commit is contained in:
John L. Villalovos 2018-04-10 17:29:33 -07:00
parent ca91d4d871
commit 6b91ba21df
41 changed files with 126 additions and 134 deletions

View File

@ -30,6 +30,11 @@ import sys
import openstackdocstheme
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
from ironic.version import version_info
html_theme = 'openstackdocs'
html_theme_path = [openstackdocstheme.get_html_theme_path()]
html_theme_options = {
@ -66,11 +71,6 @@ master_doc = 'index'
project = u'Ironic API Reference'
copyright = u'OpenStack Foundation'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
from ironic.version import version_info
# The full version, including alpha/beta/rc tags.
release = version_info.release_string()
# The short X.Y version.

View File

@ -19,7 +19,7 @@
# concurrency models can cause undefined behavior and potentially API timeouts.
import os
os.environ['EVENTLET_NO_GREENDNS'] = 'yes'
os.environ['EVENTLET_NO_GREENDNS'] = 'yes' # noqa E402
import eventlet

View File

@ -18,13 +18,13 @@ Create Date: 2016-07-06 17:43:55.846837
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '10b163d4481e'
down_revision = 'e294876e8028'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('ports', sa.Column('internal_info',

View File

@ -18,13 +18,13 @@ Create Date: 2016-02-25 11:25:29.836535
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1a59178ebdf6'
down_revision = 'daa1ba02d98'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('volume_targets',

View File

@ -18,13 +18,13 @@ Create Date: 2016-07-26 10:33:22.830739
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1d6951876d68'
down_revision = '493d8f27f235'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('storage_interface',

View File

@ -18,13 +18,13 @@ Create Date: 2015-02-26 10:46:46.861927
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1e1d5ace7dc6'
down_revision = '3ae36a5f5131'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('inspection_started_at',

View File

@ -18,13 +18,13 @@ Create Date: 2014-02-19 13:45:30.150632
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '21b331f883ef'
down_revision = '2581ebaf0cb2'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('provision_updated_at', sa.DateTime(),

View File

@ -18,13 +18,13 @@ Create Date: 2016-12-12 15:17:22.065056
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2353895ecfae'
down_revision = '1d6951876d68'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('conductor_hardware_interfaces',

View File

@ -18,13 +18,13 @@ Create Date: 2014-10-15 23:00:43.164061
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '242cc6a923b3'
down_revision = '487deb87cc9d'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('maintenance_reason',

View File

@ -19,13 +19,13 @@ Create Date: 2014-01-17 12:14:07.754448
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2581ebaf0cb2'
down_revision = None
from alembic import op
import sqlalchemy as sa
def upgrade():
# commands auto generated by Alembic - please adjust!

View File

@ -18,15 +18,14 @@ Create Date: 2015-03-18 17:08:11.470791
"""
# revision identifiers, used by Alembic.
revision = '2fb93ffd2af1'
down_revision = '4f399b21ae71'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '2fb93ffd2af1'
down_revision = '4f399b21ae71'
def upgrade():
op.alter_column('nodes', 'name',

View File

@ -18,13 +18,13 @@ Create Date: 2014-03-05 21:09:32.372463
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '31baaf680d2b'
down_revision = '3cb628139ea4'
from alembic import op
import sqlalchemy as sa
def upgrade():
# commands auto generated by Alembic - please adjust

View File

@ -18,13 +18,13 @@ Create Date: 2014-12-10 14:27:26.323540
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3ae36a5f5131'
down_revision = 'bb59b63f55a'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('name', sa.String(length=63),

View File

@ -21,12 +21,12 @@ Create Date: 2014-06-05 11:45:07.046670
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = '3bea56f25597'
down_revision = '31baaf680d2b'
from alembic import op
def upgrade():
op.create_unique_constraint("uniq_nodes0instance_uuid", "nodes",

View File

@ -18,13 +18,13 @@ Create Date: 2014-02-26 11:24:11.318023
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3cb628139ea4'
down_revision = '21b331f883ef'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('console_enabled', sa.Boolean))

View File

@ -18,13 +18,13 @@ Create Date: 2017-04-30 17:11:49.384851
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3d86a077a3f2'
down_revision = 'dbefd6bdaa2c'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('ports', sa.Column('physical_network',

View File

@ -18,13 +18,13 @@ Create Date: 2017-02-01 16:32:32.098742
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '405cfe08f18d'
down_revision = '868cb606a74a'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('rescue_interface',

View File

@ -18,13 +18,13 @@ Create Date: 2014-09-26 16:16:30.988900
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '487deb87cc9d'
down_revision = '3bea56f25597'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column(

View File

@ -18,13 +18,13 @@ Create Date: 2015-10-08 10:07:33.779516
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '48d6c242bb9b'
down_revision = '516faf1bb9b1'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table(

View File

@ -18,16 +18,16 @@ Create Date: 2016-11-15 18:09:31.362613
"""
# revision identifiers, used by Alembic.
revision = '493d8f27f235'
down_revision = '1a59178ebdf6'
from alembic import op
import sqlalchemy as sa
from sqlalchemy import sql
from ironic.conf import CONF
# revision identifiers, used by Alembic.
revision = '493d8f27f235'
down_revision = '1a59178ebdf6'
def upgrade():
op.add_column('portgroups', sa.Column('properties', sa.Text(),

View File

@ -18,13 +18,13 @@ Create Date: 2015-02-18 01:21:46.062311
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '4f399b21ae71'
down_revision = '1e1d5ace7dc6'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('clean_step', sa.Text(),

View File

@ -18,13 +18,13 @@ Create Date: 2015-08-05 13:27:31.808919
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '516faf1bb9b1'
down_revision = '789acc877671'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column('nodes', 'driver',

View File

@ -18,14 +18,14 @@ Create Date: 2015-01-14 16:55:44.718196
"""
# revision identifiers, used by Alembic.
revision = '5674c57409b9'
down_revision = '242cc6a923b3'
from alembic import op
from sqlalchemy import String
from sqlalchemy.sql import table, column, null
# revision identifiers, used by Alembic.
revision = '5674c57409b9'
down_revision = '242cc6a923b3'
node = table('nodes',
column('uuid', String(36)),
column('provision_state', String(15)))

View File

@ -18,13 +18,13 @@ Create Date: 2015-06-30 14:14:26.972368
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '5ea1b0d310e'
down_revision = '48d6c242bb9b'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('portgroups',

View File

@ -18,13 +18,13 @@ Create Date: 2016-08-25 07:00:56.662645
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '60cf717201bc'
down_revision = 'c14cef6dfedf'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('portgroups', sa.Column('standalone_ports_supported',

View File

@ -18,13 +18,13 @@ Create Date: 2015-06-26 01:21:46.062311
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '789acc877671'
down_revision = '2fb93ffd2af1'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('raid_config', sa.Text(),

View File

@ -18,13 +18,13 @@ Create Date: 2016-12-15 12:31:31.629237
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '868cb606a74a'
down_revision = '3d86a077a3f2'
from alembic import op
import sqlalchemy as sa
def upgrade():
# NOTE(rloo): In db.sqlalchemy.models, we added the 'version' column

View File

@ -18,13 +18,13 @@ Create Date: 2017-12-20 10:20:07.911788
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'b4130a7fc904'
down_revision = '405cfe08f18d'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table(

View File

@ -18,13 +18,13 @@ Create Date: 2015-01-28 14:28:22.212790
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'bb59b63f55a'
down_revision = '5674c57409b9'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('driver_internal_info',

View File

@ -18,13 +18,13 @@ Create Date: 2016-11-11 16:44:52.823881
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'bcdd431ba0bf'
down_revision = '60cf717201bc'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('boot_interface',

View File

@ -18,16 +18,16 @@ Create Date: 2016-08-01 14:05:24.197314
"""
# revision identifiers, used by Alembic.
revision = 'c14cef6dfedf'
down_revision = 'dd34e1f1303b'
from alembic import op
from sqlalchemy import String
from sqlalchemy.sql import table, column, null
from ironic.conf import CONF
# revision identifiers, used by Alembic.
revision = 'c14cef6dfedf'
down_revision = 'dd34e1f1303b'
node = table('nodes',
column('uuid', String(36)),

View File

@ -18,13 +18,13 @@ Create Date: 2015-11-26 17:19:22.074989
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'daa1ba02d98'
down_revision = 'bcdd431ba0bf'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('volume_connectors',

View File

@ -20,13 +20,13 @@ Create Date: 2017-01-17 15:28:04.653738
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'dbefd6bdaa2c'
down_revision = '2353895ecfae'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('conductor_hardware_interfaces', sa.Column('default',

View File

@ -20,13 +20,13 @@ Create Date: 2016-07-20 21:48:12.475320
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'dd34e1f1303b'
down_revision = '10b163d4481e'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('resource_class', sa.String(80),

View File

@ -18,13 +18,13 @@ Create Date: 2016-03-02 14:30:54.402864
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'e294876e8028'
down_revision = 'f6fdb920c182'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('nodes', sa.Column('network_interface', sa.String(255),

View File

@ -18,13 +18,13 @@ Create Date: 2016-06-28 13:30:19.396203
"""
from alembic import op
from oslo_db.sqlalchemy import types as db_types
# revision identifiers, used by Alembic.
revision = 'e918ff30eb42'
down_revision = 'b4130a7fc904'
from alembic import op
from oslo_db.sqlalchemy import types as db_types
def upgrade():
op.alter_column('nodes', 'instance_info',

View File

@ -18,14 +18,14 @@ Create Date: 2016-02-12 16:53:21.008580
"""
# revision identifiers, used by Alembic.
revision = 'f6fdb920c182'
down_revision = '5ea1b0d310e'
from alembic import op
from sqlalchemy import Boolean, String
from sqlalchemy.sql import table, column, null
# revision identifiers, used by Alembic.
revision = 'f6fdb920c182'
down_revision = '5ea1b0d310e'
port = table('ports',
column('uuid', String(36)),
column('pxe_enabled', Boolean()))

View File

@ -28,9 +28,8 @@ import sys
import tempfile
import eventlet
eventlet.monkey_patch(os=False)
import fixtures # noqa for I202 due to 'import eventlet' above
eventlet.monkey_patch(os=False) # noqa E402
import fixtures
from ironic_lib import utils
from oslo_concurrency import processutils
from oslo_config import fixture as config_fixture

View File

@ -13,17 +13,13 @@
# under the License.
"""Test class for Firmware Processor used by iLO management interface."""
import io
import mock
from oslo_utils import importutils
import six
from six.moves import builtins as __builtin__
import six.moves.urllib.parse as urlparse
if six.PY3:
import io
file = io.BytesIO
from ironic.common import exception
from ironic.drivers.modules.ilo import common as ilo_common
from ironic.drivers.modules.ilo import firmware_processor as ilo_fw_processor
@ -380,7 +376,7 @@ class FirmwareProcessorTestCase(base.TestCase):
def test__download_file_based_fw_to_copies_file_to_target(
self, file_image_service_mock, open_mock):
# | GIVEN |
fd_mock = mock.MagicMock(spec=file)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
any_file_based_firmware_file = 'file:///tmp/any_file_path'
@ -399,7 +395,7 @@ class FirmwareProcessorTestCase(base.TestCase):
def test__download_http_based_fw_to_downloads_the_fw_file(
self, image_service_mock, open_mock):
# | GIVEN |
fd_mock = mock.MagicMock(spec=file)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
any_http_based_firmware_file = 'http://netloc/path_to_firmware_file'

View File

@ -13,11 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
STATE_POWER_ON = "power on"
STATE_POWER_OFF = "power off"
STATE_POWERING_ON = "power on"
STATE_POWERING_OFF = "power on"
import sys
import mock
@ -34,6 +29,11 @@ from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.db import utils as db_utils
from ironic.tests.unit.objects import utils as obj_utils
STATE_POWER_ON = "power on"
STATE_POWER_OFF = "power off"
STATE_POWERING_ON = "power on"
STATE_POWERING_OFF = "power on"
xclarity_constants = importutils.try_import('xclarity_client.constants')
xclarity_client_exceptions = importutils.try_import(
'xclarity_client.exceptions')

View File

@ -101,10 +101,8 @@ setenv = PYTHONHASHSEED=0
commands = {posargs}
[flake8]
# TODO(jlvillal): We should fix the E402 errors
# [E402] Module level import not at top of file
# [W503] Line break before binary operator.
ignore = E129,E402,W503
ignore = E129,W503
filename = *.py,app.wsgi
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build
import-order-style = pep8