VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/batch/virtual_test_sheriff.py@ 78575

Last change on this file since 78575 was 77657, checked in by vboxsync, 6 years ago

vsheriff: make the code checking the full result tree for failures indicating a bad testbox actually work (needed more effort to get the failure reason)

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 71.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: virtual_test_sheriff.py 77657 2019-03-11 18:37:53Z vboxsync $
4# pylint: disable=C0301
5
6"""
7Virtual Test Sheriff.
8
9Duties:
10 - Try to a assign failure reasons to recently failed tests.
11 - Reboot or disable bad test boxes.
12
13"""
14
15from __future__ import print_function;
16
17__copyright__ = \
18"""
19Copyright (C) 2012-2019 Oracle Corporation
20
21This file is part of VirtualBox Open Source Edition (OSE), as
22available from http://www.virtualbox.org. This file is free software;
23you can redistribute it and/or modify it under the terms of the GNU
24General Public License (GPL) as published by the Free Software
25Foundation, in version 2 as it comes in the "COPYING" file of the
26VirtualBox OSE distribution. VirtualBox OSE is distributed in the
27hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
28
29The contents of this file may alternatively be used under the terms
30of the Common Development and Distribution License Version 1.0
31(CDDL) only, as it comes in the "COPYING.CDDL" file of the
32VirtualBox OSE distribution, in which case the provisions of the
33CDDL are applicable instead of those of the GPL.
34
35You may elect to license modified versions of this file under the
36terms and conditions of either the GPL or the CDDL or both.
37"""
38__version__ = "$Revision: 77657 $"
39
40
41# Standard python imports
42import sys;
43import os;
44import hashlib;
45import subprocess;
46import smtplib
47from email.mime.multipart import MIMEMultipart
48from email.mime.text import MIMEText
49from email.utils import COMMASPACE
50
51if sys.version_info[0] >= 3:
52 from io import StringIO as StringIO; # pylint: disable=import-error,no-name-in-module
53else:
54 from StringIO import StringIO as StringIO; # pylint: disable=import-error,no-name-in-module
55from optparse import OptionParser; # pylint: disable=deprecated-module
56from PIL import Image; # pylint: disable=import-error
57
58# Add Test Manager's modules path
59g_ksTestManagerDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
60sys.path.append(g_ksTestManagerDir);
61
62# Test Manager imports
63from testmanager.core.db import TMDatabaseConnection;
64from testmanager.core.build import BuildDataEx;
65from testmanager.core.failurereason import FailureReasonLogic;
66from testmanager.core.testbox import TestBoxLogic, TestBoxData;
67from testmanager.core.testcase import TestCaseDataEx;
68from testmanager.core.testgroup import TestGroupData;
69from testmanager.core.testset import TestSetLogic, TestSetData;
70from testmanager.core.testresults import TestResultLogic, TestResultFileData;
71from testmanager.core.testresultfailures import TestResultFailureLogic, TestResultFailureData;
72from testmanager.core.useraccount import UserAccountLogic;
73from testmanager.config import g_ksSmtpHost, g_kcSmtpPort, g_ksAlertFrom, \
74 g_ksAlertSubject, g_asAlertList, g_ksLomPassword;
75
76# Python 3 hacks:
77if sys.version_info[0] >= 3:
78 xrange = range; # pylint: disable=redefined-builtin,invalid-name
79
80
81class VirtualTestSheriffCaseFile(object):
82 """
83 A failure investigation case file.
84
85 """
86
87
88 ## Max log file we'll read into memory. (256 MB)
89 kcbMaxLogRead = 0x10000000;
90
91 def __init__(self, oSheriff, oTestSet, oTree, oBuild, oTestBox, oTestGroup, oTestCase):
92 self.oSheriff = oSheriff;
93 self.oTestSet = oTestSet; # TestSetData
94 self.oTree = oTree; # TestResultDataEx
95 self.oBuild = oBuild; # BuildDataEx
96 self.oTestBox = oTestBox; # TestBoxData
97 self.oTestGroup = oTestGroup; # TestGroupData
98 self.oTestCase = oTestCase; # TestCaseDataEx
99 self.sMainLog = ''; # The main log file. Empty string if not accessible.
100
101 # Generate a case file name.
102 self.sName = '#%u: %s' % (self.oTestSet.idTestSet, self.oTestCase.sName,)
103 self.sLongName = '#%u: "%s" on "%s" running %s %s (%s), "%s" by %s, using %s %s %s r%u' \
104 % ( self.oTestSet.idTestSet,
105 self.oTestCase.sName,
106 self.oTestBox.sName,
107 self.oTestBox.sOs,
108 self.oTestBox.sOsVersion,
109 self.oTestBox.sCpuArch,
110 self.oTestBox.sCpuName,
111 self.oTestBox.sCpuVendor,
112 self.oBuild.oCat.sProduct,
113 self.oBuild.oCat.sBranch,
114 self.oBuild.oCat.sType,
115 self.oBuild.iRevision, );
116
117 # Investigation notes.
118 self.tReason = None; # None or one of the ktReason_XXX constants.
119 self.dReasonForResultId = {}; # Reason assignments indexed by idTestResult.
120 self.dCommentForResultId = {}; # Comment assignments indexed by idTestResult.
121
122 #
123 # Reason.
124 #
125
126 def noteReason(self, tReason):
127 """ Notes down a possible reason. """
128 self.oSheriff.dprint(u'noteReason: %s -> %s' % (self.tReason, tReason,));
129 self.tReason = tReason;
130 return True;
131
132 def noteReasonForId(self, tReason, idTestResult, sComment = None):
133 """ Notes down a possible reason for a specific test result. """
134 self.oSheriff.dprint(u'noteReasonForId: %u: %s -> %s%s'
135 % (idTestResult, self.dReasonForResultId.get(idTestResult, None), tReason,
136 (u' (%s)' % (sComment,)) if sComment is not None else ''));
137 self.dReasonForResultId[idTestResult] = tReason;
138 if sComment is not None:
139 self.dCommentForResultId[idTestResult] = sComment;
140 return True;
141
142
143 #
144 # Test classification.
145 #
146
147 def isVBoxTest(self):
148 """ Test classification: VirtualBox (using the build) """
149 return self.oBuild.oCat.sProduct.lower() in [ 'virtualbox', 'vbox' ];
150
151 def isVBoxUnitTest(self):
152 """ Test case classification: The unit test doing all our testcase/*.cpp stuff. """
153 return self.isVBoxTest() \
154 and (self.oTestCase.sName.lower() == 'unit tests' or self.oTestCase.sName.lower() == 'misc: unit tests');
155
156 def isVBoxInstallTest(self):
157 """ Test case classification: VirtualBox Guest installation test. """
158 return self.isVBoxTest() \
159 and self.oTestCase.sName.lower().startswith('install:');
160
161 def isVBoxUSBTest(self):
162 """ Test case classification: VirtualBox USB test. """
163 return self.isVBoxTest() \
164 and self.oTestCase.sName.lower().startswith('usb:');
165
166 def isVBoxStorageTest(self):
167 """ Test case classification: VirtualBox Storage test. """
168 return self.isVBoxTest() \
169 and self.oTestCase.sName.lower().startswith('storage:');
170
171 def isVBoxGAsTest(self):
172 """ Test case classification: VirtualBox Guest Additions test. """
173 return self.isVBoxTest() \
174 and self.oTestCase.sName.lower().startswith('ga\'s tests');
175
176 def isVBoxAPITest(self):
177 """ Test case classification: VirtualBox API test. """
178 return self.isVBoxTest() \
179 and self.oTestCase.sName.lower().startswith('api:');
180
181 def isVBoxBenchmarkTest(self):
182 """ Test case classification: VirtualBox Benchmark test. """
183 return self.isVBoxTest() \
184 and self.oTestCase.sName.lower().startswith('benchmark:');
185
186 def isVBoxSmokeTest(self):
187 """ Test case classification: Smoke test. """
188 return self.isVBoxTest() \
189 and self.oTestCase.sName.lower().startswith('smoketest');
190
191
192 #
193 # Utility methods.
194 #
195
196 def getMainLog(self):
197 """
198 Tries to read the main log file since this will be the first source of information.
199 """
200 if self.sMainLog:
201 return self.sMainLog;
202 (oFile, oSizeOrError, _) = self.oTestSet.openFile('main.log', 'rb');
203 if oFile is not None:
204 try:
205 self.sMainLog = oFile.read(min(self.kcbMaxLogRead, oSizeOrError)).decode('utf-8', 'replace');
206 except Exception as oXcpt:
207 self.oSheriff.vprint(u'Error reading main log file: %s' % (oXcpt,))
208 self.sMainLog = '';
209 else:
210 self.oSheriff.vprint(u'Error opening main log file: %s' % (oSizeOrError,));
211 return self.sMainLog;
212
213 def getLogFile(self, oFile):
214 """
215 Tries to read the given file as a utf-8 log file.
216 oFile is a TestFileDataEx instance.
217 Returns empty string if problems opening or reading the file.
218 """
219 sContent = '';
220 (oFile, oSizeOrError, _) = self.oTestSet.openFile(oFile.sFile, 'rb');
221 if oFile is not None:
222 try:
223 sContent = oFile.read(min(self.kcbMaxLogRead, oSizeOrError)).decode('utf-8', 'replace');
224 except Exception as oXcpt:
225 self.oSheriff.vprint(u'Error reading the "%s" log file: %s' % (oFile.sFile, oXcpt,))
226 else:
227 self.oSheriff.vprint(u'Error opening the "%s" log file: %s' % (oFile.sFile, oSizeOrError,));
228 return sContent;
229
230 def getScreenshotSha256(self, oFile):
231 """
232 Tries to read the given screenshot file, uncompress it, and do SHA-2
233 on the raw pixels.
234 Returns SHA-2 digest string on success, None on failure.
235 """
236 (oImgFile, _, _) = self.oTestSet.openFile(oFile.sFile, 'rb');
237 try:
238 abImageFile = oImgFile.read();
239 except Exception as oXcpt:
240 self.oSheriff.vprint(u'Error reading the "%s" image file: %s' % (oFile.sFile, oXcpt,))
241 else:
242 try:
243 oImage = Image.open(StringIO(abImageFile));
244 except Exception as oXcpt:
245 self.oSheriff.vprint(u'Error opening the "%s" image bytes using PIL.Image.open: %s' % (oFile.sFile, oXcpt,))
246 else:
247 try:
248 oHash = hashlib.sha256();
249 oHash.update(oImage.tostring());
250 except Exception as oXcpt:
251 self.oSheriff.vprint(u'Error hashing the uncompressed image bytes for "%s": %s' % (oFile.sFile, oXcpt,))
252 else:
253 return oHash.hexdigest();
254 return None;
255
256
257
258 def isSingleTestFailure(self):
259 """
260 Figure out if this is a single test failing or if it's one of the
261 more complicated ones.
262 """
263 if self.oTree.cErrors == 1:
264 return True;
265 if self.oTree.deepCountErrorContributers() <= 1:
266 return True;
267 return False;
268
269
270
271class VirtualTestSheriff(object): # pylint: disable=R0903
272 """
273 Add build info into Test Manager database.
274 """
275
276 ## The user account for the virtual sheriff.
277 ksLoginName = 'vsheriff';
278
279 def __init__(self):
280 """
281 Parse command line.
282 """
283 self.oDb = None;
284 self.tsNow = None;
285 self.oTestResultLogic = None;
286 self.oTestSetLogic = None;
287 self.oFailureReasonLogic = None; # FailureReasonLogic;
288 self.oTestResultFailureLogic = None; # TestResultFailureLogic
289 self.oLogin = None;
290 self.uidSelf = -1;
291 self.oLogFile = None;
292 self.asBsodReasons = [];
293 self.asUnitTestReasons = [];
294
295 oParser = OptionParser();
296 oParser.add_option('--start-hours-ago', dest = 'cStartHoursAgo', metavar = '<hours>', default = 0, type = 'int',
297 help = 'When to start specified as hours relative to current time. Defauls is right now.', );
298 oParser.add_option('--hours-period', dest = 'cHoursBack', metavar = '<period-in-hours>', default = 2, type = 'int',
299 help = 'Work period specified in hours. Defauls is 2 hours.');
300 oParser.add_option('--real-run-back', dest = 'fRealRun', action = 'store_true', default = False,
301 help = 'Whether to commit the findings to the database. Default is a dry run.');
302 oParser.add_option('-q', '--quiet', dest = 'fQuiet', action = 'store_true', default = False,
303 help = 'Quiet execution');
304 oParser.add_option('-l', '--log', dest = 'sLogFile', metavar = '<logfile>', default = None,
305 help = 'Where to log messages.');
306 oParser.add_option('--debug', dest = 'fDebug', action = 'store_true', default = False,
307 help = 'Enables debug mode.');
308
309 (self.oConfig, _) = oParser.parse_args();
310
311 if self.oConfig.sLogFile:
312 self.oLogFile = open(self.oConfig.sLogFile, "a");
313 self.oLogFile.write('VirtualTestSheriff: $Revision: 77657 $ \n');
314
315
316 def eprint(self, sText):
317 """
318 Prints error messages.
319 Returns 1 (for exit code usage.)
320 """
321 print('error: %s' % (sText,));
322 if self.oLogFile is not None:
323 self.oLogFile.write((u'error: %s\n' % (sText,)).encode('utf-8'));
324 return 1;
325
326 def dprint(self, sText):
327 """
328 Prints debug info.
329 """
330 if self.oConfig.fDebug:
331 if not self.oConfig.fQuiet:
332 print('debug: %s' % (sText, ));
333 if self.oLogFile is not None:
334 self.oLogFile.write((u'debug: %s\n' % (sText,)).encode('utf-8'));
335 return 0;
336
337 def vprint(self, sText):
338 """
339 Prints verbose info.
340 """
341 if not self.oConfig.fQuiet:
342 print('info: %s' % (sText,));
343 if self.oLogFile is not None:
344 self.oLogFile.write((u'info: %s\n' % (sText,)).encode('utf-8'));
345 return 0;
346
347 def getFailureReason(self, tReason):
348 """ Gets the failure reason object for tReason. """
349 return self.oFailureReasonLogic.cachedLookupByNameAndCategory(tReason[1], tReason[0]);
350
351 def selfCheck(self):
352 """ Does some self checks, looking up things we expect to be in the database and such. """
353 rcExit = 0;
354 for sAttr in dir(self.__class__):
355 if sAttr.startswith('ktReason_'):
356 tReason = getattr(self.__class__, sAttr);
357 oFailureReason = self.getFailureReason(tReason);
358 if oFailureReason is None:
359 rcExit = self.eprint(u'Failed to find failure reason "%s" in category "%s" in the database!'
360 % (tReason[1], tReason[0],));
361
362 # Check the user account as well.
363 if self.oLogin is None:
364 oLogin = UserAccountLogic(self.oDb).tryFetchAccountByLoginName(VirtualTestSheriff.ksLoginName);
365 if oLogin is None:
366 rcExit = self.eprint(u'Cannot find my user account "%s"!' % (VirtualTestSheriff.ksLoginName,));
367 return rcExit;
368
369 def sendEmailAlert(self, uidAuthor, sBodyText):
370 """
371 Sends email alert.
372 """
373
374 # Get author email
375 self.oDb.execute('SELECT sEmail FROM Users WHERE uid=%s', (uidAuthor,));
376 sFrom = self.oDb.fetchOne();
377 if sFrom is not None:
378 sFrom = sFrom[0];
379 else:
380 sFrom = g_ksAlertFrom;
381
382 # Gather recipient list.
383 asEmailList = [];
384 for sUser in g_asAlertList:
385 self.oDb.execute('SELECT sEmail FROM Users WHERE sUsername=%s', (sUser,));
386 sEmail = self.oDb.fetchOne();
387 if sEmail:
388 asEmailList.append(sEmail[0]);
389 if not asEmailList:
390 return self.eprint('No email addresses to send alter to!');
391
392 # Compose the message.
393 oMsg = MIMEMultipart();
394 oMsg['From'] = sFrom;
395 oMsg['To'] = COMMASPACE.join(asEmailList);
396 oMsg['Subject'] = g_ksAlertSubject;
397 oMsg.attach(MIMEText(sBodyText, 'plain'))
398
399 # Try send it.
400 try:
401 oSMTP = smtplib.SMTP(g_ksSmtpHost, g_kcSmtpPort);
402 oSMTP.sendmail(sFrom, asEmailList, oMsg.as_string())
403 oSMTP.quit()
404 except smtplib.SMTPException as oXcpt:
405 return self.eprint('Failed to send mail: %s' % (oXcpt,));
406
407 return 0;
408
409 def badTestBoxManagement(self):
410 """
411 Looks for bad test boxes and first tries once to reboot them then disables them.
412 """
413 rcExit = 0;
414
415 #
416 # We skip this entirely if we're running in the past and not in harmless debug mode.
417 #
418 if self.oConfig.cStartHoursAgo != 0 \
419 and (not self.oConfig.fDebug or self.oConfig.fRealRun):
420 return rcExit;
421 tsNow = self.tsNow if self.oConfig.fDebug else None;
422 cHoursBack = self.oConfig.cHoursBack if self.oConfig.fDebug else 2;
423 oTestBoxLogic = TestBoxLogic(self.oDb);
424
425 #
426 # Generate a list of failures reasons we consider bad-testbox behavior.
427 #
428 aidFailureReasons = [
429 self.getFailureReason(self.ktReason_Host_DriverNotLoaded).idFailureReason,
430 self.getFailureReason(self.ktReason_Host_DriverNotUnloading).idFailureReason,
431 self.getFailureReason(self.ktReason_Host_DriverNotCompilable).idFailureReason,
432 self.getFailureReason(self.ktReason_Host_InstallationFailed).idFailureReason,
433 ];
434
435 #
436 # Get list of bad test boxes for given period and check them out individually.
437 #
438 aidBadTestBoxes = self.oTestSetLogic.fetchBadTestBoxIds(cHoursBack = cHoursBack, tsNow = tsNow,
439 aidFailureReasons = aidFailureReasons);
440 for idTestBox in aidBadTestBoxes:
441 # Skip if the testbox is already disabled or has a pending reboot command.
442 try:
443 oTestBox = TestBoxData().initFromDbWithId(self.oDb, idTestBox);
444 except Exception as oXcpt:
445 rcExit = self.eprint('Failed to get data for test box #%u in badTestBoxManagement: %s' % (idTestBox, oXcpt,));
446 continue;
447 if not oTestBox.fEnabled:
448 self.dprint(u'badTestBoxManagement: Skipping test box #%u (%s) as it has been disabled already.'
449 % ( idTestBox, oTestBox.sName, ));
450 continue;
451 if oTestBox.enmPendingCmd != TestBoxData.ksTestBoxCmd_None:
452 self.dprint(u'badTestBoxManagement: Skipping test box #%u (%s) as it has a command pending: %s'
453 % ( idTestBox, oTestBox.sName, oTestBox.enmPendingCmd));
454 continue;
455
456 # Get the most recent testsets for this box (descending on tsDone) and see how bad it is.
457 aoSets = self.oTestSetLogic.fetchSetsForTestBox(idTestBox, cHoursBack = cHoursBack, tsNow = tsNow);
458 cOkay = 0;
459 cBad = 0;
460 iFirstOkay = len(aoSets);
461 for iSet, oSet in enumerate(aoSets):
462 if oSet.enmStatus == TestSetData.ksTestStatus_BadTestBox:
463 cBad += 1;
464 else:
465 # Check for bad failure reasons.
466 oFailure = None;
467 if oSet.enmStatus in TestSetData.kasBadTestStatuses:
468 (oTree, _ ) = self.oTestResultLogic.fetchResultTree(oSet.idTestSet)
469 aoFailedResults = oTree.getListOfFailures();
470 for oFailedResult in aoFailedResults:
471 oFailure = self.oTestResultFailureLogic.getById(oFailedResult.idTestResult);
472 if oFailure is not None and oFailure.idFailureReason in aidFailureReasons:
473 break;
474 else:
475 oFailure = None;
476 if oFailure is not None:
477 cBad += 1;
478 else:
479 # This is an okay test result then.
480 ## @todo maybe check the elapsed time here, it could still be a bad run?
481 cOkay += 1;
482 if iFirstOkay > iSet:
483 iFirstOkay = iSet;
484 if iSet > 10:
485 break;
486
487 # We react if there are two or more bad-testbox statuses at the head of the
488 # history and at least three in the last 10 results.
489 if iFirstOkay >= 2 and cBad > 2:
490 if oTestBoxLogic.hasTestBoxRecentlyBeenRebooted(idTestBox, cHoursBack = cHoursBack, tsNow = tsNow):
491 sComment = u'Disabling testbox #%u (%s) - iFirstOkay=%u cBad=%u cOkay=%u' \
492 % (idTestBox, oTestBox.sName, iFirstOkay, cBad, cOkay);
493 self.vprint(sComment);
494 self.sendEmailAlert(self.uidSelf, sComment);
495 if self.oConfig.fRealRun is True:
496 try:
497 oTestBoxLogic.disableTestBox(idTestBox, self.uidSelf, fCommit = True,
498 sComment = 'Automatically disabled (iFirstOkay=%u cBad=%u cOkay=%u)'
499 % (iFirstOkay, cBad, cOkay),);
500 except Exception as oXcpt:
501 rcExit = self.eprint(u'Error disabling testbox #%u (%u): %s\n' % (idTestBox, oTestBox.sName, oXcpt,));
502 else:
503 sComment = u'Rebooting testbox #%u (%s) - iFirstOkay=%u cBad=%u cOkay=%u' \
504 % (idTestBox, oTestBox.sName, iFirstOkay, cBad, cOkay);
505 self.vprint(sComment);
506 self.sendEmailAlert(self.uidSelf, sComment);
507 if self.oConfig.fRealRun is True:
508 try:
509 oTestBoxLogic.rebootTestBox(idTestBox, self.uidSelf, fCommit = True,
510 sComment = 'Automatically rebooted (iFirstOkay=%u cBad=%u cOkay=%u)'
511 % (iFirstOkay, cBad, cOkay),);
512 except Exception as oXcpt:
513 rcExit = self.eprint(u'Error rebooting testbox #%u (%s): %s\n' % (idTestBox, oTestBox.sName, oXcpt,));
514 else:
515 self.dprint(u'badTestBoxManagement: #%u (%s) looks ok: iFirstOkay=%u cBad=%u cOkay=%u'
516 % ( idTestBox, oTestBox.sName, iFirstOkay, cBad, cOkay));
517
518 #
519 # Reset hanged testboxes
520 #
521 cStatusTimeoutMins = 10;
522
523 self.oDb.execute('SELECT TestBoxStatuses.idTestBox\n'
524 ' FROM TestBoxStatuses, TestBoxes\n'
525 ' WHERE TestBoxStatuses.tsUpdated >= (CURRENT_TIMESTAMP - interval \'%s hours\')\n'
526 ' AND TestBoxStatuses.tsUpdated < (CURRENT_TIMESTAMP - interval \'%s minutes\')\n'
527 ' AND TestBoxStatuses.idTestBox = TestBoxes.idTestBox\n'
528 ' AND Testboxes.tsExpire = \'infinity\'::timestamp', (cHoursBack,cStatusTimeoutMins));
529 for idTestBox in self.oDb.fetchAll():
530 idTestBox = idTestBox[0];
531 try:
532 oTestBox = TestBoxData().initFromDbWithId(self.oDb, idTestBox);
533 except Exception as oXcpt:
534 rcExit = self.eprint('Failed to get data for test box #%u in badTestBoxManagement: %s' % (idTestBox, oXcpt,));
535 continue;
536 # Skip if the testbox is already disabled, already reset or there's no iLOM
537 if not oTestBox.fEnabled or oTestBox.ipLom is None or oTestBox.sComment is not None and oTestBox.sComment.find('Automatically reset') >= 0:
538 self.dprint(u'badTestBoxManagement: Skipping test box #%u (%s) as it has been disabled already.'
539 % ( idTestBox, oTestBox.sName, ));
540 continue;
541 ## @todo get iLOM credentials from a table?
542 sCmd = 'sshpass -p%s ssh -oStrictHostKeyChecking=no root@%s show /SP && reset /SYS' % (g_ksLomPassword, oTestBox.ipLom,);
543 try:
544 oPs = subprocess.Popen(sCmd, stdout=subprocess.PIPE, shell=True);
545 sStdout = oPs.communicate()[0];
546 iRC = oPs.wait();
547
548 oTestBox.sComment = 'Automatically reset (iRC=%u sStdout=%s)' % (iRC, sStdout,);
549 oTestBoxLogic.editEntry(oTestBox, self.uidSelf, fCommit = True);
550
551 sComment = u'Reset testbox #%u (%s) - iRC=%u sStduot=%s' % ( idTestBox, oTestBox.sName, iRC, sStdout);
552 self.vprint(sComment);
553 self.sendEmailAlert(self.uidSelf, sComment);
554
555 except Exception as oXcpt:
556 rcExit = self.eprint(u'Error resetting testbox #%u (%s): %s\n' % (idTestBox, oTestBox.sName, oXcpt,));
557
558 return rcExit;
559
560
561 ## @name Failure reasons we know.
562 ## @{
563 ktReason_BSOD_Recovery = ( 'BSOD', 'Recovery' );
564 ktReason_BSOD_Automatic_Repair = ( 'BSOD', 'Automatic Repair' );
565 ktReason_BSOD_0000007F = ( 'BSOD', '0x0000007F' );
566 ktReason_BSOD_000000D1 = ( 'BSOD', '0x000000D1' );
567 ktReason_BSOD_C0000225 = ( 'BSOD', '0xC0000225 (boot)' );
568 ktReason_Guru_Generic = ( 'Guru Meditations', 'Generic Guru Meditation' );
569 ktReason_Guru_VERR_IEM_INSTR_NOT_IMPLEMENTED = ( 'Guru Meditations', 'VERR_IEM_INSTR_NOT_IMPLEMENTED' );
570 ktReason_Guru_VERR_IEM_ASPECT_NOT_IMPLEMENTED = ( 'Guru Meditations', 'VERR_IEM_ASPECT_NOT_IMPLEMENTED' );
571 ktReason_Guru_VERR_TRPM_DONT_PANIC = ( 'Guru Meditations', 'VERR_TRPM_DONT_PANIC' );
572 ktReason_Guru_VERR_PGM_PHYS_PAGE_RESERVED = ( 'Guru Meditations', 'VERR_PGM_PHYS_PAGE_RESERVED' );
573 ktReason_Guru_VERR_VMX_INVALID_GUEST_STATE = ( 'Guru Meditations', 'VERR_VMX_INVALID_GUEST_STATE' );
574 ktReason_Guru_VINF_EM_TRIPLE_FAULT = ( 'Guru Meditations', 'VINF_EM_TRIPLE_FAULT' );
575 ktReason_Host_HostMemoryLow = ( 'Host', 'HostMemoryLow' );
576 ktReason_Host_DriverNotLoaded = ( 'Host', 'Driver not loaded' );
577 ktReason_Host_DriverNotUnloading = ( 'Host', 'Driver not unloading' );
578 ktReason_Host_DriverNotCompilable = ( 'Host', 'Driver not compilable' );
579 ktReason_Host_InstallationFailed = ( 'Host', 'Installation failed' );
580 ktReason_Host_NotSignedWithBuildCert = ( 'Host', 'Not signed with build cert' );
581 ktReason_Host_DoubleFreeHeap = ( 'Host', 'Double free or corruption' );
582 ktReason_Host_LeftoverService = ( 'Host', 'Leftover service' );
583 ktReason_Host_Reboot_OSX_Watchdog_Timeout = ( 'Host Reboot', 'OSX Watchdog Timeout' );
584 ktReason_Host_Modprobe_Failed = ( 'Host', 'Modprobe failed' );
585 ktReason_Host_Install_Hang = ( 'Host', 'Install hang' );
586 ktReason_Host_NetworkMisconfiguration = ( 'Host', 'Network misconfiguration' );
587 ktReason_Networking_Nonexistent_host_nic = ( 'Networking', 'Nonexistent host networking interface' );
588 ktReason_OSInstall_GRUB_hang = ( 'O/S Install', 'GRUB hang' );
589 ktReason_OSInstall_Udev_hang = ( 'O/S Install', 'udev hang' );
590 ktReason_OSInstall_Sata_no_BM = ( 'O/S Install', 'SATA busmaster bit not set' );
591 ktReason_Panic_BootManagerC000000F = ( 'Panic', 'Hardware Changed' );
592 ktReason_BootManager_Image_corrupt = ( 'Unknown', 'BOOTMGR Image corrupt' );
593 ktReason_Panic_MP_BIOS_IO_APIC = ( 'Panic', 'MP-BIOS/IO-APIC' );
594 ktReason_Panic_HugeMemory = ( 'Panic', 'Huge memory assertion' );
595 ktReason_Panic_IOAPICDoesntWork = ( 'Panic', 'IO-APIC and timer does not work' );
596 ktReason_Panic_TxUnitHang = ( 'Panic', 'Tx Unit Hang' );
597 ktReason_XPCOM_Exit_Minus_11 = ( 'API / (XP)COM', 'exit -11' );
598 ktReason_XPCOM_VBoxSVC_Hang = ( 'API / (XP)COM', 'VBoxSVC hang' );
599 ktReason_XPCOM_VBoxSVC_Hang_Plus_Heap_Corruption = ( 'API / (XP)COM', 'VBoxSVC hang + heap corruption' );
600 ktReason_XPCOM_NS_ERROR_CALL_FAILED = ( 'API / (XP)COM', 'NS_ERROR_CALL_FAILED' );
601 ktReason_Unknown_Heap_Corruption = ( 'Unknown', 'Heap corruption' );
602 ktReason_Unknown_Reboot_Loop = ( 'Unknown', 'Reboot loop' );
603 ktReason_Unknown_File_Not_Found = ( 'Unknown', 'File not found' );
604 ktReason_Unknown_VM_Crash = ( 'Unknown', 'VM crash' );
605 ktReason_Unknown_HalReturnToFirmware = ( 'Unknown', 'HalReturnToFirmware' );
606 ktReason_VMM_kvm_lock_spinning = ( 'VMM', 'kvm_lock_spinning' );
607 ktReason_Ignore_Buggy_Test_Driver = ( 'Ignore', 'Buggy test driver' );
608 ktReason_Ignore_Stale_Files = ( 'Ignore', 'Stale files' );
609 ktReason_Buggy_Build_Broken_Build = ( 'Broken Build', 'Buggy build' );
610 ktReason_Unknown_VM_Start_Error = ( 'Unknown', 'VM Start Error' );
611 ktReason_Unknown_VM_Runtime_Error = ( 'Unknown', 'VM Runtime Error' );
612 ktReason_GuestBug_CompizVBoxQt = ( 'Guest Bug', 'Compiz + VirtualBox Qt GUI crash' );
613 ## @}
614
615 ## BSOD category.
616 ksBsodCategory = 'BSOD';
617 ## Special reason indicating that the flesh and blood sheriff has work to do.
618 ksBsodAddNew = 'Add new BSOD';
619
620 ## Unit test category.
621 ksUnitTestCategory = 'Unit';
622 ## Special reason indicating that the flesh and blood sheriff has work to do.
623 ksUnitTestAddNew = 'Add new';
624
625 ## Used for indica that we shouldn't report anything for this test result ID and
626 ## consider promoting the previous error to test set level if it's the only one.
627 ktHarmless = ( 'Probably', 'Caused by previous error' );
628
629
630 def caseClosed(self, oCaseFile):
631 """
632 Reports the findings in the case and closes it.
633 """
634 #
635 # Log it and create a dReasonForReasultId we can use below.
636 #
637 dCommentForResultId = oCaseFile.dCommentForResultId;
638 if oCaseFile.dReasonForResultId:
639 # Must weed out ktHarmless.
640 dReasonForResultId = {};
641 for idKey, tReason in oCaseFile.dReasonForResultId.items():
642 if tReason is not self.ktHarmless:
643 dReasonForResultId[idKey] = tReason;
644 if not dReasonForResultId:
645 self.vprint(u'TODO: Closing %s without a real reason, only %s.'
646 % (oCaseFile.sName, oCaseFile.dReasonForResultId));
647 return False;
648
649 # Try promote to single reason.
650 atValues = dReasonForResultId.values();
651 fSingleReason = True;
652 if len(dReasonForResultId) == 1 and dReasonForResultId.keys()[0] != oCaseFile.oTestSet.idTestResult:
653 self.dprint(u'Promoting single reason to whole set: %s' % (atValues[0],));
654 elif len(dReasonForResultId) > 1 and len(atValues) == atValues.count(atValues[0]):
655 self.dprint(u'Merged %d reasons to a single one: %s' % (len(atValues), atValues[0]));
656 else:
657 fSingleReason = False;
658 if fSingleReason:
659 dReasonForResultId = { oCaseFile.oTestSet.idTestResult: atValues[0], };
660 if dCommentForResultId:
661 dCommentForResultId = { oCaseFile.oTestSet.idTestResult: dCommentForResultId.values()[0], };
662 elif oCaseFile.tReason is not None:
663 dReasonForResultId = { oCaseFile.oTestSet.idTestResult: oCaseFile.tReason, };
664 else:
665 self.vprint(u'Closing %s without a reason - this should not happen!' % (oCaseFile.sName,));
666 return False;
667
668 self.vprint(u'Closing %s with following reason%s: %s'
669 % ( oCaseFile.sName, 's' if dReasonForResultId > 0 else '', dReasonForResultId, ));
670
671 #
672 # Add the test failure reason record(s).
673 #
674 for idTestResult, tReason in dReasonForResultId.items():
675 oFailureReason = self.getFailureReason(tReason);
676 if oFailureReason is not None:
677 sComment = 'Set by $Revision: 77657 $' # Handy for reverting later.
678 if idTestResult in dCommentForResultId:
679 sComment += ': ' + dCommentForResultId[idTestResult];
680
681 oAdd = TestResultFailureData();
682 oAdd.initFromValues(idTestResult = idTestResult,
683 idFailureReason = oFailureReason.idFailureReason,
684 uidAuthor = self.uidSelf,
685 idTestSet = oCaseFile.oTestSet.idTestSet,
686 sComment = sComment,);
687 if self.oConfig.fRealRun:
688 try:
689 self.oTestResultFailureLogic.addEntry(oAdd, self.uidSelf, fCommit = True);
690 except Exception as oXcpt:
691 self.eprint(u'caseClosed: Exception "%s" while adding reason %s for %s'
692 % (oXcpt, oAdd, oCaseFile.sLongName,));
693 else:
694 self.eprint(u'caseClosed: Cannot locate failure reason: %s / %s' % ( tReason[0], tReason[1],));
695 return True;
696
697 #
698 # Tools for assiting log parsing.
699 #
700
701 @staticmethod
702 def matchFollowedByLines(sStr, off, asFollowingLines):
703 """ Worker for isThisFollowedByTheseLines. """
704
705 # Advance off to the end of the line.
706 off = sStr.find('\n', off);
707 if off < 0:
708 return False;
709 off += 1;
710
711 # Match each string with the subsequent lines.
712 for iLine, sLine in enumerate(asFollowingLines):
713 offEnd = sStr.find('\n', off);
714 if offEnd < 0:
715 return iLine + 1 == len(asFollowingLines) and sStr.find(sLine, off) < 0;
716 if sLine and sStr.find(sLine, off, offEnd) < 0:
717 return False;
718
719 # next line.
720 off = offEnd + 1;
721
722 return True;
723
724 @staticmethod
725 def isThisFollowedByTheseLines(sStr, sFirst, asFollowingLines):
726 """
727 Looks for a line contining sFirst which is then followed by lines
728 with the strings in asFollowingLines. (No newline chars anywhere!)
729 Returns True / False.
730 """
731 off = sStr.find(sFirst, 0);
732 while off >= 0:
733 if VirtualTestSheriff.matchFollowedByLines(sStr, off, asFollowingLines):
734 return True;
735 off = sStr.find(sFirst, off + 1);
736 return False;
737
738 @staticmethod
739 def findAndReturnRestOfLine(sHaystack, sNeedle):
740 """
741 Looks for sNeedle in sHaystack.
742 Returns The text following the needle up to the end of the line.
743 Returns None if not found.
744 """
745 if sHaystack is None:
746 return None;
747 off = sHaystack.find(sNeedle);
748 if off < 0:
749 return None;
750 off += len(sNeedle)
751 offEol = sHaystack.find('\n', off);
752 if offEol < 0:
753 offEol = len(sHaystack);
754 return sHaystack[off:offEol]
755
756 @staticmethod
757 def findInAnyAndReturnRestOfLine(asHaystacks, sNeedle):
758 """
759 Looks for sNeedle in zeroe or more haystacks (asHaystack).
760 Returns The text following the first needed found up to the end of the line.
761 Returns None if not found.
762 """
763 for sHaystack in asHaystacks:
764 sRet = VirtualTestSheriff.findAndReturnRestOfLine(sHaystack, sNeedle);
765 if sRet is not None:
766 return sRet;
767 return None;
768
769
770 #
771 # The investigative units.
772 #
773
774 katSimpleInstallUninstallMainLogReasons = [
775 # ( Whether to stop on hit, reason tuple, needle text. )
776 ( False, ktReason_Host_LeftoverService,
777 'SERVICE_NAME: vbox' ),
778 ];
779
780 kdatSimpleInstallUninstallMainLogReasonsPerOs = {
781 'darwin': [
782 # ( Whether to stop on hit, reason tuple, needle text. )
783 ( True, ktReason_Host_DriverNotUnloading,
784 'Can\'t remove kext org.virtualbox.kext.VBoxDrv; services failed to terminate - 0xe00002c7' ),
785 ],
786 'linux': [
787 # ( Whether to stop on hit, reason tuple, needle text. )
788 ( True, ktReason_Host_DriverNotCompilable,
789 'This system is not currently set up to build kernel modules' ),
790 ( True, ktReason_Host_DriverNotCompilable,
791 'This system is currently not set up to build kernel modules' ),
792 ( True, ktReason_Host_InstallationFailed,
793 'vboxdrv.sh: failed: Look at /var/log/vbox-install.log to find out what went wrong.' ),
794 ( True, ktReason_Host_DriverNotUnloading,
795 'Cannot unload module vboxdrv'),
796 ],
797 'solaris': [
798 # ( Whether to stop on hit, reason tuple, needle text. )
799 ( True, ktReason_Host_InstallationFailed,
800 'svcadm: Couldn\'t bind to svc.configd.' ),
801 ( True, ktReason_Host_InstallationFailed,
802 'pkgadd: ERROR: postinstall script did not complete successfully' ),
803 ( True, ktReason_Host_DriverNotUnloading,
804 'can\'t unload the module: Device busy' ),
805 ],
806 };
807
808
809 def investigateInstallUninstallFailure(self, oCaseFile, oFailedResult, sResultLog, fInstall):
810 """
811 Investigates an install or uninstall failure.
812
813 We lump the two together since the installation typically also performs
814 an uninstall first and will be seeing similar issues to the uninstall.
815 """
816
817 if fInstall and oFailedResult.enmStatus == TestSetData.ksTestStatus_TimedOut:
818 oCaseFile.noteReasonForId(self.ktReason_Host_Install_Hang, oFailedResult.idTestResult)
819 return True;
820
821 atSimple = self.katSimpleInstallUninstallMainLogReasons;
822 if oCaseFile.oTestBox.sOs in self.kdatSimpleInstallUninstallMainLogReasonsPerOs:
823 atSimple = self.kdatSimpleInstallUninstallMainLogReasonsPerOs[oCaseFile.oTestBox.sOs] + atSimple;
824
825 fFoundSomething = False;
826 for fStopOnHit, tReason, sNeedle in atSimple:
827 if sResultLog.find(sNeedle) > 0:
828 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
829 if fStopOnHit:
830 return True;
831 fFoundSomething = True;
832
833 return fFoundSomething if fFoundSomething else None;
834
835
836 def investigateBadTestBox(self, oCaseFile):
837 """
838 Checks out bad-testbox statuses.
839 """
840 _ = oCaseFile;
841 return False;
842
843
844 def investigateVBoxUnitTest(self, oCaseFile):
845 """
846 Checks out a VBox unittest problem.
847 """
848
849 #
850 # Process simple test case failures first, using their name as reason.
851 # We do the reason management just like for BSODs.
852 #
853 cRelevantOnes = 0;
854 sMainLog = oCaseFile.getMainLog();
855 aoFailedResults = oCaseFile.oTree.getListOfFailures();
856 for oFailedResult in aoFailedResults:
857 if oFailedResult is oCaseFile.oTree:
858 self.vprint('TODO: toplevel failure');
859 cRelevantOnes += 1
860
861 elif oFailedResult.sName == 'Installing VirtualBox':
862 sResultLog = TestSetData.extractLogSectionElapsed(sMainLog, oFailedResult.tsCreated, oFailedResult.tsElapsed);
863 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = True)
864 cRelevantOnes += 1
865
866 elif oFailedResult.sName == 'Uninstalling VirtualBox':
867 sResultLog = TestSetData.extractLogSectionElapsed(sMainLog, oFailedResult.tsCreated, oFailedResult.tsElapsed);
868 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = False)
869 cRelevantOnes += 1
870
871 elif oFailedResult.oParent is not None:
872 # Get the 2nd level node because that's where we'll find the unit test name.
873 while oFailedResult.oParent.oParent is not None:
874 oFailedResult = oFailedResult.oParent;
875
876 # Only report a failure once.
877 if oFailedResult.idTestResult not in oCaseFile.dReasonForResultId:
878 sKey = oFailedResult.sName;
879 if sKey.startswith('testcase/'):
880 sKey = sKey[9:];
881 if sKey in self.asUnitTestReasons:
882 tReason = ( self.ksUnitTestCategory, sKey );
883 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
884 else:
885 self.dprint(u'Unit test failure "%s" not found in %s;' % (sKey, self.asUnitTestReasons));
886 tReason = ( self.ksUnitTestCategory, self.ksUnitTestAddNew );
887 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult, sComment = sKey);
888 cRelevantOnes += 1
889 else:
890 self.vprint(u'Internal error: expected oParent to NOT be None for %s' % (oFailedResult,));
891
892 #
893 # If we've caught all the relevant ones by now, report the result.
894 #
895 if len(oCaseFile.dReasonForResultId) >= cRelevantOnes:
896 return self.caseClosed(oCaseFile);
897 return False;
898
899 def extractGuestCpuStack(self, sInfoText):
900 """
901 Extracts the guest CPU stacks from the input file.
902
903 Returns a dictionary keyed by the CPU number, value being a list of
904 raw stack lines (no header).
905 Returns empty dictionary if no stacks where found.
906 """
907 dRet = {};
908 off = 0;
909 while True:
910 # Find the stack.
911 offStart = sInfoText.find('=== start guest stack VCPU ', off);
912 if offStart < 0:
913 break;
914 offEnd = sInfoText.find('=== end guest stack', offStart + 20);
915 if offEnd >= 0:
916 offEnd += 3;
917 else:
918 offEnd = sInfoText.find('=== start guest stack VCPU', offStart + 20);
919 if offEnd < 0:
920 offEnd = len(sInfoText);
921
922 sStack = sInfoText[offStart : offEnd];
923 sStack = sStack.replace('\r',''); # paranoia
924 asLines = sStack.split('\n');
925
926 # Figure the CPU.
927 asWords = asLines[0].split();
928 if len(asWords) < 6 or not asWords[5].isdigit():
929 break;
930 iCpu = int(asWords[5]);
931
932 # Add it and advance.
933 dRet[iCpu] = [sLine.rstrip() for sLine in asLines[2:-1]]
934 off = offEnd;
935 return dRet;
936
937 def investigateInfoKvmLockSpinning(self, oCaseFile, sInfoText, dLogs):
938 """ Investigates kvm_lock_spinning deadlocks """
939 #
940 # Extract the stacks. We need more than one CPU to create a deadlock.
941 #
942 dStacks = self.extractGuestCpuStack(sInfoText);
943 self.dprint('kvm_lock_spinning: found %s stacks' % (len(dStacks),));
944 if len(dStacks) >= 2:
945 #
946 # Examin each of the stacks. Each must have kvm_lock_spinning in
947 # one of the first three entries.
948 #
949 cHits = 0;
950 for iCpu in dStacks:
951 asBacktrace = dStacks[iCpu];
952 for iFrame in xrange(min(3, len(asBacktrace))):
953 if asBacktrace[iFrame].find('kvm_lock_spinning') >= 0:
954 cHits += 1;
955 break;
956 self.dprint('kvm_lock_spinning: %s/%s hits' % (cHits, len(dStacks),));
957 if cHits == len(dStacks):
958 return (True, self.ktReason_VMM_kvm_lock_spinning);
959
960 _ = dLogs; _ = oCaseFile;
961 return (False, None);
962
963 def investigateInfoHalReturnToFirmware(self, oCaseFile, sInfoText, dLogs):
964 """ Investigates HalReturnToFirmware hangs """
965 del oCaseFile
966 del sInfoText
967 del dLogs
968 # hope that's sufficient
969 return (True, self.ktReason_Unknown_HalReturnToFirmware);
970
971 ## Things we search a main or VM log for to figure out why something went bust.
972 katSimpleMainAndVmLogReasons = [
973 # ( Whether to stop on hit, reason tuple, needle text. )
974 ( False, ktReason_Guru_Generic, 'GuruMeditation' ),
975 ( False, ktReason_Guru_Generic, 'Guru Meditation' ),
976 ( True, ktReason_Guru_VERR_IEM_INSTR_NOT_IMPLEMENTED, 'VERR_IEM_INSTR_NOT_IMPLEMENTED' ),
977 ( True, ktReason_Guru_VERR_IEM_ASPECT_NOT_IMPLEMENTED, 'VERR_IEM_ASPECT_NOT_IMPLEMENTED' ),
978 ( True, ktReason_Guru_VERR_TRPM_DONT_PANIC, 'VERR_TRPM_DONT_PANIC' ),
979 ( True, ktReason_Guru_VERR_PGM_PHYS_PAGE_RESERVED, 'VERR_PGM_PHYS_PAGE_RESERVED' ),
980 ( True, ktReason_Guru_VERR_VMX_INVALID_GUEST_STATE, 'VERR_VMX_INVALID_GUEST_STATE' ),
981 ( True, ktReason_Guru_VINF_EM_TRIPLE_FAULT, 'VINF_EM_TRIPLE_FAULT' ),
982 ( True, ktReason_Networking_Nonexistent_host_nic,
983 'rc=E_FAIL text="Nonexistent host networking interface, name \'eth0\' (VERR_INTERNAL_ERROR)"' ),
984 ( True, ktReason_Host_Reboot_OSX_Watchdog_Timeout, ': "OSX Watchdog Timeout: ' ),
985 ( False, ktReason_XPCOM_NS_ERROR_CALL_FAILED,
986 'Exception: 0x800706be (Call to remote object failed (NS_ERROR_CALL_FAILED))' ),
987 ( True, ktReason_Host_HostMemoryLow, 'HostMemoryLow' ),
988 ( True, ktReason_Host_HostMemoryLow, 'Failed to procure handy pages; rc=VERR_NO_MEMORY' ),
989 ( True, ktReason_Unknown_File_Not_Found,
990 'Error: failed to start machine. Error message: File not found. (VERR_FILE_NOT_FOUND)' ),
991 ( True, ktReason_Unknown_File_Not_Found, # lump it in with file-not-found for now.
992 'Error: failed to start machine. Error message: Not supported. (VERR_NOT_SUPPORTED)' ),
993 ( False, ktReason_Unknown_VM_Crash, 'txsDoConnectViaTcp: Machine state: Aborted' ),
994 ( True, ktReason_Host_Modprobe_Failed, 'Kernel driver not installed' ),
995 ( True, ktReason_OSInstall_Sata_no_BM, 'PCHS=14128/14134/8224' ),
996 ( True, ktReason_Host_DoubleFreeHeap, 'double free or corruption' ),
997 ( False, ktReason_Unknown_VM_Start_Error, 'VMSetError: ' ),
998 ( False, ktReason_Unknown_VM_Runtime_Error, 'Console: VM runtime error: fatal=true' ),
999 ];
1000
1001 ## Things we search a VBoxHardening.log file for to figure out why something went bust.
1002 katSimpleVBoxHardeningLogReasons = [
1003 # ( Whether to stop on hit, reason tuple, needle text. )
1004 ( True, ktReason_Host_DriverNotLoaded, 'Error opening VBoxDrvStub: STATUS_OBJECT_NAME_NOT_FOUND' ),
1005 ( True, ktReason_Host_NotSignedWithBuildCert, 'Not signed with the build certificate' ),
1006 ];
1007
1008 ## Things we search a kernel.log file for to figure out why something went bust.
1009 katSimpleKernelLogReasons = [
1010 # ( Whether to stop on hit, reason tuple, needle text. )
1011 ( True, ktReason_Panic_HugeMemory, 'mm/huge_memory.c:1988' ),
1012 ( True, ktReason_Panic_IOAPICDoesntWork, 'IO-APIC + timer doesn''t work' ),
1013 ( True, ktReason_Panic_TxUnitHang, 'Detected Tx Unit Hang' ),
1014 ( True, ktReason_GuestBug_CompizVBoxQt, 'error 4 in libQt5CoreVBox' ),
1015 ( True, ktReason_GuestBug_CompizVBoxQt, 'error 4 in libgtk-3' ),
1016 ];
1017
1018 ## Things we search the _RIGHT_ _STRIPPED_ vgatext for.
1019 katSimpleVgaTextReasons = [
1020 # ( Whether to stop on hit, reason tuple, needle text. )
1021 ( True, ktReason_Panic_MP_BIOS_IO_APIC,
1022 "..MP-BIOS bug: 8254 timer not connected to IO-APIC\n\n" ),
1023 ( True, ktReason_Panic_MP_BIOS_IO_APIC,
1024 "..MP-BIOS bug: 8254 timer not connected to IO-APIC\n"
1025 "...trying to set up timer (IRQ0) through the 8259A ... failed.\n"
1026 "...trying to set up timer as Virtual Wire IRQ... failed.\n"
1027 "...trying to set up timer as ExtINT IRQ... failed :(.\n"
1028 "Kernel panic - not syncing: IO-APIC + timer doesn't work! Boot with apic=debug\n"
1029 "and send a report. Then try booting with the 'noapic' option\n"
1030 "\n" ),
1031 ( True, ktReason_OSInstall_GRUB_hang,
1032 "-----\nGRUB Loading stage2..\n\n\n\n" ),
1033 ( True, ktReason_OSInstall_GRUB_hang,
1034 "-----\nGRUB Loading stage2...\n\n\n\n" ), # the 3 dot hang appears to be less frequent
1035 ( True, ktReason_OSInstall_GRUB_hang,
1036 "-----\nGRUB Loading stage2....\n\n\n\n" ), # the 4 dot hang appears to be very infrequent
1037 ( True, ktReason_OSInstall_GRUB_hang,
1038 "-----\nGRUB Loading stage2.....\n\n\n\n" ), # the 5 dot hang appears to be more frequent again
1039 ( True, ktReason_OSInstall_Udev_hang,
1040 "\nStarting udev:\n\n\n\n" ),
1041 ( True, ktReason_OSInstall_Udev_hang,
1042 "\nStarting udev:\n------" ),
1043 ( True, ktReason_Panic_BootManagerC000000F,
1044 "Windows failed to start. A recent hardware or software change might be the" ),
1045 ( True, ktReason_BootManager_Image_corrupt,
1046 "BOOTMGR image is corrupt. The system cannot boot." ),
1047 ];
1048
1049 ## Things we search for in the info.txt file. Require handlers for now.
1050 katInfoTextHandlers = [
1051 # ( Trigger text, handler method )
1052 ( "kvm_lock_spinning", investigateInfoKvmLockSpinning ),
1053 ( "HalReturnToFirmware", investigateInfoHalReturnToFirmware ),
1054 ];
1055
1056 ## Mapping screenshot/failure SHA-256 hashes to failure reasons.
1057 katSimpleScreenshotHashReasons = [
1058 # ( Whether to stop on hit, reason tuple, lowercased sha-256 of PIL.Image.tostring output )
1059 ( True, ktReason_BSOD_Recovery, '576f8e38d62b311cac7e3dc3436a0d0b9bd8cfd7fa9c43aafa95631520a45eac' ),
1060 ( True, ktReason_BSOD_Automatic_Repair, 'c6a72076cc619937a7a39cfe9915b36d94cee0d4e3ce5ce061485792dcee2749' ),
1061 ( True, ktReason_BSOD_Automatic_Repair, '26c4d8a724ff2c5e1051f3d5b650dbda7b5fdee0aa3e3c6059797f7484a515df' ),
1062 ( True, ktReason_BSOD_0000007F, '57e1880619e13042a87100e7a38c8974b85ce3866501be621bea0cc696bb2c63' ),
1063 ( True, ktReason_BSOD_000000D1, '134621281f00a3f8aeeb7660064bffbf6187ed56d5852142328d0bcb18ef0ede' ),
1064 ( True, ktReason_BSOD_000000D1, '279f11258150c9d2fef041eca65501f3141da8df39256d8f6377e897e3b45a93' ),
1065 ( True, ktReason_BSOD_C0000225, 'bd13a144be9dcdfb16bc863ff4c8f02a86e263c174f2cd5ffd27ca5f3aa31789' ),
1066 ( True, ktReason_BSOD_C0000225, '8348b465e7ee9e59dd4e785880c57fd8677de05d11ac21e786bfde935307b42f' ),
1067 ( True, ktReason_BSOD_C0000225, '1316e1fc818a73348412788e6910b8c016f237d8b4e15b20caf4a866f7a7840e' ),
1068 ( True, ktReason_BSOD_C0000225, '54e0acbff365ce20a85abbe42bcd53647b8b9e80c68e45b2cd30e86bf177a0b5' ),
1069 ( True, ktReason_BSOD_C0000225, '50fec50b5199923fa48b3f3e782687cc381e1c8a788ebda14e6a355fbe3bb1b3' ),
1070 ];
1071
1072 def investigateVMResult(self, oCaseFile, oFailedResult, sResultLog):
1073 """
1074 Investigates a failed VM run.
1075 """
1076
1077 def investigateLogSet():
1078 """
1079 Investigates the current set of VM related logs.
1080 """
1081 self.dprint('investigateLogSet: lengths: result log %u, VM log %u, kernel log %u, vga text %u, info text %u'
1082 % ( len(sResultLog if sResultLog else ''),
1083 len(sVMLog if sVMLog else ''),
1084 len(sKrnlLog if sKrnlLog else ''),
1085 len(sVgaText if sVgaText else ''),
1086 len(sInfoText if sInfoText else ''), ));
1087
1088 #self.dprint(u'main.log<<<\n%s\n<<<\n' % (sResultLog,));
1089 #self.dprint(u'vbox.log<<<\n%s\n<<<\n' % (sVMLog,));
1090 #self.dprint(u'krnl.log<<<\n%s\n<<<\n' % (sKrnlLog,));
1091 #self.dprint(u'vgatext.txt<<<\n%s\n<<<\n' % (sVgaText,));
1092 #self.dprint(u'info.txt<<<\n%s\n<<<\n' % (sInfoText,));
1093
1094 # TODO: more
1095
1096 #
1097 # Look for BSODs. Some stupid stupid inconsistencies in reason and log messages here, so don't try prettify this.
1098 #
1099 sDetails = self.findInAnyAndReturnRestOfLine([ sVMLog, sResultLog ],
1100 'GIM: HyperV: Guest indicates a fatal condition! P0=');
1101 if sDetails is not None:
1102 # P0=%#RX64 P1=%#RX64 P2=%#RX64 P3=%#RX64 P4=%#RX64 "
1103 sKey = sDetails.split(' ', 1)[0];
1104 try: sKey = '0x%08X' % (int(sKey, 16),);
1105 except: pass;
1106 if sKey in self.asBsodReasons:
1107 tReason = ( self.ksBsodCategory, sKey );
1108 elif sKey.lower() in self.asBsodReasons: # just in case.
1109 tReason = ( self.ksBsodCategory, sKey.lower() );
1110 else:
1111 self.dprint(u'BSOD "%s" not found in %s;' % (sKey, self.asBsodReasons));
1112 tReason = ( self.ksBsodCategory, self.ksBsodAddNew );
1113 return oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult, sComment = sDetails.strip());
1114
1115 #
1116 # Look for linux panic.
1117 #
1118 if sKrnlLog is not None:
1119 for fStopOnHit, tReason, sNeedle in self.katSimpleKernelLogReasons:
1120 if sKrnlLog.find(sNeedle) > 0:
1121 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
1122 if fStopOnHit:
1123 return True;
1124 fFoundSomething = True;
1125
1126 #
1127 # Loop thru the simple stuff.
1128 #
1129 fFoundSomething = False;
1130 for fStopOnHit, tReason, sNeedle in self.katSimpleMainAndVmLogReasons:
1131 if sResultLog.find(sNeedle) > 0 or (sVMLog is not None and sVMLog.find(sNeedle) > 0):
1132 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
1133 if fStopOnHit:
1134 return True;
1135 fFoundSomething = True;
1136
1137 # Continue with vga text.
1138 if sVgaText:
1139 for fStopOnHit, tReason, sNeedle in self.katSimpleVgaTextReasons:
1140 if sVgaText.find(sNeedle) > 0:
1141 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
1142 if fStopOnHit:
1143 return True;
1144 fFoundSomething = True;
1145 _ = sInfoText;
1146
1147 # Continue with screen hashes.
1148 if sScreenHash is not None:
1149 for fStopOnHit, tReason, sHash in self.katSimpleScreenshotHashReasons:
1150 if sScreenHash == sHash:
1151 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
1152 if fStopOnHit:
1153 return True;
1154 fFoundSomething = True;
1155
1156 # Check VBoxHardening.log.
1157 if sNtHardLog is not None:
1158 for fStopOnHit, tReason, sNeedle in self.katSimpleVBoxHardeningLogReasons:
1159 if sNtHardLog.find(sNeedle) > 0:
1160 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
1161 if fStopOnHit:
1162 return True;
1163 fFoundSomething = True;
1164
1165 #
1166 # Complicated stuff.
1167 #
1168 dLogs = {
1169 'sVMLog': sVMLog,
1170 'sNtHardLog': sNtHardLog,
1171 'sScreenHash': sScreenHash,
1172 'sKrnlLog': sKrnlLog,
1173 'sVgaText': sVgaText,
1174 'sInfoText': sInfoText,
1175 };
1176
1177 # info.txt.
1178 if sInfoText:
1179 for sNeedle, fnHandler in self.katInfoTextHandlers:
1180 if sInfoText.find(sNeedle) > 0:
1181 (fStop, tReason) = fnHandler(self, oCaseFile, sInfoText, dLogs);
1182 if tReason is not None:
1183 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
1184 if fStop:
1185 return True;
1186 fFoundSomething = True;
1187
1188 #
1189 # Check for repeated reboots...
1190 #
1191 if sVMLog is not None:
1192 cResets = sVMLog.count('Changing the VM state from \'RUNNING\' to \'RESETTING\'');
1193 if cResets > 10:
1194 return oCaseFile.noteReasonForId(self.ktReason_Unknown_Reboot_Loop, oFailedResult.idTestResult,
1195 sComment = 'Counted %s reboots' % (cResets,));
1196
1197 return fFoundSomething;
1198
1199 #
1200 # Check if we got any VM or/and kernel logs. Treat them as sets in
1201 # case we run multiple VMs here (this is of course ASSUMING they
1202 # appear in the order that terminateVmBySession uploads them).
1203 #
1204 cTimes = 0;
1205 sVMLog = None;
1206 sNtHardLog = None;
1207 sScreenHash = None;
1208 sKrnlLog = None;
1209 sVgaText = None;
1210 sInfoText = None;
1211 for oFile in oFailedResult.aoFiles:
1212 if oFile.sKind == TestResultFileData.ksKind_LogReleaseVm:
1213 if 'VBoxHardening.log' not in oFile.sFile:
1214 if sVMLog is not None:
1215 if investigateLogSet() is True:
1216 return True;
1217 cTimes += 1;
1218 sInfoText = None;
1219 sVgaText = None;
1220 sKrnlLog = None;
1221 sScreenHash = None;
1222 sNtHardLog = None;
1223 sVMLog = oCaseFile.getLogFile(oFile);
1224 else:
1225 sNtHardLog = oCaseFile.getLogFile(oFile);
1226 elif oFile.sKind == TestResultFileData.ksKind_LogGuestKernel:
1227 sKrnlLog = oCaseFile.getLogFile(oFile);
1228 elif oFile.sKind == TestResultFileData.ksKind_InfoVgaText:
1229 sVgaText = '\n'.join([sLine.rstrip() for sLine in oCaseFile.getLogFile(oFile).split('\n')]);
1230 elif oFile.sKind == TestResultFileData.ksKind_InfoCollection:
1231 sInfoText = oCaseFile.getLogFile(oFile);
1232 elif oFile.sKind == TestResultFileData.ksKind_ScreenshotFailure:
1233 sScreenHash = oCaseFile.getScreenshotSha256(oFile);
1234 if sScreenHash is not None:
1235 sScreenHash = sScreenHash.lower();
1236 self.vprint(u'%s %s' % ( sScreenHash, oFile.sFile,));
1237
1238 if ( sVMLog is not None \
1239 or sNtHardLog is not None \
1240 or cTimes == 0) \
1241 and investigateLogSet() is True:
1242 return True;
1243
1244 return None;
1245
1246
1247 def isResultFromVMRun(self, oFailedResult, sResultLog):
1248 """
1249 Checks if this result and corresponding log snippet looks like a VM run.
1250 """
1251
1252 # Look for startVmEx/ startVmAndConnectToTxsViaTcp and similar output in the log.
1253 if sResultLog.find(' startVm') > 0:
1254 return True;
1255
1256 # Any other indicators? No?
1257 _ = oFailedResult;
1258 return False;
1259
1260 def investigateVBoxVMTest(self, oCaseFile, fSingleVM):
1261 """
1262 Checks out a VBox VM test.
1263
1264 This is generic investigation of a test running one or more VMs, like
1265 for example a smoke test or a guest installation test.
1266
1267 The fSingleVM parameter is a hint, which probably won't come in useful.
1268 """
1269 _ = fSingleVM;
1270
1271 #
1272 # Get a list of test result failures we should be looking into and the main log.
1273 #
1274 aoFailedResults = oCaseFile.oTree.getListOfFailures();
1275 sMainLog = oCaseFile.getMainLog();
1276
1277 #
1278 # There are a set of errors ending up on the top level result record.
1279 # Should deal with these first.
1280 #
1281 if len(aoFailedResults) == 1 and aoFailedResults[0] == oCaseFile.oTree:
1282 # Check if we've just got that XPCOM client smoke test shutdown issue. This will currently always
1283 # be reported on the top result because vboxinstall.py doesn't add an error for it. It is easy to
1284 # ignore other failures in the test if we're not a little bit careful here.
1285 if sMainLog.find('vboxinstaller: Exit code: -11 (') > 0:
1286 oCaseFile.noteReason(self.ktReason_XPCOM_Exit_Minus_11);
1287 return self.caseClosed(oCaseFile);
1288
1289 # Hang after starting VBoxSVC (e.g. idTestSet=136307258)
1290 if self.isThisFollowedByTheseLines(sMainLog, 'oVBoxMgr=<vboxapi.VirtualBoxManager object at',
1291 (' Timeout: ', ' Attempting to abort child...',) ):
1292 if sMainLog.find('*** glibc detected *** /') > 0:
1293 oCaseFile.noteReason(self.ktReason_XPCOM_VBoxSVC_Hang_Plus_Heap_Corruption);
1294 else:
1295 oCaseFile.noteReason(self.ktReason_XPCOM_VBoxSVC_Hang);
1296 return self.caseClosed(oCaseFile);
1297
1298 # Look for heap corruption without visible hang.
1299 if sMainLog.find('*** glibc detected *** /') > 0 \
1300 or sMainLog.find("-1073740940") > 0: # STATUS_HEAP_CORRUPTION / 0xc0000374
1301 oCaseFile.noteReason(self.ktReason_Unknown_Heap_Corruption);
1302 return self.caseClosed(oCaseFile);
1303
1304 # Out of memory w/ timeout.
1305 if sMainLog.find('sErrId=HostMemoryLow') > 0:
1306 oCaseFile.noteReason(self.ktReason_Host_HostMemoryLow);
1307 return self.caseClosed(oCaseFile);
1308
1309 # Stale files like vts_rm.exe (windows).
1310 offEnd = sMainLog.rfind('*** The test driver exits successfully. ***');
1311 if offEnd > 0 and sMainLog.find('[Error 145] The directory is not empty: ', offEnd) > 0:
1312 oCaseFile.noteReason(self.ktReason_Ignore_Stale_Files);
1313 return self.caseClosed(oCaseFile);
1314
1315 #
1316 # XPCOM screwup
1317 #
1318 if sMainLog.find('AttributeError: \'NoneType\' object has no attribute \'addObserver\'') > 0:
1319 oCaseFile.noteReason(self.ktReason_Buggy_Build_Broken_Build);
1320 return self.caseClosed(oCaseFile);
1321
1322 #
1323 # Go thru each failed result.
1324 #
1325 for oFailedResult in aoFailedResults:
1326 self.dprint(u'Looking at test result #%u - %s' % (oFailedResult.idTestResult, oFailedResult.getFullName(),));
1327 sResultLog = TestSetData.extractLogSectionElapsed(sMainLog, oFailedResult.tsCreated, oFailedResult.tsElapsed);
1328 if oFailedResult.sName == 'Installing VirtualBox':
1329 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = True)
1330
1331 elif oFailedResult.sName == 'Uninstalling VirtualBox':
1332 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = False)
1333
1334 elif self.isResultFromVMRun(oFailedResult, sResultLog):
1335 self.investigateVMResult(oCaseFile, oFailedResult, sResultLog);
1336
1337 elif sResultLog.find('most likely not unique') > 0:
1338 oCaseFile.noteReasonForId(self.ktReason_Host_NetworkMisconfiguration, oFailedResult.idTestResult)
1339 elif sResultLog.find('Exception: 0x800706be (Call to remote object failed (NS_ERROR_CALL_FAILED))') > 0:
1340 oCaseFile.noteReasonForId(self.ktReason_XPCOM_NS_ERROR_CALL_FAILED, oFailedResult.idTestResult);
1341
1342 elif sResultLog.find('The machine is not mutable (state is ') > 0:
1343 self.vprint('Ignoring "machine not mutable" error as it is probably due to an earlier problem');
1344 oCaseFile.noteReasonForId(self.ktHarmless, oFailedResult.idTestResult);
1345
1346 elif sResultLog.find('** error: no action was specified') > 0 \
1347 or sResultLog.find('(len(self._asXml, asText))') > 0:
1348 oCaseFile.noteReasonForId(self.ktReason_Ignore_Buggy_Test_Driver, oFailedResult.idTestResult);
1349
1350 else:
1351 self.vprint(u'TODO: Cannot place idTestResult=%u - %s' % (oFailedResult.idTestResult, oFailedResult.sName,));
1352 self.dprint(u'%s + %s <<\n%s\n<<' % (oFailedResult.tsCreated, oFailedResult.tsElapsed, sResultLog,));
1353
1354 #
1355 # Report home and close the case if we got them all, otherwise log it.
1356 #
1357 if len(oCaseFile.dReasonForResultId) >= len(aoFailedResults):
1358 return self.caseClosed(oCaseFile);
1359
1360 if oCaseFile.dReasonForResultId:
1361 self.vprint(u'TODO: Got %u out of %u - close, but no cigar. :-/'
1362 % (len(oCaseFile.dReasonForResultId), len(aoFailedResults)));
1363 else:
1364 self.vprint(u'XXX: Could not figure out anything at all! :-(');
1365 return False;
1366
1367
1368 def reasoningFailures(self):
1369 """
1370 Guess the reason for failures.
1371 """
1372 #
1373 # Get a list of failed test sets without any assigned failure reason.
1374 #
1375 cGot = 0;
1376 aoTestSets = self.oTestSetLogic.fetchFailedSetsWithoutReason(cHoursBack = self.oConfig.cHoursBack, tsNow = self.tsNow);
1377 for oTestSet in aoTestSets:
1378 self.dprint(u'');
1379 self.dprint(u'reasoningFailures: Checking out test set #%u, status %s' % ( oTestSet.idTestSet, oTestSet.enmStatus,))
1380
1381 #
1382 # Open a case file and assign it to the right investigator.
1383 #
1384 (oTree, _ ) = self.oTestResultLogic.fetchResultTree(oTestSet.idTestSet);
1385 oBuild = BuildDataEx().initFromDbWithId( self.oDb, oTestSet.idBuild, oTestSet.tsCreated);
1386 oTestBox = TestBoxData().initFromDbWithGenId( self.oDb, oTestSet.idGenTestBox);
1387 oTestGroup = TestGroupData().initFromDbWithId( self.oDb, oTestSet.idTestGroup, oTestSet.tsCreated);
1388 oTestCase = TestCaseDataEx().initFromDbWithGenId( self.oDb, oTestSet.idGenTestCase, oTestSet.tsConfig);
1389
1390 oCaseFile = VirtualTestSheriffCaseFile(self, oTestSet, oTree, oBuild, oTestBox, oTestGroup, oTestCase);
1391
1392 if oTestSet.enmStatus == TestSetData.ksTestStatus_BadTestBox:
1393 self.dprint(u'investigateBadTestBox is taking over %s.' % (oCaseFile.sLongName,));
1394 fRc = self.investigateBadTestBox(oCaseFile);
1395
1396 elif oCaseFile.isVBoxUnitTest():
1397 self.dprint(u'investigateVBoxUnitTest is taking over %s.' % (oCaseFile.sLongName,));
1398 fRc = self.investigateVBoxUnitTest(oCaseFile);
1399
1400 elif oCaseFile.isVBoxInstallTest():
1401 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1402 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1403
1404 elif oCaseFile.isVBoxUSBTest():
1405 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1406 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1407
1408 elif oCaseFile.isVBoxStorageTest():
1409 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1410 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1411
1412 elif oCaseFile.isVBoxGAsTest():
1413 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1414 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1415
1416 elif oCaseFile.isVBoxAPITest():
1417 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1418 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1419
1420 elif oCaseFile.isVBoxBenchmarkTest():
1421 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1422 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = False);
1423
1424 elif oCaseFile.isVBoxSmokeTest():
1425 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1426 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = False);
1427
1428 else:
1429 self.vprint(u'reasoningFailures: Unable to classify test set: %s' % (oCaseFile.sLongName,));
1430 fRc = False;
1431 cGot += fRc is True;
1432
1433 self.vprint(u'reasoningFailures: Got %u out of %u' % (cGot, len(aoTestSets), ));
1434 return 0;
1435
1436
1437 def main(self):
1438 """
1439 The 'main' function.
1440 Return exit code (0, 1, etc).
1441 """
1442 # Database stuff.
1443 self.oDb = TMDatabaseConnection()
1444 self.oTestResultLogic = TestResultLogic(self.oDb);
1445 self.oTestSetLogic = TestSetLogic(self.oDb);
1446 self.oFailureReasonLogic = FailureReasonLogic(self.oDb);
1447 self.oTestResultFailureLogic = TestResultFailureLogic(self.oDb);
1448 self.asBsodReasons = self.oFailureReasonLogic.fetchForSheriffByNamedCategory(self.ksBsodCategory);
1449 self.asUnitTestReasons = self.oFailureReasonLogic.fetchForSheriffByNamedCategory(self.ksUnitTestCategory);
1450
1451 # Get a fix on our 'now' before we do anything..
1452 self.oDb.execute('SELECT CURRENT_TIMESTAMP - interval \'%s hours\'', (self.oConfig.cStartHoursAgo,));
1453 self.tsNow = self.oDb.fetchOne();
1454
1455 # If we're suppost to commit anything we need to get our user ID.
1456 rcExit = 0;
1457 if self.oConfig.fRealRun:
1458 self.oLogin = UserAccountLogic(self.oDb).tryFetchAccountByLoginName(VirtualTestSheriff.ksLoginName);
1459 if self.oLogin is None:
1460 rcExit = self.eprint('Cannot find my user account "%s"!' % (VirtualTestSheriff.ksLoginName,));
1461 else:
1462 self.uidSelf = self.oLogin.uid;
1463
1464 #
1465 # Do the stuff.
1466 #
1467 if rcExit == 0:
1468 rcExit = self.selfCheck();
1469 if rcExit == 0:
1470 rcExit = self.badTestBoxManagement();
1471 rcExit2 = self.reasoningFailures();
1472 if rcExit == 0:
1473 rcExit = rcExit2;
1474 # Redo the bad testbox management after failure reasons have been assigned (got timing issues).
1475 if rcExit == 0:
1476 rcExit = self.badTestBoxManagement();
1477
1478 # Cleanup.
1479 self.oFailureReasonLogic = None;
1480 self.oTestResultFailureLogic = None;
1481 self.oTestSetLogic = None;
1482 self.oTestResultLogic = None;
1483 self.oDb.close();
1484 self.oDb = None;
1485 if self.oLogFile is not None:
1486 self.oLogFile.close();
1487 self.oLogFile = None;
1488 return rcExit;
1489
1490if __name__ == '__main__':
1491 sys.exit(VirtualTestSheriff().main());
1492
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette