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 25d506bd authored by Reto Da Forno's avatar Reto Da Forno

new parameters added to observer slot updater script

parent 96dce0f4
......@@ -3,10 +3,10 @@
__author__ = "Christoph Walser <walser@tik.ee.ethz.ch>"
__copyright__ = "Copyright 2010, ETH Zurich, Switzerland, Christoph Walser"
__license__ = "GPL"
__version__ = "$Revision$"
__date__ = "$Date$"
__id__ = "$Id$"
__source__ = "$URL$"
__version__ = "$Revision: 3134 $"
__date__ = "$Date: 2015-08-26 10:40:51 +0200 (Wed, 26 Aug 2015) $"
__id__ = "$Id: flocklab_upd_slot_assign.py 3134 2015-08-26 08:40:51Z rlim $"
__source__ = "$URL: svn://svn.ee.ethz.ch/flocklab/trunk/server/testmanagementserver/flocklab_upd_slot_assign.py $"
import os, sys, getopt, MySQLdb, errno, threading, subprocess, time, traceback, Queue, logging
......@@ -154,11 +154,13 @@ class UpdateSlotAssignThread(threading.Thread):
#
##############################################################################
def usage():
print "Usage: %s [--searchtime=<float>] [--maxretries=<int>] [--debug] [--help] [--version]" % sys.argv[0]
print "Usage: %s [--searchtime <float>] [--maxretries <int>] [--debug] [--help] [--version] [--obs <id>] [--develop]" % sys.argv[0]
print "Options:"
print " --searchtime\t\t\tOptional. If set, standard time for waiting for the ID search is overwritten."
print " --maxretries\t\t\tOptional. If set, standard number of retries for reading an ID is overwritten."
print " --debug\t\t\tPrint debug messages to log."
print " --observer\t\t\tUpdate only observer with ID <id>."
print " --develop\t\t\tUpdate only observers with status 'develop'."
print " --help\t\t\tOptional. Print this help."
print " --version\t\t\tOptional. Print version number of software and exit."
### END usage()
......@@ -178,6 +180,8 @@ def main(argv):
searchtime = None
maxretries = None
force = False
observer = ""
status = "'online', 'develop'"
# Set timezone to UTC:
os.environ['TZ'] = 'UTC'
......@@ -188,7 +192,7 @@ def main(argv):
# Get command line parameters.
try:
opts, args = getopt.getopt(argv, "hvds:m:", ["help", "version", "debug", "searchtime=", "maxretries=", "force"])
opts, args = getopt.getopt(argv, "hvds:m:fo:d", ["help", "version", "debug", "searchtime", "maxretries", "force", "observer", "develop"])
except getopt.GetoptError, err:
print str(err)
logger.warn(str(err))
......@@ -217,6 +221,16 @@ def main(argv):
sys.exit(errno.EINVAL)
elif opt in ("-f", "--force"):
force = True
elif opt in ("-o", "--observer"):
try:
observer = " AND observer_id=%u" % int(arg)
print "will only update observer %u" % int(arg)
except:
print "invalid argument '%s'" % arg
sys.exit(errno.EINVAL)
elif opt in ("-d", "--develop"):
print "will only update observers with status 'develop'"
status = "'develop'"
elif opt in ("-m", "--maxretries"):
try:
maxretries = int(arg)
......@@ -245,7 +259,7 @@ def main(argv):
logger.error("Could not connect to database")
raise
if flocklab.is_test_running(cur) and not force:
print "test is running!";
print "Test is running! You can force the target slot update on a specific observer with the flags '-f -o=<id>'.";
logger.debug("A test is running, thus exit...")
cur.close()
cn.close()
......@@ -254,7 +268,7 @@ def main(argv):
# Get all active observers from the database:
logger.debug("Going to fetch current database status for active observers...")
try:
cur.execute(""" SELECT a.serv_observer_key, a.ethernet_address, a.ip_address, b.serialid AS serialid_1, c.serialid AS serialid_2, d.serialid AS serialid_3, e.serialid AS serialid_4
sql = """ SELECT a.serv_observer_key, a.ethernet_address, a.ip_address, b.serialid AS serialid_1, c.serialid AS serialid_2, d.serialid AS serialid_3, e.serialid AS serialid_4
FROM `tbl_serv_observer` AS a
LEFT JOIN `tbl_serv_tg_adapt_list` AS b
ON a.slot_1_tg_adapt_list_fk = b.serv_tg_adapt_list_key
......@@ -264,8 +278,9 @@ def main(argv):
ON a.slot_3_tg_adapt_list_fk = d.serv_tg_adapt_list_key
LEFT JOIN `tbl_serv_tg_adapt_list` AS e
ON a.slot_4_tg_adapt_list_fk = e.serv_tg_adapt_list_key
WHERE a.status IN ('online', 'develop')
""")
WHERE a.status IN (%s) %s
""" % (status, observer)
cur.execute(sql)
except MySQLdb.Error, err:
logger.warn(str(err))
sys.exit(errno.EIO)
......
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