Add in pep8 checks for the tools directory
This is required for the admin utility. Change-Id: Ief9e428919f13e925100296dc5337a0eb8d52c15
This commit is contained in:
parent
c96d12ccab
commit
67a733df84
@ -59,7 +59,7 @@ class Visitor(object):
|
||||
(self.filename, node.lineno,
|
||||
self.lines[node.lineno - 1][:-1],
|
||||
checker.__name__, msg),
|
||||
file=sys.stderr)
|
||||
file=sys.stderr)
|
||||
self.error = 1
|
||||
return
|
||||
if debug:
|
||||
@ -82,7 +82,7 @@ class Visitor(object):
|
||||
(self.filename, node.lineno,
|
||||
self.lines[node.lineno - 1][:-1],
|
||||
predicate.__name__, msg),
|
||||
file=sys.stderr)
|
||||
file=sys.stderr)
|
||||
self.error = 1
|
||||
return
|
||||
elif action == 'warn':
|
||||
|
@ -1,3 +1,17 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import compiler
|
||||
import re
|
||||
|
||||
|
@ -12,10 +12,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
from neutron.i18n import _LI
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from tabulate import tabulate
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -27,9 +29,9 @@ def output_formatter(resource_name, resources_list, attrs):
|
||||
Depending on the --fmt cli option we format the output as
|
||||
JSON or as a table.
|
||||
"""
|
||||
LOG.info('%(resource_name)s', {'resource_name': resource_name})
|
||||
LOG.info(_LI('%(resource_name)s'), {'resource_name': resource_name})
|
||||
if not resources_list:
|
||||
LOG.info('No resources found')
|
||||
LOG.info(_LI('No resources found'))
|
||||
return ''
|
||||
|
||||
fmt = cfg.CONF.fmt
|
||||
@ -50,4 +52,4 @@ def output_formatter(resource_name, resources_list, attrs):
|
||||
for attr in attrs:
|
||||
result[attr] = resource[attr]
|
||||
js_output[resource_name].append(result)
|
||||
return json.dumps(js_output, sort_keys=True, indent=4)
|
||||
return jsonutils.dumps(js_output, sort_keys=True, indent=4)
|
||||
|
@ -15,6 +15,8 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from neutron.i18n import _LI
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -28,7 +30,8 @@ def output_header(func):
|
||||
def func_desc(*args, **kwargs):
|
||||
component = '[%s]' % func.func_name.split('_')[0].upper()
|
||||
op_desc = [n.capitalize() for n in func.func_name.split('_')[1:]]
|
||||
LOG.info('==== %s %s ====', component, ' '.join(op_desc))
|
||||
LOG.info(_LI('==== %(component)s %(operation)s ===='),
|
||||
{'component': component, 'operation': ' '.join(op_desc)})
|
||||
return func(*args, **kwargs)
|
||||
func_desc.__name__ = func.func_name
|
||||
return func_desc
|
||||
|
@ -24,6 +24,7 @@ from neutron.callbacks import registry
|
||||
from neutron import context as neutron_context
|
||||
from neutron.db import common_db_mixin as common_db
|
||||
from neutron.db import securitygroups_db as sg_db
|
||||
from neutron.i18n import _LI
|
||||
|
||||
from vmware_nsx.nsxlib.v3 import dfw_api as firewall
|
||||
|
||||
@ -66,7 +67,7 @@ def nsx_delete_security_groups(resource, event, trigger, **kwargs):
|
||||
default='no')
|
||||
|
||||
if user_confirm is False:
|
||||
LOG.info('NSX security groups cleanup aborted by user')
|
||||
LOG.info(_LI('NSX security groups cleanup aborted by user'))
|
||||
return
|
||||
|
||||
sections = firewall.list_sections()
|
||||
@ -75,8 +76,8 @@ def nsx_delete_security_groups(resource, event, trigger, **kwargs):
|
||||
if sections:
|
||||
NON_DEFAULT_SECURITY_GROUPS = -1
|
||||
for section in sections[:NON_DEFAULT_SECURITY_GROUPS]:
|
||||
LOG.info("Deleting firewall section %(display_name)s, "
|
||||
"section id %(id)s",
|
||||
LOG.info(_LI("Deleting firewall section %(display_name)s, "
|
||||
"section id %(id)s"),
|
||||
{'display_name': section['display_name'],
|
||||
'id': section['id']})
|
||||
firewall.delete_section(section['id'])
|
||||
@ -84,8 +85,8 @@ def nsx_delete_security_groups(resource, event, trigger, **kwargs):
|
||||
nsgroups = firewall.list_nsgroups()
|
||||
if nsgroups:
|
||||
for nsgroup in nsgroups:
|
||||
LOG.info("Deleting ns-group %(display_name)s, "
|
||||
"ns-group id %(id)s",
|
||||
LOG.info(_LI("Deleting ns-group %(display_name)s, "
|
||||
"ns-group id %(id)s"),
|
||||
{'display_name': nsgroup['display_name'],
|
||||
'id': nsgroup['id']})
|
||||
firewall.delete_nsgroup(nsgroup['id'])
|
||||
@ -107,7 +108,8 @@ def neutron_delete_security_groups(resource, event, trigger, **kwargs):
|
||||
'neutron security groups?',
|
||||
default='no')
|
||||
if user_confirm is False:
|
||||
LOG.info('Neutron security groups cleanup aborted by user')
|
||||
LOG.info(_LI('Neutron security groups cleanup aborted by '
|
||||
'user'))
|
||||
return
|
||||
|
||||
security_groups = neutron_sg.get_security_groups()
|
||||
@ -116,10 +118,10 @@ def neutron_delete_security_groups(resource, event, trigger, **kwargs):
|
||||
|
||||
for security_group in security_groups:
|
||||
try:
|
||||
LOG.info('Trying to delete %(sg_id)s',
|
||||
LOG.info(_LI('Trying to delete %(sg_id)s'),
|
||||
{'sg_id': security_group['id']})
|
||||
neutron_sg.delete_security_group(security_group['id'])
|
||||
LOG.info("Deleted security group name: %(name)s id: %(id)s",
|
||||
LOG.info(_LI("Deleted security group name: %(name)s id: %(id)s"),
|
||||
{'name': security_group['name'],
|
||||
'id': security_group['id']})
|
||||
except Exception as e:
|
||||
|
@ -25,18 +25,18 @@ TODO: Autocomplete command line args
|
||||
TODO: Error handling, print only options which are supported
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
import enum
|
||||
import glob
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
from os.path import basename
|
||||
import requests
|
||||
import sys
|
||||
|
||||
from neutron.callbacks import registry
|
||||
from neutron.common import config as neutron_config
|
||||
from neutron.i18n import _LE
|
||||
from neutron.i18n import _LI
|
||||
|
||||
from vmware_nsx.common import config # noqa
|
||||
|
||||
@ -52,7 +52,7 @@ requests.packages.urllib3.disable_warnings()
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Operations(Enum):
|
||||
class Operations(enum.Enum):
|
||||
LIST = 'list'
|
||||
CLEAN = 'clean'
|
||||
|
||||
@ -105,7 +105,8 @@ def _get_plugin_dir():
|
||||
|
||||
def _get_resources():
|
||||
modules = glob.glob(_get_plugin_dir() + "/*.py")
|
||||
return map(lambda module: os.path.splitext(basename(module))[0], modules)
|
||||
return map(lambda module: os.path.splitext(os.path.basename(module))[0],
|
||||
modules)
|
||||
|
||||
|
||||
cli_opts = [cfg.StrOpt('neutron-conf',
|
||||
@ -165,22 +166,24 @@ def _init_cfg():
|
||||
|
||||
def validate_resource_choice(resource, nsx_plugin):
|
||||
if nsx_plugin == 'nsxv' and resource not in nsxv_resources:
|
||||
LOG.error('Supported list of NSX-V resources: %s',
|
||||
LOG.error(_LE('Supported list of NSX-V resources: %s'),
|
||||
nsxv_resources_names)
|
||||
sys.exit(1)
|
||||
elif nsx_plugin == 'nsxv3'and resource not in nsxv3_resources:
|
||||
LOG.error('Supported list of NSX-V3 resources: %s',
|
||||
LOG.error(_LE('Supported list of NSX-V3 resources: %s'),
|
||||
nsxv3_resources_names)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def validate_op_choice(choice, nsx_plugin):
|
||||
if choice is None and nsx_plugin == 'nsxv':
|
||||
LOG.error('Supported list of operations for the NSX-V resource %s',
|
||||
LOG.error(_LE('Supported list of operations for the NSX-V resource '
|
||||
'%s'),
|
||||
nsxv_resources[cfg.CONF.resource].supported_ops)
|
||||
exit(1)
|
||||
elif choice is None and nsx_plugin == 'nsxv3':
|
||||
LOG.error('Supported list of operations for the NSX-V resource %s',
|
||||
LOG.error(_LE('Supported list of operations for the NSX-V3 resource '
|
||||
'%s'),
|
||||
nsxv3_resources[cfg.CONF.resource].supported_ops)
|
||||
sys.exit(1)
|
||||
|
||||
@ -190,7 +193,7 @@ def main(argv=sys.argv[1:]):
|
||||
_init_resource_plugin()
|
||||
|
||||
nsx_plugin_in_use = _get_plugin()
|
||||
LOG.info('NSX Plugin in use: %s', nsx_plugin_in_use)
|
||||
LOG.info(_LI('NSX Plugin in use: %s'), nsx_plugin_in_use)
|
||||
|
||||
validate_resource_choice(cfg.CONF.resource, nsx_plugin_in_use)
|
||||
validate_op_choice(cfg.CONF.operation, nsx_plugin_in_use)
|
||||
|
2
tox.ini
2
tox.ini
@ -79,7 +79,7 @@ commands = python setup.py build_sphinx
|
||||
ignore = E125,E126,E128,E129,E265,H305,H307,H402,H404,H405,H904
|
||||
show-source = true
|
||||
builtins = _
|
||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,.ropeproject
|
||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,.ropeproject,devstack
|
||||
|
||||
[testenv:pylint]
|
||||
deps =
|
||||
|
Loading…
Reference in New Issue
Block a user