added a variety of updates to templates, to reference each other.
[monitor.git] / findbadpcu.py
index 1af600c..070ddac 100755 (executable)
@@ -13,9 +13,10 @@ import threadpool
 import threading
 
 import monitor
-from monitor.pcu import reboot
+from pcucontrol  import reboot
 from monitor import config
-from monitor.database import FindbadPCURecordSync, FindbadPCURecord
+from monitor.database.info.model import FindbadPCURecordSync, FindbadPCURecord, session
+from monitor import database
 from monitor import util 
 from monitor.wrapper import plc, plccache
 from nodequery import pcu_select
@@ -274,7 +275,7 @@ def recordPingAndSSH(request, result):
 
                fbrec = FindbadPCURecord(
                                        date_checked=datetime.fromtimestamp(values['date_checked']),
-                                       record=fbsync.round,
+                                       round=fbsync.round,
                                        plc_pcuid=pcu_id,
                                        plc_pcu_stats=values['plc_pcu_stats'],
                                        dns_status=values['dnsmatch'],
@@ -283,6 +284,11 @@ def recordPingAndSSH(request, result):
                                        reboot_trial_status="%s" % values['reboot'],
                                )
                fbnodesync.round = global_round
+
+               fbnodesync.flush()
+               fbsync.flush()
+               fbrec.flush()
+
                count += 1
                print "%d %s %s" % (count, nodename, values)
 
@@ -308,9 +314,10 @@ def checkAndRecordState(l_pcus, cohash):
        for pcuname in l_pcus:
                pcu_id = int(pcuname)
                fbnodesync = FindbadPCURecordSync.findby_or_create(plc_pcuid=pcu_id, if_new_set={'round' : 0})
+               fbnodesync.flush()
 
                node_round   = fbnodesync.round
-               if node_round < global_round:
+               if node_round < global_round or config.force:
                        # recreate node stats when refreshed
                        #print "%s" % nodename
                        req = threadpool.WorkRequest(collectPingAndSSH, [pcuname, cohash], {}, 
@@ -340,6 +347,7 @@ def checkAndRecordState(l_pcus, cohash):
 
        print FindbadPCURecordSync.query.count()
        print FindbadPCURecord.query.count()
+       session.flush()
 
 
 def main():
@@ -353,10 +361,6 @@ def main():
 
        global_round = fbsync.round
 
-       if config.increment:
-               # update global round number to force refreshes across all nodes
-               global_round += 1
-               fbsync.round = global_round
 
        if config.site is not None:
                api = plc.getAuthAPI()
@@ -369,6 +373,7 @@ def main():
                l_pcus = [pcu for pcu in sets.Set(pcus)]
        elif config.pcuselect is not None:
                n, pcus = pcu_select(config.pcuselect)
+               print pcus
                # clear out dups.
                l_pcus = [pcu for pcu in sets.Set(pcus)]
 
@@ -382,6 +387,12 @@ def main():
                l_pcus = [ config.pcuid ] 
                l_pcus = [int(pcu) for pcu in l_pcus]
 
+       if config.increment:
+               # update global round number to force refreshes across all nodes
+               global_round += 1
+               fbsync.round = global_round
+       fbsync.flush()
+
        checkAndRecordState(l_pcus, cohash)
 
        return 0
@@ -406,6 +417,7 @@ if __name__ == '__main__':
                                                dbname="findbadpcus", 
                                                cachenodes=False,
                                                refresh=False,
+                                               force=False,
                                                )
        parser.add_option("-f", "--nodelist", dest="nodelist", metavar="FILE", 
                                                help="Provide the input file for the node list")
@@ -424,6 +436,8 @@ if __name__ == '__main__':
                                                help="Refresh the cached values")
        parser.add_option("-i", "--increment", action="store_true", dest="increment", 
                                                help="Increment round number to force refresh or retry")
+       parser.add_option("", "--force", action="store_true", dest="force", 
+                                               help="Force probe without incrementing global 'round'.")
        parser = parsermodule.getParser(['defaults'], parser)
        config = parsermodule.parse_args(parser)
        try: