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 c77178ac authored by Roman Trüb's avatar Roman Trüb

updated slot updater script: removed use of ip_address and added msg if no change detected

parent 13d313ba
......@@ -32,7 +32,9 @@ debug = False
class UpdateSlotAssignThread(threading.Thread):
def __init__(self, observerdata, config, logger, searchtime, maxretries, queue):
threading.Thread.__init__(self)
self.Observerdata = observerdata
self.ObsKey = observerdata[0]
self.ObsHostname = observerdata[1]
self.ObsSerialList = observerdata[2:]
self.Config = config
self.Logger = logger
self.Searchtime = searchtime
......@@ -46,20 +48,19 @@ class UpdateSlotAssignThread(threading.Thread):
cmd = "%s -s%.1f" %(cmd, self.Searchtime)
if self.Maxretries:
cmd = "%s -m%d" %(cmd, self.Maxretries)
self.Logger.debug("Observer %s: calling %s" %(self.Observerdata[1], cmd))
p = subprocess.Popen(['ssh', 'root@%s' % (self.Observerdata[2]), cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.Logger.debug("Observer %s: calling %s" %(self.ObsHostname, cmd))
p = subprocess.Popen(['ssh', 'root@%s' % (self.ObsHostname), cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rs = p.communicate()
self.Logger.debug("Observer %s: got response: %s" % (self.Observerdata[1], str(rs)))
self.Logger.debug("Observer %s: got response: %s" % (self.ObsHostname, str(rs)))
# Compare list against values stored on database if ssh command was successful
if (rs[1] != ''):
self.Logger.debug("Observer %s: returned error: %s" % (self.Observerdata[1], str(rs[1])))
self.Logger.debug("Observer %s: returned error: %s" % (self.ObsHostname, str(rs[1])))
slots = rs[0].split('\n')
if ((rs[1] == '') and (len(slots) > 1)):
cmds = []
changes = []
i = 1
for slot in slots[0:4]:
for i, slot in enumerate(slots[0:4]):
s = slot.split(' ')
slotnr = s[0][0]
serialid = s[1]
......@@ -67,18 +68,17 @@ class UpdateSlotAssignThread(threading.Thread):
# If a serial ID was found and if it differs in the database and on the observer, update the database:
if serialid == 'not':
serialid = None
if (serialid != self.Observerdata[2 + i]):
msg = "Observer %s: serial IDs for slot %s differ. Value database: %s, value observer slot: %s" % (self.Observerdata[1], slotnr, self.Observerdata[2 + i], serialid)
if (serialid != self.ObsSerialList[i]):
msg = "Observer %s: serial IDs for slot %s differ. Value database: %s, value observer slot: %s" % (self.ObsHostname, slotnr, self.ObsSerialList[i], serialid)
self.Logger.debug(msg)
changes.append((self.Observerdata[1], slotnr, self.Observerdata[2 + i], serialid))
changes.append((self.ObsHostname, slotnr, self.ObsSerialList[i], serialid))
cmds.append(""" UPDATE `tbl_serv_observer`
SET slot_%s_tg_adapt_list_fk = (
SELECT `serv_tg_adapt_list_key`
FROM `tbl_serv_tg_adapt_list`
WHERE `serialid` = '%s')
WHERE `serv_observer_key` = %s;
""" % (i, serialid, self.Observerdata[0]))
i = i + 1
""" % (i+1, serialid, self.ObsKey))
# If any changes need to be done to the database, do so:
if len(cmds) > 0:
......@@ -89,7 +89,7 @@ class UpdateSlotAssignThread(threading.Thread):
raise
try:
for cmd in cmds:
self.Logger.debug("Observer %s: executing SQL: %s" % (self.Observerdata[1], cmd))
self.Logger.debug("Observer %s: executing SQL: %s" % (self.ObsHostname, cmd))
cur.execute(cmd)
cn.commit()
......@@ -111,7 +111,7 @@ class UpdateSlotAssignThread(threading.Thread):
else:
cmd = sql % (change[2])
cur.execute(cmd)
self.Logger.debug("Observer %s: executing SQL: %s" % (self.Observerdata[1], cmd))
self.Logger.debug("Observer %s: executing SQL: %s" % (self.ObsHostname, cmd))
rs = cur.fetchone()
if rs:
old = rs[0]
......@@ -121,7 +121,7 @@ class UpdateSlotAssignThread(threading.Thread):
else:
cmd = sql % (change[3])
cur.execute(cmd)
self.Logger.debug("Observer %s: executing SQL: %s" % (self.Observerdata[1], cmd))
self.Logger.debug("Observer %s: executing SQL: %s" % (self.ObsHostname, cmd))
rs = cur.fetchone()
if rs:
new = rs[0]
......@@ -142,6 +142,9 @@ class UpdateSlotAssignThread(threading.Thread):
finally:
cur.close()
cn.close()
else:
msg = "Observer %s: No change detected!\n" % (self.ObsHostname)
self.Queue.put(msg)
return(SUCCESS)
### END UpdateSlotAssignThread
......@@ -268,7 +271,7 @@ def main(argv):
# Get all active observers from the database:
logger.debug("Going to fetch current database status for active observers...")
try:
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
sql = """ SELECT a.serv_observer_key, a.ethernet_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
......@@ -292,14 +295,14 @@ def main(argv):
# Prepare queue which is going to hold the messages returned from the threads:
q = Queue.Queue()
# Start one update thread per observer:
for observer in rs:
logger.debug("Starting thread for %s" % (observer[1]))
for observerdata in rs:
logger.debug("Starting thread for %s" % (observerdata[1]))
try:
t = UpdateSlotAssignThread(observer, config, logger, searchtime, maxretries, q)
t = UpdateSlotAssignThread(observerdata, config, logger, searchtime, maxretries, q)
threadlist.append(t)
t.start()
except:
logger.warn("Error when starting thread for observer %s: %s: %s" % (observer[1], str(sys.exc_info()[0]), str(sys.exc_info()[1])))
logger.warn("Error when starting thread for observer %s: %s: %s" % (observerdata[1], str(sys.exc_info()[0]), str(sys.exc_info()[1])))
continue
# Wait for threads to finish:
logger.debug("Joining threads")
......
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