X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=reboot.py;h=f3f7f32067fd0f69a257681fdcb39f19415fb7c9;hb=b548c69db3d1f302b4d0d08377f0231eb3c4fd58;hp=4cccdf0a3499dec0702a5c6f5d9db5d242c10976;hpb=d0652340b89d51c6115edb13d5c7c72b34dea66f;p=monitor.git diff --git a/reboot.py b/reboot.py index 4cccdf0..f3f7f32 100755 --- a/reboot.py +++ b/reboot.py @@ -11,14 +11,13 @@ import urllib2 import urllib import threading, popen2 import array, struct -#from socket import * -import socket import plc import base64 from subprocess import PIPE, Popen import ssh.pxssh as pxssh import ssh.pexpect as pexpect import socket +import moncommands # Use our versions of telnetlib and pyssh sys.path.insert(0, os.path.dirname(sys.argv[0])) @@ -559,10 +558,10 @@ class APC(PCUControl): class IntelAMT(PCUControl): def run(self, node_port, dryrun): - import soltesz - cmd = soltesz.CMD() - cmd_str = "IntelAMTSDK/Samples/RemoteControl/remoteControl" + cmd = moncommands.CMD() + #[cmd_str = "IntelAMTSDK/Samples/RemoteControl/remoteControl" + cmd_str = "cmdamt/remoteControl" if dryrun: # NOTE: -p checks the power state of the host. @@ -624,9 +623,8 @@ class HPiLO(PCUControl): class HPiLOHttps(PCUControl): def run(self, node_port, dryrun): - import soltesz - locfg = soltesz.CMD() + locfg = moncommands.CMD() cmd = "cmdhttps/locfg.pl -s %s -f %s -u %s -p '%s' | grep 'MESSAGE' | grep -v 'No error'" % ( self.host, "iloxml/Get_Network.xml", self.username, self.password) @@ -637,7 +635,7 @@ class HPiLOHttps(PCUControl): return sout.strip() if not dryrun: - locfg = soltesz.CMD() + locfg = moncommands.CMD() cmd = "cmdhttps/locfg.pl -s %s -f %s -u %s -p '%s' | grep 'MESSAGE' | grep -v 'No error'" % ( self.host, "iloxml/Reset_Server.xml", self.username, self.password) @@ -706,6 +704,7 @@ class BayTechCtrlCUnibe(PCUControl): # Control Outlets (5 ,1).........5 try: + #index = s.expect("Enter Request") index = s.expect(["Enter Request :"]) if index == 0: @@ -720,7 +719,8 @@ class BayTechCtrlCUnibe(PCUControl): print "Reboot %d" % node_port s.send("Reboot %d\r\n" % node_port) - index = s.expect(["(Y/N)?"]) + time.sleep(5) + index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"]) if index == 0: if dryrun: print "sending N" @@ -728,16 +728,21 @@ class BayTechCtrlCUnibe(PCUControl): else: print "sending Y" s.send("Y\r\n") + elif index == 1: + raise ExceptionPrompt("PCU Reported 'Port in use.'") + elif index == 2: + raise ExceptionSequence("Issued command 'Reboot' failed.") - #index = s.expect(["DS-RPC>"]) + time.sleep(5) + index = s.expect(["DS-RPC>"]) #print "got prompt back" s.close() except pexpect.EOF: - raise ExceptionPrompt("EOF before 'Enter Request' Prompt") + raise ExceptionPrompt("EOF before expected Prompt") except pexpect.TIMEOUT: - raise ExceptionPrompt("Timeout before 'Enter Request' Prompt") + raise ExceptionPrompt("Timeout before expected Prompt") return 0 @@ -757,37 +762,54 @@ class BayTechCtrlC(PCUControl): # Otherwise, the login succeeded. # Send a ctrl-c to the remote process. - print "sending ctrl-c" + print "SENDING ctrl-c" s.send(chr(3)) # Control Outlets (5 ,1).........5 try: + print "EXPECTING: ", "Enter Request :" index = s.expect(["Enter Request :"]) if index == 0: - print "5" + print "SENDING: 5" s.send("5\r\n") - index = s.expect(["DS-RPC>", "Enter user name:"]) + print "EXPECTING: ", "DS-RPC>" + index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."]) if index == 1: print "sending username" s.send(self.username + "\r\n") index = s.expect(["DS-RPC>"]) + elif index == 2: + raise ExceptionPrompt("PCU Reported 'Port in use.'") if index == 0: - print "Reboot %d" % node_port + print "SENDING: Reboot %d" % node_port s.send("Reboot %d\r\n" % node_port) - index = s.expect(["(Y/N)?"]) + print "SLEEPING: 5" + time.sleep(5) + print "EXPECTING: ", "Y/N?" + index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"]) if index == 0: if dryrun: print "sending N" s.send("N\r\n") else: - print "sending Y" + print "SENDING: Y" s.send("Y\r\n") - + elif index == 1: + raise ExceptionPrompt("PCU Reported 'Port in use.'") + elif index == 2: + raise ExceptionSequence("Issued command 'Reboot' failed.") + + # NOTE: for some reason, the script times out with the + # following line. In manual tests, it works correctly, but + # with automated tests, evidently it fails. + print "SLEEPING: 5" + time.sleep(5) + #print "TOTAL--", s.allstr, "--EOT" index = s.expect(["DS-RPC>"]) - #print "got prompt back" + print "got prompt back" s.close() @@ -814,6 +836,7 @@ class BayTech(PCUControl): # even after login... print "msg: %s" % msg self.transport.write(self.username + "\r\n") + time.sleep(5) self.ifThenSend("DS-RPC>", "Reboot %d" % node_port) # Reboot Outlet N (Y/N)? @@ -821,6 +844,7 @@ class BayTech(PCUControl): self.ifThenSend("(Y/N)?", "N") else: self.ifThenSend("(Y/N)?", "Y") + time.sleep(5) self.ifThenSend("DS-RPC>", "") self.close() @@ -904,6 +928,20 @@ class ePowerSwitchGood(PCUControl): self.close() return 0 +class CustomPCU(PCUControl): + def run(self, node_port, dryrun): + url = "https://www-itec.uni-klu.ac.at/plab-pcu/index.php" + + if not dryrun: + # Turn host off, then on + formstr = "plab%s=off" % node_port + os.system("curl --user %s:%s --form '%s' --insecure %s" % (self.username, self.password, formstr, url)) + time.sleep(5) + formstr = "plab%s=on" % node_port + os.system("curl --user %s:%s --form '%s' --insecure %s" % (self.username, self.password, formstr, url)) + else: + os.system("curl --user %s:%s --insecure %s" % (self.username, self.password, url)) + class ePowerSwitchOld(PCUControl): def run(self, node_port, dryrun): @@ -1148,12 +1186,16 @@ def pcu_name(pcu): else: return None -import soltesz -fb =soltesz.dbLoad("findbadpcus") +#import database +from monitor import database +fb = None def get_pcu_values(pcu_id): - # TODO: obviously, this shouldn't be loaded each time... - + global fb + if fb == None: + # this shouldn't be loaded each time... + fb = database.dbLoad("findbadpcus") + try: values = fb['nodes']["id_%s" % pcu_id]['values'] except: @@ -1193,6 +1235,8 @@ def reboot_policy(nodename, continue_probe, dryrun): def reboot_test(nodename, values, continue_probe, verbose, dryrun): rb_ret = "" + if 'plc_pcu_stats' in values: + values.update(values['plc_pcu_stats']) try: # DataProbe iPal (many sites) @@ -1206,7 +1250,7 @@ def reboot_test(nodename, values, continue_probe, verbose, dryrun): print values # TODO: make a more robust version of APC - if values['pcu_id'] in [1163,1055,1111,1231,1113,1127,1128,1148]: + if values['pcu_id'] in [1102,1163,1055,1111,1231,1113,1127,1128,1148]: apc = APCEurope(values, verbose, ['22', '23']) rb_ret = apc.reboot(values[nodename], dryrun) @@ -1214,11 +1258,11 @@ def reboot_test(nodename, values, continue_probe, verbose, dryrun): apc = APCBrazil(values, verbose, ['22', '23']) rb_ret = apc.reboot(values[nodename], dryrun) - elif values['pcu_id'] in [1221,1225]: + elif values['pcu_id'] in [1221,1225,1220]: apc = APCBerlin(values, verbose, ['22', '23']) rb_ret = apc.reboot(values[nodename], dryrun) - elif values['pcu_id'] in [1173,1221,1220]: + elif values['pcu_id'] in [1173,1240]: apc = APCFolsom(values, verbose, ['22', '23']) rb_ret = apc.reboot(values[nodename], dryrun) @@ -1228,7 +1272,7 @@ def reboot_test(nodename, values, continue_probe, verbose, dryrun): # BayTech DS4-RPC elif continue_probe and values['model'].find("DS4-RPC") >= 0: - if values['pcu_id'] in [1237,1052,1209,1002,1008,1041,1013,1022]: + if values['pcu_id'] in [1056,1237,1052,1209,1002,1008,1041,1013,1022]: # These require a 'ctrl-c' to be sent... baytech = BayTechCtrlC(values, verbose, ['22', '23']) rb_ret = baytech.reboot(values[nodename], dryrun) @@ -1299,6 +1343,9 @@ def reboot_test(nodename, values, continue_probe, verbose, dryrun): eps = ePowerSwitchGood(values, verbose, ['80']) rb_ret = eps.reboot(values[nodename], dryrun) + elif continue_probe and values['pcu_id'] in [1122]: + custom = CustomPCU(values, verbose, ['80', '443']) + custom.reboot(values[nodename], dryrun) elif continue_probe: rb_ret = "Unsupported_PCU"