From 3e65f778bdb51e2cf0693f4e9b1b4539ea5c294c Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 10 Apr 2019 10:02:03 +0100 Subject: [PATCH] Bump to hacking 1.1.0 This brings in a couple of new checks which must be addressed, many of which involve a rather large amount of changes, so these are ignored for now. A series of follow-up changes will resolved these. 'pycodestyle' is added as a dependency rather than it being pulled in transitively. This is necessary since we're using it in tests. Change-Id: I35c654bd39f343417e0a1124263ff31dcd0b05c9 Signed-off-by: Stephen Finucane --- lower-constraints.txt | 2 +- .../openstack/compute/availability_zone.py | 8 +++-- nova/api/openstack/compute/tenant_networks.py | 2 ++ nova/api/openstack/placement/exception.py | 6 ++-- nova/api/openstack/urlmap.py | 4 +-- nova/api/validation/parameter_types.py | 1 + nova/cmd/manage.py | 6 ++-- nova/compute/multi_cell_list.py | 10 +++--- nova/conf/database.py | 1 + nova/context.py | 3 +- nova/hacking/checks.py | 17 +++++----- nova/monkey_patch.py | 1 + nova/network/linux_net.py | 1 + nova/rpc.py | 26 ++++++++-------- .../api_sample_tests/test_compare_result.py | 8 ++--- .../tests/functional/api_samples_test_base.py | 2 +- nova/tests/functional/integrated_helpers.py | 6 ++-- .../unit/api/openstack/compute/test_cells.py | 2 +- .../openstack/compute/test_flavor_access.py | 6 ++-- .../openstack/compute/test_floating_ips.py | 13 ++++---- .../compute/test_server_migrations.py | 5 +-- .../api/openstack/compute/test_server_tags.py | 8 ++--- nova/tests/unit/api/openstack/test_wsgi.py | 2 +- nova/tests/unit/compute/test_compute.py | 8 ++--- nova/tests/unit/compute/test_compute_api.py | 16 +++++----- nova/tests/unit/compute/test_compute_mgr.py | 10 +++--- .../unit/compute/test_resource_tracker.py | 12 +++---- nova/tests/unit/image/fake.py | 1 + nova/tests/unit/image/test_glance.py | 2 ++ nova/tests/unit/network/test_neutronv2.py | 31 +++++++++---------- .../objects/test_notification.py | 1 + nova/tests/unit/objects/test_service.py | 1 + nova/tests/unit/test_hacking.py | 24 +++++++------- nova/tests/unit/utils.py | 1 + nova/tests/unit/virt/libvirt/fakelibvirt.py | 2 +- nova/tests/unit/virt/libvirt/test_driver.py | 6 ++-- nova/tests/unit/virt/vmwareapi/fake.py | 2 +- .../unit/virt/vmwareapi/test_volumeops.py | 20 ++++++------ nova/virt/disk/api.py | 6 ++-- nova/virt/libvirt/driver.py | 17 +++++----- nova/virt/vmwareapi/vm_util.py | 1 + nova/volume/cinder.py | 3 +- test-requirements.txt | 3 +- tox.ini | 11 +++++-- 44 files changed, 171 insertions(+), 147 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 13503a7938e1..166c9e7cf39a 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -101,7 +101,6 @@ paramiko==2.0.0 Paste==2.0.2 PasteDeploy==1.5.0 pbr==2.0.0 -pep8==1.5.7 pluggy==0.6.0 ply==3.11 prettytable==0.7.1 @@ -113,6 +112,7 @@ pyasn1-modules==0.2.1 pycadf==2.7.0 pycparser==2.18 pyflakes==0.8.1 +pycodestyle==2.0.0 pyinotify==0.9.6 pyroute2==0.5.4 PyJWT==1.7.0 diff --git a/nova/api/openstack/compute/availability_zone.py b/nova/api/openstack/compute/availability_zone.py index b9fa5ebf111f..70d1eb344222 100644 --- a/nova/api/openstack/compute/availability_zone.py +++ b/nova/api/openstack/compute/availability_zone.py @@ -88,9 +88,11 @@ class AvailabilityZoneController(wsgi.Controller): hosts[host] = {} for service in host_services[zone + host]: alive = self.servicegroup_api.service_is_up(service) - hosts[host][service['binary']] = {'available': alive, - 'active': True != service['disabled'], - 'updated_at': service['updated_at']} + hosts[host][service['binary']] = { + 'available': alive, + 'active': service['disabled'] is not True, + 'updated_at': service['updated_at'] + } result.append({'zoneName': zone, 'zoneState': {'available': True}, "hosts": hosts}) diff --git a/nova/api/openstack/compute/tenant_networks.py b/nova/api/openstack/compute/tenant_networks.py index f85b2ceed9ec..2187dc64963b 100644 --- a/nova/api/openstack/compute/tenant_networks.py +++ b/nova/api/openstack/compute/tenant_networks.py @@ -190,4 +190,6 @@ def _register_network_quota(): QUOTAS.register_resource(quota.CountableResource('networks', _network_count, 'quota_networks')) + + _register_network_quota() diff --git a/nova/api/openstack/placement/exception.py b/nova/api/openstack/placement/exception.py index 7973fb28b262..f6fa3ec7e4f0 100644 --- a/nova/api/openstack/placement/exception.py +++ b/nova/api/openstack/placement/exception.py @@ -67,7 +67,7 @@ class NotFound(_BaseException): class Exists(_BaseException): - msg_fmt = _("Resource already exists.") + msg_fmt = _("Resource already exists.") class InvalidInventory(_BaseException): @@ -188,7 +188,7 @@ class ProjectNotFound(NotFound): class ProjectExists(Exists): - msg_fmt = _("The project %(external_id)s already exists.") + msg_fmt = _("The project %(external_id)s already exists.") class UserNotFound(NotFound): @@ -196,7 +196,7 @@ class UserNotFound(NotFound): class UserExists(Exists): - msg_fmt = _("The user %(external_id)s already exists.") + msg_fmt = _("The user %(external_id)s already exists.") class ConsumerNotFound(NotFound): diff --git a/nova/api/openstack/urlmap.py b/nova/api/openstack/urlmap.py index 8482f9b8e59f..03f462e9d3b8 100644 --- a/nova/api/openstack/urlmap.py +++ b/nova/api/openstack/urlmap.py @@ -19,13 +19,13 @@ from oslo_log import log as logging import paste.urlmap import six +from nova.api.openstack import wsgi + if six.PY2: import urllib2 else: from urllib import request as urllib2 -from nova.api.openstack import wsgi - LOG = logging.getLogger(__name__) diff --git a/nova/api/validation/parameter_types.py b/nova/api/validation/parameter_types.py index 411c01188f01..2f63f4d8c2e0 100644 --- a/nova/api/validation/parameter_types.py +++ b/nova/api/validation/parameter_types.py @@ -164,6 +164,7 @@ def _build_regex_range(ws=True, invert=False, exclude=None): regex += "-" + re.escape(c) return regex + valid_name_regex_base = '^(?![%s])[%s]*(? - ''' % hostdev + ''' % hostdev # noqa return ''' %(name)s diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 880e42bd685f..f647915c5fac 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -7002,9 +7002,9 @@ class LibvirtConnTestCase(test.NoDBTestCase, # Call can be unpackaged as a tuple of args and kwargs # so we want to check the first arg in the args list if (len(call) == 2 and len(call[0]) == 2 and - call[0][1] in perf_events and - 'Monitoring Intel CMT' in call[0][0]): - warning_count += 1 + call[0][1] in perf_events and + 'Monitoring Intel CMT' in call[0][0]): + warning_count += 1 self.assertEqual(3, warning_count) def test_xml_and_uri_no_ramdisk_no_kernel(self): diff --git a/nova/tests/unit/virt/vmwareapi/fake.py b/nova/tests/unit/virt/vmwareapi/fake.py index 208cd579edcf..6611a8ee856d 100644 --- a/nova/tests/unit/virt/vmwareapi/fake.py +++ b/nova/tests/unit/virt/vmwareapi/fake.py @@ -1101,7 +1101,7 @@ def fake_fetch_image(context, instance, host, port, dc_name, ds_name, def _get_vm_mdo(vm_ref): """Gets the Virtual Machine with the ref from the db.""" if _db_content.get("VirtualMachine", None) is None: - raise exception.NotFound("There is no VM registered") + raise exception.NotFound("There is no VM registered") if vm_ref not in _db_content.get("VirtualMachine"): raise exception.NotFound("Virtual Machine with ref %s is not " "there" % vm_ref) diff --git a/nova/tests/unit/virt/vmwareapi/test_volumeops.py b/nova/tests/unit/virt/vmwareapi/test_volumeops.py index 8ab8dd1a2d8a..073c703a8fcf 100644 --- a/nova/tests/unit/virt/vmwareapi/test_volumeops.py +++ b/nova/tests/unit/virt/vmwareapi/test_volumeops.py @@ -153,17 +153,17 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase): @mock.patch.object(vm_util, 'reconfigure_vm') def test_update_volume_details(self, reconfigure_vm, get_vm_extra_config_spec): - volume_uuid = '26f5948e-52a3-4ee6-8d48-0a379afd0828' - device_uuid = '0d86246a-2adb-470d-a9f7-bce09930c5d' - self._volumeops._update_volume_details( - mock.sentinel.vm_ref, volume_uuid, device_uuid) + volume_uuid = '26f5948e-52a3-4ee6-8d48-0a379afd0828' + device_uuid = '0d86246a-2adb-470d-a9f7-bce09930c5d' + self._volumeops._update_volume_details( + mock.sentinel.vm_ref, volume_uuid, device_uuid) - get_vm_extra_config_spec.assert_called_once_with( - self._volumeops._session.vim.client.factory, - {'volume-%s' % volume_uuid: device_uuid}) - reconfigure_vm.assert_called_once_with(self._volumeops._session, - mock.sentinel.vm_ref, - mock.sentinel.extra_config) + get_vm_extra_config_spec.assert_called_once_with( + self._volumeops._session.vim.client.factory, + {'volume-%s' % volume_uuid: device_uuid}) + reconfigure_vm.assert_called_once_with(self._volumeops._session, + mock.sentinel.vm_ref, + mock.sentinel.extra_config) def _fake_connection_info(self): return {'driver_volume_type': 'vmdk', diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index d88e14bd90d6..c1599857ae48 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -27,9 +27,6 @@ import os import random import tempfile -if os.name != 'nt': - import crypt - from oslo_concurrency import processutils from oslo_log import log as logging from oslo_serialization import jsonutils @@ -44,6 +41,9 @@ from nova.virt.disk.vfs import api as vfs from nova.virt.image import model as imgmodel from nova.virt import images +if os.name != 'nt': + import crypt + LOG = logging.getLogger(__name__) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index f2e6693b3b37..c9939c8d3084 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -164,6 +164,7 @@ class InjectionInfo(collections.namedtuple( return ('InjectionInfo(network_info=%r, files=%r, ' 'admin_pass=)') % (self.network_info, self.files) + libvirt_volume_drivers = [ 'iscsi=nova.virt.libvirt.volume.iscsi.LibvirtISCSIVolumeDriver', 'iser=nova.virt.libvirt.volume.iser.LibvirtISERVolumeDriver', @@ -582,14 +583,14 @@ class LibvirtDriver(driver.ComputeDriver): # new enough) and "native TLS" options at the same time is # nonsensical. if (CONF.libvirt.live_migration_tunnelled and - CONF.libvirt.live_migration_with_native_tls): - msg = _("Setting both 'live_migration_tunnelled' and " - "'live_migration_with_native_tls' at the same " - "time is invalid. If you have the relevant " - "libvirt and QEMU versions, and TLS configured " - "in your environment, pick " - "'live_migration_with_native_tls'.") - raise exception.Invalid(msg) + CONF.libvirt.live_migration_with_native_tls): + msg = _("Setting both 'live_migration_tunnelled' and " + "'live_migration_with_native_tls' at the same " + "time is invalid. If you have the relevant " + "libvirt and QEMU versions, and TLS configured " + "in your environment, pick " + "'live_migration_with_native_tls'.") + raise exception.Invalid(msg) # TODO(sbauza): Remove this code once mediated devices are persisted # across reboots. diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index 322c8b133cf2..b2dfd7c7f58c 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -145,6 +145,7 @@ def vm_ref_cache_from_name(func): return _vm_ref_cache(id, func, session, name) return wrapper + # the config key which stores the VNC port VNC_CONFIG_KEY = 'config.extraConfig["RemoteDisplay.vnc.port"]' diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py index a17e5445c3c0..f8f1f9fad226 100644 --- a/nova/volume/cinder.py +++ b/nova/volume/cinder.py @@ -424,7 +424,8 @@ def translate_volume_exception(method): def translate_attachment_exception(method): - """Transforms the exception for the attachment but keeps its traceback intact. + """Transforms the exception for the attachment but keeps its traceback + intact. """ def wrapper(self, ctx, attachment_id, *args, **kwargs): try: diff --git a/test-requirements.txt b/test-requirements.txt index 36b9486c6792..87ecc3eabd65 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 +hacking>=1.1.0,<1.2.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT fixtures>=3.0.0 # Apache-2.0/BSD @@ -10,6 +10,7 @@ mock>=2.0.0 # BSD mox3>=0.20.0 # Apache-2.0 psycopg2>=2.7 # LGPL/ZPL PyMySQL>=0.7.6 # MIT License +pycodestyle>=2.0.0 # MIT License python-barbicanclient>=4.5.2 # Apache-2.0 python-ironicclient>=2.7.0 # Apache-2.0 requests-mock>=1.2.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 1ae91fd5e573..266c42e5a9c9 100644 --- a/tox.ini +++ b/tox.ini @@ -250,14 +250,19 @@ commands = bandit -r nova -x tests -n 5 -ll # line. Rejecting code for this reason is wrong. # # E251 Skipped due to https://github.com/jcrocholl/pep8/issues/301 +# +# W504 skipped since you must choose either W503 or W504 (they conflict) +# +# W503, W605, E731, and E741 temporarily skipped because of the number of +# these that have to be fixed enable-extensions = H106,H203,H904 -ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405 +ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405,W504,W605,W503,E731,E741 exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,tools/xenserver*,releasenotes # To get a list of functions that are more complex than 25, set max-complexity # to 25 and run 'tox -epep8'. -# 34 is currently the most complex thing we have +# 39 is currently the most complex thing we have # TODO(jogo): get this number down to 25 or so -max-complexity=35 +max-complexity=40 [hacking] local-check-factory = nova.hacking.checks.factory