Changeset 83964 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Apr 24, 2020 1:47:43 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 137531
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py
r82968 r83964 5 5 AUtostart testcase using. 6 6 """ 7 from __builtin__ import isinstance 7 8 8 9 __copyright__ = \ … … 31 32 32 33 # Standard Python imports. 34 import array; 33 35 import os; 34 36 import sys; 35 37 import re; 36 import array; 38 import struct; 39 import time; 40 import ssl; 41 42 # Python 3 hacks: 43 if sys.version_info[0] < 3: 44 import urllib2 as urllib; # pylint: disable=import-error,no-name-in-module 45 from urllib2 import quote as urllib_quote; # pylint: disable=import-error,no-name-in-module 46 from urllib import urlencode as urllib_urlencode; # pylint: disable=import-error,no-name-in-module 47 from urllib2 import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module 48 from urllib2 import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module 49 else: 50 import urllib; # pylint: disable=import-error,no-name-in-module 51 from urllib.parse import quote as urllib_quote; # pylint: disable=import-error,no-name-in-module 52 from urllib.parse import urlencode as urllib_urlencode; # pylint: disable=import-error,no-name-in-module 53 from urllib.request import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module 54 from urllib.request import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module 55 37 56 38 57 # Only the main script needs to modify the path. … … 47 66 from testdriver import vbox; 48 67 from testdriver import vboxcon; 68 from testdriver import vboxwrappers; 69 from common import utils; 70 71 # Python 3 hacks: 72 if sys.version_info[0] >= 3: 73 long = int # pylint: disable=redefined-builtin,invalid-name 74 xrange = range; # pylint: disable=redefined-builtin,invalid-name 75 49 76 50 77 class VBoxManageStdOutWrapper(object): … … 53 80 self.sVmRunning = ''; 54 81 82 def __del__(self): 83 self.close(); 84 85 def close(self): 86 """file.close""" 87 return; 88 55 89 def read(self, cb): 56 90 """file.read""" … … 60 94 def write(self, sText): 61 95 """VBoxManage stdout write""" 96 if sText is None: 97 return None; 98 if isinstance(sText, buffer): 99 try: sText = str(sText); # pylint: disable=redefined-variable-type 100 except: pass; 62 101 if isinstance(sText, array.array): 63 sText = sText.tostring(); 102 try: sText = sText.tostring(); 103 except: pass; 64 104 65 105 asLines = sText.splitlines(); 66 106 for sLine in asLines: 67 107 sLine = sLine.strip(); 108 109 reporter.log('Logging: ' + sLine); 68 110 69 111 # Extract the value … … 82 124 return None; 83 125 126 127 def downloadFile(sUrlFile, sDstFile, sLocalPrefix, fnLog, fnError = None, fNoProxies=True): 128 """ 129 Downloads the given file if an URL is given, otherwise assume it's 130 something on the build share and copy it from there. 131 132 Raises no exceptions, returns log + success indicator instead. 133 134 Note! This method may use proxies configured on the system and the 135 http_proxy, ftp_proxy, no_proxy environment variables. 136 137 """ 138 if fnError is None: 139 fnError = fnLog; 140 141 if sUrlFile.startswith('http://') \ 142 or sUrlFile.startswith('https://') \ 143 or sUrlFile.startswith('ftp://'): 144 # Download the file. 145 fnLog('Downloading "%s" to "%s"...' % (sUrlFile, sDstFile)); 146 try: 147 # Disable SSL certificate verification for our servers 148 ssl_ctx = ssl.create_default_context(); 149 ssl_ctx.check_hostname = False; 150 ssl_ctx.verify_mode = ssl.CERT_NONE; 151 152 ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed. 153 if not fNoProxies: 154 oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx)); 155 else: 156 oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx), urllib_ProxyHandler(proxies = dict())); 157 oSrc = oOpener.open(sUrlFile); 158 oDst = utils.openNoInherit(sDstFile, 'wb'); 159 oDst.write(oSrc.read()); 160 oDst.close(); 161 oSrc.close(); 162 except Exception as oXcpt: 163 fnError('Error downloading "%s" to "%s": %s' % (sUrlFile, sDstFile, oXcpt)); 164 return False; 165 else: 166 # Assumes file from the build share. 167 sSrcPath = os.path.join(sLocalPrefix, sUrlFile); 168 fnLog('Copying "%s" to "%s"...' % (sSrcPath, sDstFile)); 169 try: 170 utils.copyFileSimple(sSrcPath, sDstFile); 171 except Exception as oXcpt: 172 fnError('Error copying "%s" to "%s": %s' % (sSrcPath, sDstFile, oXcpt)); 173 return False; 174 175 return True; 176 177 84 178 class tdAutostartOs(object): 85 179 """ … … 87 181 """ 88 182 183 def __init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso): 184 self.oTestDriver = oTestDriver; 185 self.fpApiVer = fpApiVer; 186 self.sGuestAdditionsIso = sGuestAdditionsIso; 187 89 188 def _findFile(self, sRegExp, sTestBuildDir): 90 189 """ … … 95 194 oRegExp = re.compile(sRegExp); 96 195 97 asFiles = os.listdir(sTestBuildDir); 98 99 for sFile in asFiles: 100 if oRegExp.match(os.path.basename(sFile)) and os.path.exists(sTestBuildDir + '/' + sFile): 101 return sTestBuildDir + '/' + sFile; 196 #return most recent file if there are several ones matching the pattern 197 asFiles = [s for s in os.listdir(sTestBuildDir) 198 if os.path.isfile(os.path.join(sTestBuildDir, s))]; 199 asFiles = (s for s in asFiles 200 if oRegExp.match(os.path.basename(s)) 201 and os.path.exists(sTestBuildDir + '/' + s)); 202 asFiles = sorted(asFiles, reverse = True, key = lambda s: os.path.getmtime(os.path.join(sTestBuildDir, s))); 203 if asFiles: 204 return sTestBuildDir + '/' + asFiles[0]; 102 205 103 206 reporter.error('Failed to find a file matching "%s" in %s.' % (sRegExp, sTestBuildDir)); … … 118 221 119 222 return sVBoxCfg; 223 224 def createSession(self, oSession, sName, sUser, sPassword, cMsTimeout = 10 * 1000, fIsError = True): 225 """ 226 Creates (opens) a guest session. 227 Returns (True, IGuestSession) on success or (False, None) on failure. 228 """ 229 oGuest = oSession.o.console.guest; 230 if sName is None: 231 sName = "<untitled>"; 232 233 reporter.log('Creating session "%s" ...' % (sName,)); 234 try: 235 oGuestSession = oGuest.createSession(sUser, sPassword, '', sName); 236 except: 237 # Just log, don't assume an error here (will be done in the main loop then). 238 reporter.maybeErrXcpt(fIsError, 'Creating a guest session "%s" failed; sUser="%s", pw="%s"' 239 % (sName, sUser, sPassword)); 240 return (False, None); 241 242 reporter.log('Waiting for session "%s" to start within %dms...' % (sName, cMsTimeout)); 243 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start, ]; 244 try: 245 waitResult = oGuestSession.waitForArray(aeWaitFor, cMsTimeout); 246 247 # 248 # Be nice to Guest Additions < 4.3: They don't support session handling and 249 # therefore return WaitFlagNotSupported. 250 # 251 if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported): 252 # Just log, don't assume an error here (will be done in the main loop then). 253 reporter.maybeErr(fIsError, 'Session did not start successfully, returned wait result: %d' % (waitResult,)); 254 return (False, None); 255 reporter.log('Session "%s" successfully started' % (sName,)); 256 except: 257 # Just log, don't assume an error here (will be done in the main loop then). 258 reporter.maybeErrXcpt(fIsError, 'Waiting for guest session "%s" (usr=%s;pw=%s) to start failed:' 259 % (sName, sUser, sPassword,)); 260 return (False, None); 261 return (True, oGuestSession); 262 263 def closeSession(self, oGuestSession, fIsError = True): 264 """ 265 Closes the guest session. 266 """ 267 if oGuestSession is not None: 268 try: 269 sName = oGuestSession.name; 270 except: 271 return reporter.errorXcpt(); 272 273 reporter.log('Closing session "%s" ...' % (sName,)); 274 try: 275 oGuestSession.close(); 276 oGuestSession = None; 277 except: 278 # Just log, don't assume an error here (will be done in the main loop then). 279 reporter.maybeErrXcpt(fIsError, 'Closing guest session "%s" failed:' % (sName,)); 280 return False; 281 return True; 282 283 def guestProcessExecute(self, oGuestSession, sTestName, cMsTimeout, sExecName, asArgs = (), fGetStdOut = True, fIsError = True): 284 """ 285 Helper function to execute a program on a guest, specified in the current test. 286 Returns (True, ProcessStatus, ProcessExitCode, ProcessStdOutBuffer) on success or (False, 0, 0, None) on failure. 287 """ 288 fRc = True; # Be optimistic. 289 290 reporter.testStart(sTestName); 291 292 reporter.log2('Using session user=%s, name=%s, timeout=%d' 293 % (oGuestSession.user, oGuestSession.name, oGuestSession.timeout,)); 294 295 # 296 # Start the process: 297 # 298 reporter.log2('Executing sCmd=%s, timeoutMS=%d, asArgs=%s' 299 % (sExecName, cMsTimeout, asArgs, )); 300 fTaskFlags = []; 301 if fGetStdOut: 302 fTaskFlags = [vboxcon.ProcessCreateFlag_WaitForStdOut, 303 vboxcon.ProcessCreateFlag_WaitForStdErr]; 304 try: 305 oProcess = oGuestSession.processCreate(sExecName, 306 asArgs if self.fpApiVer >= 5.0 else asArgs[1:], 307 [], fTaskFlags, cMsTimeout); 308 except: 309 reporter.maybeErrXcpt(fIsError, 'asArgs=%s' % (asArgs,)); 310 return (False, 0, 0, None); 311 if oProcess is None: 312 return (reporter.error('oProcess is None! (%s)' % (asArgs,)), 0, 0, None); 313 314 #time.sleep(5); # try this if you want to see races here. 315 316 # Wait for the process to start properly: 317 reporter.log2('Process start requested, waiting for start (%dms) ...' % (cMsTimeout,)); 318 iPid = -1; 319 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Start, ]; 320 aBuf = None; 321 try: 322 eWaitResult = oProcess.waitForArray(aeWaitFor, cMsTimeout); 323 except: 324 reporter.maybeErrXcpt(fIsError, 'waitforArray failed for asArgs=%s' % (asArgs,)); 325 fRc = False; 326 else: 327 try: 328 eStatus = oProcess.status; 329 iPid = oProcess.PID; 330 except: 331 fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 332 else: 333 reporter.log2('Wait result returned: %d, current process status is: %d' % (eWaitResult, eStatus,)); 334 335 # 336 # Wait for the process to run to completion if necessary. 337 # 338 # Note! The above eWaitResult return value can be ignored as it will 339 # (mostly) reflect the process status anyway. 340 # 341 if eStatus == vboxcon.ProcessStatus_Started: 342 343 # What to wait for: 344 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate, 345 vboxcon.ProcessWaitForFlag_StdOut, 346 vboxcon.ProcessWaitForFlag_StdErr]; 347 348 reporter.log2('Process (PID %d) started, waiting for termination (%dms), aeWaitFor=%s ...' 349 % (iPid, cMsTimeout, aeWaitFor)); 350 acbFdOut = [0,0,0]; 351 while True: 352 try: 353 eWaitResult = oProcess.waitForArray(aeWaitFor, cMsTimeout); 354 except KeyboardInterrupt: # Not sure how helpful this is, but whatever. 355 reporter.error('Process (PID %d) execution interrupted' % (iPid,)); 356 try: oProcess.close(); 357 except: pass; 358 break; 359 except: 360 fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 361 break; 362 reporter.log2('Wait returned: %d' % (eWaitResult,)); 363 364 # Process output: 365 for eFdResult, iFd, sFdNm in [ (vboxcon.ProcessWaitResult_StdOut, 1, 'stdout'), 366 (vboxcon.ProcessWaitResult_StdErr, 2, 'stderr'), ]: 367 if eWaitResult in (eFdResult, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 368 reporter.log2('Reading %s ...' % (sFdNm,)); 369 try: 370 abBuf = oProcess.Read(1, 64 * 1024, cMsTimeout); 371 except KeyboardInterrupt: # Not sure how helpful this is, but whatever. 372 reporter.error('Process (PID %d) execution interrupted' % (iPid,)); 373 try: oProcess.close(); 374 except: pass; 375 except: 376 pass; ## @todo test for timeouts and fail on anything else! 377 else: 378 if abBuf: 379 reporter.log2('Process (PID %d) got %d bytes of %s data' % (iPid, len(abBuf), sFdNm,)); 380 acbFdOut[iFd] += len(abBuf); 381 ## @todo Figure out how to uniform + append! 382 if aBuf: 383 aBuf += str(abBuf); 384 else: 385 aBuf = str(abBuf); 386 387 ## Process input (todo): 388 #if eWaitResult in (vboxcon.ProcessWaitResult_StdIn, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 389 # reporter.log2('Process (PID %d) needs stdin data' % (iPid,)); 390 391 # Termination or error? 392 if eWaitResult in (vboxcon.ProcessWaitResult_Terminate, 393 vboxcon.ProcessWaitResult_Error, 394 vboxcon.ProcessWaitResult_Timeout,): 395 try: eStatus = oProcess.status; 396 except: fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 397 reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' 398 % (iPid, eWaitResult, eStatus,)); 399 break; 400 401 # End of the wait loop. 402 _, cbStdOut, cbStdErr = acbFdOut; 403 404 try: eStatus = oProcess.status; 405 except: fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 406 reporter.log2('Final process status (PID %d) is: %d' % (iPid, eStatus)); 407 reporter.log2('Process (PID %d) %d stdout, %d stderr' % (iPid, cbStdOut, cbStdErr)); 408 409 # 410 # Get the final status and exit code of the process. 411 # 412 try: 413 uExitStatus = oProcess.status; 414 iExitCode = oProcess.exitCode; 415 except: 416 fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 417 reporter.log2('Process (PID %d) has exit code: %d; status: %d ' % (iPid, iExitCode, uExitStatus)); 418 reporter.testDone(); 419 420 return (fRc, uExitStatus, iExitCode, aBuf); 421 422 def uploadString(self, oSession, sSrcString, sDst): 423 """ 424 Upload the string into guest. 425 """ 426 427 fRc, oGuestSession = self.createSession(oSession, 'vbox session for installing guest additions', 428 'vbox', 'password', cMsTimeout = 10 * 1000, fIsError = True); 429 if fRc is not True: 430 return reporter.errorXcpt('Upload string failed: Could not create session for vbox'); 431 432 try: 433 oFile = oGuestSession.fileOpenEx(sDst, vboxcon.FileAccessMode_ReadWrite, vboxcon.FileOpenAction_CreateOrReplace, 434 vboxcon.FileSharingMode_All, 0, []); 435 except: 436 fRc = reporter.errorXcpt('Upload string failed. Could not create and open the file %s' % sDst); 437 else: 438 try: 439 oFile.write(bytearray(sSrcString), 60*1000); 440 except: 441 fRc = reporter.errorXcpt('Upload string failed. Could not write the string into the file %s' % sDst); 442 try: 443 oFile.close(); 444 except: 445 fRc = reporter.errorXcpt('Upload string failed. Could not close the file %s' % sDst); 446 447 self.closeSession(oGuestSession); 448 return fRc; 449 450 def uploadFile(self, oSession, sSrc, sDst): 451 """ 452 Upload the string into guest. 453 """ 454 455 fRc, oGuestSession = self.createSession(oSession, 'vbox session for upload the file', 456 'vbox', 'password', cMsTimeout = 10 * 1000, fIsError = True); 457 if fRc is not True: 458 return reporter.errorXcpt('Upload file failed: Could not create session for vbox'); 459 460 try: 461 if self.fpApiVer >= 5.0: 462 oCurProgress = oGuestSession.fileCopyToGuest(sSrc, sDst, [0]); 463 else: 464 oCurProgress = oGuestSession.copyTo(sSrc, sDst, [0]); 465 except: 466 reporter.maybeErrXcpt(True, 'Upload file exception for sSrc="%s":' 467 % (self.sGuestAdditionsIso,)); 468 fRc = False; 469 else: 470 if oCurProgress is not None: 471 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr, 472 self.oTestDriver, "uploadFile"); 473 oWrapperProgress.wait(); 474 if not oWrapperProgress.isSuccess(): 475 oWrapperProgress.logResult(fIgnoreErrors = False); 476 fRc = False; 477 else: 478 fRc = reporter.error('No progress object returned'); 479 480 self.closeSession(oGuestSession); 481 return fRc; 482 483 def downloadFile(self, oSession, sSrc, sDst, fIgnoreErrors = False): 484 """ 485 Upload the string into guest. 486 """ 487 488 fRc, oGuestSession = self.createSession(oSession, 'vbox session for download the file', 489 'vbox', 'password', cMsTimeout = 10 * 1000, fIsError = True); 490 if fRc is not True: 491 if not fIgnoreErrors: 492 return reporter.errorXcpt('Download file failed: Could not create session for vbox'); 493 else: 494 reporter.log('warning: Download file failed: Could not create session for vbox'); 495 return False; 496 497 try: 498 if self.fpApiVer >= 5.0: 499 oCurProgress = oGuestSession.fileCopyFromGuest(sSrc, sDst, [0]); 500 else: 501 oCurProgress = oGuestSession.copyFrom(sSrc, sDst, [0]); 502 except: 503 if not fIgnoreErrors: 504 reporter.errorXcpt('Download file exception for sSrc="%s":' % (self.sGuestAdditionsIso,)); 505 else: 506 reporter.log('warning: Download file exception for sSrc="%s":' % (self.sGuestAdditionsIso,)); 507 fRc = False; 508 else: 509 if oCurProgress is not None: 510 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr, 511 self.oTestDriver, "downloadFile"); 512 oWrapperProgress.wait(); 513 if not oWrapperProgress.isSuccess(): 514 oWrapperProgress.logResult(fIgnoreErrors); 515 fRc = False; 516 else: 517 if not fIgnoreErrors: 518 reporter.error('No progress object returned'); 519 else: 520 reporter.log('warning: No progress object returned'); 521 fRc = False; 522 523 self.closeSession(oGuestSession); 524 return fRc; 525 526 def downloadFiles(self, oSession, asFiles, fIgnoreErrors = False): 527 """ 528 Convenience function to get files from the guest and stores it 529 into the scratch directory for later (manual) review. 530 531 Returns True on success. 532 533 Returns False on failure, logged. 534 """ 535 fRc = True; 536 for sGstFile in asFiles: 537 sTmpFile = os.path.join(self.oTestDriver.sScratchPath, 'tmp-' + os.path.basename(sGstFile)); 538 reporter.log2('Downloading file "%s" to "%s" ...' % (sGstFile, sTmpFile)); 539 # First try to remove (unlink) an existing temporary file, as we don't truncate the file. 540 try: os.unlink(sTmpFile); 541 except: pass; 542 ## @todo Check for already existing files on the host and create a new 543 # name for the current file to download. 544 fRc = self.downloadFile(oSession, sGstFile, sTmpFile, fIgnoreErrors); 545 if fRc: 546 reporter.addLogFile(sTmpFile, 'misc/other', 'guest - ' + sGstFile); 547 else: 548 if fIgnoreErrors is not True: 549 reporter.error('error downloading file "%s" to "%s"' % (sGstFile, sTmpFile)); 550 return fRc; 551 reporter.log('warning: file "%s" was not downloaded, ignoring.' % (sGstFile,)); 552 return True; 553 120 554 121 555 class tdAutostartOsLinux(tdAutostartOs): … … 124 558 """ 125 559 126 def __init__(self, oTestDriver, sTestBuildDir ):127 tdAutostartOs.__init__(self );560 def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso): 561 tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso); 128 562 self.sTestBuild = self._findFile('^VirtualBox-.*\\.run$', sTestBuildDir); 129 self.oTestDriver = oTestDriver; 130 131 def installVirtualBox(self, oSession, oTxsSession): 563 if not self.sTestBuild: 564 raise base.GenError("VirtualBox install package not found"); 565 566 def waitVMisReady(self, oSession): 567 """ 568 Waits the VM is ready after start or reboot. 569 """ 570 # Give the VM a time to reboot 571 self.oTestDriver.sleep(30); 572 573 # Waiting the VM is ready. 574 # To do it, one will try to open the guest session and start the guest process in loop 575 576 cAttempt = 0; 577 578 while cAttempt < 30: 579 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 580 'vbox', 'password', 10 * 1000, False); 581 if fRc: 582 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process', 583 30 * 1000, '/sbin/ifconfig', 584 ['ifconfig',], 585 False, False); 586 fRc = self.closeSession(oGuestSession, False) and fRc and True; # pychecker hack. 587 588 if fRc: 589 break; 590 else: 591 self.oTestDriver.sleep(10); 592 cAttempt += 1; 593 594 return fRc; 595 596 def rebootVMAndCheckReady(self, oSession): 597 """ 598 Reboot the VM and wait the VM is ready. 599 """ 600 601 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 602 'vbox', 'password', 10 * 1000, True); 603 if not fRc: 604 return fRc; 605 606 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Reboot the VM', 607 30 * 1000, '/usr/bin/sudo', 608 ['sudo', 'reboot'], 609 False, True); 610 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 611 fRc = fRc and self.waitVMisReady(oSession); 612 return fRc; 613 614 def installAdditions(self, oSession, oVM): 615 """ 616 Install guest additions in the guest. 617 """ 618 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 619 'vbox', 'password', 10 * 1000, True); 620 if not fRc: 621 return fRc; 622 623 # Install Kernel headers, which are required for actually installing the Linux Additions. 624 if oVM.OSTypeId.startswith('Debian') \ 625 or oVM.OSTypeId.startswith('Ubuntu'): 626 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers', 627 5 * 60 *1000, '/usr/bin/apt-get', 628 ['/usr/bin/apt-get', 'install', '-y', 629 'linux-headers-generic'], 630 False, True); 631 if not fRc: 632 reporter.error('Error installing Kernel headers'); 633 else: 634 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Guest Additions depdendencies', 635 5 * 60 *1000, '/usr/bin/apt-get', 636 ['/usr/bin/apt-get', 'install', '-y', 'build-essential', 637 'perl'], False, True); 638 if not fRc: 639 reporter.error('Error installing additional installer dependencies'); 640 641 elif oVM.OSTypeId.startswith('OL') \ 642 or oVM.OSTypeId.startswith('Oracle') \ 643 or oVM.OSTypeId.startswith('RHEL') \ 644 or oVM.OSTypeId.startswith('Redhat') \ 645 or oVM.OSTypeId.startswith('Cent'): 646 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers', 647 5 * 60 *1000, '/usr/bin/yum', 648 ['/usr/bin/yum', '-y', 'install', 'kernel-headers'], 649 False, True); 650 if not fRc: 651 reporter.error('Error installing Kernel headers'); 652 else: 653 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Guest Additions depdendencies', 654 5 * 60 *1000, '/usr/bin/yum', 655 ['/usr/bin/yum', '-y', 'install', 'make', 'automake', 'gcc', 656 'kernel-devel', 'dkms', 'bzip2', 'perl'], False, True); 657 if not fRc: 658 reporter.error('Error installing additional installer dependencies'); 659 660 else: 661 reporter.error('Installing Linux Additions for kind "%s" is not supported yet' % oVM.sKind); 662 fRc = False; 663 664 if fRc: 665 # 666 # The actual install. 667 # Also tell the installer to produce the appropriate log files. 668 # 669 670 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing guest additions', 671 5 * 60 *1000, '/usr/bin/sudo', 672 ['/usr/bin/sudo', '/bin/sh', 673 '/media/cdrom/VBoxLinuxAdditions.run'], 674 False, True); 675 if fRc: 676 # Due to the GA updates as separate process the above function returns before 677 # the actual installation finished. So just wait until the GA installed 678 fRc = self.waitVMisReady(oSession); 679 680 # Download log files. 681 # Ignore errors as all files above might not be present for whatever reason. 682 # 683 if fRc: 684 asLogFile = []; 685 asLogFile.append('/var/log/vboxadd-install.log'); 686 self.downloadFiles(oSession, asLogFile, fIgnoreErrors = True); 687 688 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 689 if fRc: 690 fRc = self.rebootVMAndCheckReady(oSession); 691 692 return fRc; 693 694 def installVirtualBox(self, oSession): 132 695 """ 133 696 Install VirtualBox in the guest. 134 697 """ 135 fRc = False; 136 137 if self.sTestBuild is not None: 138 fRc = self.oTestDriver.txsUploadFile(oSession, oTxsSession, self.sTestBuild, \ 139 '/tmp/' + os.path.basename(self.sTestBuild), \ 140 cMsTimeout = 120 * 1000); 141 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Installing VBox', 10 * 1000, \ 142 '/bin/chmod', 143 ('chmod', '755', '/tmp/' + os.path.basename(self.sTestBuild))); 144 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Installing VBox', 240 * 1000, \ 145 '/tmp/' + os.path.basename(self.sTestBuild)); 146 147 return fRc; 148 149 def configureAutostart(self, oSession, oTxsSession, sDefaultPolicy = 'allow', 698 if self.sTestBuild is None: 699 return False; 700 701 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 702 'vbox', 'password', 10 * 1000, True); 703 if not fRc: 704 return fRc; 705 706 fRc = self.uploadFile(oSession, self.sTestBuild, 707 '/tmp/' + os.path.basename(self.sTestBuild)); 708 709 if fRc: 710 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Allowing execution for the vbox installer', 711 30 * 1000, '/usr/bin/sudo', 712 ['/usr/bin/sudo', '/bin/chmod', '755', '/tmp/' + os.path.basename(self.sTestBuild)], 713 False, True); 714 if fRc: 715 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing VBox', 716 240 * 1000, '/usr/bin/sudo', 717 ['/usr/bin/sudo', '/tmp/' + os.path.basename(self.sTestBuild),], False, True); 718 719 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 720 return fRc; 721 722 def configureAutostart(self, oSession, sDefaultPolicy = 'allow', 150 723 asUserAllow = (), asUserDeny = ()): 151 724 """ … … 153 726 """ 154 727 728 fRc, oGuestSession = self.createSession(oSession, 'Session for confiure autostart', 729 'vbox', 'password', 10 * 1000, True); 730 if not fRc: 731 return fRc; 732 155 733 # Create autostart database directory writeable for everyone 156 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating autostart database', 10 * 1000, \157 '/bin/mkdir',158 ('mkdir', '-m', '1777', '/etc/vbox/autostart.d'));159 734 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating autostart database', 735 30 * 1000, '/usr/bin/sudo', 736 ['/usr/bin/sudo', '/bin/mkdir', '-m', '1777', '/etc/vbox/autostart.d'], 737 False, True); 160 738 # Create /etc/default/virtualbox 161 739 sVBoxCfg = 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg\n' \ 162 740 + 'VBOXAUTOSTART_DB=/etc/vbox/autostart.d\n'; 163 fRc = fRc and self.oTestDriver.txsUploadString(oSession, oTxsSession, sVBoxCfg, '/etc/default/virtualbox'); 164 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Setting permissions', 10 * 1000, \ 165 '/bin/chmod', 166 ('chmod', '644', '/etc/default/virtualbox')); 741 fRc = fRc and self.uploadString(oSession, sVBoxCfg, '/tmp/virtualbox'); 742 if fRc: 743 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Moving to destination', 744 30 * 1000, '/usr/bin/sudo', 745 ['/usr/bin/sudo', '/bin/mv', '/tmp/virtualbox', '/etc/default/virtualbox'], 746 False, True); 747 if fRc: 748 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Setting permissions', 749 30 * 1000, '/usr/bin/sudo', 750 ['/usr/bin/sudo', '/bin/chmod', '644', '/etc/default/virtualbox'], 751 False, True); 167 752 168 753 sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny); 169 fRc = fRc and self.oTestDriver.txsUploadString(oSession, oTxsSession, sVBoxCfg, '/etc/vbox/autostart.cfg'); 170 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Setting permissions', 10 * 1000, \ 171 '/bin/chmod', 172 ('chmod', '644', '/etc/vbox/autostart.cfg')); 173 174 return fRc; 175 176 def createUser(self, oTxsSession, sUser): 754 fRc = fRc and self.uploadString(oSession, sVBoxCfg, '/tmp/autostart.cfg'); 755 if fRc: 756 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Moving to destination', 757 30 * 1000, '/usr/bin/sudo', 758 ['/usr/bin/sudo', '/bin/mv', '/tmp/autostart.cfg', '/etc/vbox/autostart.cfg'], 759 False, True); 760 if fRc: 761 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Setting permissions', 762 30 * 1000, '/usr/bin/sudo', 763 ['/usr/bin/sudo', '/bin/chmod', '644', '/etc/vbox/autostart.cfg'], 764 False, True); 765 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 766 return fRc; 767 768 def createUser(self, oSession, sUser): 177 769 """ 178 770 Create a new user with the given name 179 771 """ 180 772 181 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating new user', 10 * 1000, \ 182 '/usr/sbin/useradd', 183 ('useradd', '-m', '-U', sUser)); 184 185 return fRc; 186 187 # pylint: disable=too-many-arguments 188 189 def runProgAsUser(self, oTxsSession, sTestName, cMsTimeout, sExecName, sAsUser, asArgs = (), 190 oStdIn = '/dev/null', oStdOut = '/dev/null', oStdErr = '/dev/null', oTestPipe = '/dev/null'): 191 """ 192 Runs a program as the specififed user 193 """ 194 asNewArgs = ('sudo', '-u', sAsUser, sExecName) + asArgs; 195 196 fRc = self.oTestDriver.txsRunTestRedirectStd(oTxsSession, sTestName, cMsTimeout, '/usr/bin/sudo', 197 asNewArgs, (), "", oStdIn, oStdOut, oStdErr, oTestPipe); 198 773 fRc, oGuestSession = self.createSession(oSession, 'Creating new user', 774 'vbox', 'password', 10 * 1000, True); 775 if fRc: 776 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating new user', 777 30 * 1000, '/usr/bin/sudo', 778 ['/usr/bin/sudo', '/usr/sbin/useradd', '-m', '-U', sUser], False, True); 779 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 199 780 return fRc; 200 781 201 782 # pylint: enable=too-many-arguments 202 783 203 def createTestVM(self, oSession, oTxsSession,sUser, sVmName):784 def createTestVM(self, oSession, sUser, sVmName): 204 785 """ 205 786 Create a test VM in the guest and enable autostart. 206 """ 207 208 _ = oSession; 209 210 fRc = self.runProgAsUser(oTxsSession, 'Configuring autostart database', 10 * 1000, \ 211 '/opt/VirtualBox/VBoxManage', sUser, 212 ('setproperty', 'autostartdbpath', '/etc/vbox/autostart.d')); 213 fRc = fRc and self.runProgAsUser(oTxsSession, 'Create VM ' + sVmName, 10 * 1000, \ 214 '/opt/VirtualBox/VBoxManage', sUser, 215 ('createvm', '--name', sVmName, '--register')); 216 fRc = fRc and self.runProgAsUser(oTxsSession, 'Enabling autostart for test VM', 10 * 1000, \ 217 '/opt/VirtualBox/VBoxManage', sUser, 218 ('modifyvm', sVmName, '--autostart-enabled', 'on')); 219 220 return fRc; 221 222 def checkForRunningVM(self, oSession, oTxsSession, sUser, sVmName): 787 Due to the sUser is created whithout password, 788 all calls will be perfomed using 'sudo -u sUser' 789 """ 790 791 fRc, oGuestSession = self.createSession(oSession, 'Session for create VM for user: %s' % (sUser,), 792 'vbox', 'password', 10 * 1000, True); 793 if not fRc: 794 return fRc; 795 796 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Configuring autostart database', 797 30 * 1000, '/usr/bin/sudo', 798 ['/usr/bin/sudo', '-u', sUser, '-H', '/opt/VirtualBox/VBoxManage', 799 'setproperty', 'autostartdbpath', '/etc/vbox/autostart.d'], 800 False, True); 801 if fRc: 802 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Create VM ' + sVmName, 803 30 * 1000, '/usr/bin/sudo', 804 ['/usr/bin/sudo', '-u', sUser, '-H', 805 '/opt/VirtualBox/VBoxManage', 'createvm', 806 '--name', sVmName, '--register'], False, True); 807 if fRc: 808 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Enabling autostart for test VM', 809 30 * 1000, '/usr/bin/sudo', 810 ['/usr/bin/sudo', '-u', sUser, '-H', 811 '/opt/VirtualBox/VBoxManage', 'modifyvm', 812 sVmName, '--autostart-enabled', 'on'], False, True); 813 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 814 return fRc; 815 816 def checkForRunningVM(self, oSession, sUser, sVmName): 223 817 """ 224 818 Check for VM running in the guest after autostart. 225 """ 226 227 _ = oSession; 228 229 oStdOut = VBoxManageStdOutWrapper(); 230 fRc = self.runProgAsUser(oTxsSession, 'Check for running VM', 20 * 1000, \ 231 '/opt/VirtualBox/VBoxManage', sUser, ('list', 'runningvms'), 232 '/dev/null', oStdOut, '/dev/null', '/dev/null'); 233 234 fRc = fRc is True and oStdOut.sVmRunning == sVmName; 235 236 return fRc; 819 Due to the sUser is created whithout password, 820 all calls will be perfomed using 'sudo -u sUser' 821 """ 822 823 fRc, oGuestSession = self.createSession(oSession, 'Session for checking running VMs for user: %s' % (sUser,), 824 'vbox', 'password', 10 * 1000, True); 825 if not fRc: 826 return fRc; 827 828 (fRc, _, _, aBuf) = self.guestProcessExecute(oGuestSession, 'Check for running VM', 829 30 * 1000, '/usr/bin/sudo', 830 ['/usr/bin/sudo', '-u', sUser, '-H', 831 '/opt/VirtualBox/VBoxManage', 832 'list', 'runningvms'], True, True); 833 if fRc: 834 bufWrapper = VBoxManageStdOutWrapper(); 835 bufWrapper.write(aBuf); 836 fRc = bufWrapper.sVmRunning == sVmName; 837 838 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 839 return fRc; 840 237 841 238 842 class tdAutostartOsDarwin(tdAutostartOs): … … 241 845 """ 242 846 243 def __init__(self, sTestBuildDir):847 def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso): 244 848 _ = sTestBuildDir; 245 tdAutostartOs.__init__(self); 246 247 def installVirtualBox(self, oSession, oTxsSession): 248 """ 249 Install VirtualBox in the guest. 250 """ 251 _ = oSession; 252 _ = oTxsSession; 253 return False; 254 255 def configureAutostart(self, oSession, oTxsSession): 256 """ 257 Configures the autostart feature in the guest. 258 """ 259 _ = oSession; 260 _ = oTxsSession; 261 return False; 262 263 def createTestVM(self, oSession, oTxsSession): 264 """ 265 Create a test VM in the guest and enable autostart. 266 """ 267 _ = oSession; 268 _ = oTxsSession; 269 return False; 270 271 def checkForRunningVM(self, oSession, oTxsSession): 272 """ 273 Check for VM running in the guest after autostart. 274 """ 275 _ = oSession; 276 _ = oTxsSession; 277 return False; 849 tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso); 850 raise base.GenError('Testing the autostart functionality for Darwin is not implemented'); 851 278 852 279 853 class tdAutostartOsSolaris(tdAutostartOs): … … 282 856 """ 283 857 284 def __init__(self, oTestDriver, sTestBuildDir): 285 tdAutostartOs.__init__(self); 286 self.sTestBuildDir = sTestBuildDir; 287 self.sTestBuild = self._findFile('^VirtualBox-.*-SunOS-.*\\.tar.gz$', sTestBuildDir); 288 self.oTestDriver = oTestDriver; 289 290 def installVirtualBox(self, oSession, oTxsSession): 291 """ 292 Install VirtualBox in the guest. 293 """ 294 fRc = False; 295 296 if self.sTestBuild is not None: 297 reporter.log('Testing build: %s' % (self.sTestBuild)); 298 sTestBuildFilename = os.path.basename(self.sTestBuild); 299 300 # Construct the .pkg filename from the tar.gz name. 301 oMatch = re.search(r'\d+.\d+.\d+-SunOS-r\d+', sTestBuildFilename); 302 if oMatch is not None: 303 sPkgFilename = 'VirtualBox-' + oMatch.group() + '.pkg'; 304 305 reporter.log('Extracted package filename: %s' % (sPkgFilename)); 306 307 fRc = self.oTestDriver.txsUploadFile(oSession, oTxsSession, self.sTestBuild, \ 308 '${SCRATCH}/' + sTestBuildFilename, \ 309 cMsTimeout = 120 * 1000); 310 fRc = fRc and self.oTestDriver.txsUnpackFile(oSession, oTxsSession, \ 311 '${SCRATCH}/' + sTestBuildFilename, \ 312 '${SCRATCH}', cMsTimeout = 120 * 1000); 313 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Installing package', 240 * 1000, \ 314 '/usr/sbin/pkgadd', 315 ('pkgadd', '-d', '${SCRATCH}/' + sPkgFilename, \ 316 '-n', '-a', '${SCRATCH}/autoresponse', 'SUNWvbox')); 317 return fRc; 318 319 def configureAutostart(self, oSession, oTxsSession, sDefaultPolicy = 'allow', 320 asUserAllow = (), asUserDeny = ()): 321 """ 322 Configures the autostart feature in the guest. 323 """ 324 325 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating /etc/vbox directory', 10 * 1000, \ 326 '/usr/bin/mkdir', 327 ('mkdir', '-m', '755', '/etc/vbox')); 328 329 sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny); 330 fRc = fRc and self.oTestDriver.txsUploadString(oSession, oTxsSession, sVBoxCfg, '/etc/vbox/autostart.cfg'); 331 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Setting permissions', 10 * 1000, \ 332 '/usr/bin/chmod', 333 ('chmod', '644', '/etc/vbox/autostart.cfg')); 334 335 336 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Importing the service', 10 * 1000, \ 337 '/usr/sbin/svccfg', 338 ('svccfg', '-s', 'svc:/application/virtualbox/autostart:default', \ 339 'setprop', 'config/config=/etc/vbox/autostart.cfg')); 340 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Enabling the service', 10 * 1000, \ 341 '/usr/sbin/svcadm', 342 ('svcadm', 'enable', 'svc:/application/virtualbox/autostart:default')); 343 344 return fRc; 345 346 def createUser(self, oTxsSession, sUser): 347 """ 348 Create a new user with the given name 349 """ 350 351 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating new user', 10 * 1000, \ 352 '/usr/sbin/useradd', 353 ('useradd', '-m', '-g', 'staff', sUser)); 354 355 return fRc; 356 357 # pylint: disable=too-many-arguments 358 359 def runProgAsUser(self, oTxsSession, sTestName, cMsTimeout, sExecName, sAsUser, asArgs = (), 360 oStdIn = '/dev/null', oStdOut = '/dev/null', oStdErr = '/dev/null', oTestPipe = '/dev/null'): 361 """ 362 Runs a program as the specififed user 363 """ 364 asNewArgs = ('sudo', '-u', sAsUser, sExecName) + asArgs; 365 366 fRc = self.oTestDriver.txsRunTestRedirectStd(oTxsSession, sTestName, cMsTimeout, '/usr/bin/sudo', 367 asNewArgs, (), "", oStdIn, oStdOut, oStdErr, oTestPipe); 368 369 return fRc; 370 371 # pylint: enable=too-many-arguments 372 373 def createTestVM(self, oSession, oTxsSession, sUser, sVmName): 374 """ 375 Create a test VM in the guest and enable autostart. 376 """ 377 378 _ = oSession; 379 380 fRc = self.runProgAsUser(oTxsSession, 'Create VM ' + sVmName, 10 * 1000, \ 381 '/opt/VirtualBox/VBoxManage', sUser, 382 ('createvm', '--name', sVmName, '--register')); 383 fRc = fRc and self.runProgAsUser(oTxsSession, 'Enabling autostart for test VM', 10 * 1000, \ 384 '/opt/VirtualBox/VBoxManage', sUser, 385 ('modifyvm', sVmName, '--autostart-enabled', 'on')); 386 387 return fRc; 388 389 def checkForRunningVM(self, oSession, oTxsSession, sUser, sVmName): 390 """ 391 Check for VM running in the guest after autostart. 392 """ 393 394 _ = oSession; 395 396 oStdOut = VBoxManageStdOutWrapper(); 397 fRc = self.runProgAsUser(oTxsSession, 'Check for running VM', 20 * 1000, \ 398 '/opt/VirtualBox/VBoxManage', sUser, ('list', 'runningvms'), 399 '/dev/null', oStdOut, '/dev/null', '/dev/null'); 400 401 fRc = fRc is True and oStdOut.sVmRunning == sVmName; 402 403 return fRc; 858 def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso): 859 _ = sTestBuildDir; 860 tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso); 861 raise base.GenError('Testing the autostart functionality for Solaris is not implemented'); 404 862 405 863 … … 409 867 """ 410 868 411 def __init__(self, sTestBuildDir): 412 _ = sTestBuildDir; 413 tdAutostartOs.__init__(self); 869 def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso): 870 tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso); 871 self.sTestBuild = self._findFile('^VirtualBox-.*\\.(exe|msi)$', sTestBuildDir); 872 if not self.sTestBuild: 873 raise base.GenError("VirtualBox install package not found"); 414 874 return; 415 875 416 def installVirtualBox(self, oSession, oTxsSession): 876 def waitVMisReady(self, oSession): 877 """ 878 Waits the VM is ready after start or reboot. 879 """ 880 # Give the VM a time to reboot 881 self.oTestDriver.sleep(30); 882 883 # Waiting the VM is ready. 884 # To do it, one will try to open the guest session and start the guest process in loop 885 886 cAttempt = 0; 887 888 while cAttempt < 10: 889 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 890 'vbox', 'password', 10 * 1000, False); 891 if fRc: 892 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process', 893 30 * 1000, 'C:\\Windows\\System32\\ipconfig.exe', 894 ['C:\\Windows\\System32\\ipconfig.exe',], 895 False, False); 896 fRc = self.closeSession(oGuestSession, False) and fRc and True; # pychecker hack. 897 898 if fRc: 899 break; 900 else: 901 self.oTestDriver.sleep(10); 902 cAttempt += 1; 903 904 return fRc; 905 906 def rebootVMAndCheckReady(self, oSession): 907 """ 908 Reboot the VM and wait the VM is ready. 909 """ 910 911 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 912 'vbox', 'password', 10 * 1000, True); 913 if not fRc: 914 return fRc; 915 916 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Reboot the VM', 917 30 * 1000, 'C:\\Windows\\System32\\shutdown.exe', 918 ['C:\\Windows\\System32\\shutdown.exe', '/f', 919 '/r', '/t', '0'], 920 False, True); 921 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 922 923 fRc = fRc and self.waitVMisReady(oSession); 924 return fRc; 925 926 def installAdditions(self, oSession, oVM): 927 """ 928 Installs the Windows guest additions using the test execution service. 929 """ 930 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 931 'vbox', 'password', 10 * 1000, True); 932 if not fRc: 933 return fRc; 934 # 935 # Delete relevant log files. 936 # 937 # Note! On some guests the files in question still can be locked by the OS, so ignore 938 # deletion errors from the guest side (e.g. sharing violations) and just continue. 939 # 940 asLogFiles = []; 941 fHaveSetupApiDevLog = False; 942 if oVM.OSTypeId in ('WindowsNT4',): 943 sWinDir = 'C:/WinNT/'; 944 else: 945 sWinDir = 'C:/Windows/'; 946 asLogFiles = [sWinDir + 'setupapi.log', sWinDir + 'setupact.log', sWinDir + 'setuperr.log']; 947 948 # Apply The SetupAPI logging level so that we also get the (most verbose) setupapi.dev.log file. 949 ## @todo !!! HACK ALERT !!! Add the value directly into the testing source image. Later. 950 (fHaveSetupApiDevLog, _, _, _) = \ 951 self.guestProcessExecute(oGuestSession, 'Enabling setupapi.dev.log', 952 60 * 1000, 'c:\\Windows\\System32\\reg.exe', 953 ['c:\\Windows\\System32\\reg.exe', 'add', 954 '"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Setup"', 955 '/v', 'LogLevel', '/t', 'REG_DWORD', '/d', '0xFF'], 956 False, True); 957 for sFile in asLogFiles: 958 try: oGuestSession.fsObjRemove(sFile); 959 except: pass; 960 961 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 962 963 try: 964 oCurProgress = oSession.o.console.guest.updateGuestAdditions(self.sGuestAdditionsIso, None, None); 965 except: 966 reporter.maybeErrXcpt(True, 'Updating Guest Additions exception for sSrc="%s":' 967 % (self.sGuestAdditionsIso,)); 968 fRc = False; 969 else: 970 if oCurProgress is not None: 971 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr, 972 self.oTestDriver, "installAdditions"); 973 oWrapperProgress.wait(); 974 if not oWrapperProgress.isSuccess(): 975 oWrapperProgress.logResult(fIgnoreErrors = False); 976 fRc = False; 977 else: 978 fRc = reporter.error('No progress object returned'); 979 980 if fRc: 981 fRc = self.rebootVMAndCheckReady(oSession); 982 if fRc is True: 983 # Add the Windows Guest Additions installer files to the files we want to download 984 # from the guest. 985 sGuestAddsDir = 'C:/Program Files/Oracle/VirtualBox Guest Additions/'; 986 asLogFiles.append(sGuestAddsDir + 'install.log'); 987 # Note: There won't be a install_ui.log because of the silent installation. 988 asLogFiles.append(sGuestAddsDir + 'install_drivers.log'); 989 asLogFiles.append('C:/Windows/setupapi.log'); 990 991 # Note: setupapi.dev.log only is available since Windows 2000. 992 if fHaveSetupApiDevLog: 993 asLogFiles.append('C:/Windows/setupapi.dev.log'); 994 995 # 996 # Download log files. 997 # Ignore errors as all files above might not be present (or in different locations) 998 # on different Windows guests. 999 # 1000 self.downloadFiles(oSession, asLogFiles, fIgnoreErrors = True); 1001 1002 return fRc; 1003 1004 def installVirtualBox(self, oSession): 417 1005 """ 418 1006 Install VirtualBox in the guest. 419 1007 """ 420 _ = oSession; 421 _ = oTxsSession; 422 return False; 423 424 def configureAutostart(self, oSession, oTxsSession): 1008 1009 if self.sTestBuild is None: 1010 return False; 1011 1012 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 1013 'vbox', 'password', 10 * 1000, True); 1014 if not fRc: 1015 return fRc; 1016 1017 # Used windows image already contains the C:\Temp 1018 fRc = fRc and self.uploadFile(oSession, self.sTestBuild, 1019 'C:\\Temp\\' + os.path.basename(self.sTestBuild)); 1020 1021 if fRc: 1022 if self.sTestBuild.endswith('.msi'): 1023 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing VBox', 1024 240 * 1000, 'C:\\Windows\\System32\\msiexec.exe', 1025 ['msiexec', '/quiet', '/i', 1026 'C:\\Temp\\' + os.path.basename(self.sTestBuild)], 1027 False, True); 1028 else: 1029 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing VBox', 1030 240 * 1000, 'C:\\Temp\\' + os.path.basename(self.sTestBuild), 1031 ['C:\\Temp\\' + os.path.basename(self.sTestBuild), '--silent'], 1032 False, True); 1033 1034 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 1035 return fRc; 1036 1037 def configureAutostart(self, oSession, sDefaultPolicy = 'allow', 1038 asUserAllow = (), asUserDeny = ()): 425 1039 """ 426 1040 Configures the autostart feature in the guest. 427 1041 """ 428 _ = oSession; 429 _ = oTxsSession; 430 return False; 431 432 def createTestVM(self, oSession, oTxsSession): 1042 1043 fRc, oGuestSession = self.createSession(oSession, 'Session for confiure autostart', 1044 'vbox', 'password', 10 * 1000, True); 1045 if not fRc: 1046 return fRc; 1047 1048 # Create autostart database directory writeable for everyone 1049 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Setting the autostart environment variable', 1050 30 * 1000, 'C:\\Windows\\System32\\reg.exe', 1051 ['reg', 'add', 1052 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment', 1053 '/v', 'VBOXAUTOSTART_CONFIG', '/d', 1054 'C:\\ProgramData\\autostart.cfg', '/f'], 1055 False, True); 1056 1057 sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny); 1058 fRc = fRc and self.uploadString(oSession, sVBoxCfg, 'C:\\ProgramData\\autostart.cfg'); 1059 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 1060 return fRc; 1061 1062 def createTestVM(self, oSession, sUser, sVmName): 433 1063 """ 434 1064 Create a test VM in the guest and enable autostart. 435 1065 """ 436 _ = oSession; 437 _ = oTxsSession; 438 return False; 439 440 def checkForRunningVM(self, oSession, oTxsSession): 1066 1067 fRc, oGuestSession = self.createSession(oSession, 'Session for user: %s' % (sUser,), 1068 sUser, 'password', 10 * 1000, True); 1069 if not fRc: 1070 return fRc; 1071 1072 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Create VM ' + sVmName, 1073 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 1074 ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 'createvm', 1075 '--name', sVmName, '--register'], False, True); 1076 if fRc: 1077 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Enabling autostart for test VM', 1078 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 1079 ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 1080 'modifyvm', sVmName, '--autostart-enabled', 'on'], False, True); 1081 fRc = fRc and self.uploadString(oSession, 'password', 'C:\\ProgramData\\password.cfg'); 1082 if fRc: 1083 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Install autostart service for the user', 1084 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxAutostartSvc.exe', 1085 ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxAutostartSvc.exe', 1086 'install', '--user=' + sUser, '--password-file=C:\\ProgramData\\password.cfg'], 1087 False, True); 1088 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 1089 1090 return fRc; 1091 1092 def checkForRunningVM(self, oSession, sUser, sVmName): 441 1093 """ 442 1094 Check for VM running in the guest after autostart. 443 1095 """ 444 _ = oSession; 445 _ = oTxsSession; 446 return False; 1096 1097 fRc, oGuestSession = self.createSession(oSession, 'Session for user: %s' % (sUser,), 1098 sUser, 'password', 10 * 1000, True); 1099 if not fRc: 1100 return fRc; 1101 1102 (fRc, _, _, aBuf) = self.guestProcessExecute(oGuestSession, 'Check for running VM', 1103 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 1104 ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 1105 'list', 'runningvms'], True, True); 1106 if fRc: 1107 bufWrapper = VBoxManageStdOutWrapper(); 1108 bufWrapper.write(aBuf); 1109 fRc = bufWrapper.sVmRunning == sVmName; 1110 1111 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 1112 1113 return fRc; 1114 1115 def createUser(self, oSession, sUser): 1116 """ 1117 Create a new user with the given name 1118 """ 1119 1120 fRc, oGuestSession = self.createSession(oSession, 'Creating user %s to run a VM' % sUser, 1121 'vbox', 'password', 10 * 1000, True); 1122 if not fRc: 1123 return fRc; 1124 1125 # Create user 1126 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating user %s to run a VM' % sUser, 1127 30 * 1000, 'C:\\Windows\\System32\\net.exe', 1128 ['net', 'user', sUser, 'password', '/add' ], False, True); 1129 1130 # Add the user to Administrators group 1131 if fRc: 1132 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Adding the user %s to Administrators group' % sUser, 1133 30 * 1000, 'C:\\Windows\\System32\\net.exe', 1134 ['net', 'localgroup', 'Administrators', sUser, '/add' ], False, True); 1135 1136 #Allow the user to logon as service 1137 sSecPolicyEditor = """ 1138 ' SetLogonAsAServiceRight.vbs 1139 ' Sample VBScript to set or grant Logon As A Service Right. 1140 ' Author: http://www.morgantechspace.com/ 1141 ' ------------------------------------------------------' 1142 1143 Dim strUserName,ConfigFileName,OrgStr,RepStr,inputFile,strInputFile,outputFile,obj 1144 strUserName = "%s" 1145 Dim oShell 1146 Set oShell = CreateObject ("WScript.Shell") 1147 oShell.Run "secedit /export /cfg config.inf", 0, true 1148 oShell.Run "secedit /import /cfg config.inf /db database.sdb", 0, true 1149 1150 ConfigFileName = "config.inf" 1151 OrgStr = "SeServiceLogonRight =" 1152 RepStr = "SeServiceLogonRight = " & strUserName & "," 1153 Set inputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf", 1,1,-1) 1154 strInputFile = inputFile.ReadAll 1155 inputFile.Close 1156 Set inputFile = Nothing 1157 1158 Set outputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf",2,1,-1) 1159 outputFile.Write (Replace(strInputFile,OrgStr,RepStr)) 1160 outputFile.Close 1161 Set outputFile = Nothing 1162 1163 oShell.Run "secedit /configure /db database.sdb /cfg config.inf",0,true 1164 set oShell= Nothing 1165 1166 Set obj = CreateObject("Scripting.FileSystemObject") 1167 obj.DeleteFile("config.inf") 1168 obj.DeleteFile("database.sdb") 1169 1170 WScript.Echo "Logon As A Service Right granted to user '"& strUserName &"'" 1171 """ % sUser; 1172 fRc = fRc and self.uploadString(oSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.vbs'); 1173 if fRc: 1174 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 1175 'Setting the "Logon as service" policy to the user %s' % sUser, 1176 30 * 1000, 'C:\\Windows\\System32\\cscript.exe', 1177 ['cscript.exe', 'C:\\Temp\\adjustsec.vbs', '//Nologo'], False, True); 1178 try: 1179 oGuestSession.fsObjRemove('C:\\Temp\\adjustsec.vbs'); 1180 except: 1181 fRc = reporter.errorXcpt('Removing policy script failed'); 1182 1183 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 1184 return fRc; 1185 447 1186 448 1187 class tdAutostart(vbox.TestDriver): # pylint: disable=too-many-instance-attributes … … 451 1190 """ 452 1191 453 ksOsLinux = 'tst- debian'1192 ksOsLinux = 'tst-linux' 454 1193 ksOsWindows = 'tst-win' 455 1194 ksOsDarwin = 'tst-darwin' … … 459 1198 def __init__(self): 460 1199 vbox.TestDriver.__init__(self); 461 self.asRsrcs = None; 462 self.asTestVMsDef = [self.ksOsLinux, self.ksOsSolaris]; 463 self.asTestVMs = self.asTestVMsDef; 464 self.asSkipVMs = []; 465 self.sTestBuildDir = '/home/alexander/Downloads'; 1200 self.asRsrcs = None; 1201 self.asTestVMsDef = [self.ksOsWindows, self.ksOsLinux]; 1202 self.asTestVMs = self.asTestVMsDef; 1203 self.asSkipVMs = []; 1204 self.sTestBuildDir = None; #'D:/AlexD/TestBox/TestAdditionalFiles'; 1205 self.sGuestAdditionsIso = None; #'D:/AlexD/TestBox/TestAdditionalFiles/VBoxGuestAdditions_6.1.2.iso'; 466 1206 467 1207 # … … 473 1213 reporter.log('tdAutostart Options:'); 474 1214 reporter.log(' --test-build-dir <path>'); 475 reporter.log(' Default: %s' % (self.sTestBuildDir)); 1215 reporter.log(' The directory with VirtualBox distros. The option is mandatory'); 1216 reporter.log(' without any default value. The test raises an exception if the'); 1217 reporter.log(' option is not specified.'); 1218 reporter.log(' --guest-additions-iso <path/to/iso>'); 1219 reporter.log(' The path to fresh VirtualBox Guest Additions iso. The option is'); 1220 reporter.log(' mandatory without any default value. The test raises an exception'); 1221 reporter.log(' if the option is not specified.'); 476 1222 reporter.log(' --test-vms <vm1[:vm2[:...]]>'); 477 1223 reporter.log(' Test the specified VMs in the given order. Use this to change'); … … 487 1233 if iArg >= len(asArgs): raise base.InvalidOption('The "--test-build-dir" takes a path argument'); 488 1234 self.sTestBuildDir = asArgs[iArg]; 1235 elif asArgs[iArg] == '--guest-additions-iso': 1236 iArg += 1; 1237 if iArg >= len(asArgs): raise base.InvalidOption('The "--guest-additions-iso" takes a path or url to iso argument'); 1238 self.sGuestAdditionsIso = asArgs[iArg]; 489 1239 elif asArgs[iArg] == '--test-vms': 490 1240 iArg += 1; … … 508 1258 def completeOptions(self): 509 1259 # Remove skipped VMs from the test list. 1260 if self.sTestBuildDir is None: 1261 raise base.InvalidOption('--test-build-dir is not specified') 1262 if self.sGuestAdditionsIso is None: 1263 raise base.InvalidOption('--guest-additions-iso is not specified') 1264 510 1265 for sVM in self.asSkipVMs: 511 1266 try: self.asTestVMs.remove(sVM); … … 519 1274 self.asRsrcs = []; 520 1275 if self.ksOsLinux in self.asTestVMs: 521 self.asRsrcs.append('4.2/autostart/tst-debian.vdi'); 522 if self.ksOsSolaris in self.asTestVMs: 523 self.asRsrcs.append('4.2/autostart/tst-solaris.vdi'); 1276 self.asRsrcs.append('6.0/ub1804piglit/ub1804piglit.vdi'); 1277 if self.ksOsWindows in self.asTestVMs: 1278 self.asRsrcs.append('6.0/windows7piglit/windows7piglit.vdi'); 1279 #disabled 1280 #if self.ksOsSolaris in self.asTestVMs: 1281 # self.asRsrcs.append('4.2/autostart/tst-solaris.vdi'); 524 1282 525 1283 return self.asRsrcs; … … 531 1289 return False; 532 1290 1291 # Download VBoxGuestAdditions.iso before work 1292 sDestinationIso = os.path.join(self.sScratchPath, 'VBoxGuestAdditions.iso'); 1293 utils.noxcptDeleteFile(sDestinationIso); 1294 if not downloadFile(self.sGuestAdditionsIso, sDestinationIso, '', reporter.log, reporter.error): 1295 raise base.GenError("Could not download VBoxGuestAdditions.iso"); 1296 self.sGuestAdditionsIso = sDestinationIso; 1297 533 1298 # 534 1299 # Configure the VMs we're going to use. 535 1300 # 536 1301 1302 fRc = True; 1303 537 1304 # Linux VMs 538 1305 if self.ksOsLinux in self.asTestVMs: 539 oVM = self.createTestVM(self.ksOsLinux, 1, '4.2/autostart/tst-debian.vdi', sKind = 'Debian_64', \ 1306 # ub1804piglit is created with 2 CPUs. 1307 oVM = self.createTestVM(self.ksOsLinux, 1, '6.0/ub1804piglit/ub1804piglit.vdi', sKind = 'Ubuntu_64', \ 540 1308 fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \ 541 eNic0Type = vboxcon.NetworkAdapterType_Am79C973); 1309 eNic0Type = vboxcon.NetworkAdapterType_Am79C973, cMbRam = 4096, \ 1310 cCpus = 2, sDvdImage = self.sGuestAdditionsIso); 542 1311 if oVM is None: 543 1312 return False; 544 545 # Solaris VMs546 if self.ksOsSolaris in self.asTestVMs:547 oVM = self.createTestVM(self.ksOs Solaris, 1, '4.2/autostart/tst-solaris.vdi', sKind = 'Solaris_64', \1313 # Windows VMs 1314 if self.ksOsWindows in self.asTestVMs: 1315 # windows7piglit is created with PAE enabled and 2 CPUs. 1316 oVM = self.createTestVM(self.ksOsWindows, 1, '6.0/windows7piglit/windows7piglit.vdi', sKind = 'Windows7_64', \ 548 1317 fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \ 549 sHddControllerType = "SATA Controller"); 1318 sHddControllerType = "SATA Controller", cMbRam = 4096, fPae = True, cCpus = 2, \ 1319 sDvdImage = self.sGuestAdditionsIso); 550 1320 if oVM is None: 551 1321 return False; 552 1322 553 return True; 1323 # additional options used during the windows7piglit creation 1324 oSession = self.openSession(oVM); 1325 if oSession is not None: 1326 fRc = fRc and oSession.setVRamSize(256); 1327 fRc = fRc and oSession.setVideoControllerType(vboxcon.GraphicsControllerType_VBoxSVGA) 1328 fRc = fRc and oSession.setAccelerate3DEnabled(True); 1329 fRc = fRc and oSession.enableUsbOhci(True); 1330 fRc = fRc and oSession.enableUsbHid(True); 1331 fRc = fRc and oSession.saveSettings(); 1332 fRc = oSession.close() and fRc and True; # pychecker hack. 1333 oSession = None; 1334 else: 1335 fRc = False; 1336 1337 # disabled 1338 # Solaris VMs 1339 #if self.ksOsSolaris in self.asTestVMs: 1340 # oVM = self.createTestVM(self.ksOsSolaris, 1, '4.2/autostart/tst-solaris.vdi', sKind = 'Solaris_64', \ 1341 # fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \ 1342 # sHddControllerType = "SATA Controller"); 1343 # if oVM is None: 1344 # return False; 1345 1346 return fRc; 554 1347 555 1348 def actionExecute(self): … … 563 1356 # Test execution helpers. 564 1357 # 565 def testAutostartRunProgs(self, oSession, oTxsSession, sVmName):1358 def testAutostartRunProgs(self, oSession, sVmName, oVM): 566 1359 """ 567 1360 Test VirtualBoxs autostart feature in a VM. … … 571 1364 oGuestOsHlp = None # type: tdAutostartOs 572 1365 if sVmName == self.ksOsLinux: 573 oGuestOsHlp = tdAutostartOsLinux(self, self.sTestBuildDir );1366 oGuestOsHlp = tdAutostartOsLinux(self, self.sTestBuildDir, self.fpApiVer, self.sGuestAdditionsIso); # pylint: disable=redefined-variable-type 574 1367 elif sVmName == self.ksOsSolaris: 575 oGuestOsHlp = tdAutostartOsSolaris(self, self.sTestBuildDir ); # annoying -pylint: disable=redefined-variable-type1368 oGuestOsHlp = tdAutostartOsSolaris(self, self.sTestBuildDir, self.fpApiVer, self.sGuestAdditionsIso); # pylint: disable=redefined-variable-type 576 1369 elif sVmName == self.ksOsDarwin: 577 oGuestOsHlp = tdAutostartOsDarwin(self .sTestBuildDir);1370 oGuestOsHlp = tdAutostartOsDarwin(self, self.sTestBuildDir, self.fpApiVer, self.sGuestAdditionsIso); # pylint: disable=redefined-variable-type 578 1371 elif sVmName == self.ksOsWindows: 579 oGuestOsHlp = tdAutostartOsWin(self .sTestBuildDir);1372 oGuestOsHlp = tdAutostartOsWin(self, self.sTestBuildDir, self.fpApiVer, self.sGuestAdditionsIso); # pylint: disable=redefined-variable-type 580 1373 581 1374 sTestUserAllow = 'test1'; … … 584 1377 585 1378 if oGuestOsHlp is not None: 1379 #wait the VM is ready after starting 1380 fRc = oGuestOsHlp.waitVMisReady(oSession); 1381 #install fresh guest additions 1382 fRc = fRc and oGuestOsHlp.installAdditions(oSession, oVM); 586 1383 # Create two new users 587 fRc = oGuestOsHlp.createUser(oTxsSession, sTestUserAllow);588 fRc = fRc and oGuestOsHlp.createUser(o TxsSession, sTestUserDeny);1384 fRc = fRc and oGuestOsHlp.createUser(oSession, sTestUserAllow); 1385 fRc = fRc and oGuestOsHlp.createUser(oSession, sTestUserDeny); 589 1386 if fRc is True: 590 1387 # Install VBox first 591 fRc = oGuestOsHlp.installVirtualBox(oSession , oTxsSession);1388 fRc = oGuestOsHlp.installVirtualBox(oSession); 592 1389 if fRc is True: 593 fRc = oGuestOsHlp.configureAutostart(oSession, oTxsSession, 'allow', 594 (sTestUserAllow,), (sTestUserDeny,)); 1390 fRc = oGuestOsHlp.configureAutostart(oSession, 'allow', (sTestUserAllow,), (sTestUserDeny,)); 595 1391 if fRc is True: 596 1392 # Create a VM with autostart enabled in the guest for both users 597 fRc = oGuestOsHlp.createTestVM(oSession, oTxsSession,sTestUserAllow, sTestVmName);598 fRc = fRc and oGuestOsHlp.createTestVM(oSession, oTxsSession,sTestUserDeny, sTestVmName);1393 fRc = oGuestOsHlp.createTestVM(oSession, sTestUserAllow, sTestVmName); 1394 fRc = fRc and oGuestOsHlp.createTestVM(oSession, sTestUserDeny, sTestVmName); 599 1395 if fRc is True: 600 1396 # Reboot the guest 601 (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000, \ 602 fNatForwardingForTxs = True); 1397 fRc = oGuestOsHlp.rebootVMAndCheckReady(oSession); 603 1398 if fRc is True: 604 1399 # Fudge factor - Allow the guest to finish starting up. 605 self.sleep(5); 606 fRc = oGuestOsHlp.checkForRunningVM(oSession, oTxsSession, sTestUserAllow, sTestVmName); 607 if fRc is False: 1400 self.sleep(30); 1401 fRc = oGuestOsHlp.checkForRunningVM(oSession, sTestUserAllow, sTestVmName); 1402 if fRc is True: 1403 fRc = oGuestOsHlp.checkForRunningVM(oSession, sTestUserDeny, sTestVmName); 1404 if fRc is True: 1405 reporter.error('Test VM is running inside the guest for denied user'); 1406 fRc = not fRc; 1407 else: 608 1408 reporter.error('Test VM is not running inside the guest for allowed user'); 609 610 fRc = oGuestOsHlp.checkForRunningVM(oSession, oTxsSession, sTestUserDeny, sTestVmName);611 if fRc is True:612 reporter.error('Test VM is running inside the guest for denied user');613 1409 else: 614 1410 reporter.log('Rebooting the guest failed'); … … 625 1421 fRc = False; 626 1422 627 reporter.testDone( not fRc);1423 reporter.testDone(); 628 1424 return fRc; 629 1425 … … 643 1439 fRc = fRc and oSession.enableVirtEx(True); 644 1440 fRc = fRc and oSession.enableNestedPaging(True); 1441 fRc = fRc and oSession.enableNestedHwVirt(True); 645 1442 fRc = fRc and oSession.saveSettings(); 646 1443 fRc = oSession.close() and fRc and True; # pychecker hack. … … 652 1449 if fRc is True: 653 1450 self.logVmInfo(oVM); 654 oSession , oTxsSession = self.startVmAndConnectToTxsViaTcp(sVmName, fCdWait = False, fNatForwardingForTxs = True);1451 oSession = self.startVmByName(sVmName); 655 1452 if oSession is not None: 656 self.addTask(oTxsSession); 657 658 # Fudge factor - Allow the guest to finish starting up. 659 self.sleep(5); 660 661 fRc = self.testAutostartRunProgs(oSession, oTxsSession, sVmName); 662 663 # cleanup. 664 self.removeTask(oTxsSession); 1453 fRc = self.testAutostartRunProgs(oSession, sVmName, oVM); 665 1454 self.terminateVmBySession(oSession) 666 1455 else:
Note:
See TracChangeset
for help on using the changeset viewer.