To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 0b234737 authored by Reto Da Forno's avatar Reto Da Forno

minor cleanup

parent 69dee468
#!/usr/bin/env python
#!/usr/bin/env python3
__author__ = "Christoph Walser <walser@tik.ee.ethz.ch>"
__copyright__ = "Copyright 2010, ETH Zurich, Switzerland, Christoph Walser"
......@@ -104,9 +104,9 @@ def connect_to_db(config=None, logger=None):
if ((not isinstance(config, configparser.SafeConfigParser)) or (not isinstance(logger, logging.Logger))):
return (None, None)
try:
cn = MySQLdb.connect(host=config.get('database','host'), user=config.get('database','user'), passwd=config.get('database','password'), db=config.get('database','database'), charset='utf8', use_unicode=True)
cn = MySQLdb.connect(host=config.get('database','host'), user=config.get('database','user'), passwd=config.get('database','password'), db=config.get('database','database'), charset='utf8', use_unicode=True)
cur = cn.cursor()
#cur.execute("SET sql_mode=''")
cur.execute("SET sql_mode=''")
except:
logger.error("Could not connect to the database because: %s: %s" %(str(sys.exc_info()[0]), str(sys.exc_info()[1])))
raise
......@@ -1072,7 +1072,7 @@ def scheduleLinkTest(logger, config, cur, cn, debug=False):
# Check if the lockfile is present:
lockfile = config.get("linktests", "lockfile")
if os.path.exists(lockfile):
logger.debug("Lockfile %s exists already. Skip adding new linktests.")
logger.debug("Lockfile %s exists already. Skip adding new linktests." % lockfile)
# If the last scheduled link tests are a long time ago, generate a warning since it may be that the lockfile was not deleted for whatever reason:
if lasttest > 2*nexttest:
logger.error("Lockfile %s exists and the last linktest was %d min ago (interval is %d min)"%(lockfile, lasttest, config.getint("linktests", "interval_hours")))
......
#!/usr/bin/env python
#!/usr/bin/env python3
__author__ = "Roman May"
......
#!/usr/bin/env python
#!/usr/bin/env python3
__author__ = "Christoph Walser <walserc@tik.ee.ethz.ch>, Adnan Mlika"
__copyright__ = "Copyright 2010, ETH Zurich, Switzerland"
......
#!/usr/bin/env python
#!/usr/bin/env python3
__author__ = "Christoph Walser <walserc@tik.ee.ethz.ch>, Adnan Mlika"
__copyright__ = "Copyright 2010, ETH Zurich, Switzerland"
......@@ -266,7 +266,7 @@ def main(argv):
elif opt in ("-x", "--xml"):
xmlpath = arg
if (not os.path.exists(xmlpath) or not os.path.isfile(xmlpath)):
logger.warn("Wrong API usage: XML file does not exist")
logger.warn("Wrong API usage: XML file '%s' does not exist" % xmlpath)
sys.exit(errno.EINVAL)
elif opt in ("-h", "--help"):
usage(config)
......@@ -535,11 +535,11 @@ def main(argv):
imagefile.write(base64.b64decode(image, None))
imagefile.close()
# Validate image:
p = subprocess.Popen([config.get('targetimage', 'imagevalidator'), '--quiet', '--image', imagefilename, '--platform', platform], stderr=subprocess.PIPE)
p = subprocess.Popen([config.get('targetimage', 'imagevalidator'), '--quiet', '--image', imagefilename, '--platform', platform], stderr=subprocess.PIPE, universal_newlines=True)
stdout, stderr = p.communicate()
if p.returncode != SUCCESS:
if not quiet:
print(("<b>Line %d</b>: element data: Validation of image data failed. Check if elements os and platform are set correctly and if element <data> contains correct data." %(image_line)))
print(("<b>Line %d</b>: element data: Validation of image data failed. %s" %(image_line, stderr)))
errcnt = errcnt + 1
# Remove temporary file:
os.remove(imagefilename)
......
......@@ -347,7 +347,7 @@ function validate_image($image, &$errors) {
$imagefile = tempnam(sys_get_temp_dir(), 'flocklab');
file_put_contents($imagefile, $image['data']);
$platform_list = get_available_platforms();
$cmd = "cd ".$CONFIG['tests']['testmanagementfolder']."; python ".$CONFIG['targetimage']['imagevalidator']." --image=".$imagefile." --platform=". $platform_list[$image['platform']][0]['name']." --core=".$image['core'];
$cmd = $CONFIG['targetimage']['imagevalidator']." --image=".$imagefile." --platform=". $platform_list[$image['platform']][0]['name']." --core=".$image['core'];
exec($cmd , $output, $ret);
unlink($imagefile);
if ($ret != 0) {
......@@ -427,14 +427,25 @@ function store_image($image) {
// validate test
function validate_test($test_config_file, &$errors) {
global $CONFIG;
$validate_test_errors = array();
$cmd = "python ".$CONFIG['tests']['testvalidator']." -x " . $test_config_file . " -s ".$CONFIG['xml']['schemapath']." -u " . $_SESSION['serv_users_key'];
exec($cmd , $output, $ret);
foreach ($output as $error) {
array_push($validate_test_errors, $error);
// copy xml file to testmanagement server
$cmd = "ssh ".$CONFIG['testmanagementserver']['user']."@".$CONFIG['testmanagementserver']['host']." 'mkdir ".$CONFIG['testmanagementserver']['tempdir']."'";
exec($cmd);
$cmd = "scp ".$test_config_file." ".$CONFIG['testmanagementserver']['user']."@".$CONFIG['testmanagementserver']['host'].":".$CONFIG['testmanagementserver']['tempdir'];
exec($cmd, $output, $ret);
if ($ret) {
array_push($errors, "Failed to copy file '$test_config_file' to testmanagement server.");
return 1;
}
// execute XML validation script (runs in the virtual environment on the testmanagement server, therefore we need to use SSH here)
$cmd = "ssh ".$CONFIG['testmanagementserver']['user']."@".$CONFIG['testmanagementserver']['host']." '".$CONFIG['tests']['testvalidator']." -x ".$CONFIG['testmanagementserver']['tempdir']."/".basename($test_config_file)." -s ".$CONFIG['xml']['schemapath']." -u " . $_SESSION['serv_users_key']."' 2>&1";
exec($cmd, $output, $ret);
if ($ret) {
foreach ($output as $error) {
array_push($errors, $error);
}
}
$errors = array_merge($errors, $validate_test_errors);
return count($validate_test_errors)==0;
unlink($CONFIG['testmanagementserver']['tempdir']."/".basename($test_config_file));
return $ret == 0;
}
......@@ -449,8 +460,8 @@ function validate_test($test_config_file, &$errors) {
*/
function trigger_scheduler() {
global $CONFIG;
// use SSH as a way to run the script under the user 'flocklab'
$cmd = "ssh ".$CONFIG['testmanagementserver']['user']."@".$CONFIG['testmanagementserver']['host']." '".$CONFIG['testmanagementserver']['scheduler']." --debug > /dev/null 2>&1 &'"; // ignore output and background the command
// use SSH as a way to run the script under the user 'flocklab' on the testmanagement server
$cmd = "ssh ".$CONFIG['testmanagementserver']['user']."@".$CONFIG['testmanagementserver']['host']." '".$CONFIG['testmanagementserver']['scheduler']." --debug' > /dev/null 2>&1 &";
exec($cmd);
}
......
......@@ -29,12 +29,7 @@
// The uploaded file is not XML:
array_push($errors, "Uploaded file is not XML.");
} else {
$cmd = "python ".$CONFIG['tests']['testvalidator']." -x " . $xmlfile['tmp_name'] . " -s ".$CONFIG['xml']['schemapath']." -u " . $_SESSION['serv_users_key'];
exec($cmd , $output, $ret);
foreach ($output as $error) {
array_push($errors, $error);
}
if (empty($errors) && $ret) {
if (!validate_test($xmlfile['tmp_name'], $errors) && empty($errors)) {
array_push($errors, "unknown error");
}
}
......
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