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