Fixed hacking, pep8 and pyflakes errors.

This commit is contained in:
Monty Taylor 2013-05-02 15:49:06 -04:00
parent 84a7dc47e2
commit 7bad35dd1f
13 changed files with 36 additions and 43 deletions

View File

@ -105,8 +105,10 @@ CATEGORIES = {
def methods_of(obj):
"""Get all callable methods of an object that don't start with underscore
returns a list of tuples of the form (method_name, method)"""
"""Get all callable methods of an object that don't start with underscore.
Returns a list of tuples of the form (method_name, method)
"""
result = []
for i in dir(obj):
if callable(getattr(obj, i)) and not i.startswith('_'):

View File

@ -1,6 +1,6 @@
# Copyright (c) 2012 NTT DOCOMO, INC.
# All Rights Reserved.
#
# flake8: noqa
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at

View File

@ -1,5 +1,6 @@
# Copyright (c) 2012 NTT DOCOMO, INC.
# All Rights Reserved.
# flake8: noqa
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain

View File

@ -442,7 +442,7 @@ class PXEPublicMethodsTestCase(BareMetalPXETestCase):
iqn = "iqn-%s" % self.instance['uuid']
pxe_config = 'this is a fake pxe config'
pxe_path = pxe.get_pxe_config_file_path(self.instance)
image_path = pxe.get_image_file_path(self.instance)
pxe.get_image_file_path(self.instance)
self.mox.StubOutWithMock(self.driver.virtapi, 'instance_type_get')
self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')

View File

@ -304,11 +304,9 @@ class TileraPublicMethodsTestCase(BareMetalTileraTestCase):
'kernel': [None, 'cccc'],
}
self.instance['uuid'] = 'fake-uuid'
iqn = "iqn-%s" % self.instance['uuid']
tilera_config = 'this is a fake tilera config'
self.instance['uuid'] = 'fake-uuid'
tilera_path = tilera.get_tilera_nfs_path(self.instance)
image_path = tilera.get_image_file_path(self.instance)
tilera.get_tilera_nfs_path(self.instance)
tilera.get_image_file_path(self.instance)
self.mox.StubOutWithMock(tilera, 'get_tftp_image_info')
self.mox.StubOutWithMock(tilera, 'get_partition_sizes')
@ -325,8 +323,8 @@ class TileraPublicMethodsTestCase(BareMetalTileraTestCase):
def test_activate_and_deactivate_bootloader(self):
self._create_node()
self.instance['uuid'] = 'fake-uuid'
tilera_path = tilera.get_tilera_nfs_path(self.instance)
image_path = tilera.get_image_file_path(self.instance)
tilera.get_tilera_nfs_path(self.instance)
tilera.get_image_file_path(self.instance)
self.mox.ReplayAll()
@ -356,8 +354,6 @@ class TileraPublicMethodsTestCase(BareMetalTileraTestCase):
self.mox.StubOutWithMock(tilera, 'get_tftp_image_info')
self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses')
tilera_path = tilera.get_tilera_nfs_path(self.node['id'])
tilera.get_tftp_image_info(self.instance).\
AndRaise(exception.NovaException)
self.driver._collect_mac_addresses(self.context, self.node).\

View File

@ -1,6 +1,6 @@
# Copyright (c) 2012 NTT DOCOMO, INC.
# All Rights Reserved.
#
# flake8: noqa
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at

View File

@ -92,7 +92,7 @@ def bm_node_get_all(context, service_host=None):
@sqlalchemy_api.require_admin_context
def bm_node_get_associated(context, service_host=None):
query = model_query(context, models.BareMetalNode, read_deleted="no").\
filter(models.BareMetalNode.instance_uuid != None)
filter(models.BareMetalNode.instance_uuid is not None)
if service_host:
query = query.filter_by(service_host=service_host)
return query.all()
@ -101,7 +101,7 @@ def bm_node_get_associated(context, service_host=None):
@sqlalchemy_api.require_admin_context
def bm_node_get_unassociated(context, service_host=None):
query = model_query(context, models.BareMetalNode, read_deleted="no").\
filter(models.BareMetalNode.instance_uuid == None)
filter(models.BareMetalNode.instance_uuid is None)
if service_host:
query = query.filter_by(service_host=service_host)
return query.all()
@ -111,7 +111,7 @@ def bm_node_get_unassociated(context, service_host=None):
def bm_node_find_free(context, service_host=None,
cpus=None, memory_mb=None, local_gb=None):
query = model_query(context, models.BareMetalNode, read_deleted="no")
query = query.filter(models.BareMetalNode.instance_uuid == None)
query = query.filter(models.BareMetalNode.instance_uuid is None)
if service_host:
query = query.filter_by(service_host=service_host)
if cpus is not None:

View File

