Commit 9afa6092 authored by Jérome Perrin's avatar Jérome Perrin

pylint (+some dangerous fixes)

parent 831075b1
Pipeline #18915 failed with stage
in 0 seconds
......@@ -36,6 +36,7 @@ import time
import os
import tempfile
import six
import slapos.slap
from slapos.slap.slap import ConnectionError
......@@ -44,7 +45,7 @@ from slapos.grid.utils import setRunning, setFinished
from erp5.util.taskdistribution import TaskDistributor
from erp5.util.testnode.Updater import Updater
from erp5.util.testnode.ProcessManager import SubprocessError, ProcessManager, CancellationError
from erp5.util.testnode.ProcessManager import SubprocessError, ProcessManager
......@@ -121,8 +122,7 @@ def loadConfiguration(configuration, logger):
for key in ('request_kw', ):
if key in section_entry_dict:
try:
if isinstance(section_entry_dict[key], str) or \
isinstance(section_entry_dict[key], unicode):
if isinstance(section_entry_dict[key], six.string_types):
section_entry_dict[key] = json.loads(section_entry_dict[key])
except Exception:
logger.error("Fail to load %s on %s" % (key, section_entry_dict))
......@@ -167,7 +167,7 @@ def getAndUpdateFullRevisionList(node_test_suite, working_directory,
branch = vcs_repository.get('branch')
# Make sure we have local repository
updater = Updater(repository_path, git_binary=git_binary,
branch=branch, log=logger.info, process_manager=process_manager,
Please register or sign in to reply
branch=branch, process_manager=process_manager,
working_directory=working_directory,
url=vcs_repository["url"])
......@@ -295,8 +295,8 @@ def main():
)
if test_result is None:
# We already have a test result
logger.info('Skiping test for %s, result already available (%s)' %
(test_suite['test_suite_title'], ','.join(full_revision_list)))
logger.info('Skiping test for %s, result already available (%s)',
test_suite['test_suite_title'], ','.join(full_revision_list))
continue
test_result.watcher_period = 120
......@@ -305,10 +305,10 @@ def main():
if log_file is not None:
test_result.addWatch(log, log_file, max_history_bytes=10000)
logger.info("Starting to run for %s" % test_result )
logger.info("Starting to run for %s", test_result )
test_mapping = TestMap(unit_test_dict)
logger.info("Running %s tests in parallel." % \
logger.info("Running %s tests in parallel.",
len(test_mapping.getGroupList()))
assert master_url.startswith('https:')
......@@ -335,7 +335,7 @@ def main():
running_test_dict = {}
logger.info('Starting Test Agent run %s ' % agent_parameter_dict['node_title'])
logger.info('Starting Test Agent run %s ', agent_parameter_dict['node_title'])
while True:
# Get up to parallel_task_count tasks to execute
while len(running_test_dict) < len(test_mapping.getGroupList())\
......@@ -352,13 +352,13 @@ def main():
test_line = test_result.start(
exclude_list=list(test_mapping.getExcludeList(group)))
logger.info("Test Line: %s " % test_line)
logger.info("Ran Test Set: %s " % test_mapping.ran_test_set)
logger.info("Running test dict: %s " % running_test_dict)
logger.info("Group: %s " % group)
logger.info("Test Line: %s ", test_line)
logger.info("Ran Test Set: %s ", test_mapping.ran_test_set)
logger.info("Running test dict: %s ", running_test_dict)
logger.info("Group: %s ", group)
if test_line is None:
logger.info("Removing Group (empty test line): %s " % group)
logger.info("Removing Group (empty test line): %s ", group)
test_mapping.dropGroup(group)
continue
......@@ -404,11 +404,11 @@ def main():
try:
deadline = tester.tic(now)
except ConnectionError:
logger.exception('Test execution ConnectionError for %s' % (section))
logger.exception('Test execution ConnectionError for %s', section)
deadline = next_deadline
except Exception:
logger.exception('Test execution fail for %s' % (section))
logger.exception('Test execution fail for %s', section)
test_line.stop(test_count=1, error_count=1, failure_count=0,
skip_count=0, command=tester.getInfo(),
stdout=tester.getFormatedLastMessage(),
......@@ -426,10 +426,10 @@ def main():
raise
else:
logger.info('%r' % tester)
logger.info('%r', tester)
if deadline is None:
# TODO: report how long each step took.
logger.info('Test execution finished for %s' % (section))
logger.info('Test execution finished for %s', section)
test_line.stop(test_count=1, error_count=0, failure_count=0,
skip_count=0, command=tester.getInfo(), stdout=tester.getFormatedLastMessage())
......@@ -453,10 +453,10 @@ def main():
logger.info('Sleeping %is...', to_sleep)
time.sleep(to_sleep)
if not test_result.isAlive():
for _, tester, computer_id in six.itervalues(running_test_dict):
for _, tester, _ in six.itervalues(running_test_dict):
tester.teardown()
time.sleep(300)
time.sleep(300)
finally:
if pidfile:
setFinished(pidfile)
......
......@@ -17,6 +17,8 @@ from requests.exceptions import HTTPError
from erp5.util.taskdistribution import SAFE_RPC_EXCEPTION_LIST
import six
SOFTWARE_PRODUCT_NAMESPACE = "product."
SOFTWARE_STATE_UNKNOWN = "SOFTWARE_STATE_UNKNOWN"
......@@ -52,7 +54,7 @@ def retryOnNetworkFailure(func):
while True:
try:
return func(*args, **kwargs)
except SAFE_RPC_EXCEPTION_LIST as e:
except SAFE_RPC_EXCEPTION_LIST as e: # pylint:disable=catching-non-exception
print('Network failure: %s , %s' % (sys.exc_info(), e))
except HTTPError as e:
print('Network failure: %s , %s' % (sys.exc_info(), e))
......@@ -254,8 +256,7 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
self.name = name
self.computer_guid = computer_guid
if isinstance(request_kw, str) or \
isinstance(request_kw, unicode):
if isinstance(request_kw, six.string_types):
self.request_kw = json.loads(request_kw)
else:
self.request_kw = request_kw
......
......@@ -4,6 +4,7 @@ from __future__ import print_function
from six.moves import configparser
import argparse
from six.moves import dbm_gnu as gdbm
import six
import sys
import os
......@@ -18,7 +19,7 @@ def main():
parser.add_argument('database', type=str,
help='slapcontainer database')
log_lvls = [lvl for lvl in logging._levelNames.keys()
if isinstance(lvl, basestring)]
if isinstance(lvl, six.string_types)]
parser.add_argument('--log', nargs=1, default=['INFO'],
choices=log_lvls,
metavar='lvl', help='Log level')
......
......@@ -120,4 +120,4 @@ def app(style, output, input_list, delay):
if __name__ == '__main__':
cli()
cli() # pylint:disable=no-value-for-parameter
......@@ -123,7 +123,7 @@ class EqueueServer(socketserver.ThreadingUnixStreamServer):
return False
def _runCommandIfNeeded(self, command, timestamp):
with self.thread_lock as thread_lock, self.lockfile as lockfile:
with self.thread_lock, self.lockfile:
if self._hasTakeoverBeenTriggered():
self.logger.info('Takeover has been triggered, preventing to run import script.')
return
......@@ -145,13 +145,13 @@ class EqueueServer(socketserver.ThreadingUnixStreamServer):
self.logger.info("%s finished successfully.", cmd_readable)
self.db[cmd_executable] = str(timestamp)
else:
self.logger.warning("%s exited with status %s." % (cmd_readable, p.returncode))
self.logger.warning("%s exited with status %s.", cmd_readable, p.returncode)
except subprocess.CalledProcessError as e:
self.logger.warning("%s exited with status %s. output is: \n %s" % (
self.logger.warning("%s exited with status %s. output is: \n %s",
cmd_readable,
e.returncode,
e.output,
))
)
def process_request_thread(self, request, client_address):
# Handle request
......
......@@ -51,7 +51,7 @@ def buildStatistic(history_folder):
result[day][str(entry["status"])] += 1
f.close()
for date, stat in result.iteritems():
for stat in result.values():
stats_list.append(
{"status": "ERROR" if stat["ERROR"] > 0 else "OK",
"change-time": now,
......
......@@ -183,8 +183,7 @@ def generateMonitoringData(config, public_folder, private_folder, public_url,
def savePromiseHistory(promise_name, state_dict, previous_state_list,
history_folder):
if not os.path.exists(history_folder) and os.path.isdir(history_folder):
self.logger.warning('Bad promise history folder, history is not saved...')
return
raise RuntimeError('Bad promise history folder, history is not saved...')
history_file = os.path.join(
history_folder,
......
......@@ -110,7 +110,7 @@ class MonitorPromiseLauncher(object):
except ValueError:
pid = None
if pid and os.path.exists("/proc/" + str(pid)):
self.logger.warning("A process is already running with pid " + str(pid))
self.logger.warning("A process is already running with pid %s", pid)
return []
with open(self.config.pid_path, 'w') as fpid:
......
......@@ -38,7 +38,7 @@ class Parser(OptionParser):
"""
Check arguments
"""
(options, args) = self.parse_args()
_, args = self.parse_args()
if len(args) != 2:
self.error("Incorrect number of arguments")
url, file_path = args
......
......@@ -22,8 +22,8 @@ class RunPromise(GenericPromise):
certificate_expiration_days = int(
self.getConfig('certificate-expiration-days', '15'))
except ValueError:
self.logger.error('ERROR certificate-expiration-days is wrong: %r' % (
self.getConfig('certificate-expiration-days')))
self.logger.error('ERROR certificate-expiration-days is wrong: %r',
self.getConfig('certificate-expiration-days'))
return
try:
......@@ -32,8 +32,8 @@ class RunPromise(GenericPromise):
str2bytes(fh.read()), default_backend())
except Exception as e:
self.logger.error(
'ERROR Problem loading certificate %r, error: %s' % (
certificate_file, e))
'ERROR Problem loading certificate %r, error: %s',
certificate_file, e)
return
try:
......@@ -42,22 +42,22 @@ class RunPromise(GenericPromise):
str2bytes(fh.read()), None, default_backend())
except Exception as e:
self.logger.error(
'ERROR Problem loading key %r, error: %s' % (key_file, e))
'ERROR Problem loading key %r, error: %s', key_file, e)
return
if certificate.public_key().public_numbers() != \
key.public_key().public_numbers():
self.logger.error(
'ERROR Certificate %r does not match key %r' % (
certificate_file, key_file))
'ERROR Certificate %r does not match key %r',
certificate_file, key_file)
return
if certificate.not_valid_after - datetime.timedelta(
days=certificate_expiration_days) < datetime.datetime.utcnow():
self.logger.error(
'ERROR Certificate %r will expire in less than %s days' % (
certificate_file, certificate_expiration_days))
'ERROR Certificate %r will expire in less than %s days',
certificate_file, certificate_expiration_days)
return
self.logger.info(
'OK Certificate %r and key %r are ok' % (certificate_file, key_file))
'OK Certificate %r and key %r are ok', certificate_file, key_file)
\ No newline at end of file
......@@ -32,14 +32,14 @@ class RunPromise(GenericPromise):
status = e.returncode
except Exception as e:
self.logger.error(
"ERROR %r during running command %r" % (e, command))
"ERROR %r during running command %r", e, command)
return
if status != 0:
self.logger.error(
'ERROR %r run with failure, output: %r' % (command, out))
'ERROR %r run with failure, output: %r', command, out)
else:
self.logger.info("OK %r run with success" % (command,))
self.logger.info("OK %r run with success", command)
def anomaly(self):
return self._anomaly(result_count=self.result_count, failure_amount=self.failure_amount)
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise, TestResult
from slapos.grid.promise.generic import GenericPromise
import re
import time
import os
......@@ -74,8 +74,8 @@ class RunPromise(GenericPromise):
timeout += 1
error_amount += 1
if error_amount:
self.logger.error("ERROR=%s (NOROUTE=%s, UNREACHABLENET=%s, TIMEOUT=%s)" % (
error_amount, no_route_error, network_is_unreachable, timeout))
self.logger.error("ERROR=%s (NOROUTE=%s, UNREACHABLENET=%s, TIMEOUT=%s)",
error_amount, no_route_error, network_is_unreachable, timeout)
else:
self.logger.info("OK")
......
......@@ -33,7 +33,7 @@ class RunPromise(GenericPromise):
m = r.match(line)
if m is None:
continue
dt, _, level, msg = m.groups()
dt, _, _, _ = m.groups()
try:
t = time.strptime(dt.decode('utf-8'), "%Y-%m-%d %H:%M:%S")
except ValueError:
......@@ -43,9 +43,9 @@ class RunPromise(GenericPromise):
break
error_amount += 1
if error_amount > error_threshold:
self.logger.error('ERROR: Site has %s long request' % error_amount)
self.logger.error('ERROR: Site has %s long request', error_amount)
else:
self.logger.info('INFO: Site has %s long request' % error_amount)
self.logger.info('INFO: Site has %s long request', error_amount)
def test(self):
return self._test(result_count=1, failure_amount=1)
......
......@@ -27,7 +27,7 @@ class RunPromise(GenericPromise):
if exists:
self.logger.error("ERROR %r not absent", filename)
else:
self.logger.info("OK %r state %r" % (filename, state))
self.logger.info("OK %r state %r", filename, state)
return
if not exists:
self.logger.error("ERROR %r not present", filename)
......@@ -38,19 +38,18 @@ class RunPromise(GenericPromise):
result = f.read()
except Exception as e:
self.logger.error(
"ERROR %r during opening and reading file %r" % (e, filename))
"ERROR %r during opening and reading file %r", e, filename)
return
if state == 'empty' and result != '':
message_list = ['ERROR %r not empty' % (filename,)]
if url:
message_list.append(', content available at %s' % (url,))
message_list.append(', content available at %s', url)
self.logger.error(''.join(message_list))
elif state == 'not-empty' and result == '':
self.logger.error(
"ERROR %r empty" % (filename,))
self.logger.error("ERROR %r empty", filename)
else:
self.logger.info("OK %r state %r" % (filename, state))
self.logger.info("OK %r state %r", filename, state)
def anomaly(self):
return self._anomaly(result_count=1, failure_amount=1)
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise, TestResult
from slapos.grid.promise.generic import GenericPromise
from slapos.networkbench.ping import ping, ping6
@implementer(interface.IPromise)
......
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise, TestResult
from slapos.grid.promise.generic import GenericPromise
from slapos.networkbench.ping import ping, ping6
@implementer(interface.IPromise)
......@@ -29,8 +29,8 @@ class RunPromise(GenericPromise):
result_ipv4 = ping(ipv4, count=count)
result_ipv6 = ping6(ipv6, count=count)
# push into to the log file
self.logger.info("%s host=%s code=%s, result=%s, packet_lost_ratio=%s msg=%s" % result_ipv4)
self.logger.info("%s host=%s code=%s, result=%s, packet_lost_ratio=%s msg=%s" % result_ipv6)
self.logger.info("%s host=%s code=%s, result=%s, packet_lost_ratio=%s msg=%s", *result_ipv4)
self.logger.info("%s host=%s code=%s, result=%s, packet_lost_ratio=%s msg=%s", *result_ipv6)
if result_ipv4[3] == "failed" and result_ipv6[3] != "failed":
# IPv4 is unreacheable
......@@ -54,7 +54,7 @@ class RunPromise(GenericPromise):
# Increase latency with the value.
latency4 += acceptable_delay + latency4 * acceptable_lost
if latency4 < latency6:
self.logger.error("FAIL %s (latency4) > %s (latence6)" % (latency4, latency6))
self.logger.error("FAIL %s (latency4) > %s (latence6)", latency4, latency6)
else:
# Compare if both has Same working rate
self.logger.info("OK: IPv4 reachable, IPv6 reachable")
......
......@@ -41,7 +41,7 @@ class RunPromise(GenericPromise):
try:
threshold = float(load_threshold)
except ValueError as e:
self.logger.error("CPU load threshold %r is not valid: %s" % (load_threshold, e))
self.logger.error("CPU load threshold %r is not valid: %s", load_threshold, e)
return
self.checkCPULoad(threshold or 2.2)
......
......@@ -88,7 +88,7 @@ class RunPromise(GenericPromise):
else:
self.logger.error(
"ERROR Unknown SSL error %r while accessing %r", e, url)
except requests.ConnectionError as e:
except requests.ConnectionError:
self.logger.error(
"ERROR connection not possible while accessing %r", url)
except Exception as e:
......
......@@ -31,7 +31,7 @@ class RunPromise(GenericPromise):
command_string = ' '.join(process.cmdline())
if "monitor.bootstrap" in command_string and \
self.getPartitionFolder() in command_string:
for i in range(0, 15):
for _ in range(0, 15):
if process.is_running():
time.sleep(1)
else:
......
......@@ -26,7 +26,7 @@ class RunPromise(GenericPromise):
args = [wrapper, 'metric', 'get', 'proxy.process.cache.percent_full']
message = "Cache not available, occupation: %s"
else:
self.logger.error("Wrapper %r not supported." % (wrapper,))
self.logger.error("Wrapper %r not supported.", wrapper)
return
try:
......
......@@ -226,7 +226,7 @@ class QemuQMPWrapper(object):
try:
self._readResponse(only_event=True)
except socket.error as err:
if err[0] == errno.EAGAIN:
if err[0] == errno.EAGAIN: # pylint:disable=unsubscriptable-object
# No data available
pass
finally:
......
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111
import datetime
import hashlib
......
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111
import os
import re
......
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111,R0904,R0903
from six.moves import configparser
import datetime
import flask
import json
import logging
import logging.handlers
import os
......@@ -60,7 +60,7 @@ class Config:
file_handler = logging.FileHandler(self.log_file)
file_handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
self.logger.addHandler(file_handler)
self.logger.info('Configured logging to file %r' % self.log_file)
self.logger.info('Configured logging to file %r', self.log_file)
self.logger.info("Started.")
self.logger.info(os.environ['PATH'])
......
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111,R0904
#############################################
# !!! Attention !!!
......@@ -28,14 +27,13 @@ from six.moves.urllib.request import Request, urlopen
import six
from slapos.runner.utils import (getProfilePath,
getSession, isInstanceRunning,
isSoftwareRunning, startProxy,
isInstanceRunning,
isSoftwareRunning,
isSoftwareReleaseReady,
runSlapgridUntilSuccess, runInstanceWithLock,
getBuildAndRunParams, saveBuildAndRunParams)
from slapos.runner import views
import slapos.slap
from slapos.htpasswd import HtpasswdFile
from .run import Config
import erp5.util.taskdistribution as taskdistribution
......
# pylint: disable-msg=W0311,C0103
import os
import signal
import time
......
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142
from six.moves import configparser
import datetime
......@@ -18,7 +17,6 @@ from six.moves.urllib.request import urlopen
import six.moves.xmlrpc_client as xmlrpclib
from xml.dom import minidom
import xml_marshaller
from flask import jsonify
from slapos.runner.gittools import cloneRepo
......@@ -100,7 +98,7 @@ def getRcode(config):
try:
parser.read(config['knowledge0_cfg'])
return parser.get('public', 'recovery-code')
except (configparser.NoSectionError, IOError) as e:
except (configparser.NoSectionError, IOError):
return None
def getUsernameList(config):
......@@ -868,10 +866,7 @@ def cloneDefaultGit(config):
default_git = os.path.join(config['runner_workdir'],
'project', 'default_repo')
if not os.path.exists(default_git):
data = {'path': default_git,
'repo': config['default_repo'],
}
cloneRepo(data)
cloneRepo(config['default_repo'], default_git)
def buildAndRun(config):
......
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111
import codecs
import json
......@@ -21,7 +20,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, checkUserCred
getProfilePath, getSlapgridResult,
html_escape,
listFolder, getBuildAndRunParams,
getProjectTitle, getRcode, updateUserCredential,
getProjectTitle, updateUserCredential,
getSlapStatus, getSvcStatus,
getSvcTailProcess, getUsernameList, isInstanceRunning,
isSoftwareRunning, isSoftwareReleaseReady, isText,
......@@ -31,7 +30,6 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, checkUserCred
removeSoftwareByName, runSlapgridUntilSuccess,
saveBuildAndRunParams,
setMiniShellHistory,
stopProxy,
svcStartStopProcess, svcStartAll, svcStopAll, tail,
updateInstanceParameter)
......@@ -68,8 +66,7 @@ def before_request():
return redirect(url_for('setAccount'))
"""
session['title'] = getProjectTitle(app.config)
g.instance_monitoring_url = app.config['instance_monitoring_url']
g.instance_monitoring_url = app.config['instance_monitoring_url'] # pylint:disable=assigning-non-slot
# general views
def home():
return render_template('index.html')
......@@ -114,7 +111,6 @@ def getSlapgridParameters():
def manageRepository():
public_key = open(app.config['public_key']).read()
account = [] #getSession(app.config)
git_user_path = os.path.join(app.config['etc_dir'], '.git_user')
name = email = ""
if os.path.exists(git_user_path):
......@@ -377,8 +373,8 @@ def removeFile():
def removeSoftwareDir():
status, message = removeSoftwareByName(app.config, request.form['md5'],
request.form['title'])
status, message = removeSoftwareByName( # pylint:disable=unpacking-non-sequence,useless-suppression
app.config, request.form['md5'], request.form['title'])
return jsonify(code=status, result=message)
......@@ -524,9 +520,9 @@ def slapgridResult():
def stopSlapgrid():
counter_file = os.path.join(app.config['runner_workdir'], '.turn-left')
open(counter_file, 'w+').write(str(0))
result = sup_process.killRunningProcess(app.config, request.form['type'])
return jsonify(result=result)
with open(counter_file, 'w+') as f:
f.write(str(0))
return jsonify(result=sup_process.killRunningProcess(app.config, request.form['type']))
def getPath():
......
......@@ -66,7 +66,7 @@ extra_config_dict = {{
def format_status(self, date, status):
"""" return a string formatted like backupserver status """
if date.tzinfo is not None:
raise "Date should be UTC"
raise ValueError("Date should be UTC")
return "{}+0000, DUMMY_STATISTIC_NAME, SOFTINSTTEST, backup {}\n".format(date.replace(microsecond=0).isoformat(), status)
def test_check_backup_ok(self):
......
......@@ -26,7 +26,7 @@
##############################################################################
from slapos.test.promise.plugin import TestPromisePluginMixin
from slapos.grid.promise import PromiseError
class TestCheckServerCPULoad(TestPromisePluginMixin):
......
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