Enable zuul unit tests for stx-gui

Enable pylint and fix tox errors resulting from that.

Story: 2003863
Task: 27931

Change-Id: I3455f29ec182ed91966d4724cf49dceb314a1387
Signed-off-by: Kristine Bujold <kristine.bujold@windriver.com>
This commit is contained in:
Kristine Bujold 2018-11-21 16:53:55 -05:00
parent 4f0afaf708
commit e79dcfae87
25 changed files with 301 additions and 44 deletions

View File

@ -7,12 +7,26 @@
- build-openstack-releasenotes
- openstack-tox-pep8
- openstack-tox-linters
- stx-gui-pylint
gate:
jobs:
- build-openstack-releasenotes
- openstack-tox-pep8
- openstack-tox-linters
- stx-gui-pylint
post:
jobs:
- publish-stx-tox
- publish-stx-releasenotes
- job:
name: stx-gui-pylint
parent: openstack-tox-pylint
description: Run pylint for stx-gui
vars:
tox_envlist: pylint
required-projects:
- openstack/stx-config
- openstack/stx-fault
- openstack/stx-update
- openstack/stx-nfv

224
pylint.rc Executable file
View File

@ -0,0 +1,224 @@
[MASTER]
# Specify a configuration file.
rcfile=pylint.rc
# Python code to execute, usually for sys.path manipulation such as pygtk.require().
#init-hook=
# Add files or directories to the blacklist. They should be base names, not paths.
#ignore=
# Pickle collected data for later comparisons.
persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
[MESSAGES CONTROL]
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time.
#enable=
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
# W0201 attribute-defined-outside-init
# W0212 protected-access var starting with _ used outside class or descendant
# W0221 arguments-differ
# W0222 signature-differs
# W0235 useless-super-delegation
# W0403 relative-import warning
# W0511 fixme
# W0613 Unused argument warning
# W0703 broad except warning
# E0202 method-hidden
# E0203 access-member-before-definition
# E1101 no-member
disable=C, R, W0201, W0212, W0221, W0222, W0235, W0403, W0511, W0613, W0703,
E0202, E0203, E1101
[REPORTS]
# Set the output format. Available formats are text, parseable, colorized, msvs
# (visual studio) and html
output-format=text
# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no
# Tells whether to display a full report or only the messages
reports=no
# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
# respectively contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
[SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines=4
# Ignore comments when computing similarities.
ignore-comments=yes
# Ignore docstrings when computing similarities.
ignore-docstrings=yes
[FORMAT]
# Maximum number of characters on a single line.
max-line-length=85
# Maximum number of lines in a module
max-module-lines=1000
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 tab).
indent-string=' '
[TYPECHECK]
# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
ignore-mixin-members=yes
# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set).
ignored-classes=SQLObject,sqlalchemy,scoped_session,_socketobject,ObjectData,GuestService,Network,SwUpdate
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular
# expressions are accepted.
generated-members=REQUEST,acl_users,aq_parent
[BASIC]
# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input
# Regular expression which should only match correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
# Regular expression which should only match correct module level names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
# Regular expression which should only match correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$
# Regular expression which should only match correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct list comprehension /
# generator expression variable names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=__.*__
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
[VARIABLES]
# Tells whether we should check for unused import in __init__ files.
init-import=no
# A regular expression matching the beginning of the name of dummy variables
# (i.e. not used).
dummy-variables-rgx=_|dummy
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=
[IMPORTS]
# Deprecated modules which should not be used, separated by a comma
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report RP0402 must not be disabled)
import-graph=
# Create a graph of external dependencies in the given file (report RP0402 must
# not be disabled)
ext-import-graph=
# Create a graph of internal dependencies in the given file (report RP0402 must
# not be disabled)
int-import-graph=
[DESIGN]
# Maximum number of arguments for function / method
max-args=5
# Argument names that match this expression will be ignored. Default to name
# with leading underscore
ignored-argument-names=_.*
# Maximum number of locals for function / method body
max-locals=15
# Maximum number of return / yield for function / method body
max-returns=6
# Maximum number of branch for function / method body
max-branchs=12
# Maximum number of statements in function / method body
max-statements=50
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of attributes for a class (see R0902).
max-attributes=7
# Minimum number of public methods for a class (see R0903).
min-public-methods=2
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
[CLASSES]
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp
# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
[EXCEPTIONS]
# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception

View File

@ -1,2 +1,2 @@
SRC_DIR="starlingx-dashboard"
TIS_PATCH_VER=17
TIS_PATCH_VER=20

View File

@ -64,9 +64,9 @@ def provider_network_modify(request, providernet_id, **kwargs):
def provider_network_range_create(request, **kwargs):
body = {'providernet_range': kwargs}
range = neutronclient(request).create_providernet_range(body=body).get(
_range = neutronclient(request).create_providernet_range(body=body).get(
'providernet_range')
return ProviderNetworkRange(range)
return ProviderNetworkRange(_range)
def provider_network_range_list(request, **params):
@ -77,9 +77,9 @@ def provider_network_range_list(request, **params):
def provider_network_range_get(request, range_id,
expand_subnet=True, **params):
range = neutronclient(request).show_providernet_range(
_range = neutronclient(request).show_providernet_range(
range_id, **params).get('providernet_range')
return ProviderNetworkRange(range)
return ProviderNetworkRange(_range)
def provider_network_range_delete(request, range_id):
@ -88,9 +88,9 @@ def provider_network_range_delete(request, range_id):
def provider_network_range_modify(request, range_id, **kwargs):
body = {'providernet_range': kwargs}
range = neutronclient(request).update_providernet_range(
_range = neutronclient(request).update_providernet_range(
range_id, body=body).get('providernet_range')
return ProviderNetworkRange(range)
return ProviderNetworkRange(_range)
def qos_list(request):

View File

@ -64,8 +64,8 @@ class Client(object):
return self._make_request(self.token_id, "GET", self.version,
"query_hosts")
def upload(self, file):
encoder = MultipartEncoder(fields=file)
def upload(self, patchfile):
encoder = MultipartEncoder(fields=patchfile)
return self._make_request(self.token_id, "POST", self.version,
"upload", encoder=encoder)
@ -206,8 +206,8 @@ def get_message(data):
def upload_patch(request, patchfile, name):
file = {'file': (name, patchfile,)}
resp = _patching_client(request).upload(file)
_file = {'file': (name, patchfile,)}
resp = _patching_client(request).upload(_file)
return get_message(resp)

View File

@ -244,7 +244,7 @@ class UnsuppressEvent(tables.BatchAction):
class EventsSuppressionTable(tables.DataTable):
# noinspection PyMethodParameters
def description_inject(row_data):
def description_inject(row_data): # pylint: disable=no-self-argument
description = \
escape_html(str(row_data.description)).replace("\n", "<br/>")
description = description.replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;")

View File

@ -115,7 +115,7 @@ class ActiveAlarmsTab(tabs.TableTab):
search_opts = {}
# get retrieve parameters from request/session env
limit = \
self.request.GET.get(tables.AlarmsTable._meta.limit_param,
self.request.GET.get(tables.AlarmsTable.Meta.limit_param,
None)
search_opts = self.get_filters()
@ -150,8 +150,8 @@ class ActiveAlarmsTab(tabs.TableTab):
event_types = self.tab_group.kwargs['suppression_list']
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve event suppression table \ '
'list.'))
_('Unable to retrieve event suppression table'
' list.'))
return event_types
@ -236,10 +236,10 @@ class EventLogTab(tabs.TableTab):
# get retrieve parameters from request/session env
marker = \
self.request.GET.get(tables.EventLogsTable._meta.pagination_param,
self.request.GET.get(tables.EventLogsTable.Meta.pagination_param,
None)
limit = \
self.request.GET.get(tables.EventLogsTable._meta.limit_param,
self.request.GET.get(tables.EventLogsTable.Meta.limit_param,
None)
search_opts = self.get_filters({'marker': marker,
'limit': limit,

View File

@ -135,7 +135,7 @@ class BannerView(TemplateView):
template_name = 'header/_alarm_banner.html'
def get_context_data(self, **kwargs):
context = super(TemplateView, self).get_context_data(**kwargs)
context = super(BannerView, self).get_context_data(**kwargs)
if not self.request.is_ajax():
raise exceptions.NotFound()

View File

@ -28,9 +28,9 @@ LOG = logging.getLogger(__name__)
def get_alarms_for_entity(alarms, entity_str):
matched = []
for alarm in alarms:
for id in alarm.entity_instance_id.split('.'):
for _id in alarm.entity_instance_id.split('.'):
try:
if entity_str == id.split('=')[1]:
if entity_str == _id.split('=')[1]:
matched.append(alarm)
except Exception:
# malformed entity_instance_id
@ -73,7 +73,7 @@ class OverviewTab(tabs.TableTab):
def _get_tenant_list(self):
if not hasattr(self, "_tenants"):
try:
tenants, has_more = api.keystone.tenant_list(self.request)
tenants, has_more = api.keystone.tenant_list(self.request) # noqa pylint: disable=unused-variable
except Exception:
tenants = []
msg = _('Unable to retrieve instance project information.')

View File

@ -140,10 +140,10 @@ class UsageView(tables.MultiTableView):
try:
_object = stx_api.nova.get_detail_usage(self.request, dev_id)
_object.sort(key=lambda f: (f.host))
id = 0
_id = 0
for u in _object:
id += 1
u.id = id
_id += 1
u.id = _id
self._detail_object = _object
except Exception:

View File

@ -269,10 +269,12 @@ class UpdateMemory(forms.SelfHandlingForm):
try:
for nd in node:
node_found = False
memory = None
for m in self.host.memorys:
for n in self.host.nodes:
if m.inode_uuid == n.uuid:
if int(n.numa_node) == int(node.index(nd)):
memory = m
node_found = True
break
if node_found:
@ -288,7 +290,7 @@ class UpdateMemory(forms.SelfHandlingForm):
new_data['vm_hugepages_nr_1G_pending'] = pages_1G[nd]
if new_data:
stx_api.sysinv.host_memory_update(request, m.uuid,
stx_api.sysinv.host_memory_update(request, memory.uuid,
**new_data)
else:

View File

@ -296,7 +296,7 @@ class ParamForm(ParamMixin, forms.SelfHandlingForm):
return data
def get_context_data(self, **kwargs):
context = super(EditParam, self).get_context_data(**kwargs)
context = super(ParamForm, self).get_context_data(**kwargs)
context.update(self._lvg)
return context

View File

@ -24,7 +24,7 @@ class EditView(forms.ModalFormView):
success_url = 'horizon:admin:inventory:localvolumegroupdetail'
def get_form(self, form_class):
self.form = super(self.__class__, self).get_form(form_class)
self.form = super(EditView, self).get_form(form_class)
return self.form
def get_context_data(self, **kwargs):

View File

@ -124,10 +124,9 @@ def profile_get_uuid(request, profilename):
for iprofile in profiles:
if iprofile.profilename == profilename:
break
else:
raise forms.ValidationError("Profile not found: %s" % profilename)
return iprofile.uuid
return iprofile.uuid
raise forms.ValidationError("Profile not found: %s" % profilename)
class AddHostInfoAction(workflows.Action):

View File

@ -103,7 +103,7 @@ class CreateProviderNetworkRange(forms.SelfHandlingForm):
**kwargs)
tenant_choices = [('', _("Select a project"))]
tenants, has_more = api.keystone.tenant_list(request)
tenants, has_more = api.keystone.tenant_list(request) # noqa pylint: disable=unused-variable
for tenant in tenants:
if tenant.enabled:
tenant_choices.append((tenant.id, tenant.name))

View File

@ -58,7 +58,7 @@ class DetailView(tables.MultiTableView):
def _get_tenant_list(self):
if not hasattr(self, "_tenants"):
try:
tenants, has_more = api.keystone.tenant_list(self.request)
tenants, has_more = api.keystone.tenant_list(self.request) # noqa pylint: disable=unused-variable
except Exception:
tenants = []
msg = _('Unable to retrieve instance project information.')

View File

@ -78,7 +78,7 @@ class CreateForm(forms.SelfHandlingForm):
all_projects = []
try:
# Get list of available projects.
all_projects, has_more = api.keystone.tenant_list(request)
all_projects, has_more = api.keystone.tenant_list(request) # noqa pylint: disable=unused-variable
projects_list = [(project.id, project.name)
for project in all_projects]

View File

@ -106,7 +106,7 @@ class EditAttachmentsView(tables.DataTableView, forms.ModalFormView):
def get_initial(self):
try:
instances, has_more = api.nova.server_list(self.request)
instances, has_more = api.nova.server_list(self.request) # noqa pylint: disable=unused-variable
except Exception:
instances = []
exceptions.handle(self.request,

View File

@ -6,7 +6,6 @@
import logging
from django.core.urlresolvers import reverse # noqa
from django.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _

View File

@ -10,7 +10,7 @@ from django.utils.translation import ugettext_lazy as _
import horizon
# Load the api rest services into Horizon
import starlingx_dashboard.api.rest # noqa
import starlingx_dashboard.api.rest # noqa: F401 pylint: disable=unused-import
class DCAdmin(horizon.Dashboard):

View File

@ -7,7 +7,7 @@
import logging
from django.core.urlresolvers import reverse # noqa
from django.template.defaultfilters import safe, title # noqa
from django.template.defaultfilters import safe
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy

View File

@ -39,7 +39,6 @@ DELETABLE_STATES = ("available", "error")
class DeleteServerGroup(tables.DeleteAction):
data_type_singular = _("Server Group")
data_type_plural = _("Server Groups")
action_past = _("Scheduled deletion of")
@staticmethod
def action_present(count):
@ -213,8 +212,6 @@ class ServerGroupsTable(tables.DataTable):
class DetachServerGroup(tables.BatchAction):
name = "detach"
action_present = _("Detach")
action_past = _("Detaching") # This action is asynchronous.
data_type_singular = _("Server Group")
data_type_plural = _("Server Groups")
classes = ('btn-danger', 'btn-detach')

View File

@ -106,7 +106,7 @@ class EditAttachmentsView(tables.DataTableView, forms.ModalFormView):
def get_initial(self):
try:
instances, has_more = api.nova.server_list(self.request)
instances, has_more = api.nova.server_list(self.request) # noqa pylint: disable=unused-variable
except Exception:
instances = []
exceptions.handle(self.request,

View File

@ -1,2 +1,2 @@
from starlingx_dashboard.stx_horizon.tables.actions import FixedWithQueryFilter # noqa
from starlingx_dashboard.stx_horizon.tables.actions import LimitAction # noqa
from starlingx_dashboard.horizon.tables.actions import FixedWithQueryFilter # noqa
from starlingx_dashboard.horizon.tables.actions import LimitAction # noqa

22
tox.ini
View File

@ -2,6 +2,7 @@
envlist = pep8
minversion = 2.3
skipsdist = True
stxdir = {toxinidir}/..
[testenv]
install_command = pip install -U {opts} {packages}
@ -54,6 +55,27 @@ deps =
commands =
flake8
[testenv:pylint]
basepython = python2.7
usedevelop = False
skip_install = True
deps = {[testenv]deps}
git+git://github.com/starlingx-staging/stx-python-novaclient.git
git+git://github.com/starlingx-staging/stx-python-neutronclient.git
git+git://github.com/starlingx-staging/stx-horizon.git
git+git://github.com/starlingx-staging/stx-distcloud-client.git
-e{[tox]stxdir}/stx-config/sysinv/cgts-client/cgts-client
-e{[tox]stxdir}/stx-config/sysinv/sysinv/sysinv
-e{[tox]stxdir}/stx-fault/python-fmclient/fmclient
-e{[tox]stxdir}/stx-update/cgcs-patch/cgcs-patch
-e{[tox]stxdir}/stx-nfv/nfv/nfv-client
requests-toolbelt
pylint
commands =
pylint --rcfile=./pylint.rc --version
pylint starlingx-dashboard/starlingx-dashboard/starlingx_dashboard \
--rcfile=./pylint.rc
[testenv:venv]
basepython = python3
commands = {posargs}