Commit 18e875c9 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

merge test_start/end_planned/_act as they are the same, and some cleanup

parent 741d63c2
...@@ -247,10 +247,8 @@ CREATE TABLE `tbl_serv_tests` ( ...@@ -247,10 +247,8 @@ CREATE TABLE `tbl_serv_tests` (
`description` text COLLATE utf8_bin, `description` text COLLATE utf8_bin,
`owner_fk` int(10) unsigned NOT NULL, `owner_fk` int(10) unsigned NOT NULL,
`testconfig_xml` longtext COLLATE utf8_bin NOT NULL, `testconfig_xml` longtext COLLATE utf8_bin NOT NULL,
`time_start_wish` datetime NOT NULL, `time_start` datetime NOT NULL,
`time_start_act` datetime DEFAULT NULL, `time_end` datetime NOT NULL,
`time_end_wish` datetime NOT NULL,
`time_end_act` datetime DEFAULT NULL,
`setuptime` int(11) DEFAULT NULL COMMENT 'Time needed to setup the test', `setuptime` int(11) DEFAULT NULL COMMENT 'Time needed to setup the test',
`cleanuptime` int(11) DEFAULT NULL COMMENT 'Time needed to cleanup the test', `cleanuptime` int(11) DEFAULT NULL COMMENT 'Time needed to cleanup the test',
`test_status` enum('not schedulable','planned','preparing','running','cleaning up','syncing','synced','finished','aborting','failed','todelete','deleted','retention expiring') COLLATE utf8_bin NOT NULL DEFAULT 'not schedulable', `test_status` enum('not schedulable','planned','preparing','running','cleaning up','syncing','synced','finished','aborting','failed','todelete','deleted','retention expiring') COLLATE utf8_bin NOT NULL DEFAULT 'not schedulable',
......
...@@ -112,8 +112,8 @@ def main(argv): ...@@ -112,8 +112,8 @@ def main(argv):
else: else:
try: try:
# Check for tests to delete --- # Check for tests to delete ---
sql = """SELECT `serv_tests_key`, `time_start_wish` sql = """SELECT `serv_tests_key`, `time_start`
FROM `tbl_serv_tests` FROM `tbl_serv_tests`
WHERE (`test_status` = 'todelete') WHERE (`test_status` = 'todelete')
""" """
if ( cur.execute(sql) <= 0 ): if ( cur.execute(sql) <= 0 ):
...@@ -190,7 +190,7 @@ def main(argv): ...@@ -190,7 +190,7 @@ def main(argv):
# Check for tests that are stuck --- # Check for tests that are stuck ---
sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests` sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests`
WHERE ((`test_status` IN ('preparing', 'aborting', 'cleaning up', 'syncing', 'synced')) OR (`test_status` = 'running' AND `dispatched` = 1)) WHERE ((`test_status` IN ('preparing', 'aborting', 'cleaning up', 'syncing', 'synced')) OR (`test_status` = 'running' AND `dispatched` = 1))
AND (TIMESTAMPDIFF(MINUTE, `time_end_wish`, '%s') > %d) AND (TIMESTAMPDIFF(MINUTE, `time_end`, '%s') > %d)
""" """
if cur.execute(sql % (now, maxtestcleanuptime)) <= 0: if cur.execute(sql % (now, maxtestcleanuptime)) <= 0:
logger.debug("No stuck tests found.") logger.debug("No stuck tests found.")
...@@ -211,7 +211,7 @@ def main(argv): ...@@ -211,7 +211,7 @@ def main(argv):
# Check for tests that are still running, but should have been stopped (NOTE: needs to be AFTER the checking for stuck tests!) --- # Check for tests that are still running, but should have been stopped (NOTE: needs to be AFTER the checking for stuck tests!) ---
sql = """SELECT `serv_tests_key`, `test_status` FROM `tbl_serv_tests` sql = """SELECT `serv_tests_key`, `test_status` FROM `tbl_serv_tests`
WHERE (`test_status` = 'running') AND (`time_end_wish` <= '%s') AND (`dispatched` = 0) WHERE (`test_status` = 'running') AND (`time_end` <= '%s') AND (`dispatched` = 0)
""" """
cur.execute(sql % (now)) cur.execute(sql % (now))
rs = cur.fetchall() rs = cur.fetchall()
...@@ -245,7 +245,7 @@ def main(argv): ...@@ -245,7 +245,7 @@ def main(argv):
testid = int(command.split('testid=', 1)[1].split()[0]) testid = int(command.split('testid=', 1)[1].split()[0])
# check stop time of this test # check stop time of this test
sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests` sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests`
WHERE `serv_tests_key`=%d AND TIMESTAMPDIFF(MINUTE, `time_end_wish`, '%s') > %d WHERE `serv_tests_key`=%d AND TIMESTAMPDIFF(MINUTE, `time_end`, '%s') > %d
""" """
if cur.execute(sql % (testid, now, maxtestcleanuptime)) > 0: if cur.execute(sql % (testid, now, maxtestcleanuptime)) > 0:
# thread is stuck -> add to list and kill # thread is stuck -> add to list and kill
......
...@@ -313,7 +313,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id): ...@@ -313,7 +313,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
flocklab.set_test_status(cur, cn, testid, 'preparing') flocklab.set_test_status(cur, cn, testid, 'preparing')
# Get start/stop time --- # Get start/stop time ---
cur.execute("SELECT `time_start_wish`, `time_end_wish`, `owner_fk` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid) cur.execute("SELECT `time_start`, `time_end`, `owner_fk` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid)
# Times are going to be of datetime type: # Times are going to be of datetime type:
ret = cur.fetchone() ret = cur.fetchone()
starttime = ret[0] starttime = ret[0]
...@@ -788,7 +788,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id): ...@@ -788,7 +788,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
# check if we're still in time --- # check if we're still in time ---
if len(errors) == 0: if len(errors) == 0:
now = time.strftime(flocklab.config.get("database", "timeformat"), time.gmtime(time.time() - 10)) # allow 10s tolerance now = time.strftime(flocklab.config.get("database", "timeformat"), time.gmtime(time.time() - 10)) # allow 10s tolerance
cur.execute("SELECT `serv_tests_key` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d AND `time_start_wish` <= '%s'" % (testid, now)) cur.execute("SELECT `serv_tests_key` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d AND `time_start` <= '%s'" % (testid, now))
if cur.fetchone() is not None: if cur.fetchone() is not None:
msg = "Setup for test ID %d took too much time." % (testid) msg = "Setup for test ID %d took too much time." % (testid)
errors.append(msg) errors.append(msg)
...@@ -798,12 +798,10 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id): ...@@ -798,12 +798,10 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
if len(errors) == 0: if len(errors) == 0:
logger.debug("Setting test status in DB to running...") logger.debug("Setting test status in DB to running...")
flocklab.set_test_status(cur, cn, testid, 'running') flocklab.set_test_status(cur, cn, testid, 'running')
cur.execute("UPDATE `tbl_serv_tests` SET `time_start_act` = `time_start_wish` WHERE `serv_tests_key` = %d" %testid)
cn.commit()
else: else:
logger.debug("Setting test status in DB to aborting...") logger.debug("Setting test status in DB to aborting...")
flocklab.set_test_status(cur, cn, testid, 'aborting') flocklab.set_test_status(cur, cn, testid, 'aborting')
cur.execute("UPDATE `tbl_serv_tests` SET `time_start_act` = `time_start_wish`, `time_end_act` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" %testid) cur.execute("UPDATE `tbl_serv_tests` SET `time_end` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" % testid)
cn.commit() cn.commit()
logger.debug("At end of start_test(). Returning...") logger.debug("At end of start_test(). Returning...")
...@@ -926,10 +924,6 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False): ...@@ -926,10 +924,6 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False):
for err in errs[1]: for err in errs[1]:
#logger.error("Error from test stop thread: %s" %(str(err[0]))) #logger.error("Error from test stop thread: %s" %(str(err[0])))
warnings.append(err[0]) warnings.append(err[0])
# Set stop time in DB ---
cur.execute("UPDATE `tbl_serv_tests` SET `time_end_act` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" %testid)
cn.commit()
except Exception: except Exception:
msg = "Unexpected error: %s: %s\n%s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1]), traceback.format_exc()) msg = "Unexpected error: %s: %s\n%s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1]), traceback.format_exc())
...@@ -1051,7 +1045,7 @@ def evaluate_linkmeasurement(testid, cur): ...@@ -1051,7 +1045,7 @@ def evaluate_linkmeasurement(testid, cur):
logger = flocklab.get_logger() logger = flocklab.get_logger()
errors = [] errors = []
# if link measurement, evaluate data # if link measurement, evaluate data
cur.execute("SELECT `username`, `time_start_act` FROM `tbl_serv_tests` LEFT JOIN `tbl_serv_users` ON (`serv_users_key`=`owner_fk`) WHERE (`serv_tests_key` = %s)" % testid) cur.execute("SELECT `username`, `time_start` FROM `tbl_serv_tests` LEFT JOIN `tbl_serv_users` ON (`serv_users_key`=`owner_fk`) WHERE (`serv_tests_key` = %s)" % testid)
ret = cur.fetchone() ret = cur.fetchone()
if ret and ret[0] == flocklab.config.get('linktests', 'user'): if ret and ret[0] == flocklab.config.get('linktests', 'user'):
teststarttime = ret[1] teststarttime = ret[1]
...@@ -1415,7 +1409,7 @@ def main(argv): ...@@ -1415,7 +1409,7 @@ def main(argv):
flocklab.send_mail_to_admin(msg) flocklab.send_mail_to_admin(msg)
# Get the stop time from the database # Get the stop time from the database
cur.execute("SELECT `time_end_wish` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid) cur.execute("SELECT `time_end` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
ret = cur.fetchone() ret = cur.fetchone()
stoptimestamp = datetime.datetime.timestamp(ret[0]) + 1 # postpone by 1s to give services on observers time to shut down stoptimestamp = datetime.datetime.timestamp(ret[0]) + 1 # postpone by 1s to give services on observers time to shut down
if not stoptimestamp or stoptimestamp < time.time(): if not stoptimestamp or stoptimestamp < time.time():
...@@ -1488,7 +1482,7 @@ def main(argv): ...@@ -1488,7 +1482,7 @@ def main(argv):
logger.debug("Fetcher has set test status to '%s'." % status) logger.debug("Fetcher has set test status to '%s'." % status)
# Check the actual runtime: if < 0, test failed # Check the actual runtime: if < 0, test failed
cur.execute("SELECT TIME_TO_SEC(TIMEDIFF(`time_end_act`, `time_start_act`)) FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid) cur.execute("SELECT TIME_TO_SEC(TIMEDIFF(`time_end`, `time_start`)) FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
test_runtime = cur.fetchone()[0] test_runtime = cur.fetchone()[0]
if not test_runtime or int(test_runtime) < 0: if not test_runtime or int(test_runtime) < 0:
logger.info("Negative runtime detected, marking test as 'failed'.") logger.info("Negative runtime detected, marking test as 'failed'.")
......
...@@ -1068,7 +1068,7 @@ def main(argv): ...@@ -1068,7 +1068,7 @@ def main(argv):
serialdict = {0: 'r', 1: 'w'} serialdict = {0: 'r', 1: 'w'}
#find out the start and stoptime of the test #find out the start and stoptime of the test
cur.execute("SELECT `time_start_wish`, `time_end_wish` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid) cur.execute("SELECT `time_start`, `time_end` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
# Times are going to be of datetime type: # Times are going to be of datetime type:
ret = cur.fetchone() ret = cur.fetchone()
teststarttime = ret[0] teststarttime = ret[0]
...@@ -1078,7 +1078,7 @@ def main(argv): ...@@ -1078,7 +1078,7 @@ def main(argv):
# Find out which services are used to allocate working threads later on --- # Find out which services are used to allocate working threads later on ---
# Get the XML config from the database and check which services are used in the test. # Get the XML config from the database and check which services are used in the test.
servicesUsed_dict = {'gpiotracing': 'gpioTracingConf', 'powerprofiling': 'powerProfilingConf', 'serial': 'serialConf', 'datatrace': 'dataTraceConf'} servicesUsed_dict = {'gpiotracing': 'gpioTracingConf', 'powerprofiling': 'powerProfilingConf', 'serial': 'serialConf', 'datatrace': 'dataTraceConf'}
cur.execute("SELECT `testconfig_xml` FROM `tbl_serv_tests` WHERE (`serv_tests_key` = %s)" %testid) cur.execute("SELECT `testconfig_xml` FROM `tbl_serv_tests` WHERE (`serv_tests_key` = %s)" % testid)
ret = cur.fetchone() ret = cur.fetchone()
if not ret: if not ret:
msg = "No XML found in database for testid %d." %testid msg = "No XML found in database for testid %d." %testid
......
...@@ -113,20 +113,22 @@ def main(argv): ...@@ -113,20 +113,22 @@ def main(argv):
logger.debug("Expiration lead time is %s days" % expiration_leadtime) logger.debug("Expiration lead time is %s days" % expiration_leadtime)
try: try:
# Get all users that have ran tests: # Get all users that have ran tests:
sql = """ SELECT DISTINCT `owner_fk` sql = """
FROM `tbl_serv_tests` SELECT DISTINCT `owner_fk`
WHERE (`test_status` IN ('not schedulable','finished','failed', 'retention expiring')) FROM `tbl_serv_tests`
""" WHERE (`test_status` IN ('not schedulable','finished','failed', 'retention expiring'))
"""
if ( cur.execute(sql) <= 0 ): if ( cur.execute(sql) <= 0 ):
logger.info("No users found which ran tests.") logger.info("No users found which ran tests.")
else: else:
rs = cur.fetchall() rs = cur.fetchall()
ownerids = [str(i[0]) for i in rs] ownerids = [str(i[0]) for i in rs]
for ownerid in ownerids: for ownerid in ownerids:
sql = """ SELECT `retention_time`, `email`, `username`, `is_active` sql = """
FROM `tbl_serv_users` SELECT `retention_time`, `email`, `username`, `is_active`
WHERE (`serv_users_key` = %s) FROM `tbl_serv_users`
""" % (ownerid) WHERE (`serv_users_key` = %s)
""" % (ownerid)
cur.execute(sql) cur.execute(sql)
rs = cur.fetchone() rs = cur.fetchone()
retention_time_user = rs[0] retention_time_user = rs[0]
...@@ -136,11 +138,12 @@ def main(argv): ...@@ -136,11 +138,12 @@ def main(argv):
logger.debug("Checking tests of user %s (users retention time is %d days)." % (ownerusername, retention_time_user)) logger.debug("Checking tests of user %s (users retention time is %d days)." % (ownerusername, retention_time_user))
# Check for each user (taking into account her individual retention time [-1 means saving data forever]) if there are tests to be cleaned soon and inform the user about these tests. # Check for each user (taking into account her individual retention time [-1 means saving data forever]) if there are tests to be cleaned soon and inform the user about these tests.
if retention_time_user != -1: if retention_time_user != -1:
sql = """ SELECT `serv_tests_key`, `title`, DATE(`time_end_act`), `test_status` sql = """
FROM `tbl_serv_tests` SELECT `serv_tests_key`, `title`, DATE(`time_end`), `test_status`
WHERE ((`owner_fk` = %s) AND (`time_end_act` < ADDDATE(NOW(), -(%s + %s))) AND (`test_status` IN ('not schedulable','finished','failed'))) FROM `tbl_serv_tests`
ORDER BY `time_end_act` DESC WHERE ((`owner_fk` = %s) AND (`time_end` < ADDDATE(NOW(), -(%s + %s))) AND (`test_status` IN ('not schedulable','finished','failed')))
""" % (ownerid, retention_time_user, expiration_leadtime) ORDER BY `time_end` DESC
""" % (ownerid, retention_time_user, expiration_leadtime)
if(cur.execute(sql) > 0): if(cur.execute(sql) > 0):
rs = cur.fetchall() rs = cur.fetchall()
msg_expiring = """Dear FlockLab user,\n\n\ msg_expiring = """Dear FlockLab user,\n\n\
...@@ -170,10 +173,11 @@ Yours faithfully,\nthe FlockLab server""" ...@@ -170,10 +173,11 @@ Yours faithfully,\nthe FlockLab server"""
continue continue
else: else:
# Mark the tests in the database: # Mark the tests in the database:
sql = """ UPDATE `tbl_serv_tests` sql = """
SET `test_status` = 'retention expiring', `retention_expiration_warned` = NOW() UPDATE `tbl_serv_tests`
WHERE `serv_tests_key` IN (%s) SET `test_status` = 'retention expiring', `retention_expiration_warned` = NOW()
""" WHERE `serv_tests_key` IN (%s)
"""
cur.execute(sql%(testids)) cur.execute(sql%(testids))
cn.commit() cn.commit()
logger.debug("Set test status to 'retention expiring' for tests.") logger.debug("Set test status to 'retention expiring' for tests.")
...@@ -181,11 +185,12 @@ Yours faithfully,\nthe FlockLab server""" ...@@ -181,11 +185,12 @@ Yours faithfully,\nthe FlockLab server"""
logger.debug("Found no tests whose retention time expires soon.") logger.debug("Found no tests whose retention time expires soon.")
# Check for each user if there are tests which are to be marked for deletion as their retention time expired: # Check for each user if there are tests which are to be marked for deletion as their retention time expired:
sql = """ SELECT `serv_tests_key`, `title`, DATE(`time_end_act`) sql = """
FROM `tbl_serv_tests` SELECT `serv_tests_key`, `title`, DATE(`time_end`)
WHERE ((`owner_fk` = %s) AND (`time_end_act` < ADDDATE(NOW(), -(%s))) AND (`test_status` = 'retention expiring') AND (`retention_expiration_warned` < ADDDATE(NOW(), -(%s+1)))) FROM `tbl_serv_tests`
ORDER BY `time_end_act` DESC WHERE ((`owner_fk` = %s) AND (`time_end` < ADDDATE(NOW(), -(%s))) AND (`test_status` = 'retention expiring') AND (`retention_expiration_warned` < ADDDATE(NOW(), -(%s+1))))
""" ORDER BY `time_end` DESC
"""
if(cur.execute(sql % (ownerid, retention_time_user, expiration_leadtime)) > 0): if(cur.execute(sql % (ownerid, retention_time_user, expiration_leadtime)) > 0):
rs = cur.fetchall() rs = cur.fetchall()
msg_deleted = """Dear FlockLab user,\n\n\ msg_deleted = """Dear FlockLab user,\n\n\
...@@ -214,10 +219,11 @@ Yours faithfully,\nthe FlockLab server""" ...@@ -214,10 +219,11 @@ Yours faithfully,\nthe FlockLab server"""
continue continue
else: else:
# Mark the tests in the database: # Mark the tests in the database:
sql = """ UPDATE `tbl_serv_tests` sql = """
SET `test_status` = 'todelete' UPDATE `tbl_serv_tests`
WHERE `serv_tests_key` IN (%s) SET `test_status` = 'todelete'
""" WHERE `serv_tests_key` IN (%s)
"""
cur.execute(sql%(testids)) cur.execute(sql%(testids))
cn.commit() cn.commit()
logger.debug("Set test status to 'todelete' for tests.") logger.debug("Set test status to 'todelete' for tests.")
......
...@@ -183,10 +183,10 @@ def main(argv): ...@@ -183,10 +183,10 @@ def main(argv):
earlieststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) - datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat")) earlieststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) - datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat"))
lateststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) + datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat")) lateststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) + datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat"))
# Check if a test is going to start soon: # Check if a test is going to start soon:
sql = """SELECT `serv_tests_key`,`time_start_wish` sql = """SELECT `serv_tests_key`,`time_start`
FROM `tbl_serv_tests` FROM `tbl_serv_tests`
WHERE (`time_start_wish` >= '%s') WHERE (`time_start` >= '%s')
AND (`time_start_wish` <= '%s') AND (`time_start` <= '%s')
AND (`test_status` = 'planned') AND (`test_status` = 'planned')
AND (`dispatched` = 0) AND (`dispatched` = 0)
""" % (earlieststart, lateststart) """ % (earlieststart, lateststart)
...@@ -208,12 +208,12 @@ def main(argv): ...@@ -208,12 +208,12 @@ def main(argv):
# Check for test which have been missed --- # Check for test which have been missed ---
sql1 = """SELECT `serv_tests_key` sql1 = """SELECT `serv_tests_key`
FROM `tbl_serv_tests` FROM `tbl_serv_tests`
WHERE (`time_start_wish` < '%s') WHERE (`time_start` < '%s')
AND (`test_status` = 'planned') AND (`test_status` = 'planned')
""" % earlieststart """ % earlieststart
sql2 = """UPDATE `tbl_serv_tests` sql2 = """UPDATE `tbl_serv_tests`
SET `test_status` = 'failed' SET `test_status` = 'failed'
WHERE (`time_start_wish` < '%s') WHERE (`time_start` < '%s')
AND (`test_status` = 'planned') AND (`test_status` = 'planned')
""" % earlieststart """ % earlieststart
nmissed = cur.execute(sql1) nmissed = cur.execute(sql1)
......
...@@ -152,7 +152,7 @@ def update_configuration_from_db(): ...@@ -152,7 +152,7 @@ def update_configuration_from_db():
flocklab.error_logandexit(msg, errno.EAGAIN) flocklab.error_logandexit(msg, errno.EAGAIN)
try: try:
# Get the XML config from the database: # Get the XML config from the database:
cur.execute("SELECT `testconfig_xml`, `serv_tests_key` FROM `tbl_serv_tests` WHERE (`test_status` IN ('preparing', 'running') AND `time_end_wish` >= NOW())") cur.execute("SELECT `testconfig_xml`, `serv_tests_key` FROM `tbl_serv_tests` WHERE (`test_status` IN ('preparing', 'running') AND `time_end` >= NOW())")
ret = cur.fetchall() ret = cur.fetchall()
for testconfig in ret: for testconfig in ret:
logger.debug("Create proxy config for test %d" % testconfig[1]) logger.debug("Create proxy config for test %d" % testconfig[1])
......
...@@ -625,9 +625,9 @@ def get_obs_from_id(cursor=None, obsid=0): ...@@ -625,9 +625,9 @@ def get_obs_from_id(cursor=None, obsid=0):
return FAILED return FAILED
try: try:
sql = " SELECT `ethernet_address`, `status` \ sql = "SELECT `ethernet_address`, `status` \
FROM `tbl_serv_observer` \ FROM `tbl_serv_observer` \
WHERE `observer_id`=%d;" WHERE `observer_id`=%d;"
cursor.execute(sql %obsid) cursor.execute(sql %obsid)
rs = cursor.fetchone() rs = cursor.fetchone()
...@@ -1014,7 +1014,7 @@ def is_test_running(cursor=None): ...@@ -1014,7 +1014,7 @@ def is_test_running(cursor=None):
cursor.execute(""" cursor.execute("""
SELECT COUNT(serv_tests_key) FROM tbl_serv_tests SELECT COUNT(serv_tests_key) FROM tbl_serv_tests
WHERE test_status IN('preparing', 'running', 'aborting', 'cleaning up') WHERE test_status IN('preparing', 'running', 'aborting', 'cleaning up')
AND TIMESTAMPDIFF(MINUTE, time_end_wish, '%s') <= %d AND TIMESTAMPDIFF(MINUTE, time_end, '%s') <= %d
""" % (now, maxcleanuptime)) """ % (now, maxcleanuptime))
rs = cursor.fetchone() rs = cursor.fetchone()
if rs[0] != 0: if rs[0] != 0:
......
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
exit(); exit();
} }
$db = db_connect(); $db = db_connect();
$sql = "SELECT title, description, test_status as status, UNIX_TIMESTAMP(time_start_wish) AS start_planned, UNIX_TIMESTAMP(time_start_act) AS start_act, UNIX_TIMESTAMP(time_end_wish) AS end_planned, UNIX_TIMESTAMP(time_end_act) AS end_act $sql = "SELECT title, description, test_status as status, UNIX_TIMESTAMP(time_start) AS start, UNIX_TIMESTAMP(time_end) AS end
FROM `flocklab`.`tbl_serv_tests` FROM `flocklab`.`tbl_serv_tests`
WHERE serv_tests_key=".intval($_POST['id']); WHERE serv_tests_key=".intval($_POST['id']);
if ($userrole != 'admin' && $userrole != 'internal') { if ($userrole != 'admin' && $userrole != 'internal') {
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
else { else {
$row = mysqli_fetch_assoc($res); $row = mysqli_fetch_assoc($res);
if ($row) { if ($row) {
echo json_encode(array('status' => 'ok', 'output' => array('title' => $row['title'], 'description' => $row['description'], 'status' => $row['status'], 'start_planned' => $row['start_planned'], 'start' => $row['start_act'], 'end_planned' => $row['end_planned'], 'end' => $row['end_act']))); echo json_encode(array('status' => 'ok', 'output' => array('title' => $row['title'], 'description' => $row['description'], 'status' => $row['status'], 'start' => $row['start'], 'end' => $row['end'], 'start_planned' => $row['start'], 'end_planned' => $row['end']))); // keep start_planned / end_planned for backwards compatibility (flocklab tools)
} else { } else {
echo json_encode(array('status' => 'error', 'output' => 'test ID '.intval($_POST['id']).' not found')); echo json_encode(array('status' => 'error', 'output' => 'test ID '.intval($_POST['id']).' not found'));
} }
......
...@@ -40,23 +40,23 @@ ...@@ -40,23 +40,23 @@
$mysqlstart = date( 'Y-m-d H:i:s T', $_GET['start']); $mysqlstart = date( 'Y-m-d H:i:s T', $_GET['start']);
$mysqlend = date('Y-m-d H:i:s T', $_GET['end']); $mysqlend = date('Y-m-d H:i:s T', $_GET['end']);
$mini = isset($_GET['mini']) && $_GET['mini']==TRUE; $mini = isset($_GET['mini']) && $_GET['mini']==TRUE;
// Connect to database and get the corresponding events: // Connect to database and get the corresponding events:
$guard_setup_sec = $CONFIG['tests']['setuptime']; $guard_setup_sec = $CONFIG['tests']['setuptime'];
$guard_cleanup_sec = $CONFIG['tests']['cleanuptime']; $guard_cleanup_sec = $CONFIG['tests']['cleanuptime'];
$db = db_connect(); $db = db_connect();
// planned tests // planned tests
$sql = "SELECT `a`.serv_tests_key, `a`.title, `a`.description, `a`.time_start_wish, `a`.time_end_wish, `a`.owner_fk, $sql = "SELECT `a`.serv_tests_key, `a`.title, `a`.description, `a`.time_start, `a`.time_end, `a`.owner_fk,
`b`.username, `b`.firstname, `b`.lastname, `a`.time_start_act, `a`.time_end_act, `a`.test_status, `b`.username, `b`.firstname, `b`.lastname, `a`.test_status,
DATE_ADD(`a`.time_start_wish, INTERVAL -".$guard_setup_sec." SECOND) as time_start_offset, DATE_ADD(`a`.time_start, INTERVAL -".$guard_setup_sec." SECOND) as time_start_offset,
DATE_ADD(`a`.time_end_wish, INTERVAL ".$guard_cleanup_sec." SECOND) as time_end_offset DATE_ADD(`a`.time_end, INTERVAL ".$guard_cleanup_sec." SECOND) as time_end_offset
FROM `tbl_serv_tests` AS `a` FROM `tbl_serv_tests` AS `a`
LEFT JOIN `tbl_serv_users` AS `b` ON `a`.owner_fk = `b`.serv_users_key LEFT JOIN `tbl_serv_users` AS `b` ON `a`.owner_fk = `b`.serv_users_key
WHERE (`a`.test_status NOT IN ('not schedulable') OR (`a`.test_status_preserved IS NOT NULL AND `a`.test_status_preserved IN ('finished','failed'))) WHERE (`a`.test_status NOT IN ('not schedulable') OR (`a`.test_status_preserved IS NOT NULL AND `a`.test_status_preserved IN ('finished','failed')))
AND ( (`a`.time_start_wish BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') OR (`a`.time_end_wish BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') ) AND ( (`a`.time_start BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') OR (`a`.time_end BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') )
ORDER BY `a`.time_start_wish"; ORDER BY `a`.time_start";
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get calendar data from database because: ' . mysqli_error($db)); $rs = mysqli_query($db, $sql) or flocklab_die('Cannot get calendar data from database because: ' . mysqli_error($db));
// Build the array of events: // Build the array of events:
$events = array(); $events = array();
while ($row = mysqli_fetch_array($rs)) { while ($row = mysqli_fetch_array($rs)) {
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
$events[] = array( $events[] = array(
'id' => $row['serv_tests_key'], 'id' => $row['serv_tests_key'],
'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'], 'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_act'])).' - '.date("H:i", strtotime($row['time_end_act'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'], 'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start_act'], 'start' => $row['time_start'],
'end' => $row['time_end_act'], 'end' => $row['time_end'],
'allDay' => false, 'allDay' => false,
'color' => '#eca427', 'color' => '#eca427',
); );
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
'title' => 'Test setup', 'title' => 'Test setup',
'description' => $mini?'':'Time needed by FlockLab to setup your test.', 'description' => $mini?'':'Time needed by FlockLab to setup your test.',
'start' => $row['time_start_offset'], 'start' => $row['time_start_offset'],
'end' => $row['time_start_wish'], 'end' => $row['time_start'],
'allDay' => false, 'allDay' => false,
'color' => 'orange', 'color' => 'orange',
); );
...@@ -88,9 +88,9 @@ ...@@ -88,9 +88,9 @@
$events[] = array( $events[] = array(
'id' => $row['serv_tests_key'], 'id' => $row['serv_tests_key'],
'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'], 'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_wish'])).' - '.date("H:i", strtotime($row['time_end_wish'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'], 'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start_wish'], 'start' => $row['time_start'],
'end' => $row['time_end_wish'], 'end' => $row['time_end'],
'allDay' => false, 'allDay' => false,
'color' => '#eca427', 'color' => '#eca427',
); );
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
'id' => 'service', 'id' => 'service',
'title' => 'Test cleanup', 'title' => 'Test cleanup',
'description' => $mini?'':'Time needed by FlockLab to cleanup your test.', 'description' => $mini?'':'Time needed by FlockLab to cleanup your test.',
'start' => $row['time_end_wish'], 'start' => $row['time_end'],
'end' => $row['time_end_offset'], 'end' => $row['time_end_offset'],
'allDay' => false, 'allDay' => false,
'color' => 'orange', 'color' => 'orange',
...@@ -110,47 +110,47 @@ ...@@ -110,47 +110,47 @@
$event = array( $event = array(
'id' => $row['serv_tests_key'], 'id' => $row['serv_tests_key'],
'title' => $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')', 'title' => $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')',
'description' => $mini?'':'ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_wish'])).' - '.date("H:i", strtotime($row['time_end_wish'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'] . '<br/> User: ' . $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')' . '<br/>Status: ' . $row['test_status'], 'description' => $mini?'':'ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'] . '<br/> User: ' . $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')' . '<br/>Status: ' . $row['test_status'],
'allDay' => false, 'allDay' => false,
); );
if (isset($row['time_start_act'])) if (isset($row['time_start']))
$event['start'] = $row['time_start_act']; $event['start'] = $row['time_start'];
else else
$event['start'] = $row['time_start_offset']; $event['start'] = $row['time_start_offset'];
if (isset($row['time_end_act'])) if (isset($row['time_end']))
$event['end'] = $row['time_end_act']; $event['end'] = $row['time_end'];
else else
$event['end'] = $row['time_end_offset']; $event['end'] = $row['time_end_offset'];