vboxwrappers.py revision 1c43cacd545be15afb64413d49eccbecff95e759
# -*- coding: utf-8 -*-
# $Id$
# pylint: disable=C0302
"""
VirtualBox Wrapper Classes
"""
__copyright__ = \
"""
Copyright (C) 2010-2015 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
__version__ = "$Revision$"
# Standard Python imports.
import array
import os
import socket
import sys
# Validation Kit imports.
from testdriver import base;
from testdriver import reporter;
from testdriver import txsclient;
from testdriver import vboxcon;
from testdriver import vbox;
""" Translate a controller name to a storage bus. """
if sController == "IDE Controller":
elif sController == "SATA Controller":
elif sController == "Floppy Controller":
elif sController == "SAS Controller":
elif sController == "SCSI Controller":
else:
return iType;
def _nameMachineState(eState):
""" Gets the name (string) of a machine state."""
return 'Unknown-%s' % (eState,);
"""
Wrapper around the IVirtualBox object that adds some (hopefully) useful
utility methods
The real object can be accessed thru the o member. That said, members can
be accessed directly as well.
"""
# Try ourselves first.
try:
except:
#try:
# oAttr = dir(self)[sName];
#except AttributeError:
return oAttr;
#
# Utilities.
#
"""
Create an instance of the given VirtualBoxEventHandlerBase sub-class
and register it.
The new instance is returned on success. None is returned on error.
"""
"""
Deletes a disk image from the host, given it's location.
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
try:
else:
except:
"""
Deletes a disk image from the host, given an IMedium reference.
Returns True on success and False on failure. Error information is logged.
"""
try: oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'delete disk %s' % (oIMedium.location));
class ProgressWrapper(TdTaskBase):
"""
Wrapper around a progress object for making it a task and providing useful
utility methods.
The real progress object can be accessed thru the o member.
"""
return '<%s sName=%s, oProgress=%s >' \
#
# TdTaskBase overrides.
#
"""
Overrides TdTaskBase.pollTask().
This method returns False until the progress object has completed.
"""
try:
try:
return True;
except:
pass;
finally:
return False;
"""
Overrides TdTaskBase.waitForTask().
"""
while not fState:
if cMsElapsed > cMsTimeout:
break;
if cMsToWait > 500:
cMsToWait = 500;
try:
except KeyboardInterrupt: raise;
except: pass;
return fState;
#
# Utility methods.
#
"""
Tests if the progress object completed successfully.
Returns True on success, False on failure or incomplete.
"""
if not self.isCompleted():
return False;
def isCompleted(self):
"""
Wrapper around IProgress.completed.
"""
def isCancelable(self):
"""
Wrapper around IProgress.cancelable.
"""
try:
except:
return fRc;
def wasCanceled(self):
"""
Wrapper around IProgress.canceled.
"""
try:
except:
return fRc;
"""
Wrapper around IProgress.cancel()
Returns True on success, False on failure (logged as error).
"""
try:
except:
return False;
return True;
"""
Wrapper around IProgress.resultCode.
"""
try:
except:
iRc = -1;
return iRc;
def getErrInfoResultCode(self):
"""
Wrapper around IProgress.errorInfo.resultCode.
Returns the string on success, -1 on bad objects (logged as error), and
-2 on missing errorInfo object.
"""
iRc = -1;
try:
except:
else:
if oErrInfo is None:
iRc = -2;
else:
try:
except:
return iRc;
def getErrInfoText(self):
"""
Wrapper around IProgress.errorInfo.text.
Returns the string on success, None on failure. Missing errorInfo is
not logged as an error, all other failures are.
"""
sText = None;
try:
except:
else:
if oErrInfo is not None:
try:
except:
return sText;
def stringifyErrorInfo(self):
"""
Formats IProgress.errorInfo into a string.
"""
try:
except:
sErr = 'no error info';
else:
return sErr;
def stringifyResult(self):
"""
Stringify the result.
"""
if self.isCompleted():
if self.wasCanceled():
else:
else:
return sRet;
""" Logs the result. """
and fIgnoreErrors is False:
"""
See vbox.TestDriver.waitOnProgress.
"""
"""
Wait on the progress object for a while.
Returns the resultCode of the progress object if completed.
Returns -1 on timeout, logged as error if fErrorOnTimeout is set.
Returns -2 is the progress object is invalid or waitForCompletion
fails (logged as errors).
"""
while True:
try:
break;
except:
return -2;
if cMsElapsed > cMsTimeout:
if fErrorOnTimeout:
return -1;
try:
except:
return -2;
try:
except:
rc = -2;
return rc;
def waitForOperation(self, iOperation, cMsTimeout = 60000, fErrorOnTimeout = True, cMsInterval = 1000, \
fIgnoreErrors = False):
"""
Wait for the completion of a operation.
Negative iOperation values are relative to operationCount (this
property may changed at runtime).
Returns 0 if the operation completed normally.
Returns -1 on timeout, logged as error if fErrorOnTimeout is set.
Returns -2 is the progress object is invalid or waitForCompletion
fails (logged as errors).
Returns -3 if if the operation completed with an error, this is logged
as an error.
"""
while True:
try:
if iOperation >= 0:
else:
return 0;
if iCurrentOperation == iRealOperation \
return -3;
return 0;
except:
if fIgnoreErrors:
else:
return -2;
if cMsElapsed > cMsTimeout:
if fErrorOnTimeout:
if fIgnoreErrors:
else:
return -1;
try:
except:
if fIgnoreErrors:
else:
return -2;
# Not reached.
def doQuickApiTest(self):
"""
Queries everything that is stable and easy to get at and checks that
they don't throw errors.
"""
if True:
try:
except:
return False;
try:
# Very noisy -- only enable for debugging purposes.
#reporter.log2('%s: op=%u/%u/%s: %u%%; total=%u%% cancel=%s/%s compl=%s rem=%us; desc=%s' \
# % (self.sName, iOp, cOps, sOpDesc, iOpPct, iPct, fCanceled, fCancelable, fCompleted, \
# cSecsRemain, sDesc));
except:
return False;
return True;
class SessionWrapper(TdTaskBase):
"""
Wrapper around a machine session. The real session object can be accessed
thru the o member (short is good, right :-).
"""
def __init__(self, oSession, oVM, oVBox, oVBoxMgr, oTstDrv, fRemoteSession, sFallbackName = None, sLogFile = None):
"""
Initializes the session wrapper.
"""
self.oConsoleEventHandler = None;
try:
except:
if sFallbackName is not None:
else:
try:
except:
# Try cache the SessionPID.
"""
Destructor that makes sure the callbacks are deregistered and
that the session is closed.
"""
if self.oConsoleEventHandler is not None:
self.oConsoleEventHandler = None;
if self.o is not None:
try:
except:
pass;
self.o = None;
return '<%s: sUuid=%s, sName=%s, uPid=%s, sDbgCreated=%s, fRemoteSession=%s, oSession=%s,' \
' oConsoleEventHandler=%s, oVM=%s >' \
#
# TdTaskBase overrides.
#
def __pollTask(self):
""" Internal poller """
# Poll for events after doing the remote GetState call, otherwise we
# might end up sleepless because XPCOM queues a cleanup event.
try:
try:
return True;
finally:
# Switch
return False;
return False;
return False;
return False;
return False;
return False;
return False;
return False;
return False;
return False;
# *Beeep* fudge!
return False;
return True;
"""
Overrides TdTaskBase.pollTask().
This method returns False while the VM is online and running normally.
"""
# HACK ALERT: Lazily try registering the console event handler if
# we're not ready.
# HACK ALERT: Lazily try get the PID and add it to the PID file.
return fRc;
"""
Overrides TdTaskBase.waitForTask().
"""
while not fState:
if cMsElapsed > cMsTimeout:
break;
except KeyboardInterrupt: raise;
except: pass;
return fState;
"""
HACK ALERT!
Overrides TdTaskBase.setTaskOwner() so we can try call
registerEventHandlerForTask() again when when the testdriver calls
addTask() after VM has been spawned. Related to pollTask() above.
The testdriver must not add the task too early for this to work!
"""
if oOwner is not None:
#
# Task helpers.
#
"""
Registers the console event handlers for working the task state.
"""
if self.oConsoleEventHandler is not None:
return True;
self.oConsoleEventHandler = self.registerDerivedEventHandler(vbox.SessionConsoleEventHandler, {}, False);
return self.oConsoleEventHandler is not None;
def assertPoweredOff(self):
"""
Asserts that the VM is powered off, reporting an error if not.
Returns True if powered off, False + error msg if not.
"""
try:
try:
except Exception:
return True;
finally:
return True;
% (_nameMachineState(eState),));
return False;
def getMachineStateWithName(self):
"""
as a human readable string. On error, the constants will be set to
None and the string will be the error message.
"""
try:
except:
finally:
"""
Reports a premature virtual machine termination.
Returns False to facilitate simpler error paths.
"""
if enmState is not None \
#
# Look for process crash info.
#
""" processCollectCrashInfo callback. """
return False;
#
# ISession / IMachine / ISomethingOrAnother wrappers.
#
"""
Closes the session if it's open and removes it from the
vbox.TestDriver.aoRemoteSessions list.
Returns success indicator.
"""
if self.o is not None:
# Get the pid in case we need to kill the process later on.
# Try close it.
try:
else:
self.o.unlockMachine();
self.o = None;
except KeyboardInterrupt:
raise;
except:
# Kludge to ignore VBoxSVC's closing of our session when the
# direct session closes / VM process terminates. Fun!
if not fIgnore:
# Remove it from the remote session list if applicable (not 100% clean).
try:
except:
return fRc;
"""
Saves the settings and optionally closes the session.
Returns success indicator.
"""
try:
try:
except:
return False;
finally:
if fClose:
return True;
"""
Discards the settings and optionally closes the session.
"""
try:
try:
except:
return False;
finally:
if fClose:
return True;
"""
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
reporter.errorXcpt('failed to set HWVirtExPropertyType_Enabled=%s for "%s"' % (fEnable, self.sName));
else:
try:
except:
else:
else:
## @todo Modify CFGM to do the same for old VBox versions?
return fRc;
"""
Enables or disables nested paging..
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
reporter.errorXcpt('failed to set HWVirtExPropertyType_NestedPaging=%s for "%s"' % (fEnable, self.sName));
else:
return fRc;
"""
Enables or disables LongMode.
Returns True on success and False on failure. Error information is logged.
"""
# Supported.
return True;
try:
except:
else:
return fRc;
"""
Enables or disables PAE
Returns True on success and False on failure. Error information is logged.
"""
try:
else:
except:
else:
return fRc;
"""
Enables or disables the IO-APIC
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
else:
return fRc;
"""
Enables or disables the HPET
Returns True on success and False on failure. Error information is logged.
"""
try:
else:
except:
else:
return fRc;
"""
Enables or disables the USB HID
Returns True on success and False on failure. Error information is logged.
"""
try:
if fEnable:
if cOhciCtls == 0:
else:
else:
else:
else:
except:
else:
return fRc;
"""
Enables or disables the USB OHCI controller
Returns True on success and False on failure. Error information is logged.
"""
try:
if fEnable:
if cOhciCtls == 0:
else:
else:
if cOhciCtls == 1:
else:
except:
else:
return fRc;
"""
Enables or disables the USB EHCI controller, enables also OHCI if it is still disabled.
Returns True on success and False on failure. Error information is logged.
"""
try:
if fEnable:
if cOhciCtls == 0:
if cEhciCtls == 0:
else:
else:
if cEhciCtls == 1:
else:
except:
else:
return fRc;
"""
Enables or disables the USB XHCI controller. Error information is logged.
"""
try:
if fEnable:
if cXhciCtls == 0:
else:
if cXhciCtls == 1:
except:
else:
return fRc;
"""
Sets the firmware type.
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
else:
return fRc;
"""
Sets up the boot logo. fEnable toggles the fade and boot menu
settings as well as the mode.
"""
try:
if fEnable:
else:
except:
reporter.errorXcpt('failed to set logoFadeIn/logoFadeOut/bootMenuMode=%s for "%s"' % (fEnable, self.sName));
else:
return fRc;
"""
Configures VRDP.
"""
try:
else:
except:
try:
else:
except:
if fRc:
return fRc;
"""
Helper that translate the adapter type into a driver name.
"""
sName = 'pcnet';
sName = 'e1000';
sName = 'virtio-net';
else:
sName = 'pcnet';
return sName;
"""
Sets up NAT forwarding for port 5042 if applicable, cleans up if not.
"""
try:
except:
return False;
# Nuke the old setup for all possible adapter types (in case we're
# called after it changed).
try:
except:
# Set up port forwarding if NAT attachment.
try:
except:
return False;
return True;
try:
except:
return False;
try:
else:
except:
return False;
except: pass;
try:
oNatEngine.addRedirect('txs', vboxcon.NATProtocol_TCP, '127.0.0.1', '%s' % (iHostPort), '', '5042');
except:
return False;
else:
if fTraceEnabled:
else:
try:
except:
return False;
return True;
"""
Sets the NIC type of the specified NIC.
Returns True on success and False on failure. Error information is logged.
"""
try:
try:
except:
return False;
try:
except:
reporter.errorXcpt('failed to set NIC type on slot %s to %s for VM "%s"' % (iNic, eType, self.sName));
return False;
finally:
return False;
return True;
"""
Sets the NIC trace enabled flag and file path.
Returns True on success and False on failure. Error information is logged.
"""
try:
try:
except:
return False;
try:
except:
return False;
finally:
return False;
return True;
"""
Return the default network / interface name for the NIC attachment type.
"""
sRetName = '';
else:
sRetName = 'eth0';
try:
for oHostNic in aoHostNics:
break;
except:
try:
for oHostNic in aoHostNics:
break;
if sRetName == '':
except:
if sRetName == '':
sRetName = 'HostInterfaceNetwork-vboxnet0';
sRetName = 'VBoxTest';
sRetName = '';
else:
return sRetName;
"""
Sets the attachment type of the specified NIC.
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
return False;
try:
if eAttachmentType is not None:
try:
else:
oNic.attachToNAT();
else:
except:
return False;
else:
try:
except:
reporter.errorXcpt('failed to get the attachment type on slot %s for VM "%s"' % (iNic, self.sName));
return False;
finally:
if sName is not None:
# Resolve the special 'default' name.
if sName == 'default':
# The name translate to different attributes depending on the
# attachment type.
try:
## @todo check this out on windows, may have to do a
# translation of the name there or smth IIRC.
try:
else:
except:
return False;
try:
else:
except:
return False;
try:
except:
return False;
try:
except:
return False;
finally:
return False;
return True;
"""
Sets the MAC address of the specified NIC.
Returns True on success and False on failure. Error information is logged.
"""
# Resolve missing MAC address prefix
sHostName = '';
try:
except:
sDefaultMac = '%02X%02X%02X%02X%02X%02X' \
# Get the NIC object and try set it address.
try:
except:
return False;
try:
except:
return False;
return True;
"""
Set the RAM size of the VM.
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
else:
return fRc;
"""
Set the RAM size of the VM.
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
else:
return fRc;
"""
Set the number of CPUs.
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
else:
return fRc;
"""
Makes sure the specified controller is attached to the VM, attaching it
if necessary.
"""
try:
try:
except:
try:
except:
reporter.errorXcpt('addStorageController("%s",%s) failed on "%s"' % (sController, iType, self.sName) );
return False;
finally:
return True;
"""
Set maximum ports count for storage controller
"""
try:
return True
except:
return False
"""
Set guest boot order type
@param iPosition boot order position
@param eType device type (vboxcon.DeviceType_HardDisk,
vboxcon.DeviceType_DVD, vboxcon.DeviceType_Floppy)
"""
try:
except:
return True
"""
Similar to ensureControllerAttached, except it will change the type.
"""
try:
except:
try:
except:
reporter.errorXcpt('addStorageController("%s",%s) failed on "%s"' % (sController, iType, self.sName) );
return False;
try:
except:
reporter.errorXcpt('failed to set controller type of "%s" on "%s" to %s' % (sController, self.sName, eType) );
return False;
return True;
"""
Attaches a DVD drive to a VM, optionally with an ISO inserted.
Returns True on success and False on failure. Error information is logged.
"""
# Input validation.
return None;
return False;
oImage = None;
sImageUuid = "";
if sImage is not None:
try:
except:
try:
oImage = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_DVD, vboxcon.AccessMode_ReadOnly, False);
else:
else:
return False;
except:
return False;
try:
except:
return False;
# Attach the DVD.
try:
else:
except:
else:
return fRc;
"""
Attaches a HD to a VM.
Returns True on success and False on failure. Error information is logged.
"""
# Input validation.
return None;
return False;
# Find the HD, registering it if necessary (as immutable).
try:
except:
try:
oHd = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_HardDisk, vboxcon.AccessMode_ReadOnly, False);
else:
except:
return False;
try:
if fImmutable:
else:
except:
if fImmutable:
else:
return False;
# Attach it.
try:
else:
except:
else:
return fRc;
def createAndAttachHd(self, sHd, sFmt = "VDI", sController = "IDE Controller", cb = 10*1024*1024*1024, \
"""
Creates and attaches a HD to a VM.
Returns True on success and False on failure. Error information is logged.
"""
return False;
try:
oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
else:
except:
return False;
try:
if fImmutable:
else:
except:
if fImmutable:
else:
# Attach it.
try:
else:
except:
else:
# Delete disk in case of an error
try:
except:
else:
return fRc;
"""
Detaches a HD, if attached, and returns a reference to it (IMedium).
In order to delete the detached medium, the caller must first save
the changes made in this session.
Returns (fRc, oHd), where oHd is None unless fRc is True, and fRc is
your standard success indicator. Error information is logged.
"""
# What's attached?
try:
except:
return (True, None);
# Detach it.
try:
except:
"""
Attaches a floppy image to a VM.
Returns True on success and False on failure. Error information is logged.
"""
# Input validation.
## @todo Fix this wrt to bootsector-xxx.img from the validationkit.zip.
##if not self.oTstDrv.isResourceFile(sFloppy):
## reporter.fatal('"%s" is not in the resource set' % (sFloppy));
## return None;
return False;
# Find the floppy image, registering it if necessary (as immutable).
try:
except:
try:
oFloppy = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_Floppy, vboxcon.AccessMode_ReadOnly, False);
else:
except:
return False;
## @todo the following works but causes trouble below (asserts in main).
#try:
# oFloppy.type = vboxcon.MediumType_Immutable;
#except:
# reporter.errorXcpt('failed to make floppy "%s" immutable' % (sFullName));
# return False;
# Attach it.
try:
else:
except:
else:
return fRc;
"""
Attaches a HD to a VM.
Returns True on success and False on failure. Error information is logged.
"""
else:
return False;
## @todo Implement me!
if enmType is not None: pass
return True;
"""
Configures the VM according to the preferences of the guest type.
"""
try:
except:
return False;
try:
except:
return False;
# get the attributes.
try:
#sFamilyId = oOsType.familyId;
#f64Bit = oOsType.is64Bit;
#cMBHdd = oOsType.recommendedHDD;
else:
else:
eFirmwareType = -1;
except:
return False;
# Do the setting. Continue applying settings on error in case the
# caller ignores the return code
return fRc;
"""
Creates a USB device filter and inserts it into the VM.
Returns True on success.
Returns False on failure (logged).
"""
try:
try:
except:
else:
except:
return fRc;
"""
Gets a guest property value.
Returns the value on success, None on failure (logged).
"""
try:
except:
return None;
return sValue;
"""
Sets a guest property value.
Returns the True on success, False on failure (logged).
"""
try:
except:
return False;
return True;
"""
Deletes a guest property value.
Returns the True on success, False on failure (logged).
"""
try:
else:
except:
return False;
return True;
"""
Sets extra data.
Returns the True on success, False on failure (logged).
"""
try:
except:
return False;
return True;
"""
Gets extra data.
Returns value on success, None on failure.
"""
try:
except:
return None
return sValue
"""
Sets up the teleporter for the VM.
Returns True on success, False on failure (logged).
"""
try:
except:
return False;
return True;
"""
Enables or disables the teleporter of the VM.
Returns True on success, False on failure (logged).
"""
try:
except:
return False;
return True;
def teleport(self, sHostname = 'localhost', uPort = 6500, sPassword = 'password', cMsMaxDowntime = 250):
"""
Wrapper around the IConsole::teleport() method.
Returns a progress object on success, None on failure (logged).
"""
reporter.log2('"%s"::teleport(%s,%s,%s,%s)...' % (self.sName, sHostname, uPort, sPassword, cMsMaxDowntime));
try:
except:
reporter.errorXcpt('IConsole::teleport(%s,%s,%s,%s) failed' % (sHostname, uPort, sPassword, cMsMaxDowntime));
return None;
"""
Gets the IGuestOSType interface for the machine.
return IGuestOSType interface on success, None + errorXcpt on failure.
No exceptions raised.
"""
try:
except:
return None;
try:
except:
return None;
return oOsType;
"""
Changes the OS type.
returns True on success, False + errorXcpt on failure.
No exceptions raised.
"""
try:
except:
return False;
return True;
"""
Sets a paravirtualisation provider.
Returns the True on success, False on failure (logged).
"""
try:
except:
return False;
return True;
#
# IConsole wrappers.
#
"""
Powers off the VM.
Returns True on success.
Returns False on IConsole::powerDown() failure.
Returns None if the progress object returns failure.
"""
try:
except:
if fFudgeOnFailure:
return False;
if rc < 0:
if fFudgeOnFailure:
return None;
# Wait for the VM to really power off or we'll fail to open a new session to it.
"""
Restores the given snapshot.
Returns True on success.
Returns False on IConsole::restoreSnapshot() failure.
Returns None if the progress object returns failure.
"""
try:
except:
if fFudgeOnFailure:
return False;
if rc < 0:
if fFudgeOnFailure:
return None;
"""
Deletes the given snapshot merging the diff image into the base.
Returns True on success.
Returns False on IConsole::deleteSnapshot() failure.
"""
try:
oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'Delete Snapshot %s' % (oSnapshot));
except:
if fFudgeOnFailure:
return False;
return True;
def takeSnapshot(self, sName, sDescription = '', fPause = True, fFudgeOnFailure = True, cMsTimeout = 30 * 1000):
"""
Takes a snapshot with the given name
Returns True on success.
Returns False on IConsole::takeSnapshot() or VM state change failure.
"""
try:
oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'Take Snapshot %s' % (sName));
except:
if fFudgeOnFailure:
return False;
return True;
"""
Returns the snapshot object with the given name
Returns snapshot object on success.
Returns None if there is no snapshot with the given name.
"""
"""
Take screenshot from the given display and save it to specified file.
Returns True on success
Returns False on failure.
"""
try:
else:
except:
return False
return True
#
# Other methods.
#
def getPrimaryIp(self):
"""
Tries to obtain the primary IP address of the guest via the guest
properties.
Returns IP address on success.
Returns empty string on failure.
"""
return sIpAddr;
return '';
"""
Gets the process ID for the direct session unless it's ourselves.
"""
try:
else:
try:
else:
except:
else:
"""
Retrieves and adds the release and debug logs to the test report.
"""
# Add each of the requested release logs to the report.
try:
elif iLog > 0:
else:
except:
else:
# Now for the hardened windows startup log.
try:
except:
else:
# Now for the debug log.
return fRc;
"""
Create an instance of the given ConsoleEventHandlerBase sub-class and
register it.
The new instance is returned on success. None is returned on error.
"""
# We need a console object.
try:
return None;
# Add the base class arguments.
"""
Enables the testing part of the VMMDev.
Returns True on success and False on failure. Error information is logged.
"""
try:
except:
else:
return fRc;
#
# Test eXecution Service methods.
#
def txsConnectViaTcp(self, cMsTimeout = 10*60000, sIpAddr = None, sMacAddr = None, fNatForwardingForTxs = False):
"""
addresses are specified, we'll get the IP from the guest additions.
Returns a TxsConnectTask object on success, None + log on failure.
"""
# If the VM is configured with a NAT interface, connect to local host.
if sIpAddr == None:
try:
except:
return None;
if fUseNatForTxs:
sIpAddr = '127.0.0.1';
# Kick off the task.
try:
except:
oTask = None;
return oTask;
"""
Attempts to connect to a TXS instance.
Returns True if a connection was established, False if not (only grave
failures are logged as errors).
Note! The timeout is more of a guideline...
"""
if oTxsSession is None:
return False;
# Wait for the connect task to time out.
if oRc != oTxsSession:
if oRc is not None:
return False;
# Check the status.
if not oTxsSession.isSuccess():
return False;
return oTxsSession.syncDisconnect();
class TxsConnectTask(TdTaskBase):
"""
Class that takes care of connecting to a VM.
"""
""" Class for looking for IPv4 address changes on interface 0."""
"""Look for IP address."""
self.sNextIpAddr = None;
self.oVBoxEventHandler = None;
self.oTxsSession = None;
# Skip things we don't implement.
if sMacAddr is not None:
if fReversedSetup is True:
else:
#
# If we've got no IP address, register callbacks that listens for
# the primary network adaptor of the VM to set a IPv4 guest prop.
# Note! The order in which things are done here is kind of important.
#
# 0. The caller zaps the property before starting the VM.
#try:
# oSession.delGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
#except:
# reporter.logXcpt();
# 1. Register the callback / event listener object.
self.oVBoxEventHandler = self.oVBox.registerDerivedEventHandler(self.TxsConnectTaskVBoxCallback, dArgs);
# 2. Query the guest properties.
try:
except:
raise;
else:
if sIpAddr is not None:
# end __init__
""" Make sure we deregister the callback. """
return '<%s cMsTimeout=%s, sIpAddr=%s, sNextIpAddr=%s, sMacAddr=%s, fReversedSetup=%s,' \
' oTxsSession=%s oVBoxEventHandler=%s, oVBox=%s>' \
% (TdTaskBase.toString(self), self.cMsTimeout, self.sIpAddr, self.sNextIpAddr, self.sMacAddr, self.fReversedSetup,
def _deregisterEventHandler(self):
"""Deregisters the event handler."""
if self.oVBoxEventHandler is not None:
self.oVBoxEventHandler = None;
return fRc;
"""Called when we get an IP. Will create a TXS session and signal the task."""
if sIpAddr is not None \
and sIpAddr != '':
try:
i = int(s);
if str(i) != s:
raise Exception();
except:
else:
return None;
else:
return None;
"""
Calls txsclient.openTcpSession and switches our task to reflect the
state of the subtask.
"""
if self.oTxsSession is None:
else:
return None;
"""
Called by the TXS session task when it's done.
We'll signal the task completed or retry depending on the result.
"""
# Disassociate ourselves with the session (avoid cyclic ref)
oTxsSession.setTaskOwner(None);
if self.oTxsSession is not None:
if not fSuccess:
self.oTxsSession = None;
else:
# Signal done, or retry?
if fSuccess \
or self.fReversedSetup \
else:
return True;
#
# Public methods
#
"""
Returns the connected TXS session object on success.
Returns None on failure or if the task has not yet completed.
"""
oTxsSession = None;
return oTxsSession;
def cancelTask(self):
""" Cancels the task. """
if not self.fSignalled:
if oTxsSession is not None:
oTxsSession.setTaskOwner(None);
return True;