Fix pep8 errors in tacker code

This Patch fixes pep8 errors and
enables this tests for all new patches to tacker.

E125 continuation line does not distinguish itself from next logical line
E126 continuation line over-indented for hanging indent
E129 visually indented line with same indent as next logical line
H302 import only modules
H904 Wrap long lines in parentheses instead of a backslash

see OpenStack Style Guidelines
http://docs.openstack.org/developer/hacking/

Change-Id: I29e8ac8e6cfcd547e9bdab599635d07f0df6e3d6
Related-Bug: 1515930
This commit is contained in:
Martin Oemke 2016-01-27 21:09:42 +01:00
parent 8a8956ba89
commit bcb6f07df8
24 changed files with 90 additions and 89 deletions

View File

@ -92,7 +92,7 @@ def get_limit_and_marker(request):
def _get_pagination_max_limit():
max_limit = -1
if (cfg.CONF.pagination_max_limit.lower() !=
constants.PAGINATION_INFINITE):
constants.PAGINATION_INFINITE):
try:
max_limit = int(cfg.CONF.pagination_max_limit)
if max_limit == 0:

View File

@ -127,9 +127,9 @@ class Controller(object):
context,
'%s:%s' % (self._plugin_handlers[self.SHOW], attr_name),
data,
might_not_exist=True):
# this attribute is visible, check next one
continue
might_not_exist=True):
# this attribute is visible, check next one
continue
# if the code reaches this point then either the policy check
# failed or the attribute was not visible in the first place
attributes_to_exclude.append(attr_name)
@ -535,10 +535,10 @@ class Controller(object):
for attr, attr_vals in attr_info.iteritems():
if attr_vals['allow_post']:
if ('default' not in attr_vals and
attr not in res_dict):
msg = _("Failed to parse request. Required "
"attribute '%s' not specified") % attr
raise webob.exc.HTTPBadRequest(msg)
attr not in res_dict):
msg = _("Failed to parse request. Required "
"attribute '%s' not specified") % attr
raise webob.exc.HTTPBadRequest(msg)
res_dict[attr] = res_dict.get(attr,
attr_vals.get('default'))
else:
@ -553,7 +553,7 @@ class Controller(object):
for attr, attr_vals in attr_info.iteritems():
if (attr not in res_dict or
res_dict[attr] is attributes.ATTR_NOT_SPECIFIED):
res_dict[attr] is attributes.ATTR_NOT_SPECIFIED):
continue
# Convert values if necessary
if 'convert_to' in attr_vals:

View File

@ -20,9 +20,9 @@ CONF = cfg.CONF
OPTS = [
cfg.StrOpt('heat_uri',
default='http://localhost:8004/v1',
help=_("Heat service URI to create VNF resources"
"specified in the VNFD templates")),
default='http://localhost:8004/v1',
help=_("Heat service URI to create VNF resources"
"specified in the VNFD templates")),
]
CONF.register_opts(OPTS, group='tacker_heat')
@ -41,10 +41,10 @@ class OpenstackClients(object):
def _keystone_client(self):
return ks_client.Client(
tenant_name=self.auth_tenant_name,
username=self.auth_username,
password=self.auth_password,
auth_url=self.auth_url)
tenant_name=self.auth_tenant_name,
username=self.auth_username,
password=self.auth_password,
auth_url=self.auth_url)
def _heat_client(self):
tenant_id = self.auth_token['tenant_id']

View File

@ -52,8 +52,8 @@ def init(conf):
global TRANSPORT, NOTIFIER
exmods = get_allowed_exmods()
TRANSPORT = oslo_messaging.get_transport(conf,
allowed_remote_exmods=exmods,
aliases=TRANSPORT_ALIASES)
allowed_remote_exmods=exmods,
aliases=TRANSPORT_ALIASES)
NOTIFIER = oslo_messaging.Notifier(TRANSPORT)

View File

@ -147,7 +147,7 @@ class CommonDbMixin(object):
def _apply_dict_extend_functions(self, resource_type,
response, db_object):
for func in self._dict_extend_functions.get(
resource_type, []):
resource_type, []):
args = (response, db_object)
if isinstance(func, basestring):
func = getattr(self, func, None)

View File

@ -31,4 +31,4 @@ import sqlalchemy as sa
def upgrade(active_plugins=None, options=None):
op.alter_column('devicetemplateattributes',
'value', type_=sa.TEXT(65535), nullable=True)
'value', type_=sa.TEXT(65535), nullable=True)

View File

@ -88,7 +88,7 @@ def validate_head_file(config):
head_path = os.path.join(script.versions, HEAD_FILENAME)
if (os.path.isfile(head_path) and
open(head_path).read().strip() == script.get_current_head()):
open(head_path).read().strip() == script.get_current_head()):
return
else:
alembic_util.err(_('HEAD file does not match migration timeline head'))

View File

@ -323,8 +323,8 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
def _device_attribute_update_or_create(
self, context, device_id, key, value):
arg = (self._model_query(context, DeviceAttribute).
filter(DeviceAttribute.device_id == device_id).
filter(DeviceAttribute.key == key).first())
filter(DeviceAttribute.device_id == device_id).
filter(DeviceAttribute.key == key).first())
if arg:
arg.value = value
else:
@ -482,7 +482,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
def get_devices(self, context, filters=None, fields=None):
devices = self._get_collection(context, Device, self._make_device_dict,
filters=filters, fields=fields)
filters=filters, fields=fields)
# Ugly hack to mask internaly used record
return [device for device in devices
if uuidutils.is_uuid_like(device['id'])]

View File

@ -62,8 +62,8 @@ class BaseTackerTest(base.TestCase):
tenant_name = cfg.CONF.keystone_authtoken.project_name
auth_uri = cfg.CONF.keystone_authtoken.auth_uri + '/v2.0'
return tacker_client.Client(username=username, password=password,
tenant_name=tenant_name,
auth_url=auth_uri)
tenant_name=tenant_name,
auth_url=auth_uri)
@classmethod
def wait_until_vnf_status(cls, vnf_id, target_status, timeout,
@ -72,8 +72,8 @@ class BaseTackerTest(base.TestCase):
while True:
vnf_result = cls.client.show_vnf(vnf_id)
status = vnf_result['vnf']['status']
if (status == target_status) or ((int(time.time()) -
start_time) > timeout):
if (status == target_status) or (
(int(time.time()) - start_time) > timeout):
break
time.sleep(sleep_interval)
@ -99,19 +99,22 @@ class BaseTackerTest(base.TestCase):
def verify_vnf_restart(self, vnfd_instance, vnf_instance):
vnf_id = vnf_instance['vnf']['id']
vnf_current_status = self.wait_until_vnf_active(vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
vnf_current_status = self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
self.assertEqual(vnf_current_status, 'ACTIVE')
self.validate_vnf_instance(vnfd_instance, vnf_instance)
self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
vnf_current_status = self.wait_until_vnf_dead(vnf_id,
constants.VNF_CIRROS_DEAD_TIMEOUT,
constants.DEAD_SLEEP_TIME)
vnf_current_status = self.wait_until_vnf_dead(
vnf_id,
constants.VNF_CIRROS_DEAD_TIMEOUT,
constants.DEAD_SLEEP_TIME)
self.assertEqual(vnf_current_status, 'DEAD')
vnf_current_status = self.wait_until_vnf_active(vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
vnf_current_status = self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
self.assertEqual(vnf_current_status, 'ACTIVE')
self.validate_vnf_instance(vnfd_instance, vnf_instance)

View File

@ -43,9 +43,10 @@ class VnfTestCreate(base.BaseTackerTest):
self.validate_vnf_instance(vnfd_instance, vnf_instance)
vnf_id = vnf_instance['vnf']['id']
vnf_current_status = self.wait_until_vnf_active(vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
vnf_current_status = self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
self.assertEqual(vnf_current_status, 'ACTIVE')
self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])

View File

@ -38,7 +38,7 @@ class VnfTestMultipleVDU(base.BaseTackerTest):
# Create vnf with vnfd_id
vnfd_id = vnfd_instance['vnfd']['id']
vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':
"test_vnf_with_multiple_vdus"}}
"test_vnf_with_multiple_vdus"}}
vnf_instance = self.client.create_vnf(body=vnf_arg)
vnf_id = vnf_instance['vnf']['id']

View File

@ -59,9 +59,10 @@ class VnfmTestParam(base.BaseTackerTest):
self.validate_vnf_instance(vnfd_instance, vnf_instance)
vnf_id = vnf_instance['vnf']['id']
vnf_current_status = self.wait_until_vnf_active(vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
vnf_current_status = self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
self.assertEqual('ACTIVE', vnf_current_status)
self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
vnf_instance = self.client.show_vnf(vnf_id)
@ -93,7 +94,7 @@ class VnfmTestParam(base.BaseTackerTest):
def test_vnf_param(self):
vnfd_instance = self._test_vnfd_create('sample_cirros_vnf_param.yaml')
vnf_instance = self._test_vnf_create(vnfd_instance,
'test_vnf_with_parameters',
'sample_cirros_vnf_values.yaml')
'test_vnf_with_parameters',
'sample_cirros_vnf_values.yaml')
self._test_vnf_delete(vnf_instance)
self._test_vnfd_delete(vnfd_instance)

View File

@ -340,7 +340,7 @@ class RequestDeserializerTest(testtools.TestCase):
def test_deserialize(self):
"""Test RequestDeserializer.deserialize."""
with mock.patch.object(
self.deserializer, 'get_action_args') as mock_method:
self.deserializer, 'get_action_args') as mock_method:
mock_method.return_value = {'action': 'create'}
request = wsgi.Request.blank('/')
request.headers['Accept'] = 'application/xml'

View File

@ -44,7 +44,7 @@ class TestVNFMonitorHTTPPing(testtools.TestCase):
'mgmt_ip': 'a.b.c.d'
}
monitor_return = self.monitor_http_ping.monitor_call(test_device,
test_kwargs)
test_kwargs)
self.assertEqual(monitor_return, 'failure')
def test_monitor_url(self):

View File

@ -31,10 +31,10 @@ class TestVNFMonitorPing(testtools.TestCase):
'mgmt_ip': 'a.b.c.d'
}
mock_ping_cmd = ['ping',
'-c', 5,
'-W', 1,
'-i', '0.2',
'a.b.c.d']
'-c', 5,
'-W', 1,
'-i', '0.2',
'a.b.c.d']
self.monitor_ping.monitor_call(test_device,
test_kwargs)
mock_utils_execute.assert_called_once_with(mock_ping_cmd,
@ -48,7 +48,7 @@ class TestVNFMonitorPing(testtools.TestCase):
'mgmt_ip': 'a.b.c.d'
}
monitor_return = self.monitor_ping.monitor_call(test_device,
test_kwargs)
test_kwargs)
self.assertEqual(monitor_return, 'failure')
def test_monitor_url(self):

View File

@ -62,7 +62,7 @@ class TestVNFMonitor(testtools.TestCase):
'mgmt_url': '{"vdu1": "a.b.c.d"}',
'attributes': {
'monitoring_policy': json.dumps(
MOCK_VNF_DEVICE['monitoring_policy'])
MOCK_VNF_DEVICE['monitoring_policy'])
}
}
action_cb = mock.MagicMock()

View File

@ -259,7 +259,7 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
elif 'user_data' in vdu_dict or 'user_data_format' in vdu_dict:
raise vnfm.UserDataFormatNotFound()
if ('placement_policy' in vdu_dict and
'availability_zone' in vdu_dict['placement_policy']):
'availability_zone' in vdu_dict['placement_policy']):
properties['availability_zone'] = vdu_dict[
'placement_policy']['availability_zone']
if 'config' in vdu_dict:
@ -276,9 +276,10 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
# This should be removed after Mitaka
if monitoring_policy == 'ping' and failure_policy == 'respawn':
vdu_dict['monitoring_policy'] = {'ping': {
'actions': {
'failure': 'respawn'
}}}
'actions':
{
'failure': 'respawn'
}}}
vdu_dict.pop('failure_policy')
if monitoring_policy != 'noop':
@ -294,7 +295,7 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
if monitoring_dict.keys():
device['attributes']['monitoring_policy'] = jsonutils.dumps(
monitoring_dict)
monitoring_dict)
heat_template_yaml = yaml.dump(template_dict)
fields['template'] = heat_template_yaml

View File

@ -254,7 +254,7 @@ class DeviceNova(abstract_driver.DeviceAbstractDriver):
instance = nova.servers.get(device_id)
except self._novaclient.exceptions.NotFound:
LOG.error(_LE("server %s is not found") %
device_id)
device_id)
return
instance.delete()
@ -280,7 +280,7 @@ class DeviceNova(abstract_driver.DeviceAbstractDriver):
instance = nova.servers.get(device_id)
except self._novaclient.exceptions.NotFound:
LOG.error(_LE("server %s is not found") %
device_id)
device_id)
return
instance.interface_attach(port_id, None, None)
@ -292,6 +292,6 @@ class DeviceNova(abstract_driver.DeviceAbstractDriver):
instance = nova.servers.get(device_id)
except self._novaclient.exceptions.NotFound:
LOG.error(_LE("server %s is not found") %
device_id)
device_id)
return
instance.interface_detach(port_id)

View File

@ -62,7 +62,7 @@ class DeviceMgmtOpenWRT(abstract_driver.DeviceMGMTAbstractDriver):
@log.log
def mgmt_call(self, plugin, context, device, kwargs):
if (kwargs[mgmt_constants.KEY_ACTION] !=
mgmt_constants.ACTION_UPDATE_DEVICE):
mgmt_constants.ACTION_UPDATE_DEVICE):
return
dev_attrs = device.get('attributes', {})

View File

