Changeset 76325 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Dec 20, 2018 7:08:46 PM (6 years ago)
- Location:
- trunk/src/VBox/ValidationKit/testmanager
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testmanager/batch/virtual_test_sheriff.py
r73145 r76325 43 43 import os; 44 44 import hashlib; 45 import subprocess; 46 import smtplib 45 47 if sys.version_info[0] >= 3: 46 48 from io import StringIO as StringIO; # pylint: disable=import-error,no-name-in-module … … 49 51 from optparse import OptionParser; # pylint: disable=deprecated-module 50 52 from PIL import Image; # pylint: disable=import-error 53 54 from email.mime.multipart import MIMEMultipart 55 from email.mime.text import MIMEText 56 from email.utils import COMMASPACE 51 57 52 58 # Add Test Manager's modules path … … 65 71 from testmanager.core.testresultfailures import TestResultFailureLogic, TestResultFailureData; 66 72 from testmanager.core.useraccount import UserAccountLogic; 73 from testmanager.config import g_ksSmtpHost, g_kcSmtpPort, g_ksAlertSubject, g_asAlertList; 67 74 68 75 # Python 3 hacks: … … 358 365 rcExit = self.eprint(u'Cannot find my user account "%s"!' % (VirtualTestSheriff.ksLoginName,)); 359 366 return rcExit; 367 368 def emailAlert(self, uidAuthor, sBodyText): 369 asEmailList = []; 370 371 # Get author email 372 self.oDb.execute('SELECT sEmail FROM Users WHERE uid=%s', (uidAuthor,)); 373 sFrom = self.oDb.fetchOne(); 374 if sFrom is not None: 375 sFrom = sFrom[0]; 376 else: 377 sFrom = '[email protected]'; 378 379 for sUser in g_asAlertList: 380 self.oDb.execute('SELECT sEmail FROM Users WHERE sUsername=%s', (sUser,)); 381 sEmail = self.oDb.fetchOne(); 382 if sEmail is None: 383 # No address to send an alert. 384 return; 385 asEmailList.append(sEmail[0]); 386 387 oMsg = MIMEMultipart(); 388 oMsg['From'] = sFrom; 389 oMsg['To'] = COMMASPACE.join(asEmailList); 390 oMsg['Subject'] = g_ksAlertSubject; 391 oMsg.attach(MIMEText(sBodyText, 'plain')) 392 393 try: 394 oSMTP = smtplib.SMTP(g_ksSmtpHost, g_kcSmtpPort); 395 oSMTP.sendmail(sFrom, asEmailList, oMsg.as_string()) 396 oSMTP.quit() 397 except smtplib.SMTPException as oXcpt: 398 rcExit = self.eprint('Failed to send mail: %s' % (oXcpt,)); 360 399 361 400 … … 454 493 % (iFirstOkay, cBad, cOkay),); 455 494 except Exception as oXcpt: 456 rcExit = self.eprint(u'Error rebooting testbox #%u (% u): %s\n' % (idTestBox, oTestBox.sName, oXcpt,));495 rcExit = self.eprint(u'Error rebooting testbox #%u (%s): %s\n' % (idTestBox, oTestBox.sName, oXcpt,)); 457 496 else: 458 497 self.dprint(u'badTestBoxManagement: #%u (%s) looks ok: iFirstOkay=%u cBad=%u cOkay=%u' 459 498 % ( idTestBox, oTestBox.sName, iFirstOkay, cBad, cOkay)); 499 # 500 # Reset hanged testboxes 501 # 502 cStatusTimeoutMins = 10; 503 504 self.oDb.execute('SELECT idTestBox FROM TestBoxStatuses WHERE tsUpdated < (CURRENT_TIMESTAMP - interval \'%s minutes\')', (cStatusTimeoutMins,)); 505 for idTestBox in self.oDb.fetchAll(): 506 idTestBox = idTestBox[0]; 507 try: 508 oTestBox = TestBoxData().initFromDbWithId(self.oDb, idTestBox); 509 except Exception as oXcpt: 510 rcExit = self.eprint('Failed to get data for test box #%u in badTestBoxManagement: %s' % (idTestBox, oXcpt,)); 511 continue; 512 # Skip if the testbox is already disabled, already reset or there's no iLOM 513 if not oTestBox.fEnabled or oTestBox.ipLom is None or \ 514 oTestBox.sComment is not None and oTestBox.sComment.find('Automatically reset') >= 0: 515 self.dprint(u'badTestBoxManagement: Skipping test box #%u (%s) as it has been disabled already.' 516 % ( idTestBox, oTestBox.sName, )); 517 continue; 518 ## @todo get iLOM credentials from a table? 519 sCmd = 'sshpass -pchangeme ssh -oStrictHostKeyChecking=no root@%s show /SP && reset /SYS' % (oTestBox.ipLom,); 520 try: 521 oPs = subprocess.Popen(sCmd, stdout=subprocess.PIPE, shell=True); 522 sStdout = oPs.communicate()[0]; 523 iRC = oPs.wait(); 524 525 oTestBox.sComment = 'Automatically reset (iRC=%u sStdout=%s)' % (iRC, sStdout,); 526 oTestBoxLogic.editEntry(oTestBox, self.uidSelf, fCommit = True); 527 528 sComment = u'Reset testbox #%u (%s) - iRC=%u sStduot=%s' % ( idTestBox, oTestBox.sName, iRC, sStdout); 529 self.vprint(sComment); 530 531 self.emailAlert(self.uidSelf, sComment); 532 533 except Exception as oXcpt: 534 rcExit = self.eprint(u'Error reseting testbox #%u (%s): %s\n' % (idTestBox, oTestBox.sName, oXcpt,)); 535 460 536 return rcExit; 461 537 -
trunk/src/VBox/ValidationKit/testmanager/config.py
r69111 r76325 186 186 ## @} 187 187 188 ## @name Virtual Sheriff email alerts 189 ## @{ 190 191 ## SMTP server host name. 192 g_ksSmtpHost = 'internal-mail-router.oracle.com'; 193 ## SMTP server port number. 194 g_kcSmtpPort = 25; 195 ## Subject for email alert. 196 g_ksAlertSubject = 'Virtual Sheriff alert'; 197 ## List of users to send alerts. 198 g_asAlertList = ['lelik', 'werner']; 199 200 ## @}
Note:
See TracChangeset
for help on using the changeset viewer.