cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0302
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox Wrapper Classes
1c43cacd545be15afb64413d49eccbecff95e759vboxsyncCopyright (C) 2010-2015 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard Python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Translate a controller name to a storage bus. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Gets the name (string) of a machine state."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_PoweredOff: return 'PoweredOff';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Saved: return 'Saved';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Teleported: return 'Teleported';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Aborted: return 'Aborted';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Running: return 'Running';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Paused: return 'Paused';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Stuck: return 'GuruMeditation';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Teleporting: return 'Teleporting';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_LiveSnapshotting: return 'LiveSnapshotting';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Starting: return 'Starting';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Stopping: return 'Stopping';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Saving: return 'Saving';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Restoring: return 'Restoring';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_TeleportingPausedVM: return 'TeleportingPausedVM';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_TeleportingIn: return 'TeleportingIn';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_FaultTolerantSyncing: return 'FaultTolerantSyncing';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_DeletingSnapshotOnline: return 'DeletingSnapshotOnline';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_DeletingSnapshotPaused: return 'DeletingSnapshotPaused';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_RestoringSnapshot: return 'RestoringSnapshot';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_DeletingSnapshot: return 'DeletingSnapshot';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_SettingUp: return 'SettingUp';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass VirtualBoxWrapper(object): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around the IVirtualBox object that adds some (hopefully) useful
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync utility methods
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The real object can be accessed thru the o member. That said, members can
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync be accessed directly as well.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oVBox, oVBoxMgr, fpApiVer, oTstDrv):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Try ourselves first.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # oAttr = dir(self)[sName];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #except AttributeError:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Utilities.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def registerDerivedEventHandler(self, oSubClass, dArgs = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Create an instance of the given VirtualBoxEventHandlerBase sub-class
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and register it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The new instance is returned on success. None is returned on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgsCopy = dArgs.copy() if dArgs is not None else dict();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oSubClass.registerDerivedEventHandler(self.oVBoxMgr, self.fpApiVer, oSubClass, dArgsCopy,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Deletes a disk image from the host, given it's location.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oIMedium = self.oVBox.openMedium(sHdLocation, vboxcon.DeviceType_HardDisk,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oIMedium = self.oVBox.openMedium(sHdLocation, vboxcon.DeviceType_HardDisk,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oIMedium = self.oVBox.openHardDisk(sHdLocation, vboxcon.AccessMode_ReadOnly, False, "", False, "");
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return reporter.errorXcpt('failed to open hd "%s"' % (sHdLocation));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Deletes a disk image from the host, given an IMedium reference.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: return reporter.errorXcpt('deleteStorage() for disk %s failed' % (oIMedium,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'delete disk %s' % (oIMedium.location));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around a progress object for making it a task and providing useful
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync utility methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The real progress object can be accessed thru the o member.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oProgress, oVBoxMgr, oTstDrv, sName):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return '<%s sName=%s, oProgress=%s >' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # TdTaskBase overrides.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.pollTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync This method returns False until the progress object has completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.waitForTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Process XPCOM/COM events while waiting.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Utility methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Tests if the progress object completed successfully.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure or incomplete.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.cancelable.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.canceled.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.cancel()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure (logged as error).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.resultCode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.errorInfo.resultCode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the string on success, -1 on bad objects (logged as error), and
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync -2 on missing errorInfo object.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.errorInfo.text.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the string on success, None on failure. Missing errorInfo is
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync not logged as an error, all other failures are.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oErrInfo is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Formats IProgress.errorInfo into a string.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Stringify the result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Canceled, hrc=%s' % (self.sName, vbox.ComError.toString(self.getResult()));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Success (hrc=%s)' % (self.sName, vbox.ComError.toString(self.getResult()));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Failed! %s' % (self.sName, self.stringifyErrorInfo());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Not completed yet...' % (self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Logs the result. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync See vbox.TestDriver.waitOnProgress.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.oTstDrv.waitOnProgress(self.o, cMsInterval);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def wait(self, cMsTimeout = 60000, fErrorOnTimeout = True, cMsInterval = 1000):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wait on the progress object for a while.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the resultCode of the progress object if completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns -1 on timeout, logged as error if fErrorOnTimeout is set.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns -2 is the progress object is invalid or waitForCompletion
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fails (logged as errors).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Timing out after waiting for %u s on "%s"' % (cMsTimeout / 1000, self.sName))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def waitForOperation(self, iOperation, cMsTimeout = 60000, fErrorOnTimeout = True, cMsInterval = 1000, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wait for the completion of a operation.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Negative iOperation values are relative to operationCount (this
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync property may changed at runtime).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns 0 if the operation completed normally.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns -1 on timeout, logged as error if fErrorOnTimeout is set.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns -2 is the progress object is invalid or waitForCompletion
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fails (logged as errors).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns -3 if if the operation completed with an error, this is logged
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync as an error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Timing out after waiting for %u s on "%s" operation %d' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Timing out after waiting for %u s on "%s" operation %d' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.waitForOperationCompletion(iRealOperation, cMsInterval);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Not reached.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Queries everything that is stable and easy to get at and checks that
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync they don't throw errors.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('%s: %s' % (self.sName, self.o,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Very noisy -- only enable for debugging purposes.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #reporter.log2('%s: op=%u/%u/%s: %u%%; total=%u%% cancel=%s/%s compl=%s rem=%us; desc=%s' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # % (self.sName, iOp, cOps, sOpDesc, iOpPct, iPct, fCanceled, fCancelable, fCompleted, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # cSecsRemain, sDesc));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = iPct; _ = sDesc; _ = fCancelable; _ = cSecsRemain; _ = fCanceled; _ = fCompleted; _ = iOp;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around a machine session. The real session object can be accessed
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync thru the o member (short is good, right :-).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oSession, oVM, oVBox, oVBoxMgr, oTstDrv, fRemoteSession, sFallbackName = None, sLogFile = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initializes the session wrapper.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVM = oVM; # Not the session machine. Useful backdoor...
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sFallbackName is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Try cache the SessionPID.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Destructor that makes sure the callbacks are deregistered and
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync that the session is closed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return '<%s: sUuid=%s, sName=%s, uPid=%s, sDbgCreated=%s, fRemoteSession=%s, oSession=%s,' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' oConsoleEventHandler=%s, oVM=%s >' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (type(self).__name__, self.sUuid, self.sName, self.uPid, self.sDbgCreated, self.fRemoteSession,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # TdTaskBase overrides.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Internal poller """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Poll for events after doing the remote GetState call, otherwise we
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # might end up sleepless because XPCOM queues a cleanup event.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_UNEXPECTED):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_LiveSnapshotting:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_TeleportingPausedVM:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # *Beeep* fudge!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('SessionWrapper::pollTask: eState=%s' % (eState));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.pollTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync This method returns False while the VM is online and running normally.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # HACK ALERT: Lazily try registering the console event handler if
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # we're not ready.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # HACK ALERT: Lazily try get the PID and add it to the PID file.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.waitForTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Process XPCOM/COM events while waiting.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: self.oVBoxMgr.waitForEvents(cMsTimeout - cMsElapsed);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync HACK ALERT!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.setTaskOwner() so we can try call
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync registerEventHandlerForTask() again when when the testdriver calls
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync addTask() after VM has been spawned. Related to pollTask() above.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The testdriver must not add the task too early for this to work!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oOwner is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Task helpers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Registers the console event handlers for working the task state.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oConsoleEventHandler = self.registerDerivedEventHandler(vbox.SessionConsoleEventHandler, {}, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Asserts that the VM is powered off, reporting an error if not.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True if powered off, False + error msg if not.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Expected machine state "PoweredOff", machine is in the "%s" state instead.'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the current machine state both as a constant number/whatever and
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync as a human readable string. On error, the constants will be set to
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync None and the string will be the error message.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (None, '[error getting state: %s]' % (self.oVBoxMgr.xcptToString(),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def reportPrematureTermination(self, sPrefix = ''):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reports a premature virtual machine termination.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False to facilitate simpler error paths.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error(sPrefix + 'The virtual machine terminated prematurely!!');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (enmState, sStateNm) = self.getMachineStateWithName();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error(sPrefix + 'Machine state: %s' % (sStateNm,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if enmState is not None \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Look for process crash info.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ processCollectCrashInfo callback. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.addLogFile(sLogFile, 'crash/dump/vm' if fBinary else 'crash/report/vm');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync utils.processCollectCrashInfo(self.uPid, reporter.log, addCrashFile);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # ISession / IMachine / ISomethingOrAnother wrappers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Closes the session if it's open and removes it from the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.TestDriver.aoRemoteSessions list.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns success indicator.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Get the pid in case we need to kill the process later on.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Try close it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Kludge to ignore VBoxSVC's closing of our session when the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # direct session closes / VM process terminates. Fun!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: fIgnore = self.o.state == vboxcon.SessionState_Unlocked;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('ISession::unlockMachine failed on %s' % (self.o));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Remove it from the remote session list if applicable (not 100% clean).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('SessionWrapper::close: Removing myself from oTstDrv.aoRemoteSessions');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Saves the settings and optionally closes the session.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns success indicator.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('saveSettings failed on %s' % (self.o));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Discards the settings and optionally closes the session.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('discardSettings failed on %s' % (self.o));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables AMD-V/VT-x.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setHWVirtExProperty(vboxcon.HWVirtExPropertyType_Enabled, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HWVirtExPropertyType_Enabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HWVirtExPropertyType_Enabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fRc and hasattr(vboxcon, 'HWVirtExPropertyType_Force'):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setHWVirtExProperty(vboxcon.HWVirtExPropertyType_Force, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HWVirtExPropertyType_Force=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HWVirtExPropertyType_Force=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Warning! vboxcon has no HWVirtExPropertyType_Force attribute.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo Modify CFGM to do the same for old VBox versions?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables nested paging..
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo Add/remove force CFGM thing, we don't want fallback logic when testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setHWVirtExProperty(vboxcon.HWVirtExPropertyType_NestedPaging, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HWVirtExPropertyType_NestedPaging=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HWVirtExPropertyType_NestedPaging=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables LongMode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Supported.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer < 4.2 or not hasattr(vboxcon, 'HWVirtExPropertyType_LongMode'):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setCPUProperty(vboxcon.CPUPropertyType_LongMode, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set CPUPropertyType_LongMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set CPUPropertyType_LongMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables PAE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setCPUProperty(vboxcon.CPUPropertyType_PAE, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setCpuProperty(vboxcon.CpuPropertyType_PAE, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set CPUPropertyType_PAE=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set CPUPropertyType_PAE=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the IO-APIC
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.IOAPICEnabled = fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set BIOSSettings.IOAPICEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set BIOSSettings.IOAPICEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the HPET
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HpetEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HpetEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the USB HID
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.AddUSBController('OHCI', vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHIDType = vboxcon.PointingHIDType_ComboMouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHIDType = vboxcon.KeyboardHIDType_ComboKeyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHidType = vboxcon.PointingHidType_ComboMouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHidType = vboxcon.KeyboardHidType_ComboKeyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHIDType = vboxcon.PointingHIDType_PS2Mouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHIDType = vboxcon.KeyboardHIDType_PS2Keyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHidType = vboxcon.PointingHidType_PS2Mouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHidType = vboxcon.KeyboardHidType_PS2Keyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to change UsbHid to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('changed UsbHid to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the USB OHCI controller
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.AddUSBController('OHCI', vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to change OHCI to %s for "%s"' % (fEnable, self.sName));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('changed OHCI to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the USB EHCI controller, enables also OHCI if it is still disabled.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.addUSBController('OHCI', vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cEhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_EHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.addUSBController('EHCI', vboxcon.USBControllerType_EHCI);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync cEhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_EHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to change EHCI to %s for "%s"' % (fEnable, self.sName));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('changed EHCI to %s for "%s"' % (fEnable, self.sName));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync Enables or disables the USB XHCI controller. Error information is logged.
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync cXhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_XHCI);
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync self.o.machine.addUSBController('XHCI', vboxcon.USBControllerType_XHCI);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync cXhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_XHCI);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.errorXcpt('failed to change XHCI to %s for "%s"' % (fEnable, self.sName));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('changed XHCI to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the firmware type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set firmwareType=%s for "%s"' % (eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set firmwareType=%s for "%s"' % (eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupBootLogo(self, fEnable, cMsLogoDisplay = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets up the boot logo. fEnable toggles the fade and boot menu
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync settings as well as the mode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.logoFadeIn = not fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.logoFadeOut = not fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.logoDisplayTime = cMsLogoDisplay;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.bootMenuMode = vboxcon.BIOSBootMenuMode_Disabled;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.bootMenuMode = vboxcon.BIOSBootMenuMode_MessageAndMenu;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set logoFadeIn/logoFadeOut/bootMenuMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set logoFadeIn/logoFadeOut/bootMenuMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Configures VRDP.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set VRDEServer::enabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.VRDEServer.setVRDEProperty("TCP/Ports", str(uPort));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set VRDEServer::ports=%s for "%s"' % (uPort, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set VRDEServer.enabled/ports=%s/%s for "%s"' % (fEnable, uPort, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Helper that translate the adapter type into a driver name.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eNicType == vboxcon.NetworkAdapterType_Am79C970A \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eNicType == vboxcon.NetworkAdapterType_Am79C973:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eNicType == vboxcon.NetworkAdapterType_I82540EM \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eNicType == vboxcon.NetworkAdapterType_I82543GC \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eNicType == vboxcon.NetworkAdapterType_I82545EM:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eNicType == vboxcon.NetworkAdapterType_Virtio:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Unknown adapter type "%s" (VM: "%s")' % (eNicType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupNatForwardingForTxs(self, iNic = 0, iHostPort = 5042):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets up NAT forwarding for port 5042 if applicable, cleans up if not.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Nuke the old setup for all possible adapter types (in case we're
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # called after it changed).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for sConfig in ('VBoxInternal/Devices/%s/%u/LUN#0/AttachedDriver/Config' % (sName, iNic), \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VBoxInternal/Devices/%s/%u/LUN#0/Config' % (sName, iNic)):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('%s/txs/Protocol' % (sConfig), '');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('%s/txs/HostPort' % (sConfig), '');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('%s/txs/GuestPort' % (sConfig), '');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Set up port forwarding if NAT attachment.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachmentType on %s failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachmentType/traceEnabled on %s failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Failed to get INATEngine data on "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNatEngine.addRedirect('txs', vboxcon.NATProtocol_TCP, '127.0.0.1', '%s' % (iHostPort), '', '5042');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Failed to add a addRedirect redirect on "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sConfig = 'VBoxInternal/Devices/%s/%u/LUN#0/AttachedDriver/Config' % (sName, iNic)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sConfig = 'VBoxInternal/Devices/%s/%u/LUN#0/Config' % (sName, iNic)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('%s/txs/Protocol' % (sConfig), 'TCP');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('%s/txs/HostPort' % (sConfig), '%s' % (iHostPort));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('%s/txs/GuestPort' % (sConfig), '5042');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Failed to set NAT extra data on "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the NIC type of the specified NIC.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set NIC type on slot %s to %s for VM "%s"' % (iNic, eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set NIC type on slot %s to %s for VM "%s"' % (iNic, eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setNicTraceEnabled(self, fTraceEnabled, sTraceFile, iNic = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the NIC trace enabled flag and file path.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set NIC trace flag on slot %s to %s for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set NIC trace on slot %s to "%s" (path "%s") for VM "%s"' %
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Return the default network / interface name for the NIC attachment type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttachmentType == vboxcon.NetworkAttachmentType_Bridged:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoHostNics = self.oVBoxMgr.getArray(self.oVBox.host, 'networkInterfaces');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oHostNic.interfaceType == vboxcon.HostNetworkInterfaceType_Bridged \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oHostNic.status == vboxcon.HostNetworkInterfaceStatus_Up:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoHostNics = self.oVBoxMgr.getArray(self.oVBox.host, 'networkInterfaces');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oHostNic.interfaceType == vboxcon.HostNetworkInterfaceType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oHostNic.status == vboxcon.HostNetworkInterfaceStatus_Up:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Internal:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('eAttachmentType=%s is not known' % (eAttachmentType));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setNicAttachment(self, eAttachmentType, sName = None, iNic = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the attachment type of the specified NIC.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttachmentType is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Bridged:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Internal:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise base.GenError("eAttachmentType=%s is invalid" % (eAttachmentType));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the attachment type on slot %s to %s for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to get the attachment type on slot %s for VM "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sName is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Resolve the special 'default' name.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The name translate to different attributes depending on the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # attachment type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttachmentType == vboxcon.NetworkAttachmentType_Bridged:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo check this out on windows, may have to do a
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # translation of the name there or smth IIRC.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the hostInterface property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the internalNetwork property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Internal:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the internalNetwork property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the NATNetwork property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set NIC type on slot %s to %s for VM "%s"' % (iNic, eAttachmentType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the MAC address of the specified NIC.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Resolve missing MAC address prefix
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync abHostIP = socket.inet_aton(socket.gethostbyname(sHostName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to determin the host IP for "%s".' % (sHostName,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync abHostIP = array.array('B', (0x80, 0x86, 0x00, 0x00)).tostring();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (0x02, ord(abHostIP[0]), ord(abHostIP[1]), ord(abHostIP[2]), ord(abHostIP[3]), iNic);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sMacAddr = sDefaultMac[0:(11 - cchMacAddr)] + sMacAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Get the NIC object and try set it address.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the MAC address on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set MAC address on slot %s to %s for VM "%s"' % (iNic, sMacAddr, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set the RAM size of the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the RAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set the RAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set the RAM size of the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the VRAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set the VRAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set the number of CPUs.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the CPU count of "%s" to %s' % (self.sName, cCpus));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set the CPU count of "%s" to %s' % (self.sName, cCpus));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Makes sure the specified controller is attached to the VM, attaching it
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if necessary.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.getStorageControllerByName(sController);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.addStorageController(sController, iType);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('added storage controller "%s" (type %s) to %s' % (sController, iType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('addStorageController("%s",%s) failed on "%s"' % (sController, iType, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setStorageControllerPortCount(self, sController, iPortCount):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set maximum ports count for storage controller
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl = self.o.machine.getStorageControllerByName(sController)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set controller "%s" port count to value %d' % (sController, iPortCount))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('unable to set storage controller "%s" ports count to %d' % (sController, iPortCount))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set guest boot order type
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @param iPosition boot order position
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @param eType device type (vboxcon.DeviceType_HardDisk,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vboxcon.DeviceType_DVD, vboxcon.DeviceType_Floppy)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return reporter.errorXcpt('Unable to set boot order.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Set boot order [%d] for device %s' % (iPosition, str(eType)))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setStorageControllerType(self, eType, sController = "IDE Controller"):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Similar to ensureControllerAttached, except it will change the type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl = self.o.machine.getStorageControllerByName(sController);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl = self.o.machine.addStorageController(sController, iType);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('added storage controller "%s" (type %s) to %s' % (sController, iType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('addStorageController("%s",%s) failed on "%s"' % (sController, iType, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set controller type of "%s" on "%s" to %s' % (sController, self.sName, eType) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set controller type of "%s" on "%s" to %s' % (sController, self.sName, eType) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def attachDvd(self, sImage = None, sController = "IDE Controller", iPort = 1, iDevice = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attaches a DVD drive to a VM, optionally with an ISO inserted.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Input validation.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sImage is not None and not self.oTstDrv.isResourceFile(sImage)\
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and not os.path.isabs(sImage): ## fixme - testsuite unzip ++
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.fatal('"%s" is not in the resource set' % (sImage));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Find/register the image if specified.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sImage is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sFullName = self.oTstDrv.getFullResourceName(sImage)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oImage = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_DVD, vboxcon.AccessMode_ReadOnly, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oImage = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_DVD, vboxcon.AccessMode_ReadOnly);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open DVD image "%s" xxx' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open DVD image "%s" yyy' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open DVD image "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to get the UUID of "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach the DVD.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_DVD, oImage);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_DVD, sImageUuid);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,HardDisk,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, sImageUuid, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached DVD to %s, image="%s"' % (self.sName, sImage));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def attachHd(self, sHd, sController = "IDE Controller", iPort = 0, iDevice = 0, fImmutable = True, fForceResource = True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attaches a HD to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Input validation.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync if fForceResource and not self.oTstDrv.isResourceFile(sHd):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.fatal('"%s" is not in the resource set' % (sHd,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Find the HD, registering it if necessary (as immutable).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_HardDisk, vboxcon.AccessMode_ReadOnly, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_HardDisk, vboxcon.AccessMode_ReadOnly);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.oVBox.openHardDisk(sFullName, vboxcon.AccessMode_ReadOnly, False, "", False, "");
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open hd "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" immutable' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" normal' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd.id);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,HardDisk,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, oHd.id, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached "%s" to %s' % (sHd, self.sName));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def createBaseHd(self, sHd, sFmt = "VDI", cb = 10*1024*1024*1024):
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Creates a base HD.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Returns Medium object on success and None on failure. Error information is logged.
1c43cacd545be15afb64413d49eccbecff95e759vboxsync oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgressXpcom = oHd.createBaseStorage(cb, (vboxcon.MediumVariant_Standard, ))
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create base disk %s' % (sHd));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync reporter.errorXcpt('failed to create base hd "%s"' % (sHd));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def createDiffHd(self, oParentHd, sHd, sFmt = "VDI"):
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Creates a differencing HD.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Returns Medium object on success and None on failure. Error information is logged.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgressXpcom = oParentHd.createDiffStorage(oHd, (vboxcon.MediumVariant_Standard, ))
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create diff disk %s' % (sHd));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync reporter.errorXcpt('failed to create diff hd "%s"' % (sHd));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def createAndAttachHd(self, sHd, sFmt = "VDI", sController = "IDE Controller", cb = 10*1024*1024*1024, \
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Creates and attaches a HD to a VM.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Returns True on success and False on failure. Error information is logged.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync if oHd is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" immutable' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" normal' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd.id);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,HardDisk,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, oHd.id, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached "%s" to %s' % (sHd, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Delete disk in case of an error
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('deleteStorage() for disk %s failed' % (sHd,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'delete disk %s' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def detachHd(self, sController = "IDE Controller", iPort = 0, iDevice = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Detaches a HD, if attached, and returns a reference to it (IMedium).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync In order to delete the detached medium, the caller must first save
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync the changes made in this session.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns (fRc, oHd), where oHd is None unless fRc is True, and fRc is
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync your standard success indicator. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # What's attached?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.o.machine.getMedium(sController, iPort, iDevice);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.oVBoxMgr.xcptIsEqual(None, self.oVBoxMgr.constants.VBOX_E_OBJECT_NOT_FOUND):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('No HD attached (to %s %s:%s)' % (sController, iPort, iDevice));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (True, None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (reporter.errorXcpt('Error getting media at port %s, device %s, on %s.'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Detach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.detachDevice(sController, iPort, iDevice);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (reporter.errorXcpt('detachDevice("%s",%s,%s) failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, self.sName) ), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('detached HD ("%s",%s,%s) from %s' % (sController, iPort, iDevice, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def attachFloppy(self, sFloppy, sController = "Floppy Controller", iPort = 0, iDevice = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attaches a floppy image to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Input validation.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo Fix this wrt to bootsector-xxx.img from the validationkit.zip.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ##if not self.oTstDrv.isResourceFile(sFloppy):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## reporter.fatal('"%s" is not in the resource set' % (sFloppy));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Find the floppy image, registering it if necessary (as immutable).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sFullName = self.oTstDrv.getFullResourceName(sFloppy);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFloppy = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_Floppy, vboxcon.AccessMode_ReadOnly, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFloppy = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_Floppy, vboxcon.AccessMode_ReadOnly);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFloppy = self.oVBox.openFloppyImage(sFullName, "");
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open floppy "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo the following works but causes trouble below (asserts in main).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # oFloppy.type = vboxcon.MediumType_Immutable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # reporter.errorXcpt('failed to make floppy "%s" immutable' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_Floppy, oFloppy);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_Floppy, oFloppy.id);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,Floppy,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, oFloppy.id, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached "%s" to %s' % (sFloppy, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attaches a HD to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sType == "PCNet": enmType = vboxcon.NetworkAdapterType_Am79C973;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sType == "PCNetOld": enmType = vboxcon.NetworkAdapterType_Am79C970A;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sType == "E1000": enmType = vboxcon.NetworkAdapterType_I82545EM; # MT Server
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sType == "E1000Desk": enmType = vboxcon.NetworkAdapterType_I82540EM; # MT Desktop
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sType == "E1000Srv2": enmType = vboxcon.NetworkAdapterType_I82543GC; # T Server
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sType == "Virtio": enmType = vboxcon.NetworkAdapterType_Virtio;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Invalid NIC type: "%s" (sXXX=%s)' % (sType, sXXX));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo Implement me!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if enmType is not None: pass
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupPreferredConfig(self): # pylint: disable=R0914
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Configures the VM according to the preferences of the guest type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to obtain the OSTypeId for "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getGuestOSType("%s") failed for "%s"' % (sOsTypeId, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # get the attributes.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #sFamilyId = oOsType.familyId;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #f64Bit = oOsType.is64Bit;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #cMBHdd = oOsType.recommendedHDD;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eStorCtlType = oOsType.recommendedHDStorageController;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eStorCtlType = oOsType.recommendedHdStorageController;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eStorCtlType = vboxcon.StorageControllerType_PIIX4;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('exception reading IGuestOSType(%s) attribute' % (sOsTypeId));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Do the setting. Continue applying settings on error in case the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # caller ignores the return code
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setFirmwareType(eFirmwareType): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eStorCtlType == vboxcon.StorageControllerType_PIIX3 \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eStorCtlType == vboxcon.StorageControllerType_PIIX4 \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eStorCtlType == vboxcon.StorageControllerType_ICH6:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setStorageControllerType(eStorCtlType, "IDE Controller"):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addUsbDeviceFilter(self, sName, sVendorId, sProductId):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Creates a USB device filter and inserts it into the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync usbDevFilter = self.o.machine.USBDeviceFilters.createDeviceFilter(sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.USBDeviceFilters.insertDeviceFilter(0, usbDevFilter);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('insertDeviceFilter(%s) failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('inserted USB device filter "%s" to %s' % (sName, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('createDeviceFilter("%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets a guest property value.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the value on success, None on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sValue = self.o.machine.getGuestPropertyValue(sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::getGuestPropertyValue("%s") failed' % (sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets a guest property value.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setGuestPropertyValue(sName, sValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::setGuestPropertyValue("%s","%s") failed' % (sName, sValue));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Deletes a guest property value.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Unable to delete guest property "%s"' % (sName,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets extra data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::setExtraData("%s","%s") failed' % (sKey, sValue));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets extra data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns value on success, None on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::setExtraData("%s","%s") failed' % (sKey, sValue))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupTeleporter(self, fEnabled=True, uPort = 6500, sAddress = '', sPassword = ''):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets up the teleporter for the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('setupTeleporter(%s, %s, %s, %s)' % (fEnabled, sPassword, uPort, sAddress));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the teleporter of the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::teleporterEnabled=%s failed' % (fEnable));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def teleport(self, sHostname = 'localhost', uPort = 6500, sPassword = 'password', cMsMaxDowntime = 250):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around the IConsole::teleport() method.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a progress object on success, None on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('"%s"::teleport(%s,%s,%s,%s)...' % (self.sName, sHostname, uPort, sPassword, cMsMaxDowntime));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = self.o.console.teleport(sHostname, uPort, sPassword, cMsMaxDowntime)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IConsole::teleport(%s,%s,%s,%s) failed' % (sHostname, uPort, sPassword, cMsMaxDowntime));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return ProgressWrapper(oProgress, self.oVBoxMgr, self.oTstDrv, 'teleport %s' % (self.sName,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the IGuestOSType interface for the machine.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return IGuestOSType interface on success, None + errorXcpt on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync No exceptions raised.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to obtain the OSTypeId for "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getGuestOSType("%s") failed for "%s"' % (sOsTypeId, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Changes the OS type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync returns True on success, False + errorXcpt on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync No exceptions raised.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the OSTypeId for "%s" to "%s"' % (self.sName, sNewTypeId));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets a paravirtualisation provider.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Unable to set paravirtualisation provider "%s"' % (iProvider,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # IConsole wrappers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Powers off the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False on IConsole::powerDown() failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None if the progress object returns failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt('IConsole::powerDown failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.reportError(oProgress, 'powerDown for "%s" failed' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Wait for the VM to really power off or we'll fail to open a new session to it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def restoreSnapshot(self, oSnapshot, fFudgeOnFailure = True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Restores the given snapshot.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync Returns False on IMachine::restoreSnapshot() failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None if the progress object returns failure.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgress = self.o.machine.restoreSnapshot(oSnapshot);
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgress = self.o.console.restoreSnapshot(oSnapshot);
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync reporter.logXcpt('IMachine::restoreSnapshot failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.reportError(oProgress, 'restoreSnapshot for "%s" failed' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def deleteSnapshot(self, oSnapshot, fFudgeOnFailure = True, cMsTimeout = 30 * 1000):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Deletes the given snapshot merging the diff image into the base.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync Returns False on IMachine::deleteSnapshot() failure.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.machine.deleteSnapshot(oSnapshot);
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.console.deleteSnapshot(oSnapshot);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'Delete Snapshot %s' % (oSnapshot));
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync reporter.logXcpt('IMachine::deleteSnapshot failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def takeSnapshot(self, sName, sDescription = '', fPause = True, fFudgeOnFailure = True, cMsTimeout = 30 * 1000):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Takes a snapshot with the given name
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync Returns False on IMachine::takeSnapshot() or VM state change failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.oVM.state is vboxcon.MachineState_Running:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.machine.takeSnapshot(sName, sDescription);
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.console.takeSnapshot(sName, sDescription);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'Take Snapshot %s' % (sName));
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync reporter.logXcpt('IMachine::takeSnapshot failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the snapshot object with the given name
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns snapshot object on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None if there is no snapshot with the given name.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Take screenshot from the given display and save it to specified file.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False on failure.
44a028033f962688c3d776dfd1c8467e3d6774a3vboxsync iWidth, iHeight, _, _, _, _ = self.o.console.display.getScreenResolution(iScreenId)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aPngData = self.o.console.display.takeScreenShotToArray(iScreenId, iWidth, iHeight,
44a028033f962688c3d776dfd1c8467e3d6774a3vboxsync iWidth, iHeight, _, _, _ = self.o.console.display.getScreenResolution(iScreenId)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aPngData = self.o.console.display.takeScreenShotPNGToArray(iScreenId, iWidth, iHeight)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Other methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Tries to obtain the primary IP address of the guest via the guest
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync properties.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns IP address on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns empty string on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = self.getGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the process ID for the direct session unless it's ourselves.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.uPid is None and self.o is not None and self.fRemoteSession:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if vbox.ComError.equal(oXcpt, vbox.ComError.E_UNEXPECTED):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Retrieves and adds the release and debug logs to the test report.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add each of the requested release logs to the report.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sLogFile = '%s/VBox.log.%u' % (self.oVM.logFolder, iLog);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sLogFile is not None and sLogFile != '': # the None bit is for a 3.2.0 bug.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.addLogFile(sLogFile, 'log/release/vm', '%s #%u' % (self.sName, iLog),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sAltName = '%s-%s' % (self.sName, os.path.basename(sLogFile),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Now for the hardened windows startup log.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sLogFile = os.path.join(self.oVM.logFolder, 'VBoxStartup.log');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.addLogFile(sLogFile, 'log/release/vm', '%s startup log' % (self.sName, ),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sAltName = '%s-%s' % (self.sName, os.path.basename(sLogFile),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Now for the debug log.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.sLogFile is not None and os.path.isfile(self.sLogFile):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.addLogFile(self.sLogFile, 'log/debug/vm', '%s debug' % (self.sName, ),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sAltName = '%s-%s' % (self.sName, os.path.basename(self.sLogFile),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def registerDerivedEventHandler(self, oSubClass, dArgs = None, fMustSucceed = True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Create an instance of the given ConsoleEventHandlerBase sub-class and
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync register it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The new instance is returned on success. None is returned on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # We need a console object.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fMustSucceed or vbox.ComError.notEqual(oXcpt, vbox.ComError.E_UNEXPECTED):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Failed to get ISession::console for "%s"' % (self.sName, ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add the base class arguments.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgsCopy = dArgs.copy() if dArgs is not None else dict();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oSubClass.registerDerivedEventHandler(self.oVBoxMgr, self.fpApiVer, oSubClass, dArgsCopy,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fMustSucceed = fMustSucceed, sLogSuffix = sLogSuffix);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableVmmDevTestingPart(self, fEnabled, fEnableMMIO = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables the testing part of the VMMDev.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('VBoxInternal/Devices/VMMDev/0/Config/TestingEnabled',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('VBoxInternal/Devices/VMMDev/0/Config/TestingMMIO',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('VM name "%s", fEnabled=%s' % (self.sName, fEnabled));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set VMMDevTesting=%s for "%s"' % (fEnabled, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Test eXecution Service methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def txsConnectViaTcp(self, cMsTimeout = 10*60000, sIpAddr = None, sMacAddr = None, fNatForwardingForTxs = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Connects to the TXS using TCP/IP as transport. If no IP or MAC is
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync addresses are specified, we'll get the IP from the guest additions.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a TxsConnectTask object on success, None + log on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # If the VM is configured with a NAT interface, connect to local host.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oNic.attachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Kick off the task.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTask = TxsConnectTask(self, cMsTimeout, sIpAddr, sMacAddr, fReversedSetup);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def txsTryConnectViaTcp(self, cMsTimeout, sHostname, fReversed = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attempts to connect to a TXS instance.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True if a connection was established, False if not (only grave
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync failures are logged as errors).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Note! The timeout is more of a guideline...
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise base.GenError('Empty sHostname is not implemented yet');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession = txsclient.tryOpenTcpSession(cMsTimeout, sHostname, fReversedSetup = fReversed,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Wait for the connect task to time out.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oRc is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('oRc=%s, expected %s' % (oRc, oTxsSession));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check the status.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('TxsSession is ready, isSuccess() -> %s.' % (oTxsSession.isSuccess(),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Class that takes care of connecting to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync class TxsConnectTaskVBoxCallback(vbox.VirtualBoxEventHandlerBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Class for looking for IPv4 address changes on interface 0."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.VirtualBoxEventHandlerBase.__init__(self, dArgs); # pylint: disable=W0233
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def onGuestPropertyChange(self, sMachineId, sName, sValue, sFlags):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Look for IP address."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('onGuestPropertyChange(,%s,%s,%s,%s)' % (sMachineId, sName, sValue, sFlags));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oParentTask._setIp(sValue); # pylint: disable=W0212
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oSession, cMsTimeout, sIpAddr, sMacAddr, fReversedSetup):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Skip things we don't implement.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sMacAddr is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('TxsConnectTask does not implement sMacAddr yet');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('TxsConnectTask: sIpAddr=%s fReversedSetup=%s' % (sIpAddr, fReversedSetup))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, fReversedSetup = True);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sIpAddr is not None and sIpAddr.strip() != '':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, cMsIdleFudge = 5000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # If we've got no IP address, register callbacks that listens for
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # the primary network adaptor of the VM to set a IPv4 guest prop.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Note! The order in which things are done here is kind of important.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 0. The caller zaps the property before starting the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # oSession.delGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # reporter.logXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 1. Register the callback / event listener object.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgs = {'oParentTask':self, 'sMachineId':oSession.o.machine.id};
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBoxEventHandler = self.oVBox.registerDerivedEventHandler(self.TxsConnectTaskVBoxCallback, dArgs);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 2. Query the guest properties.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = oSession.getGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP") failed');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sIpAddr is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # end __init__
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Make sure we deregister the callback. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return '<%s cMsTimeout=%s, sIpAddr=%s, sNextIpAddr=%s, sMacAddr=%s, fReversedSetup=%s,' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' oTxsSession=%s oVBoxEventHandler=%s, oVBox=%s>' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (TdTaskBase.toString(self), self.cMsTimeout, self.sIpAddr, self.sNextIpAddr, self.sMacAddr, self.fReversedSetup,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTxsSession, self.oVBoxEventHandler, self.oVBox);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Deregisters the event handler."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Called when we get an IP. Will create a TXS session and signal the task."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sIpAddr is not None \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if str(i) != s:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, cMsIdleFudge = 5000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('TxsConnectTask: Ignoring Bad ip "%s"' % (sIpAddr));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('TxsConnectTask: Ignoring empty ip "%s"' % (sIpAddr));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _openTcpSession(self, sIpAddr, uPort = None, fReversedSetup = False, cMsIdleFudge = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Calls txsclient.openTcpSession and switches our task to reflect the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync state of the subtask.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('_openTcpSession: sIpAddr=%s, uPort=%d, fReversedSetup=%s' % \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (sIpAddr, uPort if uPort is not None else 0, fReversedSetup));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTxsSession = txsclient.openTcpSession(self.cMsTimeout, sIpAddr, uPort, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('_openTcpSession: sNextIpAddr=%s' % (sIpAddr,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Called by the TXS session task when it's done.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync We'll signal the task completed or retry depending on the result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Disassociate ourselves with the session (avoid cyclic ref)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Signal done, or retry?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = self.sNextIpAddr if self.sNextIpAddr is not None else self.sIpAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, cMsIdleFudge = 5000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Public methods
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the connected TXS session object on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None on failure or if the task has not yet completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oTxsSession is not None and not oTxsSession.isSuccess():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Cancels the task. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oTxsSession is not None: