Commit d6859078 authored by Neil Williams's avatar Neil Williams Committed by Linaro Code Review
Browse files

pylint-django changes.

Identified using pylint-django plugin, only in unstable/stretch.

Change-Id: I65ca9fde297363aed965d5789b8e10692c839ecb
parent fc39959e
......@@ -5,10 +5,13 @@ from django.contrib.auth.admin import UserAdmin
from django.db.models import Q
from lava_scheduler_app.models import (
Device, DeviceStateTransition, DeviceType, TestJob, Tag, JobFailureTag,
User, Worker, DefaultDeviceOwner, DeviceDictionaryTable,
User, Worker, DefaultDeviceOwner,
Architecture, ProcessorFamily, BitWidth, Core
)
# django admin API itself isn't pylint clean, so some settings must be suppressed.
# pylint: disable=no-self-use,function-redefined
class DefaultOwnerInline(admin.StackedInline):
"""
......@@ -31,21 +34,21 @@ admin.site.unregister(User)
admin.site.register(User, UserAdmin)
def offline_action(modeladmin, request, queryset):
def offline_action(modeladmin, request, queryset): # pylint: disable=unused-argument
for device in queryset.filter(status__in=[Device.IDLE, Device.RUNNING, Device.RESERVED]):
if device.can_admin(request.user):
device.put_into_maintenance_mode(request.user, "admin action")
offline_action.short_description = "take offline"
def online_action(modeladmin, request, queryset):
def online_action(modeladmin, request, queryset): # pylint: disable=unused-argument
for device in queryset.filter(status__in=[Device.OFFLINE, Device.OFFLINING]):
if device.can_admin(request.user):
device.put_into_online_mode(request.user, "admin action")
online_action.short_description = "take online"
def online_action_without_health_check(modeladmin, request, queryset):
def online_action_without_health_check(modeladmin, request, queryset): # pylint: disable=unused-argument,invalid-name
for device in queryset.filter(status__in=[Device.OFFLINE, Device.OFFLINING]):
if device.can_admin(request.user):
device.put_into_online_mode(request.user, "admin action", True)
......@@ -53,7 +56,7 @@ online_action_without_health_check.short_description = \
"take online without manual health check"
def retire_action(modeladmin, request, queryset):
def retire_action(modeladmin, request, queryset): # pylint: disable=unused-argument
for device in queryset:
if device.can_admin(request.user):
new_status = device.RETIRED
......@@ -65,14 +68,14 @@ def retire_action(modeladmin, request, queryset):
retire_action.short_description = "retire"
def cancel_action(modeladmin, request, queryset):
def cancel_action(modeladmin, request, queryset): # pylint: disable=unused-argument
for testjob in queryset:
if testjob.can_cancel(request.user):
testjob.cancel(request.user)
cancel_action.short_description = 'cancel selected jobs'
def health_unknown(modeladmin, request, queryset):
def health_unknown(modeladmin, request, queryset): # pylint: disable=unused-argument
for device in queryset.filter(health_status=Device.HEALTH_PASS):
device.health_status = Device.HEALTH_UNKNOWN
device.save()
......@@ -309,14 +312,15 @@ class DeviceTypeAdmin(admin.ModelAdmin):
ordering = ['name']
def hide_worker_action(modeladmin, request, queryset):
# API defined by django admin
def hide_worker_action(modeladmin, request, queryset): # pylint: disable=unused-argument
for worker in queryset.filter(display=True):
worker.display = False
worker.save()
hide_worker_action.short_description = "Hide selected worker(s)"
def show_worker_action(modeladmin, request, queryset):
def show_worker_action(modeladmin, request, queryset): # pylint: disable=unused-argument
for worker in queryset.filter(display=False):
worker.display = True
worker.save()
......
......@@ -33,6 +33,9 @@ from lava_scheduler_app.dbutils import testjob_submission
# functions need to be members to be exposed in the API
# pylint: disable=no-self-use
# to make a function visible in the API, it must be a member of SchedulerAPI
# pylint: disable=no-self-use
class SchedulerAPI(ExposedAPI):
......@@ -607,7 +610,7 @@ class SchedulerAPI(ExposedAPI):
bundle_sha1 = ""
try:
bundle_sha1 = job.results_link.split('/')[-2]
except:
except IndexError:
pass
job_status = {
......
import re
# DEPRECATED
# pylint: disable=invalid-name,old-style-class,no-init
def getDispatcherErrors(logfile):
errors = []
......
......@@ -21,8 +21,6 @@ from django.db.models import Q
from django_restricted_resource.managers import RestrictedResourceQuerySet
from lava_scheduler_app import utils
class RestrictedTestJobQuerySet(RestrictedResourceQuerySet):
......
......@@ -174,7 +174,7 @@ class JobTable(LavaTable):
super(JobTable, self).__init__(*args, **kwargs)
self.length = 25
id = RestrictedIDLinkColumn(verbose_name="ID", accessor="id")
id = RestrictedIDLinkColumn(verbose_name="ID", accessor="id") # pylint: disable=invalid-name
device = tables.Column(accessor='device_sort')
duration = tables.Column(accessor='duration_sort')
duration.orderable = False
......
# unit tests for primary and secondary connections
import os
import yaml
import logging
from lava_scheduler_app.models import (
Device,
DeviceType,
DeviceDictionary,
JobPipeline,
TestJob,
Tag,
DevicesUnavailableException,
_pipeline_protocols,
SubmissionException,
)
from django.db import models
from django_testscenarios.ubertest import TestCase
from lava_scheduler_app.tests.test_pipeline import YamlFactory
from lava_scheduler_app.utils import jinja_template_path, split_multinode_yaml
from lava_scheduler_app.tests.test_submission import ModelFactory, TestCaseWithFactory
from lava_scheduler_app.schema import SubmissionException
from lava_scheduler_app.utils import jinja_template_path
from lava_scheduler_app.tests.test_submission import TestCaseWithFactory
# TestCaseWithFactory cannot help causing too-many-ancestors, so ignore
# pylint: disable=too-many-ancestors
class YamlSshFactory(YamlFactory):
def make_job_data(self, actions=None, **kw):
......
......@@ -20,6 +20,8 @@ from django.contrib.auth.models import User
from lava_dispatcher.pipeline.device import PipelineDevice
# pylint: disable=blacklisted-name,too-many-ancestors,invalid-name
# python3 needs print to be a function, so disable pylint
# pylint: disable=superfluous-parens
class ModelFactory(object):
......@@ -34,7 +36,7 @@ class ModelFactory(object):
def getUniqueString(self, prefix='generic'):
return '%s-%d' % (prefix, self.getUniqueInteger())
def get_unique_user(self, prefix='generic'):
def get_unique_user(self, prefix='generic'): # pylint: disable=no-self-use
return "%s-%d" % (prefix, User.objects.count() + 1)
def make_user(self):
......@@ -270,10 +272,11 @@ class DeviceDictionaryTest(TestCaseWithFactory):
loader=jinja2.ChoiceLoader([dict_loader, type_loader]),
trim_blocks=True)
template = env.get_template("%s.jinja2" % 'cubie')
device_configuration = template.render()
# pylint gets this wrong from jinja
device_configuration = template.render() # pylint: disable=no-member
chk_template = prepare_jinja_template('cubie', jinja_data, system_path=False, path=jinja2_path)
self.assertEqual(template.render(), chk_template.render())
self.assertEqual(template.render(), chk_template.render()) # pylint: disable=no-member
yaml_data = yaml.load(device_configuration)
self.assertTrue(validate_device(yaml_data))
self.assertIn('timeouts', yaml_data)
......@@ -354,9 +357,9 @@ class DeviceDictionaryTest(TestCaseWithFactory):
vlan.save()
del vlan
vlan = DeviceDictionary.get('vlanned1')
cmp = str(devicedictionary_to_jinja2(vlan.parameters, 'vland.jinja2'))
cmp_str = str(devicedictionary_to_jinja2(vlan.parameters, 'vland.jinja2'))
for line in str(data).split('\n'):
self.assertIn(line, cmp)
self.assertIn(line, cmp_str)
def test_network_map(self):
"""
......
......@@ -14,10 +14,7 @@ from lava_scheduler_app.models import (
_check_submit_to_device,
)
from lava_scheduler_app.dbutils import match_vlan_interface
from django.db import models
from django.db.models import Q
from django.core.exceptions import ValidationError
from django_testscenarios.ubertest import TestCase
from django.contrib.auth.models import Group, Permission, User
from collections import OrderedDict
from lava_scheduler_app.utils import (
......@@ -355,11 +352,13 @@ class TestPipelineSubmit(TestCaseWithFactory):
menu_data = device_config['actions']['boot']['methods']['uefi-menu']['nfs']
self.assertIn(
job_ctx['nfsroot_args'],
[item['select']['enter'] for item in menu_data if 'enter' in item['select'] and
[
item['select']['enter'] for item in menu_data if 'enter' in item['select'] and
'new Entry' in item['select']['wait']][0]
)
self.assertEqual(
[item['select']['items'][0] for item in menu_data if 'select' in item and
[
item['select']['items'][0] for item in menu_data if 'select' in item and
'items' in item['select'] and 'TFTP' in item['select']['items'][0]][0],
'TFTP on MAC Address: FF:01:00:69:AA:CC' # matches the job_ctx
)
......@@ -369,7 +368,8 @@ class TestPipelineSubmit(TestCaseWithFactory):
# the variable, the job could set it to override the device type template default, as shown by the
# override of the base_nfsroot_args by allowing nfsroot_args in the device type template..
self.assertEqual(
[item['select']['enter'] for item in menu_data if 'select' in item and
[
item['select']['enter'] for item in menu_data if 'select' in item and
'wait' in item['select'] and 'Description' in item['select']['wait']][0],
'console=ttyO0,115200 earlyprintk=uart8250-32bit,0x1c020000 debug '
'root=/dev/nfs rw 172.164.56.2:/home/user/nfs/,tcp,hard,intr ip=dhcp'
......@@ -825,7 +825,7 @@ class TestYamlMultinode(TestCaseWithFactory):
for job in job_list:
self.assertEqual(job.requested_device_type, device_type)
def test_multinode_with_retired(self):
def test_multinode_with_retired(self): # pylint: disable=too-many-statements
"""
check handling with retired devices in device_list
"""
......@@ -944,7 +944,7 @@ class VlanInterfaces(TestCaseWithFactory):
device_dict.save()
self.filename = os.path.join(os.path.dirname(__file__), 'bbb-cubie-vlan-group.yaml')
def test_vlan_interface(self):
def test_vlan_interface(self): # pylint: disable=too-many-locals
device_dict = DeviceDictionary.get('bbb-01')
chk = {
'hostname': 'bbb-01',
......
......@@ -38,14 +38,16 @@ from lava_scheduler_app.dbutils import(
)
import simplejson
logger = logging.getLogger()
logger.level = logging.INFO # change to DEBUG to see *all* output
stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)
LOGGER = logging.getLogger()
LOGGER.level = logging.INFO # change to DEBUG to see *all* output
LOGGER.addHandler(logging.StreamHandler(sys.stdout))
# filter out warnings from django sub systems like httpresponse
warnings.filterwarnings('ignore', r"Using mimetype keyword argument is deprecated")
warnings.filterwarnings('ignore', r"StrAndUnicode is deprecated")
# pylint gets confused with TestCase
# pylint: disable=no-self-use,invalid-name,too-many-ancestors,too-many-public-methods
# Based on http://www.technobabble.dk/2008/apr/02/xml-rpc-dispatching-through-django-test-client/
class TestTransport(xmlrpclib.Transport, object):
......@@ -75,11 +77,11 @@ class ModelFactory(object):
def __init__(self):
self._int = 0
def getUniqueInteger(self):
def getUniqueInteger(self): # pylint: disable=invalid-name
self._int += 1
return self._int
def getUniqueString(self, prefix='generic'):
def getUniqueString(self, prefix='generic'): # pylint: disable=invalid-name
return '%s-%d' % (prefix, self.getUniqueInteger())
def get_unique_user(self, prefix='generic'): # pylint: disable=no-self-use
......@@ -116,7 +118,7 @@ class ModelFactory(object):
def ensure_device_type(self, name=None):
if name is None:
name = self.getUniqueString('name')
logging.debug("asking for a device_type with name %s" % name)
logging.debug("asking for a device_type with name %s", name)
device_type = DeviceType.objects.get_or_create(name=name)[0]
self.make_device(device_type)
return device_type
......@@ -128,7 +130,7 @@ class ModelFactory(object):
name=name, health_check_job=health_check_job)
if created:
device_type.save()
logging.debug("asking for a device of type %s" % device_type.name)
logging.debug("asking for a device of type %s", device_type.name)
return device_type
def make_hidden_device_type(self, name=None, health_check_job=None):
......@@ -139,7 +141,7 @@ class ModelFactory(object):
name=name, health_check_job=health_check_job)
if created:
device_type.save()
logging.debug("asking for a device of type %s" % device_type.name)
logging.debug("asking for a device of type %s", device_type.name)
return device_type
def ensure_tag(self, name): # pylint: disable=no-self-use
......@@ -155,8 +157,8 @@ class ModelFactory(object):
# a hidden device type will override is_public
device = Device(device_type=device_type, is_public=is_public, hostname=hostname, **kw)
device.tags = tags
logging.debug("making a device of type %s %s %s with tags '%s'"
% (device_type, device.is_public, device.hostname, ", ".join([x.name for x in device.tags.all()])))
logging.debug("making a device of type %s %s %s with tags '%s'",
device_type, device.is_public, device.hostname, ", ".join([x.name for x in device.tags.all()]))
device.save()
return device
......@@ -766,6 +768,7 @@ class TestHiddenTestJob(TestCaseWithFactory): # pylint: disable=too-many-ancest
self.assertRaises(DevicesUnavailableException, TestJob.from_json_and_user, j, anon_user)
# FIXME: move class and tests into a new file
class TestSchedulerAPI(TestCaseWithFactory): # pylint: disable=too-many-ancestors
def server_proxy(self, user=None, password=None): # pylint: disable=no-self-use
......
import logging
import sys
from django.contrib.auth.models import Group, Permission, User
from django.test import TransactionTestCase
from django.test.client import Client
from django.contrib.auth.models import User
from django_testscenarios.ubertest import TestCase
from lava_scheduler_app.models import (
Device,
......@@ -24,10 +22,12 @@ from dashboard_app.views import (
)
from dashboard_app.models import BundleStream
logger = logging.getLogger()
logger.level = logging.INFO # change to DEBUG to see *all* output
stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)
LOGGER = logging.getLogger()
LOGGER.level = logging.INFO # change to DEBUG to see *all* output
LOGGER.addHandler(logging.StreamHandler(sys.stdout))
# pylint does not like TestCaseWithFactory
# pylint: disable=too-many-ancestors
class TestTable(LavaTable):
......@@ -49,7 +49,7 @@ class TestTestTable(TestCase):
logging.debug("Creating an empty LavaTable")
self.assertEqual(table.length, 10)
def test_default_length(self):
def test_default_length_table(self):
table = TestLengthTable(self.data)
logging.debug("Creating a derived LavaTable")
self.assertEqual(table.length, 25)
......@@ -84,7 +84,7 @@ class TestDeviceView(LavaView):
class TestJobView(LavaView):
def get_queryset(self, request=None):
def get_queryset(self):
return all_jobs_with_custom_sort()
......@@ -166,7 +166,7 @@ class TestForDeviceTable(TestCase):
self.assertEqual(table.prepare_terms_data(view), {prefix: {}})
self.assertEqual(table.prepare_times_data(view), {prefix: []})
def test_device_table_model(self):
def test_device_table_model2(self):
view = TestDeviceView(None, model=Device, table_class=TestDeviceTable)
table = TestDeviceTable(view.get_table_data())
self.assertEqual(table.prepare_search_data(view),
......@@ -196,19 +196,19 @@ class TestHiddenDevicesInDeviceTable(TestCase):
def test_device_table_view(self):
device_type = DeviceType(name="generic", owners_only=False, health_check_job='')
device_type.save()
device_type.save() # pylint: disable=no-member
device = Device(device_type=device_type, hostname='generic1', status=Device.OFFLINE)
user = self.make_user()
device.user = user
device.save()
device.save() # pylint: disable=no-member
view = TestDeviceView(None)
self.assertEqual(len(view.get_queryset()), 1)
def test_device_table_hidden(self):
hidden = DeviceType(name="hidden", owners_only=True, health_check_job='')
hidden.save()
hidden.save() # pylint: disable=no-member
device = Device(device_type=hidden, hostname='hidden1', status=Device.OFFLINE)
device.save()
device.save() # pylint: disable=no-member
view = TestDeviceView(None)
self.assertEqual(len(view.get_queryset()), 0)
......
......@@ -5,12 +5,9 @@ from lava_scheduler_app.utils import split_multinode_yaml
from lava_scheduler_app.dbutils import match_vlan_interface
from lava_scheduler_app.models import (
Device,
DeviceType,
DeviceDictionary,
JobPipeline,
TestJob,
Tag,
DevicesUnavailableException,
)
from lava_scheduler_app.utils import (
devicedictionary_to_jinja2,
......@@ -21,19 +18,21 @@ from lava_scheduler_app.tests.test_pipeline import YamlFactory
from lava_scheduler_app.dbutils import find_device_for_job
from lava_dispatcher.pipeline.device import NewDevice
from lava_dispatcher.pipeline.parser import JobParser
from lava_dispatcher.pipeline.connection import Protocol
from lava_dispatcher.pipeline.protocols.vland import VlandProtocol
from lava_dispatcher.pipeline.protocols.multinode import MultinodeProtocol
# pylint does not like TestCaseWithFactory
# pylint: disable=too-many-ancestors,no-self-use
class VlandFactory(YamlFactory):
def __init__(self):
super(YamlFactory, self).__init__()
super(VlandFactory, self).__init__()
self.bbb1 = None
self.cubie1 = None
def setUp(self):
def setUp(self): # pylint: disable=invalid-name
bbb_type = self.make_device_type(name='bbb')
cubie_type = self.make_device_type(name='cubietruck')
self.bbb1 = self.make_device(bbb_type, hostname='bbb1')
......
......@@ -28,7 +28,6 @@ import socket
import logging
import urlparse
import simplejson
import models
import subprocess
import datetime
import netifaces
......@@ -85,9 +84,8 @@ def rewrite_hostname(result_url):
return result_url
def split_multi_job(json_jobdata, target_group):
def split_multi_job(json_jobdata, target_group): # pylint: disable=too-many-branches,too-many-statements,too-many-locals
node_json = {}
all_nodes = {}
node_actions = {}
node_lmp = {}
shared_config = get_shared_device_config("/etc/lava-server/shared-device-config.yaml")
......@@ -170,9 +168,8 @@ def split_multi_job(json_jobdata, target_group):
return node_json
def split_vm_job(json_jobdata, vm_group):
def split_vm_job(json_jobdata, vm_group): # pylint: disable=too-many-locals,too-many-statements,too-many-branches
node_json = {}
all_nodes = {}
node_actions = {}
vms_list = []
......@@ -292,7 +289,8 @@ def get_lshw_out():
return simplejson.dumps(lshw_out)
def get_ip_address():
# pylint gets confused with netifaces
def get_ip_address(): # pylint: disable=no-member
"""Returns the IP address of the default interface, if found.
"""
ip = '0.0.0.0'
......@@ -322,7 +320,7 @@ def format_sw_info_to_html(data_dict):
return html_content
def installed_packages(prefix=None, package_name=None):
def installed_packages(prefix=None, package_name=None): # pylint: disable=too-many-locals
"""Queries dpkg and filters packages that are related to PACKAGE_NAME.
PREFIX is the installation prefix for the given instance ie.,
......@@ -338,7 +336,7 @@ def installed_packages(prefix=None, package_name=None):
proc = subprocess.Popen(package_cmd, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
package_out, package_err = proc.communicate()
package_out, _ = proc.communicate()
pack_re = re.compile(r"ii\s+(?P<package>\S+)\s+(?P<version>\S+)\s+.*",
re.MULTILINE)
for package in pack_re.findall(package_out):
......@@ -350,7 +348,7 @@ def installed_packages(prefix=None, package_name=None):
cmd = "grep exports %s" % python_path
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate()
out, _ = proc.communicate()
# The output of the command looks like the following, which is a
# string, we process this string to populate the package dictionary.
......@@ -404,7 +402,7 @@ def get_software_info():
# Populate the git status of server code from exports directory.
settings = Settings("lava-server")
instance_config_path = settings._get_pathname("instance")
instance_config_path = settings._get_pathname("instance") # pylint: disable=protected-access
instance_config = ConfigFile.load(instance_config_path)
prefix = os.path.join(instance_config.LAVA_PREFIX,
instance_config.LAVA_INSTANCE)
......@@ -427,7 +425,7 @@ def get_heartbeat_timeout():
If there is no value found, we return a default timeout value 300.
"""
settings = Settings("lava-server")
worker_config_path = settings._get_pathname("worker")
worker_config_path = settings._get_pathname("worker") # pylint: disable=protected-access
try:
worker_config = ConfigFile.load(worker_config_path)
if worker_config and worker_config.HEARTBEAT_TIMEOUT != '':
......@@ -457,7 +455,7 @@ def last_scheduler_tick():
return __last_scheduler_tick
def process_repeat_parameter(json_jobdata):
def process_repeat_parameter(json_jobdata): # pylint: disable=too-many-branches
new_json = {}
new_actions = []
allowed_actions = ["delpoy_linaro_image", "deploy_image",
......@@ -684,8 +682,8 @@ def map_context_overrides(base_template, devicetype_template, system=True): # p
devicetype_data = content.read()
base_keys = []
devicetype_keys = []
base_pattern = '{%\s+set\s+(?P<key>\w+)'
devicetype_pattern = '{{\s+(?P<key>\w+)'
base_pattern = r'{%\s+set\s+(?P<key>\w+)'
devicetype_pattern = r'{{\s+(?P<key>\w+)'
for line in base_data.split('\n'):
match = re.match(base_pattern, line)
if match:
......@@ -718,7 +716,7 @@ def allowed_overrides(device_dict, system=True):
return None
with open(devicetype_file, 'r') as content:
devicetype_data = content.read()
extends_pattern = "{%\s+extends\s+'(?P<key>\S+)'"
extends_pattern = r"{%\s+extends\s+'(?P<key>\S+)'"
base_template = None
for line in devicetype_data.split('\n'):
match = re.search(extends_pattern, line)
......@@ -742,7 +740,7 @@ def _split_multinode_vland(submission, jobs):
return jobs
def split_multinode_yaml(submission, target_group): # pylint: disable=too-many-branches,too-many-locals
def split_multinode_yaml(submission, target_group): # pylint: disable=too-many-branches,too-many-locals,too-many-statements
"""
Handles the lava-multinode protocol requirements.
Uses the multinode protocol requirements to generate as many YAML
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment