fix N401 errors, stop ignoring all N4* errors
We had previously been ignoring all our custom N4xx hacking.py errors. This fixes all the N401 errors "doc strings should not start with a space" and reduces the ignore set down to N402 only "single line docstrings should end with period". It also fixes the N401 parser to catch only docstrings, and not tripple quoted string blocks used later on in a function. Clean up a few of the more crazy uses of """ in our code Clean up additional funky comments to make indents a bit more consistent, and pull in lines when possible. Change-Id: I9040a1d2ca7efda83bd5e425b95d1408b5b63577
This commit is contained in:
@@ -313,7 +313,8 @@ class API(base.Base):
|
||||
raise exception.InvalidMetadataSize(reason=msg)
|
||||
|
||||
def _check_requested_networks(self, context, requested_networks):
|
||||
""" Check if the networks requested belongs to the project
|
||||
"""
|
||||
Check if the networks requested belongs to the project
|
||||
and the fixed IP address for each network provided is within
|
||||
same the network block
|
||||
"""
|
||||
|
||||
@@ -335,8 +335,10 @@ _RE_DB = {
|
||||
|
||||
|
||||
def raise_if_duplicate_entry_error(integrity_error, engine_name):
|
||||
""" In this function will be raised DBDuplicateEntry exception if integrity
|
||||
error wrap unique constraint violation. """
|
||||
"""
|
||||
In this function will be raised DBDuplicateEntry exception if integrity
|
||||
error wrap unique constraint violation.
|
||||
"""
|
||||
|
||||
def get_columns_from_uniq_cons_or_name(columns):
|
||||
# note(boris-42): UniqueConstraint name convention: "uniq_c1_x_c2_x_c3"
|
||||
|
||||
@@ -1136,8 +1136,10 @@ def get_dev(network):
|
||||
|
||||
|
||||
class LinuxNetInterfaceDriver(object):
|
||||
"""Abstract class that defines generic network host API"""
|
||||
""" for for all Linux interface drivers."""
|
||||
"""
|
||||
Abstract class that defines generic network host API
|
||||
for for all Linux interface drivers.
|
||||
"""
|
||||
|
||||
def plug(self, network, mac_address):
|
||||
"""Create Linux device, return device name"""
|
||||
|
||||
@@ -27,14 +27,16 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MiniDNS(dns_driver.DNSDriver):
|
||||
""" Trivial DNS driver. This will read/write to a local, flat file
|
||||
"""
|
||||
Trivial DNS driver. This will read/write to a local, flat file
|
||||
and have no effect on your actual DNS system. This class is
|
||||
strictly for testing purposes, and should keep you out of dependency
|
||||
hell.
|
||||
|
||||
Note that there is almost certainly a race condition here that
|
||||
will manifest anytime instances are rapidly created and deleted.
|
||||
A proper implementation will need some manner of locking."""
|
||||
A proper implementation will need some manner of locking.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
if CONF.log_dir:
|
||||
|
||||
@@ -1782,17 +1782,12 @@ class ServersControllerCreateTest(test.TestCase):
|
||||
fake_method)
|
||||
|
||||
def _check_admin_pass_len(self, server_dict):
|
||||
""" utility function - check server_dict for adminPass
|
||||
length.
|
||||
|
||||
"""
|
||||
"""utility function - check server_dict for adminPass length."""
|
||||
self.assertEqual(CONF.password_length,
|
||||
len(server_dict["adminPass"]))
|
||||
|
||||
def _check_admin_pass_missing(self, server_dict):
|
||||
""" utility function - check server_dict for absence
|
||||
of adminPass
|
||||
"""
|
||||
"""utility function - check server_dict for absence of adminPass."""
|
||||
self.assertTrue("adminPass" not in server_dict)
|
||||
|
||||
def _test_create_instance(self):
|
||||
|
||||
@@ -4303,12 +4303,12 @@ class LibvirtDriverTestCase(test.TestCase):
|
||||
self.stubs.Set(utils, 'execute', fake_execute)
|
||||
|
||||
ins_ref = self._create_instance()
|
||||
""" dest is different host case """
|
||||
# dest is different host case
|
||||
out = self.libvirtconnection.migrate_disk_and_power_off(
|
||||
None, ins_ref, '10.0.0.2', None, None)
|
||||
self.assertEquals(out, disk_info_text)
|
||||
|
||||
""" dest is same host case """
|
||||
# dest is same host case
|
||||
out = self.libvirtconnection.migrate_disk_and_power_off(
|
||||
None, ins_ref, '10.0.0.1', None, None)
|
||||
self.assertEquals(out, disk_info_text)
|
||||
@@ -4325,19 +4325,19 @@ class LibvirtDriverTestCase(test.TestCase):
|
||||
self.stubs.Set(self.libvirtconnection, 'get_info',
|
||||
fake_get_info)
|
||||
|
||||
""" instance not found case """
|
||||
# instance not found case
|
||||
self.assertRaises(exception.NotFound,
|
||||
self.libvirtconnection._wait_for_running,
|
||||
{'name': 'not_found',
|
||||
'uuid': 'not_found_uuid'})
|
||||
|
||||
""" instance is running case """
|
||||
# instance is running case
|
||||
self.assertRaises(utils.LoopingCallDone,
|
||||
self.libvirtconnection._wait_for_running,
|
||||
{'name': 'running',
|
||||
'uuid': 'running_uuid'})
|
||||
|
||||
""" else case """
|
||||
# else case
|
||||
self.libvirtconnection._wait_for_running({'name': 'else',
|
||||
'uuid': 'other_uuid'})
|
||||
|
||||
|
||||
@@ -386,7 +386,6 @@ class FakeDriver(driver.ComputeDriver):
|
||||
return 'disabled'
|
||||
|
||||
def get_disk_available_least(self):
|
||||
""" """
|
||||
pass
|
||||
|
||||
def get_volume_connector(self, instance):
|
||||
|
||||
@@ -2579,9 +2579,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
timer.start(interval=0.5).wait()
|
||||
|
||||
def _fetch_instance_kernel_ramdisk(self, context, instance):
|
||||
""" Download kernel and ramdisk for given instance in the given
|
||||
instance directory.
|
||||
"""
|
||||
"""Download kernel and ramdisk for instance in instance directory."""
|
||||
instance_dir = os.path.join(CONF.instances_path, instance['name'])
|
||||
if instance['kernel_id']:
|
||||
libvirt_utils.fetch_image(context,
|
||||
@@ -3000,8 +2998,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
def get_diagnostics(self, instance):
|
||||
def get_io_devices(xml_doc):
|
||||
""" get the list of io devices from the
|
||||
xml document."""
|
||||
"""get the list of io devices from the xml document."""
|
||||
result = {"volumes": [], "ifaces": []}
|
||||
try:
|
||||
doc = etree.fromstring(xml_doc)
|
||||
|
||||
@@ -39,8 +39,8 @@ CONF.import_opt('state_path', 'nova.config')
|
||||
|
||||
|
||||
class NfsVolumeDriver(volume.LibvirtVolumeDriver):
|
||||
""" Class implements libvirt part of volume driver for NFS
|
||||
"""
|
||||
"""Class implements libvirt part of volume driver for NFS."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Create back-end to nfs and check connection"""
|
||||
super(NfsVolumeDriver, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -189,7 +189,7 @@ class XenAPIDriver(driver.ComputeDriver):
|
||||
block_device_info)
|
||||
|
||||
def snapshot(self, context, instance, image_id, update_task_state):
|
||||
""" Create snapshot from a running VM instance """
|
||||
"""Create snapshot from a running VM instance."""
|
||||
self._vmops.snapshot(context, instance, image_id, update_task_state)
|
||||
|
||||
def reboot(self, instance, network_info, reboot_type,
|
||||
@@ -515,24 +515,24 @@ class XenAPIDriver(driver.ComputeDriver):
|
||||
return self._vmops.unfilter_instance(instance_ref, network_info)
|
||||
|
||||
def refresh_security_group_rules(self, security_group_id):
|
||||
""" Updates security group rules for all instances
|
||||
associated with a given security group
|
||||
Invoked when security group rules are updated
|
||||
"""
|
||||
"""Updates security group rules for all instances associated with a
|
||||
given security group.
|
||||
|
||||
Invoked when security group rules are updated."""
|
||||
return self._vmops.refresh_security_group_rules(security_group_id)
|
||||
|
||||
def refresh_security_group_members(self, security_group_id):
|
||||
""" Updates security group rules for all instances
|
||||
associated with a given security group
|
||||
Invoked when instances are added/removed to a security group
|
||||
"""
|
||||
"""Updates security group rules for all instances associated with a
|
||||
given security group.
|
||||
|
||||
Invoked when instances are added/removed to a security group."""
|
||||
return self._vmops.refresh_security_group_members(security_group_id)
|
||||
|
||||
def refresh_instance_security_rules(self, instance):
|
||||
""" Updates security group rules for specified instance
|
||||
"""Updates security group rules for specified instance.
|
||||
|
||||
Invoked when instances are added/removed to a security group
|
||||
or when a rule is added/removed to a security group
|
||||
"""
|
||||
or when a rule is added/removed to a security group."""
|
||||
return self._vmops.refresh_instance_security_rules(instance)
|
||||
|
||||
def refresh_provider_fw_rules(self):
|
||||
|
||||
@@ -31,8 +31,7 @@ class Dom0IptablesFirewallDriver(firewall.IptablesFirewallDriver):
|
||||
|
||||
This class provides an implementation for nova.virt.Firewall
|
||||
using iptables. This class is meant to be used with the xenapi
|
||||
backend and uses xenapi plugin to enforce iptables rules in dom0
|
||||
|
||||
backend and uses xenapi plugin to enforce iptables rules in dom0.
|
||||
"""
|
||||
def _plugin_execute(self, *cmd, **kwargs):
|
||||
# Prepare arguments for plugin call
|
||||
|
||||
@@ -1600,8 +1600,8 @@ class VMOps(object):
|
||||
|
||||
def check_can_live_migrate_source(self, ctxt, instance_ref,
|
||||
dest_check_data):
|
||||
""" Check if it is possible to execute live migration
|
||||
on the source side.
|
||||
"""Check if it's possible to execute live migration on the source side.
|
||||
|
||||
:param context: security context
|
||||
:param instance_ref: nova.db.sqlalchemy.models.Instance object
|
||||
:param dest_check_data: data returned by the check on the
|
||||
|
||||
@@ -121,7 +121,7 @@ function run_pep8 {
|
||||
srcfiles+=" setup.py"
|
||||
|
||||
# Until all these issues get fixed, ignore.
|
||||
ignore='--ignore=N4,E12,E711,E721,E712'
|
||||
ignore='--ignore=N402,E12,E711,E721,E712'
|
||||
|
||||
${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
|
||||
|
||||
|
||||
@@ -268,17 +268,22 @@ def nova_import_no_db_in_virt(logical_line, filename):
|
||||
yield (0, "NOVA N307: nova.db import not allowed in nova/virt/*")
|
||||
|
||||
|
||||
def nova_docstring_start_space(physical_line):
|
||||
def nova_docstring_start_space(physical_line, previous_logical):
|
||||
"""Check for docstring not start with space.
|
||||
|
||||
nova HACKING guide recommendation for docstring:
|
||||
Docstring should not start with space
|
||||
N401
|
||||
"""
|
||||
pos = max([physical_line.find(i) for i in DOCSTRING_TRIPLE]) # start
|
||||
if (pos != -1 and len(physical_line) > pos + 1):
|
||||
# it's important that we determine this is actually a docstring,
|
||||
# and not a doc block used somewhere after the first line of a
|
||||
# function def
|
||||
if (previous_logical.startswith("def ") or
|
||||
previous_logical.startswith("class ")):
|
||||
pos = max([physical_line.find(i) for i in DOCSTRING_TRIPLE])
|
||||
if (pos != -1 and len(physical_line) > pos + 4):
|
||||
if (physical_line[pos + 3] == ' '):
|
||||
return (pos, "NOVA N401: one line docstring should not start with"
|
||||
return (pos, "NOVA N401: docstring should not start with"
|
||||
" a space")
|
||||
|
||||
|
||||
|
||||
4
tox.ini
4
tox.ini
@@ -21,9 +21,9 @@ downloadcache = ~/cache/pip
|
||||
[testenv:pep8]
|
||||
deps=pep8==1.3.3
|
||||
commands =
|
||||
python tools/hacking.py --ignore=N4,E12,E711,E721,E712 --repeat --show-source \
|
||||
python tools/hacking.py --ignore=N402,E12,E711,E721,E712 --repeat --show-source \
|
||||
--exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg .
|
||||
python tools/hacking.py --ignore=N4,E12,E711,E721,E712 --repeat --show-source \
|
||||
python tools/hacking.py --ignore=N402,E12,E711,E721,E712 --repeat --show-source \
|
||||
--filename=nova* bin
|
||||
|
||||
[testenv:pylint]
|
||||
|
||||
Reference in New Issue
Block a user