Commit d38c6b26 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

fix error in previous commit (duplicate column name in select clause) and some cleanup

parent 18e875c9
...@@ -711,14 +711,14 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id): ...@@ -711,14 +711,14 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
for (thread, obskey) in thread_list: for (thread, obskey) in thread_list:
# Wait max 75% of the setuptime: # Wait max 75% of the setuptime:
thread.join(timeout=(flocklab.config.getint('tests','setuptime')*0.75)) thread.join(timeout=(flocklab.config.getint('tests','setuptime')*0.75))
if thread.isAlive(): if thread.is_alive():
# Timeout occurred. Signal the thread to abort: # Timeout occurred. Signal the thread to abort:
logger.error("Telling thread for test start on observer ID %s to abort..." % (str(obsdict_key[obskey][1]))) logger.error("Telling thread for test start on observer ID %s to abort..." % (str(obsdict_key[obskey][1])))
thread.abort() thread.abort()
# Wait again for the aborted threads: # Wait again for the aborted threads:
for (thread, obskey) in thread_list: for (thread, obskey) in thread_list:
thread.join(timeout=10) thread.join(timeout=10)
if thread.isAlive(): if thread.is_alive():
msg = "Thread for test start on observer ID %s timed out and will be aborted now." % (str(obsdict_key[obskey][1])) msg = "Thread for test start on observer ID %s timed out and will be aborted now." % (str(obsdict_key[obskey][1]))
errors.append(msg) errors.append(msg)
logger.error(msg) logger.error(msg)
...@@ -884,7 +884,7 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False): ...@@ -884,7 +884,7 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False):
# Wait for all threads to finish: # Wait for all threads to finish:
for (thread, obskey) in thread_list: for (thread, obskey) in thread_list:
thread.join(timeout=(flocklab.config.getint('tests','cleanuptime') * 0.75)) thread.join(timeout=(flocklab.config.getint('tests','cleanuptime') * 0.75))
if thread.isAlive(): if thread.is_alive():
# Timeout occurred. Signal the thread to abort: # Timeout occurred. Signal the thread to abort:
msg = "Telling thread for test stop on observer ID %s to abort..." %(str(obsdict_key[obskey][1])) msg = "Telling thread for test stop on observer ID %s to abort..." %(str(obsdict_key[obskey][1]))
logger.error(msg) logger.error(msg)
...@@ -893,7 +893,7 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False): ...@@ -893,7 +893,7 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False):
# Wait again for the aborted threads: # Wait again for the aborted threads:
for (thread, obskey) in thread_list: for (thread, obskey) in thread_list:
thread.join(timeout=10) thread.join(timeout=10)
if thread.isAlive(): if thread.is_alive():
msg = "Thread for test stop on observer ID %s is still alive but should be aborted now." %(str(obsdict_key[obskey][1])) msg = "Thread for test stop on observer ID %s is still alive but should be aborted now." %(str(obsdict_key[obskey][1]))
errors.append(msg) errors.append(msg)
logger.error(msg) logger.error(msg)
......
...@@ -323,7 +323,7 @@ def main(argv): ...@@ -323,7 +323,7 @@ def main(argv):
else: else:
thread_timeoutadd = 0 thread_timeoutadd = 0
t.join(timeout=(10 + thread_timeoutadd)) t.join(timeout=(10 + thread_timeoutadd))
if t.isAlive(): if t.is_alive():
logger.warning("Timeout when joining thread - is still alive...") logger.warning("Timeout when joining thread - is still alive...")
except: except:
logger.warning("Error when joining threads...") logger.warning("Error when joining threads...")
......
...@@ -173,7 +173,7 @@ function destroy_session() { ...@@ -173,7 +173,7 @@ function destroy_session() {
session_destroy(); session_destroy();
// Destroy the sesssion cookie if it exists: // Destroy the sesssion cookie if it exists:
if( isset($_COOKIE[session_name()])) if (isset($_COOKIE[session_name()]))
setcookie(session_name(), null, 0); setcookie(session_name(), null, 0);
} }
...@@ -188,8 +188,8 @@ function destroy_session() { ...@@ -188,8 +188,8 @@ function destroy_session() {
*/ */
function check_testid($testid, $userid) { function check_testid($testid, $userid) {
$db = db_connect(); $db = db_connect();
$sql = "SELECT owner_fk $sql = "SELECT owner_fk
FROM tbl_serv_tests FROM tbl_serv_tests
WHERE serv_tests_key = " . $testid; WHERE serv_tests_key = " . $testid;
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db)); $rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db));
$owner = mysqli_fetch_array($rs); $owner = mysqli_fetch_array($rs);
...@@ -211,8 +211,8 @@ function check_testid($testid, $userid) { ...@@ -211,8 +211,8 @@ function check_testid($testid, $userid) {
*/ */
function check_imageid($imageid, $userid) { function check_imageid($imageid, $userid) {
$db = db_connect(); $db = db_connect();
$sql = "SELECT owner_fk $sql = "SELECT owner_fk
FROM tbl_serv_targetimages FROM tbl_serv_targetimages
WHERE serv_targetimages_key = " . $imageid; WHERE serv_targetimages_key = " . $imageid;
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db)); $rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db));
$owner = mysqli_fetch_array($rs); $owner = mysqli_fetch_array($rs);
...@@ -342,8 +342,8 @@ function get_available_platforms() { ...@@ -342,8 +342,8 @@ function get_available_platforms() {
function get_testconfig($testid) { function get_testconfig($testid) {
$db = db_connect(); $db = db_connect();
$sql = "SELECT `testconfig_xml` $sql = "SELECT `testconfig_xml`
FROM tbl_serv_tests FROM tbl_serv_tests
WHERE ".($_SESSION['is_admin']?"":("owner_fk = " . $_SESSION['serv_users_key'] . " AND "))."`serv_tests_key`=".mysqli_real_escape_string($db, $testid); WHERE ".($_SESSION['is_admin']?"":("owner_fk = " . $_SESSION['serv_users_key'] . " AND "))."`serv_tests_key`=".mysqli_real_escape_string($db, $testid);
$res = mysqli_query($db, $sql); $res = mysqli_query($db, $sql);
if ($res !== false) { if ($res !== false) {
...@@ -355,8 +355,8 @@ function get_testconfig($testid) { ...@@ -355,8 +355,8 @@ function get_testconfig($testid) {
function get_teststatus($testid) { function get_teststatus($testid) {
$db = db_connect(); $db = db_connect();
$sql = "SELECT `test_status` $sql = "SELECT `test_status`
FROM tbl_serv_tests FROM tbl_serv_tests
WHERE owner_fk = " . $_SESSION['serv_users_key'] . " AND `serv_tests_key`=".mysqli_real_escape_string($db, $testid); WHERE owner_fk = " . $_SESSION['serv_users_key'] . " AND `serv_tests_key`=".mysqli_real_escape_string($db, $testid);
$res = mysqli_query($db, $sql); $res = mysqli_query($db, $sql);
if ($res !== false) { if ($res !== false) {
...@@ -616,7 +616,7 @@ function add_test_mappings($testId, $testconfig) { ...@@ -616,7 +616,7 @@ function add_test_mappings($testId, $testconfig) {
$targedIds = preg_split("/[\s]+/", trim($tc->targetIds)); $targedIds = preg_split("/[\s]+/", trim($tc->targetIds));
else else
$targedIds = $observerIds; $targedIds = $observerIds;
if(isset($tc->dbImageId)) { if (isset($tc->dbImageId)) {
$dbImageId = iterator_to_array($tc->dbImageId, false); $dbImageId = iterator_to_array($tc->dbImageId, false);
} }
else else
...@@ -921,13 +921,11 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) { ...@@ -921,13 +921,11 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
$guard_setup_sec = $CONFIG['tests']['setuptime']; $guard_setup_sec = $CONFIG['tests']['setuptime'];
$guard_cleanup_sec = $CONFIG['tests']['cleanuptime']; $guard_cleanup_sec = $CONFIG['tests']['cleanuptime'];
$allow_parallel_tests = $CONFIG['tests']['allowparalleltests']; $allow_parallel_tests = $CONFIG['tests']['allowparalleltests'];
$isAsap = !isset($testconfig->generalConf->schedule->start); $is_asap = !isset($testconfig->generalConf->schedule->start);
$duration = $testconfig->generalConf->schedule->duration; $duration = $testconfig->generalConf->schedule->duration;
$now = new DateTime ();
$now->setTimeZone(new DateTimeZone("UTC"));
// start is time start wish - setup time // start is time start wish - setup time
// end is time end wish + cleanup time // end is time end wish + cleanup time
if (!$isAsap) { if (!$is_asap) {
$start = new DateTime($testconfig->generalConf->schedule->start); $start = new DateTime($testconfig->generalConf->schedule->start);
$start->setTimeZone(new DateTimeZone("UTC")); $start->setTimeZone(new DateTimeZone("UTC"));
$end = clone $start; $end = clone $start;
...@@ -948,9 +946,9 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) { ...@@ -948,9 +946,9 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
array_push($resourcesdict[$r['obskey']][$r['restype']], $r); array_push($resourcesdict[$r['obskey']][$r['restype']], $r);
} }
$sql = "SELECT UNIX_TIMESTAMP(`time_start`) as `utime_start`, UNIX_TIMESTAMP(`time_end`) as `utime_end`, `observer_fk`, `resource_type` $sql = "SELECT UNIX_TIMESTAMP(a.`time_start`) as `utime_start`, UNIX_TIMESTAMP(a.`time_end`) as `utime_end`, a.`observer_fk`, a.`resource_type`
FROM `tbl_serv_resource_allocation` a left join tbl_serv_tests b on (b.serv_tests_key = a.test_fk) FROM `tbl_serv_resource_allocation` a LEFT JOIN tbl_serv_tests b on (b.serv_tests_key = a.test_fk)
WHERE (`time_end` >= '".$start->format(DATE_ISO8601)."' AND test_status in ('planned','preparing','running','cleaning up','syncing','synced','aborting')".(isset($exclude_test)?" AND `test_fk`!=".$exclude_test:"").")"; WHERE (a.time_end >= '".$start->format(DATE_ISO8601)."' AND b.test_status in ('planned','preparing','running','cleaning up','syncing','synced','aborting')".(isset($exclude_test) ? " AND `test_fk`!=".$exclude_test : "").")";
$res_usedresources = mysqli_query($db, $sql); $res_usedresources = mysqli_query($db, $sql);
$sql = "SELECT UNIX_TIMESTAMP(`time_start`) as `utime_start`, UNIX_TIMESTAMP(`time_end`) as `utime_end`, max(ifnull(user_fk,-1) = ".$_SESSION['serv_users_key'].") as `reservation_match` $sql = "SELECT UNIX_TIMESTAMP(`time_start`) as `utime_start`, UNIX_TIMESTAMP(`time_end`) as `utime_end`, max(ifnull(user_fk,-1) = ".$_SESSION['serv_users_key'].") as `reservation_match`
FROM `tbl_serv_reservations` LEFT JOIN `tbl_serv_user_groups` ON `group_fk`=`group_id_fk` FROM `tbl_serv_reservations` LEFT JOIN `tbl_serv_user_groups` ON `group_fk`=`group_id_fk`
...@@ -959,42 +957,42 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) { ...@@ -959,42 +957,42 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
$res_reservations = mysqli_query($db, $sql); $res_reservations = mysqli_query($db, $sql);
# Now check for all resource usage intervals if they overlap in time with an already scheduled test or reservations # Now check for all resource usage intervals if they overlap in time with an already scheduled test or reservations
$shiftOffset = $start->format("U"); $shiftOffset = $start->format("U");
$testShift = $start->format("U"); $testShift = $start->format("U");
while(True) { while (True) {
$maxShift = 0; # keep track of largest shift needed to resolve dependencies $maxShift = 0; # keep track of largest shift needed to resolve dependencies
if (mysqli_num_rows($res_reservations)>0) { if (mysqli_num_rows($res_reservations) > 0) {
mysqli_data_seek($res_reservations, 0); mysqli_data_seek($res_reservations, 0);
$ustart = $testShift; $ustart = $testShift;
$uend = $end->format("U") + $testShift - $shiftOffset; $uend = $end->format("U") + $testShift - $shiftOffset;
while($row = mysqli_fetch_assoc($res_reservations)) { while ($row = mysqli_fetch_assoc($res_reservations)) {
# for every ret, check for collisions # for every ret, check for collisions
if($row['utime_start'] <= $uend and $row['utime_end'] >= $ustart) { if ($row['utime_start'] <= $uend and $row['utime_end'] >= $ustart) {
if (!$isAsap) if (!$is_asap)
return Array('feasible'=>False, 'start_time'=>$start, 'end_time'=>$end); return Array('feasible'=>False, 'start_time'=>$start, 'end_time'=>$end);
else { else {
$shift = $row['utime_end'] - $ustart; $shift = $row['utime_end'] - $ustart;
if($shift > $maxShift) if ($shift > $maxShift)
$maxShift = $shift; $maxShift = $shift;
} }
} }
} }
} }
if (mysqli_num_rows($res_usedresources)>0) { if (mysqli_num_rows($res_usedresources) > 0) {
mysqli_data_seek($res_usedresources, 0); mysqli_data_seek($res_usedresources, 0);
while($row = mysqli_fetch_assoc($res_usedresources)) { while ($row = mysqli_fetch_assoc($res_usedresources)) {
if (!$allow_parallel_tests) { if (!$allow_parallel_tests) {
# if observer is used, then treat it as a collision (parallel tests on same observer cause problems) # if observer is used, then treat it as a collision (parallel tests on same observer cause problems)
if (isset($resourcesdict[$row['observer_fk']])) { if (isset($resourcesdict[$row['observer_fk']])) {
# observer is used by the new test, check the start and end times # observer is used by the new test, check the start and end times
$ustart = $testShift; $ustart = $testShift;
$uend = $end->format("U") + $testShift - $shiftOffset; $uend = $end->format("U") + $testShift - $shiftOffset;
if($row['utime_start'] <= $uend and $row['utime_end'] >= $ustart) { if ($row['utime_start'] <= $uend and $row['utime_end'] >= $ustart) {
if (!$isAsap) if (!$is_asap)
return Array('feasible'=>False, 'start_time'=>$start, 'end_time'=>$end); return Array('feasible'=>False, 'start_time'=>$start, 'end_time'=>$end);
else { else {
$shift = $row['utime_end'] - $ustart; $shift = $row['utime_end'] - $ustart;
if($shift > $maxShift) if ($shift > $maxShift)
$maxShift = $shift; $maxShift = $shift;
} }
} }
...@@ -1002,14 +1000,14 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) { ...@@ -1002,14 +1000,14 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
} else { } else {
# for every ret, check for collisions # for every ret, check for collisions
if (isset($resourcesdict[$row['observer_fk']]) && isset($resourcesdict[$row['observer_fk']][$row['resource_type']])) { if (isset($resourcesdict[$row['observer_fk']]) && isset($resourcesdict[$row['observer_fk']][$row['resource_type']])) {
foreach($resourcesdict[$row['observer_fk']][$row['resource_type']] as $r) { foreach ($resourcesdict[$row['observer_fk']][$row['resource_type']] as $r) {
//echo "<!--";print_r($row);echo "-->"; //echo "<!--";print_r($row);echo "-->";
if($row['utime_start'] <= $r['time_end'] + $testShift and $row['utime_end'] >= $r['time_start'] + $testShift) { if ($row['utime_start'] <= $r['time_end'] + $testShift and $row['utime_end'] >= $r['time_start'] + $testShift) {
if (!$isAsap) if (!$is_asap)
return Array('feasible'=>False, 'start_time'=>$start, 'end_time'=>$end); return Array('feasible'=>False, 'start_time'=>$start, 'end_time'=>$end);
else { else {
$shift = $row['utime_end'] - ($r['time_start'] + $testShift); $shift = $row['utime_end'] - ($r['time_start'] + $testShift);
if($shift > $maxShift) if ($shift > $maxShift)
$maxShift = $shift; $maxShift = $shift;
} }
} }
...@@ -1028,7 +1026,7 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) { ...@@ -1028,7 +1026,7 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
$end->modify('+'.($testShift - $shiftOffset).' seconds'); $end->modify('+'.($testShift - $shiftOffset).' seconds');
$start->modify('+'.$guard_setup_sec.' seconds'); $start->modify('+'.$guard_setup_sec.' seconds');
$end->modify('-'.$guard_cleanup_sec.' seconds'); $end->modify('-'.$guard_cleanup_sec.' seconds');
return Array('feasible'=>True,'start_time'=>$start, 'end_time'=>$end); return Array('feasible'=>True, 'start_time'=>$start, 'end_time'=>$end);
} }
function adjust_schedule_tag(&$testconfig) { function adjust_schedule_tag(&$testconfig) {
...@@ -1142,12 +1140,12 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort ...@@ -1142,12 +1140,12 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
foreach($testconfig->targetConf as $tc) { foreach($testconfig->targetConf as $tc) {
foreach($tc->embeddedImageId as $eId) { foreach($tc->embeddedImageId as $eId) {
$eId = trim($eId); $eId = trim($eId);
if(!in_array($eId, $used_embeddedImages)) if (!in_array($eId, $used_embeddedImages))
array_push($used_embeddedImages, $eId); array_push($used_embeddedImages, $eId);
} }
foreach($tc->dbImageId as $dbId) { foreach($tc->dbImageId as $dbId) {
$dbId = (int)trim($dbId); $dbId = (int)trim($dbId);
if(!in_array($dbId, $used_dbImages)) if (!in_array($dbId, $used_dbImages))
array_push($used_dbImages, $dbId); array_push($used_dbImages, $dbId);
} }
} }
...@@ -1161,7 +1159,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort ...@@ -1161,7 +1159,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
} }
foreach($testconfig->embeddedImageConf as $im) { foreach($testconfig->embeddedImageConf as $im) {
$eId = trim($im->embeddedImageId); $eId = trim($im->embeddedImageId);
if(array_key_exists($eId, $embeddedImages)) { if (array_key_exists($eId, $embeddedImages)) {
array_push($errors, "Provided embedded images do not have unique IDs."); array_push($errors, "Provided embedded images do not have unique IDs.");
} }
else { else {
...@@ -1180,15 +1178,15 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort ...@@ -1180,15 +1178,15 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
} }
// check if there are images without a data block: // check if there are images without a data block:
foreach(array_keys($embeddedImages) as $imID) { foreach(array_keys($embeddedImages) as $imID) {
if(strlen($embeddedImages[$imID]['data']) == 0) { if (strlen($embeddedImages[$imID]['data']) == 0) {
// find the first entry which matches the platform (compare only first 3 characters) // find the first entry which matches the platform (compare only first 3 characters)
foreach($embeddedImages as $eIm) { foreach($embeddedImages as $eIm) {
if(strncmp($eIm['platform'], $embeddedImages[$imID]['platform'], 3) && strlen($eIm['data']) > 0) { if (strncmp($eIm['platform'], $embeddedImages[$imID]['platform'], 3) && strlen($eIm['data']) > 0) {
$embeddedImages[$imID]['data'] = $eIm['data']; // use the image data of this entry $embeddedImages[$imID]['data'] = $eIm['data']; // use the image data of this entry
break; break;
} }
} }
if(strlen($embeddedImages[$imID]['data']) == 0) { if (strlen($embeddedImages[$imID]['data']) == 0) {
// no image data found -> abort // no image data found -> abort
array_push($errors, "No data provided for embedded image ID ".$imID."."); array_push($errors, "No data provided for embedded image ID ".$imID.".");
break; break;
...@@ -1239,7 +1237,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort ...@@ -1239,7 +1237,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
# fetch observer keys # fetch observer keys
$db = db_connect(); $db = db_connect();
$obskeys = Array(); $obskeys = Array();
$sql = "select `serv_observer_key`, `observer_id` from tbl_serv_observer"; $sql = "SELECT `serv_observer_key`, `observer_id` FROM tbl_serv_observer";
$res = mysqli_query($db, $sql) or flocklab_die('Cannot fetch observer information from database because: ' . mysqli_error($db)); $res = mysqli_query($db, $sql) or flocklab_die('Cannot fetch observer information from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_assoc($res)) { while ($row = mysqli_fetch_assoc($res)) {
$obskeys[$row['observer_id']] = $row['serv_observer_key']; $obskeys[$row['observer_id']] = $row['serv_observer_key'];
...@@ -1386,7 +1384,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort ...@@ -1386,7 +1384,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
function acquire_db_lock($key) { function acquire_db_lock($key) {
$db = db_connect(); $db = db_connect();
$done = False; $done = False;
while(!$done) { while (!$done) {
$sql = "lock tables tbl_serv_locks write"; $sql = "lock tables tbl_serv_locks write";
mysqli_query($db, $sql) or flocklab_die('Cannot acquire database lock because: ' . mysqli_error($db)); mysqli_query($db, $sql) or flocklab_die('Cannot acquire database lock because: ' . mysqli_error($db));
$sql = "delete from tbl_serv_locks where expiry_time < now()"; $sql = "delete from tbl_serv_locks where expiry_time < now()";
......
Supports Markdown
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