@ -105,16 +105,16 @@ class IPMI(base.PowerManager):
self.password = node['pm_password']
self.port = node['terminal_port']
if self.node_id == None:
if self.node_id is None:
raise exception.InvalidParameterValue(_("Node id not supplied "
"to IPMI"))
if self.address == None:
if self.address is None:
raise exception.InvalidParameterValue(_("Address not supplied "
"to IPMI"))
if self.user == None:
if self.user is None:
raise exception.InvalidParameterValue(_("User not supplied "
"to IPMI"))
if self.password == None:
if self.password is None:
raise exception.InvalidParameterValue(_("Password not supplied "
"to IPMI"))

View File

@ -216,7 +216,7 @@ def get_tftp_image_info(instance, instance_type):
image_info['ramdisk'][0] = str(instance['ramdisk_id'])
image_info['deploy_kernel'][0] = get_deploy_aki_id(instance_type)
image_info['deploy_ramdisk'][0] = get_deploy_ari_id(instance_type)
except KeyError as e:
except KeyError:
pass
missing_labels = []
@ -462,7 +462,7 @@ class PXE(base.NodeDriver):
status = row.get('task_state')
if (status == baremetal_states.DEPLOYING
and locals['started'] == False):
and locals['started'] is False):
LOG.info(_("PXE deploy started for instance %s")
% instance['uuid'])
locals['started'] = True

View File

@ -128,8 +128,7 @@ def get_partition_sizes(instance):
def get_tftp_image_info(instance):
"""
Generate the paths for tftp files for this instance.
"""Generate the paths for tftp files for this instance.
Raises NovaException if
- instance does not contain kernel_id
@ -139,7 +138,7 @@ def get_tftp_image_info(instance):
}
try:
image_info['kernel'][0] = str(instance['kernel_id'])
except KeyError as e:
except KeyError:
pass
missing_labels = []
@ -287,7 +286,6 @@ class Tilera(base.NodeDriver):
kernel
./fs_node_id/
"""
image_info = get_tftp_image_info(instance)
(root_mb, swap_mb) = get_partition_sizes(instance)
tilera_nfs_path = get_tilera_nfs_path(node['id'])
image_file_path = get_image_file_path(instance)
@ -333,7 +331,7 @@ class Tilera(base.NodeDriver):
bm_utils.unlink_without_raise(path)
try:
macs = self._collect_mac_addresses(context, node)
self._collect_mac_addresses(context, node)
except db_exc.DBError:
pass
@ -343,8 +341,7 @@ class Tilera(base.NodeDriver):
os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
def _iptables_set(self, node_ip, user_data):
"""
Sets security setting (iptables:port) if needed.
"""Sets security setting (iptables:port) if needed.
iptables -A INPUT -p tcp ! -s $IP --dport $PORT -j DROP
/tftpboot/iptables_rule script sets iptables rule on the given node.
@ -367,7 +364,7 @@ class Tilera(base.NodeDriver):
status = row.get('task_state')
if (status == baremetal_states.DEPLOYING and
locals['started'] == False):
locals['started'] is False):
LOG.info(_('Tilera deploy started for instance %s')
% instance['uuid'])
locals['started'] = True
@ -380,7 +377,7 @@ class Tilera(base.NodeDriver):
user_data = instance['user_data']
try:
self._iptables_set(node_ip, user_data)
except Exception as ex:
except Exception:
self.deactivate_bootloader(context, node, instance)
raise exception.NovaException(_("Node is "
"unknown error state."))

View File

@ -78,22 +78,21 @@ class Pdu(base.PowerManager):
self.password = node['pm_password']
self.port = node['terminal_port']
if self.node_id == None:
if self.node_id is None:
raise exception.InvalidParameterValue(_("Node id not supplied "
"to PDU"))
if self.address == None:
if self.address is None:
raise exception.InvalidParameterValue(_("Address not supplied "
"to PDU"))
if self.user == None:
if self.user is None:
raise exception.InvalidParameterValue(_("User not supplied "
"to PDU"))
if self.password == None:
if self.password is None:
raise exception.InvalidParameterValue(_("Password not supplied "
"to PDU"))
def _exec_pdutool(self, mode):
"""
Changes power state of the given node.
"""Changes power state of the given node.
According to the mode (1-ON, 2-OFF, 3-REBOOT), power state can be
changed. /tftpboot/pdu_mgr script handles power management of
@ -108,8 +107,8 @@ class Pdu(base.PowerManager):
return CONF.baremetal.tile_pdu_off
else:
try:
out = utils.execute(CONF.baremetal.tile_pdu_mgr,
CONF.baremetal.tile_pdu_ip, mode)
utils.execute(CONF.baremetal.tile_pdu_mgr,
CONF.baremetal.tile_pdu_ip, mode)
time.sleep(CONF.baremetal.tile_power_wait)
return mode
except exception.ProcessExecutionError:

View File

@ -262,7 +262,5 @@ class LibvirtVolumeDriver(VolumeDriver):
mount_device)
def get_all_block_devices(self):
"""
Return all block devices in use on this node.
"""
"""Return all block devices in use on this node."""
return _list_backingstore_path()

View File

@ -29,6 +29,6 @@ commands =
commands = {posargs}
[flake8]
ignore = E12,E711,E721,E712,H302,H303,H403,H404,F
ignore = E12
builtins = _
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build