Commit 019a0760 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

minor changes

parent a7f73068
......@@ -60,7 +60,6 @@ def main(argv):
elif opt in ("-e", "--email"):
send_email = True
elif opt in ("-d", "--debug"):
logger.debug("Detected debug flag.")
logger.setLevel(logging.DEBUG)
elif opt in ("-t", "--testid"):
try:
......
......@@ -8,18 +8,6 @@ logger = None
debug = False
##############################################################################
#
# Error classes
#
##############################################################################
class Error(Exception):
""" Base class for exception. """
pass
### END Error classes
##############################################################################
#
# StopTestThread
......@@ -56,7 +44,7 @@ class StopTestThread(threading.Thread):
if ("No such file or directory" in err):
msg = "SD card on observer ID %s is not mounted, observer will thus be omitted for this test." % (self._obsdict_key[self._obskey][1])
else:
msg = "Observer ID %s is not reachable (returned: %d: %s, %s)." % (self._obsdict_key[self._obskey][1], rs, out, err)
msg = "Observer ID %s is not reachable (returned %d: %s, %s)." % (self._obsdict_key[self._obskey][1], rs, out, err)
else:
msg = "Observer ID %s is not responsive (SSH returned %d)." % (self._obsdict_key[self._obskey][1], rs)
errors.append((msg, errno.EHOSTUNREACH, self._obsdict_key[self._obskey][1]))
......@@ -83,10 +71,11 @@ class StopTestThread(threading.Thread):
errors.append((msg, errno.EHOSTUNREACH, self._obsdict_key[self._obskey][1]))
logger.error(msg)
else:
errors.append(("Test stop script on observer ID %s failed with error code %s." % (str(self._obsdict_key[self._obskey][1]), str(errno.errorcode[rs])), rs, self._obsdict_key[self._obskey][1]))
logger.error("Test stop script on observer ID %s failed with error message:\n%s" % (str(self._obsdict_key[self._obskey][1]), str(out)))
errors.append(("Test stop script on observer ID %s failed with error code %d." % (str(self._obsdict_key[self._obskey][1]), rs), rs, self._obsdict_key[self._obskey][1]))
logger.error("Test stop script on observer ID %s failed with error code %d and message:\n%s" % (str(self._obsdict_key[self._obskey][1]), rs, str(out)))
logger.error("Tried to execute: %s" % (" ".join(cmd)))
except Error:
except:
logger.debug("Exception: %s, %s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1])))
# Main thread requested abort.
# Close a possibly still running subprocess:
if (p is not None) and (p.poll() is not None):
......@@ -172,26 +161,24 @@ class StartTestThread(threading.Thread):
logger.error(msg)
else:
logger.debug("Upload of target image and config XML to observer ID %s succeeded." % (self._obsdict_key[self._obskey][1]))
# Start the script on the observer which starts the test:
# Run the script on the observer which starts the test:
remote_cmd = flocklab.config.get("observer", "starttestscript") + " --testid=%d --xml=%s/%s --serialport=%d" % (self._testid, testconfigfolder, os.path.basename(self._xmldict_key[self._obskey][0]), obsdataport)
if debug:
remote_cmd += " --debug"
cmd = ['ssh', '%s' % (self._obsdict_key[self._obskey][2]), remote_cmd]
#DEBUG logger.debug("execute %s" %(str(cmd)))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
while p.returncode == None:
self._abortEvent.wait(1.0)
p.poll()
if self._abortEvent.is_set():
p.kill()
flocklab.debug("Abort is set, start test process for observer %s killed." % (self._obsdict_key[self._obskey][1]))
logger.debug("Abort is set, start test process for observer %s killed." % (self._obsdict_key[self._obskey][1]))
else:
out, err = p.communicate()
rs = p.wait()
if rs != flocklab.SUCCESS:
errors.append(("Test start script on observer ID %s failed with error code %s." % (self._obsdict_key[self._obskey][1], errno.errorcode[rs]), rs, self._obsdict_key[self._obskey][1]))
logger.error("Test start script on observer ID %s failed with error message:\n%s" % (str(self._obsdict_key[self._obskey][1]), str(out)))
logger.error("Tried to execute: %s" % (" ".join(cmd)))
errors.append(("Test start script on observer ID %s failed with error code %d." % (self._obsdict_key[self._obskey][1], rs), rs, self._obsdict_key[self._obskey][1]))
logger.error("Test start script on observer ID %s failed with error code %d and message:\n%s" % (str(self._obsdict_key[self._obskey][1]), rs, str(out)))
else:
logger.debug("Test start script on observer ID %s succeeded." % (self._obsdict_key[self._obskey][1]))
# Remove image file and xml on server:
......@@ -202,7 +189,8 @@ class StartTestThread(threading.Thread):
os.remove(image[0])
logger.debug("Removed target image %s for observer ID %s" % (self._imagedict_key[self._obskey][0], self._obsdict_key[self._obskey][1]))
except Error:
except:
logger.debug("Exception: %s, %s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1])))
# Main thread requested abort.
# Close a possibly still running subprocess:
if (p is not None) and (p.poll() is not None):
......@@ -714,6 +702,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
if len(errors) == 0:
if serialProxyUsed:
# Start serial proxy:
logger.debug("Starting serial proxy...")
cmd = [flocklab.config.get("dispatcher", "serialproxyscript"), "--notify"]
if debug:
cmd.append("--debug")
......@@ -1213,16 +1202,15 @@ def main(argv):
elif opt in ("-d", "--debug"):
debug = True
logger.setLevel(logging.DEBUG)
logger.debug("Detected debug flag.")
elif opt in ("-h", "--help"):
usage()
sys.exit(flocklab.SUCCESS)
elif opt in ("-t", "--testid"):
try:
testid = int(arg)
if testid <= 0:
raise Error
except:
testid = 0
if testid <= 0:
logger.warn("Wrong API usage: testid has to be a positive number")
sys.exit(errno.EINVAL)
else:
......
This diff is collapsed.
......@@ -89,7 +89,7 @@ def obs_connect_process(conreqQueue, condoneQueue, _stopevent):
worklist.remove(w)
except ConnectionRefusedError:
logger.info("Could not connect to observer %s on port %d, will retry later.." % (w[0],w[1]))
time.sleep(2)
time.sleep(5)
except Exception:
logger.info("Could not connect to observer %s on port %d: %s, %s\n%s" % (w[0], w[1], str(sys.exc_info()[0]), str(sys.exc_info()[1]), traceback.format_exc()))
pass
......
......@@ -13,7 +13,7 @@ from email.utils import formatdate, make_msgid
### Global variables ###
SUCCESS = 0
FAILED = -1
FAILED = -2 # note: must be negative, and -1 (= 255) is reserved for SSH error
scriptpath = os.path.dirname(os.path.abspath(sys.argv[0]))
scriptname = os.path.basename(os.path.abspath(sys.argv[0])) # name of caller script
configfile = "/home/flocklab/flocklab_config.ini"
......@@ -397,15 +397,15 @@ def get_test_obs(cursor=None, testid=0):
2 if there was an error in processing the request
"""
if ((type(cursor) != MySQLdb.cursors.Cursor) or (type(testid) != int) or (testid <= 0) or (check_test_id(cursor, testid) != 0)):
return 1
return FAILED
try:
cursor.execute("SELECT `a`.serv_observer_key, `a`.observer_id, `b`.node_id \
FROM tbl_serv_observer AS `a` \
LEFT JOIN tbl_serv_map_test_observer_targetimages AS `b` \
ON `a`.serv_observer_key = `b`.observer_fk \
WHERE `b`.test_fk = %d \
ORDER BY `a`.observer_id" %testid)
FROM tbl_serv_observer AS `a` \
LEFT JOIN tbl_serv_map_test_observer_targetimages AS `b` \
ON `a`.serv_observer_key = `b`.observer_fk \
WHERE `b`.test_fk = %d \
ORDER BY `a`.observer_id" % testid)
rs = cursor.fetchall()
obsdict_bykey = {}
......@@ -418,7 +418,7 @@ ORDER BY `a`.observer_id" %testid)
except:
logger = get_logger()
logger.error("%s: %s" %(str(sys.exc_info()[0]), str(sys.exc_info()[1])))
return 2
return FAILED
### END get_test_obs()
......@@ -436,11 +436,11 @@ def get_fetcher_pid(testid):
if (p.returncode == 0):
return int(out)
else:
return -1
return FAILED
except:
logger = get_logger()
logger.error("%s: %s" %(str(sys.exc_info()[0]), str(sys.exc_info()[1])))
return -2
return FAILED
### END get_fetcher_pid()
......
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