@ -114,15 +114,15 @@ class VNFMonitor(object):
hosting_vnf = self._hosting_vnfs.pop(device_id, None)
if hosting_vnf:
LOG.debug('deleting device_id %(device_id)s, Mgmt IP %(ips)s',
{'device_id': device_id,
'ips': hosting_vnf['management_ip_addresses']})
{'device_id': device_id,
'ips': hosting_vnf['management_ip_addresses']})
def run_monitor(self, hosting_vnf):
mgmt_ips = hosting_vnf['management_ip_addresses']
vdupolicies = hosting_vnf['monitoring_policy']['vdus']
vnf_delay = hosting_vnf['monitoring_policy'].get(
'monitoring_delay', self.boot_wait)
'monitoring_delay', self.boot_wait)
for vdu in vdupolicies.keys():
if hosting_vnf.get('dead'):
@ -135,8 +135,8 @@ class VNFMonitor(object):
vdu_delay = params.get('monitoring_delay', vnf_delay)
if not timeutils.is_older_than(
hosting_vnf['boot_at'],
vdu_delay):
hosting_vnf['boot_at'],
vdu_delay):
continue
actions = policy[driver].get('actions', {})
@ -171,7 +171,7 @@ class VNFMonitor(object):
def monitor_call(self, driver, device_dict, kwargs):
return self._invoke(driver,
device=device_dict, kwargs=kwargs)
device=device_dict, kwargs=kwargs)
@six.add_metaclass(abc.ABCMeta)
@ -293,9 +293,9 @@ class ActionRespawnHeat(ActionPolicy):
# ungly hack to keep id unchanged
dead_device_id = device_id + '-DEAD-' + failure_count_str
LOG.debug(_('%(dead)s %(new)s %(cur)s'),
{'dead': dead_device_id,
'new': new_device_id,
'cur': device_id})
{'dead': dead_device_id,
'new': new_device_id,
'cur': device_id})
plugin.rename_device_id(context, device_id, dead_device_id)
plugin.rename_device_id(context, new_device_id, device_id)
LOG.debug('Delete dead device')

View File

@ -58,10 +58,10 @@ class VNFMonitorPing(abstract_driver.VNFMonitorAbstractDriver):
:return: bool - True or string 'failure' depending on pingability.
"""
ping_cmd = ['ping',
'-c', count,
'-W', timeout,
'-i', interval,
mgmt_ip]
'-c', count,
'-W', timeout,
'-i', interval,
mgmt_ip]
try:
linux_utils.execute(ping_cmd, check_exit_code=True)

View File

@ -47,7 +47,7 @@ class VNFMMgmtMixin(object):
'Hosting Device/logical service '
'instance tacker plugin will use')),
cfg.IntOpt('boot_wait', default=30,
help=_('Time interval to wait for VM to boot')),
help=_('Time interval to wait for VM to boot')),
]
cfg.CONF.register_opts(OPTS, 'tacker')
@ -167,7 +167,7 @@ class VNFMPlugin(vm_db.VNFMPluginDb, VNFMMgmtMixin):
if 'monitoring_policy' in dev_attrs and mgmt_url:
def action_cb(hosting_vnf_, action):
action_cls = monitor.ActionPolicy.get_policy(action,
device_dict)
device_dict)
if action_cls:
action_cls.execute_action(self, hosting_vnf['device'])
@ -250,7 +250,7 @@ class VNFMPlugin(vm_db.VNFMPluginDb, VNFMMgmtMixin):
if instance_id is None:
self._create_device_post(context, device_id, None, None,
device_dict)
device_dict)
return
device_dict['instance_id'] = instance_id

View File

@ -705,7 +705,7 @@ class XMLDeserializer(TextDeserializer):
parseError = False
# Python2.7
if (hasattr(etree, 'ParseError') and
isinstance(e, getattr(etree, 'ParseError'))):
isinstance(e, getattr(etree, 'ParseError'))):
parseError = True
# Python2.6
elif isinstance(e, expat.ExpatError):
@ -752,9 +752,9 @@ class XMLDeserializer(TextDeserializer):
result = dict()
for attr in node.keys():
if (attr == 'xmlns' or
attr.startswith('xmlns:') or
attr == constants.XSI_ATTR or
attr == constants.TYPE_ATTR):
attr.startswith('xmlns:') or
attr == constants.XSI_ATTR or
attr == constants.TYPE_ATTR):
continue
result[self._get_key(attr)] = node.get(attr)
children = list(node)

View File

@ -55,13 +55,8 @@ commands =
commands = {posargs}
[flake8]
# E125 continuation line does not distinguish itself from next logical line
# E126 continuation line over-indented for hanging indent
# E128 continuation line under-indented for visual indent
# E129 visually indented line with same indent as next logical line
# H302 import only modules
# H904 Wrap long lines in parentheses instead of a backslash
ignore = E125,E126,E128,E129,H302,H904
ignore = E128
show-source = true
builtins = _
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,.ropeproject