cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0302
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox Wrapper Classes
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
1c43cacd545be15afb64413d49eccbecff95e759vboxsyncCopyright (C) 2010-2015 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard Python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport array
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport os
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport socket
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport sys
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom common import utils;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testdriver import base;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testdriver import reporter;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testdriver import txsclient;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testdriver import vboxcon;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testdriver import vbox;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testdriver.base import TdTaskBase;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncdef _ControllerNameToBus(sController):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Translate a controller name to a storage bus. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sController == "IDE Controller":
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = vboxcon.StorageBus_IDE;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sController == "SATA Controller":
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = vboxcon.StorageBus_SATA;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sController == "Floppy Controller":
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = vboxcon.StorageBus_Floppy;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sController == "SAS Controller":
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = vboxcon.StorageBus_SAS;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sController == "SCSI Controller":
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = vboxcon.StorageBus_SCSI;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = vboxcon.StorageBus_Null;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return iType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncdef _nameMachineState(eState):
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';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return 'Unknown-%s' % (eState,);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass VirtualBoxWrapper(object): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around the IVirtualBox object that adds some (hopefully) useful
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync utility methods
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The real object can be accessed thru the o member. That said, members can
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync be accessed directly as well.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oVBox, oVBoxMgr, fpApiVer, oTstDrv):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o = oVBox;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBoxMgr = oVBoxMgr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fpApiVer = fpApiVer;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv = oTstDrv;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __getattr__(self, sName):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Try ourselves first.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oAttr = self.__dict__[sName];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # oAttr = dir(self)[sName];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #except AttributeError:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oAttr = getattr(self.o, sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oAttr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Utilities.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def registerDerivedEventHandler(self, oSubClass, dArgs = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Create an instance of the given VirtualBoxEventHandlerBase sub-class
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and register it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The new instance is returned on success. None is returned on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgsCopy = dArgs.copy() if dArgs is not None else dict();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgsCopy['oVBox'] = self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oSubClass.registerDerivedEventHandler(self.oVBoxMgr, self.fpApiVer, oSubClass, dArgsCopy,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o, 'IVirtualBox', 'IVirtualBoxCallback');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def deleteHdByLocation(self, sHdLocation):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oIMedium = self.oVBox.findHardDisk(sHdLocation);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oIMedium = self.oVBox.openMedium(sHdLocation, vboxcon.DeviceType_HardDisk,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vboxcon.AccessMode_ReadWrite, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oIMedium = self.oVBox.openMedium(sHdLocation, vboxcon.DeviceType_HardDisk,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vboxcon.AccessMode_ReadWrite);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oIMedium = self.oVBox.openHardDisk(sHdLocation, vboxcon.AccessMode_ReadOnly, False, "", False, "");
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return reporter.errorXcpt('failed to open hd "%s"' % (sHdLocation));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.deleteHdByMedium(oIMedium)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def deleteHdByMedium(self, oIMedium):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: oProgressCom = oIMedium.deleteStorage();
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 except: return reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.wait();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.logResult();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oProgress.isSuccess();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass ProgressWrapper(TdTaskBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oProgress, oVBoxMgr, oTstDrv, sName):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TdTaskBase.__init__(self, utils.getCallerName());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o = oProgress;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBoxMgr = oVBoxMgr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv = oTstDrv;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sName = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def toString(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return '<%s sName=%s, oProgress=%s >' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (TdTaskBase.toString(self), self.sName, self.o);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # TdTaskBase overrides.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def pollTask(self, fLocked = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.pollTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync This method returns False until the progress object has completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.doQuickApiTest();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o.completed:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def waitForTask(self, cMsTimeout = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.waitForTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Process XPCOM/COM events while waiting.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync msStart = base.timestampMilli();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fState = self.pollTask(False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while not fState:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMsElapsed = base.timestampMilli() - msStart;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cMsElapsed > cMsTimeout:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync break;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMsToWait = cMsTimeout - cMsElapsed;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cMsToWait > 500:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMsToWait = 500;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.waitForCompletion(cMsToWait);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except KeyboardInterrupt: raise;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fState = self.pollTask(False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fState;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Utility methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isSuccess(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Tests if the progress object completed successfully.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure or incomplete.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.isCompleted():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.getResult() >= 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isCompleted(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.pollTask();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isCancelable(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.cancelable.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = self.o.cancelable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def wasCanceled(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.canceled.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = self.o.canceled;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def cancel(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.cancel()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure (logged as error).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.cancel();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getResult(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.resultCode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iRc = self.o.resultCode;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iRc = -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return iRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getErrInfoResultCode(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.errorInfo.resultCode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the string on success, -1 on bad objects (logged as error), and
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync -2 on missing errorInfo object.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iRc = -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oErrInfo = self.o.errorInfo;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oErrInfo is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iRc = -2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iRc = oErrInfo.resultCode;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return iRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getErrInfoText(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around IProgress.errorInfo.text.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the string on success, None on failure. Missing errorInfo is
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync not logged as an error, all other failures are.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sText = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oErrInfo = self.o.errorInfo;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2Xcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oErrInfo is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sText = oErrInfo.text;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sText;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def stringifyErrorInfo(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Formats IProgress.errorInfo into a string.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oErrInfo = self.o.errorInfo;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sErr = 'no error info';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sErr = vbox.stringifyErrorInfo(oErrInfo);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sErr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def stringifyResult(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Stringify the result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.isCompleted():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.wasCanceled():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Canceled, hrc=%s' % (self.sName, vbox.ComError.toString(self.getResult()));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif self.getResult() == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Success' % (self.sName,);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif self.getResult() > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Success (hrc=%s)' % (self.sName, vbox.ComError.toString(self.getResult()));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Failed! %s' % (self.sName, self.stringifyErrorInfo());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRet = 'Progress %s: Not completed yet...' % (self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sRet;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def logResult(self, fIgnoreErrors = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Logs the result. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sText = self.stringifyResult();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.isCompleted() and self.getResult() < 0 \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and fIgnoreErrors is False:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return reporter.error(sText);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return reporter.log(sText);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def waitOnProgress(self, cMsInterval = 1000):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync See vbox.TestDriver.waitOnProgress.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.doQuickApiTest();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.oTstDrv.waitOnProgress(self.o, cMsInterval);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def wait(self, cMsTimeout = 60000, fErrorOnTimeout = True, cMsInterval = 1000):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wait on the progress object for a while.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync msStart = base.timestampMilli();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while True:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.doQuickApiTest();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o.completed:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync break;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return -2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMsElapsed = base.timestampMilli() - msStart;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cMsElapsed > cMsTimeout:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fErrorOnTimeout:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Timing out after waiting for %u s on "%s"' % (cMsTimeout / 1000, self.sName))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.waitForCompletion(cMsInterval);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return -2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync rc = self.o.resultCode;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync rc = -2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return rc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def waitForOperation(self, iOperation, cMsTimeout = 60000, fErrorOnTimeout = True, cMsInterval = 1000, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fIgnoreErrors = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wait for the completion of a operation.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Negative iOperation values are relative to operationCount (this
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync property may changed at runtime).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync msStart = base.timestampMilli();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while True:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.doQuickApiTest();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iCurrentOperation = self.o.operation;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOperations = self.o.operationCount;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iOperation >= 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iRealOperation = iOperation;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iRealOperation = cOperations + iOperation;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iCurrentOperation > iRealOperation:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iCurrentOperation == iRealOperation \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and iRealOperation >= cOperations - 1 \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.o.completed:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o.resultCode < 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.logResult(fIgnoreErrors);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return -3;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fIgnoreErrors:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return -2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMsElapsed = base.timestampMilli() - msStart;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cMsElapsed > cMsTimeout:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fErrorOnTimeout:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fIgnoreErrors:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Timing out after waiting for %u s on "%s" operation %d' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (cMsTimeout / 1000, self.sName, iOperation))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Timing out after waiting for %u s on "%s" operation %d' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (cMsTimeout / 1000, self.sName, iOperation))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.waitForOperationCompletion(iRealOperation, cMsInterval);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fIgnoreErrors:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt(self.sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return -2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Not reached.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def doQuickApiTest(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Queries everything that is stable and easy to get at and checks that
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync they don't throw errors.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if True:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iPct = self.o.operationPercent;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sDesc = self.o.description;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fCancelable = self.o.cancelable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cSecsRemain = self.o.timeRemaining;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fCanceled = self.o.canceled;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fCompleted = self.o.completed;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iOp = self.o.operation;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOps = self.o.operationCount;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iOpPct = self.o.operationPercent;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sOpDesc = self.o.operationDescription;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('%s: %s' % (self.sName, self.o,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
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 _ = cOps; _ = iOpPct; _ = sOpDesc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass SessionWrapper(TdTaskBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around a machine session. The real session object can be accessed
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync thru the o member (short is good, right :-).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oSession, oVM, oVBox, oVBoxMgr, oTstDrv, fRemoteSession, sFallbackName = None, sLogFile = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initializes the session wrapper.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TdTaskBase.__init__(self, utils.getCallerName());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o = oSession;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBox = oVBox;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBoxMgr = oVBoxMgr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVM = oVM; # Not the session machine. Useful backdoor...
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv = oTstDrv;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fpApiVer = oTstDrv.fpApiVer;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fRemoteSession = fRemoteSession;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sLogFile = sLogFile;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oConsoleEventHandler = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uPid = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sName = oSession.machine.name;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sFallbackName is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sName = sFallbackName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: self.sName = str(oSession.machine);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: self.sName = 'is-this-vm-already-off'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sUuid = oSession.machine.id;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sUuid = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Try cache the SessionPID.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.getPid();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __del__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Destructor that makes sure the callbacks are deregistered and
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync that the session is closed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oConsoleEventHandler is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oConsoleEventHandler.unregister();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oConsoleEventHandler = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.close();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('close session %s' % (self.o));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TdTaskBase.__del__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def toString(self):
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 self.o, self.oConsoleEventHandler, self.oVM,);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __str__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.toString();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # TdTaskBase overrides.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __pollTask(self):
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 try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eState = self.o.machine.state;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except Exception, oXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_UNEXPECTED):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Switch
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Running:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Paused:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Teleporting:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_LiveSnapshotting:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Starting:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Stopping:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Saving:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_Restoring:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_TeleportingPausedVM:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_TeleportingIn:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # *Beeep* fudge!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer < 3.2 \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and eState == vboxcon.MachineState_PoweredOff \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.getAgeAsMs() < 3000:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('SessionWrapper::pollTask: eState=%s' % (eState));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def pollTask(self, fLocked = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.pollTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync This method returns False while the VM is online and running normally.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = self.__pollTask();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # HACK ALERT: Lazily try registering the console event handler if
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # we're not ready.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not fRc and self.oConsoleEventHandler is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.registerEventHandlerForTask();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # HACK ALERT: Lazily try get the PID and add it to the PID file.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not fRc and self.uPid is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.getPid();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def waitForTask(self, cMsTimeout = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Overrides TdTaskBase.waitForTask().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Process XPCOM/COM events while waiting.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync msStart = base.timestampMilli();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fState = self.pollTask(False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while not fState:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMsElapsed = base.timestampMilli() - msStart;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cMsElapsed > cMsTimeout:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync break;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: self.oVBoxMgr.waitForEvents(cMsTimeout - cMsElapsed);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except KeyboardInterrupt: raise;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fState = self.pollTask(False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fState;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setTaskOwner(self, oOwner):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The testdriver must not add the task too early for this to work!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oOwner is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.registerEventHandlerForTask()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TdTaskBase.setTaskOwner(self, oOwner);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Task helpers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def registerEventHandlerForTask(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Registers the console event handlers for working the task state.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oConsoleEventHandler is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oConsoleEventHandler = self.registerDerivedEventHandler(vbox.SessionConsoleEventHandler, {}, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.oConsoleEventHandler is not None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def assertPoweredOff(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eState = self.oVM.state;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except Exception:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eState == vboxcon.MachineState_PoweredOff:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Expected machine state "PoweredOff", machine is in the "%s" state instead.'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (_nameMachineState(eState),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getMachineStateWithName(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eState = self.oVM.state;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (None, '[error getting state: %s]' % (self.oVBoxMgr.xcptToString(),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (eState, _nameMachineState(eState));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def reportPrematureTermination(self, sPrefix = ''):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reports a premature virtual machine termination.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False to facilitate simpler error paths.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error(sPrefix + 'The virtual machine terminated prematurely!!');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (enmState, sStateNm) = self.getMachineStateWithName();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error(sPrefix + 'Machine state: %s' % (sStateNm,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if enmState is not None \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and enmState == vboxcon.MachineState_Aborted \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.uPid is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Look for process crash info.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addCrashFile(sLogFile, fBinary):
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # ISession / IMachine / ISomethingOrAnother wrappers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def close(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Closes the session if it's open and removes it from the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.TestDriver.aoRemoteSessions list.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns success indicator.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Get the pid in case we need to kill the process later on.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.getPid();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Try close it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer < 3.3:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.close();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.unlockMachine();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except KeyboardInterrupt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
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 except: fIgnore = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not fIgnore:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('ISession::unlockMachine failed on %s' % (self.o));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Remove it from the remote session list if applicable (not 100% clean).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fRc and self.fRemoteSession:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self in self.oTstDrv.aoRemoteSessions:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('SessionWrapper::close: Removing myself from oTstDrv.aoRemoteSessions');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.aoRemoteSessions.remove(self)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.uPid is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.pidFileRemove(self.uPid);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def saveSettings(self, fClose = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Saves the settings and optionally closes the session.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns success indicator.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.saveSettings();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('saveSettings failed on %s' % (self.o));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fClose:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.close();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def discardSettings(self, fClose = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Discards the settings and optionally closes the session.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.discardSettings();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('discardSettings failed on %s' % (self.o));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fClose:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.close();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableVirtEx(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables AMD-V/VT-x.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Enable/disable it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setHWVirtExProperty(vboxcon.HWVirtExPropertyType_Enabled, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HWVirtExPropertyType_Enabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HWVirtExPropertyType_Enabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Force/unforce it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fRc and hasattr(vboxcon, 'HWVirtExPropertyType_Force'):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setHWVirtExProperty(vboxcon.HWVirtExPropertyType_Force, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HWVirtExPropertyType_Force=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HWVirtExPropertyType_Force=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Warning! vboxcon has no HWVirtExPropertyType_Force attribute.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo Modify CFGM to do the same for old VBox versions?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableNestedPaging(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables nested paging..
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo Add/remove force CFGM thing, we don't want fallback logic when testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setHWVirtExProperty(vboxcon.HWVirtExPropertyType_NestedPaging, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HWVirtExPropertyType_NestedPaging=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HWVirtExPropertyType_NestedPaging=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableLongMode(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables LongMode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Supported.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer < 4.2 or not hasattr(vboxcon, 'HWVirtExPropertyType_LongMode'):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Enable/disable it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setCPUProperty(vboxcon.CPUPropertyType_LongMode, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set CPUPropertyType_LongMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set CPUPropertyType_LongMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enablePae(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables PAE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 3.2: # great, ain't it?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setCPUProperty(vboxcon.CPUPropertyType_PAE, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setCpuProperty(vboxcon.CpuPropertyType_PAE, fEnable);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set CPUPropertyType_PAE=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set CPUPropertyType_PAE=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableIoApic(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the IO-APIC
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.IOAPICEnabled = fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set BIOSSettings.IOAPICEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set BIOSSettings.IOAPICEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableHpet(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the HPET
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.HPETEnabled = fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.hpetEnabled = fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set HpetEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set HpetEnabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableUsbHid(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the USB HID
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fEnable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.3:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cOhciCtls == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.AddUSBController('OHCI', vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.usbController.enabled = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHIDType = vboxcon.PointingHIDType_ComboMouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHIDType = vboxcon.KeyboardHIDType_ComboKeyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHidType = vboxcon.PointingHidType_ComboMouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHidType = vboxcon.KeyboardHidType_ComboKeyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHIDType = vboxcon.PointingHIDType_PS2Mouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHIDType = vboxcon.KeyboardHIDType_PS2Keyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.pointingHidType = vboxcon.PointingHidType_PS2Mouse;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.keyboardHidType = vboxcon.KeyboardHidType_PS2Keyboard;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to change UsbHid to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('changed UsbHid to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableUsbOhci(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the USB OHCI controller
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fEnable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.3:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cOhciCtls == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.AddUSBController('OHCI', vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.usbController.enabled = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.3:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cOhciCtls == 1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.RemoveUSBController('OHCI');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.usbController.enabled = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to change OHCI to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('changed OHCI to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableUsbEhci(self, fEnable):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fEnable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.3:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cOhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cOhciCtls == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.addUSBController('OHCI', vboxcon.USBControllerType_OHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cEhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_EHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cEhciCtls == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.addUSBController('EHCI', vboxcon.USBControllerType_EHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.usbController.enabled = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.usbController.enabledEHCI = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.3:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync cEhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_EHCI);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cEhciCtls == 1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.RemoveUSBController('EHCI');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.usbController.enabledEHCI = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to change EHCI to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('changed EHCI to %s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync def enableUsbXhci(self, fEnable):
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync """
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync Enables or disables the USB XHCI controller. Error information is logged.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync """
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync fRc = True;
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync try:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync if fEnable:
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync cXhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_XHCI);
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync if cXhciCtls == 0:
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync self.o.machine.addUSBController('XHCI', vboxcon.USBControllerType_XHCI);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync else:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync cXhciCtls = self.o.machine.getUSBControllerCountByType(vboxcon.USBControllerType_XHCI);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync if cXhciCtls == 1:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync self.o.machine.RemoveUSBController('XHCI');
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync except:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.errorXcpt('failed to change XHCI to %s for "%s"' % (fEnable, self.sName));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync fRc = False;
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync else:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('changed XHCI to %s for "%s"' % (fEnable, self.sName));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync self.oTstDrv.processPendingEvents();
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setFirmwareType(self, eType):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the firmware type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.firmwareType = eType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set firmwareType=%s for "%s"' % (eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set firmwareType=%s for "%s"' % (eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupBootLogo(self, fEnable, cMsLogoDisplay = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets up the boot logo. fEnable toggles the fade and boot menu
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync settings as well as the mode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.logoFadeIn = not fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.logoFadeOut = not fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.logoDisplayTime = cMsLogoDisplay;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fEnable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.bootMenuMode = vboxcon.BIOSBootMenuMode_Disabled;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.BIOSSettings.bootMenuMode = vboxcon.BIOSBootMenuMode_MessageAndMenu;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set logoFadeIn/logoFadeOut/bootMenuMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set logoFadeIn/logoFadeOut/bootMenuMode=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupVrdp(self, fEnable, uPort = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Configures VRDP.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.VRDEServer.enabled = fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.VRDPServer.enabled = fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set VRDEServer::enabled=%s for "%s"' % (fEnable, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if uPort is not None and fRc:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.VRDEServer.setVRDEProperty("TCP/Ports", str(uPort));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.VRDPServer.ports = str(uPort);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set VRDEServer::ports=%s for "%s"' % (uPort, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fRc:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set VRDEServer.enabled/ports=%s/%s for "%s"' % (fEnable, uPort, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getNicDriverNameFromType(self, eNicType):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Helper that translate the adapter type into a driver name.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eNicType == vboxcon.NetworkAdapterType_Am79C970A \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eNicType == vboxcon.NetworkAdapterType_Am79C973:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sName = 'pcnet';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eNicType == vboxcon.NetworkAdapterType_I82540EM \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eNicType == vboxcon.NetworkAdapterType_I82543GC \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or eNicType == vboxcon.NetworkAdapterType_I82545EM:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sName = 'e1000';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eNicType == vboxcon.NetworkAdapterType_Virtio:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sName = 'virtio-net';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Unknown adapter type "%s" (VM: "%s")' % (eNicType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sName = 'pcnet';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupNatForwardingForTxs(self, iNic = 0, iHostPort = 5042):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets up NAT forwarding for port 5042 if applicable, cleans up if not.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic = self.o.machine.getNetworkAdapter(iNic);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Nuke the old setup for all possible adapter types (in case we're
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # called after it changed).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for sName in ('pcnet', 'e1000', 'virtio-net'):
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 try:
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 except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Set up port forwarding if NAT attachment.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eAttType = oNic.attachmentType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachmentType on %s failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttType != vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eNicType = oNic.adapterType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fTraceEnabled = oNic.traceEnabled;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachmentType/traceEnabled on %s failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNatEngine = oNic.NATEngine;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNatEngine = oNic.natDriver;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Failed to get INATEngine data on "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: oNatEngine.removeRedirect('txs');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNatEngine.addRedirect('txs', vboxcon.NATProtocol_TCP, '127.0.0.1', '%s' % (iHostPort), '', '5042');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Failed to add a addRedirect redirect on "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sName = self.getNicDriverNameFromType(eNicType);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fTraceEnabled:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sConfig = 'VBoxInternal/Devices/%s/%u/LUN#0/AttachedDriver/Config' % (sName, iNic)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sConfig = 'VBoxInternal/Devices/%s/%u/LUN#0/Config' % (sName, iNic)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
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 except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Failed to set NAT extra data on "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setNicType(self, eType, iNic = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the NIC type of the specified NIC.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic = self.o.machine.getNetworkAdapter(iNic);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.adapterType = eType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set NIC type on slot %s to %s for VM "%s"' % (iNic, eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setupNatForwardingForTxs(iNic):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set NIC type on slot %s to %s for VM "%s"' % (iNic, eType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setNicTraceEnabled(self, fTraceEnabled, sTraceFile, iNic = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the NIC trace enabled flag and file path.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic = self.o.machine.getNetworkAdapter(iNic);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.traceEnabled = fTraceEnabled;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.traceFile = sTraceFile;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set NIC trace flag on slot %s to %s for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (iNic, fTraceEnabled, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setupNatForwardingForTxs(iNic):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set NIC trace on slot %s to "%s" (path "%s") for VM "%s"' %
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (iNic, fTraceEnabled, sTraceFile, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getDefaultNicName(self, eAttachmentType):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Return the default network / interface name for the NIC attachment type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = '';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttachmentType == vboxcon.NetworkAttachmentType_Bridged:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oTstDrv.sDefBridgedNic is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = self.oTstDrv.sDefBridgedNic;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = 'eth0';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoHostNics = self.oVBoxMgr.getArray(self.oVBox.host, 'networkInterfaces');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oHostNic in aoHostNics:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oHostNic.interfaceType == vboxcon.HostNetworkInterfaceType_Bridged \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oHostNic.status == vboxcon.HostNetworkInterfaceStatus_Up:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = oHostNic.name;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync break;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoHostNics = self.oVBoxMgr.getArray(self.oVBox.host, 'networkInterfaces');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oHostNic in aoHostNics:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oHostNic.interfaceType == vboxcon.HostNetworkInterfaceType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oHostNic.status == vboxcon.HostNetworkInterfaceStatus_Up:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = oHostNic.name;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync break;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sRetName == '':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = oHostNic.name;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sRetName == '':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = 'HostInterfaceNetwork-vboxnet0';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Internal:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = 'VBoxTest';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sRetName = '';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('eAttachmentType=%s is not known' % (eAttachmentType));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sRetName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setNicAttachment(self, eAttachmentType, sName = None, iNic = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the attachment type of the specified NIC.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic = self.o.machine.getNetworkAdapter(iNic);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttachmentType is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.attachmentType = eAttachmentType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if eAttachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.attachToNAT();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Bridged:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.attachToBridgedInterface();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Internal:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.attachToInternalNetwork();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.attachToHostOnlyInterface();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise base.GenError("eAttachmentType=%s is invalid" % (eAttachmentType));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the attachment type on slot %s to %s for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (iNic, eAttachmentType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eAttachmentType = oNic.attachmentType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to get the attachment type on slot %s for VM "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sName is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Resolve the special 'default' name.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sName == 'default':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sName = self.getDefaultNicName(eAttachmentType);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The name translate to different attributes depending on the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # attachment type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
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 try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.bridgedInterface = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.hostInterface = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the hostInterface property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (iNic, sName, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_HostOnly:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.hostOnlyInterface = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.hostInterface = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the internalNetwork property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (iNic, sName, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_Internal:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.internalNetwork = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the internalNetwork property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (iNic, sName, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif eAttachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.NATNetwork = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the NATNetwork property on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (iNic, sName, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setupNatForwardingForTxs(iNic):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set NIC type on slot %s to %s for VM "%s"' % (iNic, eAttachmentType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setNicMacAddress(self, sMacAddr, iNic = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets the MAC address of the specified NIC.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Resolve missing MAC address prefix
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cchMacAddr = len(sMacAddr) > 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cchMacAddr > 0 and cchMacAddr < 12:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sHostName = '';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sHostName = socket.getfqdn();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sys.platform == 'win32' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and sHostName.endswith('.sun.com') \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and not sHostName.endswith('.germany.sun.com'):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sHostName = socket.gethostname(); # klugde.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync abHostIP = socket.inet_aton(socket.gethostbyname(sHostName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to determin the host IP for "%s".' % (sHostName,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync abHostIP = array.array('B', (0x80, 0x86, 0x00, 0x00)).tostring();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sDefaultMac = '%02X%02X%02X%02X%02X%02X' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (0x02, ord(abHostIP[0]), ord(abHostIP[1]), ord(abHostIP[2]), ord(abHostIP[3]), iNic);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sMacAddr = sDefaultMac[0:(11 - cchMacAddr)] + sMacAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Get the NIC object and try set it address.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic = self.o.machine.getNetworkAdapter(iNic);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic.MACAddress = sMacAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the MAC address on slot %s to "%s" for VM "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (iNic, sMacAddr, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set MAC address on slot %s to %s for VM "%s"' % (iNic, sMacAddr, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setRamSize(self, cMB):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set the RAM size of the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.memorySize = cMB;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the RAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set the RAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setVRamSize(self, cMB):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set the RAM size of the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.VRAMSize = cMB;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the VRAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set the VRAM size of "%s" to %s' % (self.sName, cMB));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setCpuCount(self, cCpus):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set the number of CPUs.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.CPUCount = cCpus;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the CPU count of "%s" to %s' % (self.sName, cCpus));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set the CPU count of "%s" to %s' % (self.sName, cCpus));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def ensureControllerAttached(self, sController):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Makes sure the specified controller is attached to the VM, attaching it
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if necessary.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.getStorageControllerByName(sController);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = _ControllerNameToBus(sController);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.addStorageController(sController, iType);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('added storage controller "%s" (type %s) to %s' % (sController, iType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('addStorageController("%s",%s) failed on "%s"' % (sController, iType, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync finally:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setStorageControllerPortCount(self, sController, iPortCount):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Set maximum ports count for storage controller
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl = self.o.machine.getStorageControllerByName(sController)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl.portCount = iPortCount
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set controller "%s" port count to value %d' % (sController, iPortCount))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('unable to set storage controller "%s" ports count to %d' % (sController, iPortCount))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setBootOrder(self, iPosition, eType):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setBootOrder(iPosition, eType)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return reporter.errorXcpt('Unable to set boot order.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Set boot order [%d] for device %s' % (iPosition, str(eType)))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setStorageControllerType(self, eType, sController = "IDE Controller"):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Similar to ensureControllerAttached, except it will change the type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl = self.o.machine.getStorageControllerByName(sController);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iType = _ControllerNameToBus(sController);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl = self.o.machine.addStorageController(sController, iType);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('added storage controller "%s" (type %s) to %s' % (sController, iType, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('addStorageController("%s",%s) failed on "%s"' % (sController, iType, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCtl.controllerType = eType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set controller type of "%s" on "%s" to %s' % (sController, self.sName, eType) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set controller type of "%s" on "%s" to %s' % (sController, self.sName, eType) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def attachDvd(self, sImage = None, sController = "IDE Controller", iPort = 1, iDevice = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 """
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.ensureControllerAttached(sController):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Find/register the image if specified.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oImage = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sImageUuid = "";
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sImage is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sFullName = self.oTstDrv.getFullResourceName(sImage)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oImage = self.oVBox.findDVDImage(sFullName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oImage = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_DVD, vboxcon.AccessMode_ReadOnly, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oImage = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_DVD, vboxcon.AccessMode_ReadOnly);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oImage = self.oVBox.openDVDImage(sFullName, "");
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except vbox.ComException, oXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oXcpt.errno != -1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open DVD image "%s" xxx' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open DVD image "%s" yyy' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open DVD image "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sImageUuid = oImage.id;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to get the UUID of "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach the DVD.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_DVD, oImage);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_DVD, sImageUuid);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,HardDisk,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, sImageUuid, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached DVD to %s, image="%s"' % (self.sName, sImage));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def attachHd(self, sHd, sController = "IDE Controller", iPort = 0, iDevice = 0, fImmutable = True, fForceResource = True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attaches a HD to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.ensureControllerAttached(sController):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Find the HD, registering it if necessary (as immutable).
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync if fForceResource:
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync sFullName = self.oTstDrv.getFullResourceName(sHd);
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync else:
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync sFullName = sHd;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.oVBox.findHardDisk(sFullName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_HardDisk, vboxcon.AccessMode_ReadOnly, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_HardDisk, vboxcon.AccessMode_ReadOnly);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.oVBox.openHardDisk(sFullName, vboxcon.AccessMode_ReadOnly, False, "", False, "");
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open hd "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fImmutable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd.type = vboxcon.MediumType_Immutable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd.type = vboxcon.MediumType_Normal;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fImmutable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" immutable' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" normal' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd.id);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,HardDisk,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, oHd.id, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached "%s" to %s' % (sHd, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def createBaseHd(self, sHd, sFmt = "VDI", cb = 10*1024*1024*1024):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Creates a base HD.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Returns Medium object on success and None on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
580e040eb04ce04ec23c4a2a32ee89445bedcc21vboxsync if self.fpApiVer >= 5.0:
1c43cacd545be15afb64413d49eccbecff95e759vboxsync oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
1c43cacd545be15afb64413d49eccbecff95e759vboxsync else:
1c43cacd545be15afb64413d49eccbecff95e759vboxsync oHd = self.oVBox.createHardDisk(sFmt, sHd);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgressXpcom = oHd.createBaseStorage(cb, (vboxcon.MediumVariant_Standard, ))
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create base disk %s' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.wait();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.logResult();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync reporter.errorXcpt('failed to create base hd "%s"' % (sHd));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oHd = None
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync return oHd;
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def createDiffHd(self, oParentHd, sHd, sFmt = "VDI"):
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync """
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Creates a differencing HD.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Returns Medium object on success and None on failure. Error information is logged.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync """
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync try:
580e040eb04ce04ec23c4a2a32ee89445bedcc21vboxsync if self.fpApiVer >= 5.0:
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync else:
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oHd = self.oVBox.createHardDisk(sFmt, sHd);
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgressXpcom = oParentHd.createDiffStorage(oHd, (vboxcon.MediumVariant_Standard, ))
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create diff disk %s' % (sHd));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgress.wait();
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oProgress.logResult();
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync except:
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync reporter.errorXcpt('failed to create diff hd "%s"' % (sHd));
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oHd = None
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync return oHd;
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync def createAndAttachHd(self, sHd, sFmt = "VDI", sController = "IDE Controller", cb = 10*1024*1024*1024, \
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync iPort = 0, iDevice = 0, fImmutable = True):
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync """
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Creates and attaches a HD to a VM.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync Returns True on success and False on failure. Error information is logged.
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync """
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync if not self.ensureControllerAttached(sController):
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync return False;
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync oHd = self.createBaseHd(sHd, sFmt, cb)
f494a0572bb12f7671e0adf39f9a4aec3307b9dcvboxsync if oHd is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fImmutable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd.type = vboxcon.MediumType_Immutable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd.type = vboxcon.MediumType_Normal;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fImmutable:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" immutable' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set hd "%s" normal' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fRc is True:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_HardDisk, oHd.id);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,HardDisk,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, oHd.id, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached "%s" to %s' % (sHd, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Delete disk in case of an error
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fRc is False:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgressCom = oHd.deleteStorage();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('deleteStorage() for disk %s failed' % (sHd,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'delete disk %s' % (sHd));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.wait();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.logResult();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def detachHd(self, sController = "IDE Controller", iPort = 0, iDevice = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Detaches a HD, if attached, and returns a reference to it (IMedium).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync In order to delete the detached medium, the caller must first save
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync the changes made in this session.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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 """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # What's attached?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oHd = self.o.machine.getMedium(sController, iPort, iDevice);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oVBoxMgr.xcptIsOurXcptKind() \
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 % (iPort, iDevice, sController)), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Detach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.detachDevice(sController, iPort, iDevice);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
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 return (True, oHd);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def attachFloppy(self, sFloppy, sController = "Floppy Controller", iPort = 0, iDevice = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attaches a floppy image to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.ensureControllerAttached(sController):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Find the floppy image, registering it if necessary (as immutable).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sFullName = self.oTstDrv.getFullResourceName(sFloppy);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFloppy = self.oVBox.findFloppyImage(sFullName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFloppy = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_Floppy, vboxcon.AccessMode_ReadOnly, False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFloppy = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_Floppy, vboxcon.AccessMode_ReadOnly);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFloppy = self.oVBox.openFloppyImage(sFullName, "");
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to open floppy "%s"' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo the following works but causes trouble below (asserts in main).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # oFloppy.type = vboxcon.MediumType_Immutable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # reporter.errorXcpt('failed to make floppy "%s" immutable' % (sFullName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_Floppy, oFloppy);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.attachDevice(sController, iPort, iDevice, vboxcon.DeviceType_Floppy, oFloppy.id);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('attachDevice("%s",%s,%s,Floppy,"%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sController, iPort, iDevice, oFloppy.id, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('attached "%s" to %s' % (sFloppy, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupNic(self, sType, sXXX):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attaches a HD to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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 else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Invalid NIC type: "%s" (sXXX=%s)' % (sType, sXXX));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo Implement me!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if enmType is not None: pass
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupPreferredConfig(self): # pylint: disable=R0914
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Configures the VM according to the preferences of the guest type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sOsTypeId = self.o.machine.OSTypeId;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to obtain the OSTypeId for "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oOsType = self.oVBox.getGuestOSType(sOsTypeId);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getGuestOSType("%s") failed for "%s"' % (sOsTypeId, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # get the attributes.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #sFamilyId = oOsType.familyId;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #f64Bit = oOsType.is64Bit;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fIoApic = oOsType.recommendedIOAPIC;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fVirtEx = oOsType.recommendedVirtEx;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMBRam = oOsType.recommendedRAM;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMBVRam = oOsType.recommendedVRAM;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #cMBHdd = oOsType.recommendedHDD;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eNicType = oOsType.adapterType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 3.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fPae = oOsType.recommendedPAE;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fUsbHid = oOsType.recommendedUSBHID;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fHpet = oOsType.recommendedHPET;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eStorCtlType = oOsType.recommendedHDStorageController;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fPae = oOsType.recommendedPae;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fUsbHid = oOsType.recommendedUsbHid;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fHpet = oOsType.recommendedHpet;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eStorCtlType = oOsType.recommendedHdStorageController;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eFirmwareType = oOsType.recommendedFirmware;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fPae = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fUsbHid = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fHpet = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eFirmwareType = -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eStorCtlType = vboxcon.StorageControllerType_PIIX4;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('exception reading IGuestOSType(%s) attribute' % (sOsTypeId));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Do the setting. Continue applying settings on error in case the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # caller ignores the return code
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.enableIoApic(fIoApic): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.enableVirtEx(fVirtEx): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.enablePae(fPae): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setRamSize(cMBRam): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setVRamSize(cMBVRam): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setNicType(eNicType, 0): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 3.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.setFirmwareType(eFirmwareType): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.enableUsbHid(fUsbHid): fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.enableHpet(fHpet): 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 fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addUsbDeviceFilter(self, sName, sVendorId, sProductId):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Creates a USB device filter and inserts it into the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync usbDevFilter = self.o.machine.USBDeviceFilters.createDeviceFilter(sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync usbDevFilter.active = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync usbDevFilter.vendorId = sVendorId;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync usbDevFilter.productId = sProductId;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.USBDeviceFilters.insertDeviceFilter(0, usbDevFilter);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('insertDeviceFilter(%s) failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (0, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('inserted USB device filter "%s" to %s' % (sName, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('createDeviceFilter("%s") failed on "%s"' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (sName, self.sName) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getGuestPropertyValue(self, sName):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets a guest property value.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the value on success, None on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sValue = self.o.machine.getGuestPropertyValue(sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::getGuestPropertyValue("%s") failed' % (sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sValue;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setGuestPropertyValue(self, sName, sValue):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets a guest property value.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setGuestPropertyValue(sName, sValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::setGuestPropertyValue("%s","%s") failed' % (sName, sValue));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def delGuestPropertyValue(self, sName):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Deletes a guest property value.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oMachine = self.o.machine;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oMachine.deleteGuestProperty(sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oMachine.setGuestPropertyValue(sName, '');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Unable to delete guest property "%s"' % (sName,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setExtraData(self, sKey, sValue):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets extra data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData(sKey, sValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::setExtraData("%s","%s") failed' % (sKey, sValue));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getExtraData(self, sKey):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets extra data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns value on success, None on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sValue = self.o.machine.getExtraData(sKey)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::setExtraData("%s","%s") failed' % (sKey, sValue))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sValue
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setupTeleporter(self, fEnabled=True, uPort = 6500, sAddress = '', sPassword = ''):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets up the teleporter for the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.teleporterAddress = sAddress;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.teleporterPort = uPort;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.teleporterPassword = sPassword;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.teleporterEnabled = fEnabled;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('setupTeleporter(%s, %s, %s, %s)' % (fEnabled, sPassword, uPort, sAddress));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableTeleporter(self, fEnable=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables or disables the teleporter of the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.teleporterEnabled = fEnable;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::teleporterEnabled=%s failed' % (fEnable));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def teleport(self, sHostname = 'localhost', uPort = 6500, sPassword = 'password', cMsMaxDowntime = 250):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Wrapper around the IConsole::teleport() method.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a progress object on success, None on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('"%s"::teleport(%s,%s,%s,%s)...' % (self.sName, sHostname, uPort, sPassword, cMsMaxDowntime));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = self.o.console.teleport(sHostname, uPort, sPassword, cMsMaxDowntime)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getOsType(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the IGuestOSType interface for the machine.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return IGuestOSType interface on success, None + errorXcpt on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync No exceptions raised.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sOsTypeId = self.o.machine.OSTypeId;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to obtain the OSTypeId for "%s"' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oOsType = self.oVBox.getGuestOSType(sOsTypeId);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('getGuestOSType("%s") failed for "%s"' % (sOsTypeId, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oOsType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setOsType(self, sNewTypeId):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Changes the OS type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync returns True on success, False + errorXcpt on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync No exceptions raised.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.OSTypeId = sNewTypeId;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('failed to set the OSTypeId for "%s" to "%s"' % (self.sName, sNewTypeId));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setParavirtProvider(self, iProvider):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Sets a paravirtualisation provider.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the True on success, False on failure (logged).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.paravirtProvider = iProvider
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('Unable to set paravirtualisation provider "%s"' % (iProvider,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # IConsole wrappers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def powerOff(self, fFudgeOnFailure = True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Powers off the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False on IConsole::powerDown() failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None if the progress object returns failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = self.o.console.powerDown();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt('IConsole::powerDown failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fFudgeOnFailure:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.waitForTask(1000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync rc = self.oTstDrv.waitOnProgress(oProgress);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if rc < 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.close();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fFudgeOnFailure:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.reportError(oProgress, 'powerDown for "%s" failed' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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 return self.waitForTask(30 * 1000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def restoreSnapshot(self, oSnapshot, fFudgeOnFailure = True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Restores the given snapshot.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync Returns False on IMachine::restoreSnapshot() failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None if the progress object returns failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync if self.fpApiVer >= 5.0:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgress = self.o.machine.restoreSnapshot(oSnapshot);
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync else:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgress = self.o.console.restoreSnapshot(oSnapshot);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync reporter.logXcpt('IMachine::restoreSnapshot failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fFudgeOnFailure:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.waitForTask(1000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync rc = self.oTstDrv.waitOnProgress(oProgress);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if rc < 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.close();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fFudgeOnFailure:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.reportError(oProgress, 'restoreSnapshot for "%s" failed' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.waitForTask(30 * 1000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def deleteSnapshot(self, oSnapshot, fFudgeOnFailure = True, cMsTimeout = 30 * 1000):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Deletes the given snapshot merging the diff image into the base.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync Returns False on IMachine::deleteSnapshot() failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync if self.fpApiVer >= 5.0:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.machine.deleteSnapshot(oSnapshot);
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync else:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.console.deleteSnapshot(oSnapshot);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'Delete Snapshot %s' % (oSnapshot));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.wait(cMsTimeout);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.logResult();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync reporter.logXcpt('IMachine::deleteSnapshot failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fFudgeOnFailure:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.waitForTask(1000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def takeSnapshot(self, sName, sDescription = '', fPause = True, fFudgeOnFailure = True, cMsTimeout = 30 * 1000):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Takes a snapshot with the given name
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success.
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync Returns False on IMachine::takeSnapshot() or VM state change failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fPause is True \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.oVM.state is vboxcon.MachineState_Running:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.console.pause();
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync if self.fpApiVer >= 5.0:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.machine.takeSnapshot(sName, sDescription);
de8abf39b0667a2f317f00d5b39a0e65599dc1e6vboxsync else:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync oProgressCom = self.o.console.takeSnapshot(sName, sDescription);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress = ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oTstDrv, 'Take Snapshot %s' % (sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.wait(cMsTimeout);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oProgress.logResult();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
7ffe7543b32c5dfd3aede1d7f2c1332c7508f6ccvboxsync reporter.logXcpt('IMachine::takeSnapshot failed on %s' % (self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fFudgeOnFailure:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.waitOnDirectSessionClose(self.oVM, 5000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.waitForTask(1000); # fudge
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fPause is True \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.oVM.state is vboxcon.MachineState_Paused:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.console.resume();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def findSnapshot(self, sName):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the snapshot object with the given name
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns snapshot object on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None if there is no snapshot with the given name.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.oVM.findSnapshot(sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def takeScreenshot(self, sFilename, iScreenId=0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Take screenshot from the given display and save it to specified file.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns False on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
580e040eb04ce04ec23c4a2a32ee89445bedcc21vboxsync if self.fpApiVer >= 5.0:
44a028033f962688c3d776dfd1c8467e3d6774a3vboxsync iWidth, iHeight, _, _, _, _ = self.o.console.display.getScreenResolution(iScreenId)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aPngData = self.o.console.display.takeScreenShotToArray(iScreenId, iWidth, iHeight,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vboxcon.BitmapFormat_PNG)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
44a028033f962688c3d776dfd1c8467e3d6774a3vboxsync iWidth, iHeight, _, _, _ = self.o.console.display.getScreenResolution(iScreenId)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aPngData = self.o.console.display.takeScreenShotPNGToArray(iScreenId, iWidth, iHeight)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt("Unable to take screenshot")
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFile = open(sFilename, 'wb')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFile.write(aPngData)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFile.close()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Other methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getPrimaryIp(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Tries to obtain the primary IP address of the guest via the guest
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync properties.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns IP address on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns empty string on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = self.getGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if vbox.isIpAddrValid(sIpAddr):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return sIpAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return '';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getPid(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the process ID for the direct session unless it's ourselves.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.uPid is None and self.o is not None and self.fRemoteSession:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uPid = self.o.machine.sessionPID;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uPid = self.o.machine.sessionPid;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if uPid != os.getpid() and uPid != 0xffffffff:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uPid = uPid;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except Exception, oXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if vbox.ComError.equal(oXcpt, vbox.ComError.E_UNEXPECTED):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 4.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uPid = self.oVM.sessionPID;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uPid = self.oVM.sessionPid;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if uPid != os.getpid() and uPid != 0xffffffff:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uPid = uPid;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2Xcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2Xcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.uPid is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('getPid: %u' % (self.uPid,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.pidFileAdd(self.uPid);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.uPid;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addLogsToReport(self, cReleaseLogs = 1):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Retrieves and adds the release and debug logs to the test report.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add each of the requested release logs to the report.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for iLog in range(0, cReleaseLogs):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer >= 3.2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sLogFile = self.oVM.queryLogFilename(iLog);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif iLog > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sLogFile = '%s/VBox.log' % (self.oVM.logFolder,);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sLogFile = '%s/VBox.log.%u' % (self.oVM.logFolder, iLog);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt('iLog=%s' % (iLog,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Now for the hardened windows startup log.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sLogFile = os.path.join(self.oVM.logFolder, 'VBoxStartup.log');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.logXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if os.path.isfile(sLogFile):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.addLogFile(sLogFile, 'log/release/vm', '%s startup log' % (self.sName, ),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sAltName = '%s-%s' % (self.sName, os.path.basename(sLogFile),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def registerDerivedEventHandler(self, oSubClass, dArgs = None, fMustSucceed = True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Create an instance of the given ConsoleEventHandlerBase sub-class and
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync register it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The new instance is returned on success. None is returned on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # We need a console object.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oConsole = self.o.console;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except Exception, oXcpt:
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add the base class arguments.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgsCopy = dArgs.copy() if dArgs is not None else dict();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgsCopy['oSession'] = self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dArgsCopy['oConsole'] = oConsole;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sLogSuffix = 'on %s' % (self.sName,)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oSubClass.registerDerivedEventHandler(self.oVBoxMgr, self.fpApiVer, oSubClass, dArgsCopy,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oConsole, 'IConsole', 'IConsoleCallback',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fMustSucceed = fMustSucceed, sLogSuffix = sLogSuffix);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def enableVmmDevTestingPart(self, fEnabled, fEnableMMIO = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Enables the testing part of the VMMDev.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True on success and False on failure. Error information is logged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('VBoxInternal/Devices/VMMDev/0/Config/TestingEnabled',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '1' if fEnabled else '');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.o.machine.setExtraData('VBoxInternal/Devices/VMMDev/0/Config/TestingMMIO',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '1' if fEnableMMIO and fEnabled else '');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('VM name "%s", fEnabled=%s' % (self.sName, fEnabled));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('set VMMDevTesting=%s for "%s"' % (fEnabled, self.sName));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Test eXecution Service methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def txsConnectViaTcp(self, cMsTimeout = 10*60000, sIpAddr = None, sMacAddr = None, fNatForwardingForTxs = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a TxsConnectTask object on success, None + log on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # If the VM is configured with a NAT interface, connect to local host.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fReversedSetup = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fUseNatForTxs = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sIpAddr == None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNic = self.oVM.getNetworkAdapter(0);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oNic.attachmentType == vboxcon.NetworkAttachmentType_NAT:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fUseNatForTxs = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fUseNatForTxs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fReversedSetup = not fNatForwardingForTxs;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = '127.0.0.1';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Kick off the task.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTask = TxsConnectTask(self, cMsTimeout, sIpAddr, sMacAddr, fReversedSetup);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTask = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oTask;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def txsTryConnectViaTcp(self, cMsTimeout, sHostname, fReversed = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attempts to connect to a TXS instance.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True if a connection was established, False if not (only grave
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync failures are logged as errors).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Note! The timeout is more of a guideline...
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sHostname is None or sHostname.strip() == '':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise base.GenError('Empty sHostname is not implemented yet');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession = txsclient.tryOpenTcpSession(cMsTimeout, sHostname, fReversedSetup = fReversed,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMsIdleFudge = cMsTimeout / 2);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oTxsSession is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Wait for the connect task to time out.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.addTask(oTxsSession);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oRc = self.oTstDrv.waitForTasks(cMsTimeout);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.removeTask(oTxsSession);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oRc != oTxsSession:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oRc is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('oRc=%s, expected %s' % (oRc, oTxsSession));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTstDrv.processPendingEvents();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession.cancelTask(); # this is synchronous
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check the status.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('TxsSession is ready, isSuccess() -> %s.' % (oTxsSession.isSuccess(),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not oTxsSession.isSuccess():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('Disconnecting from TXS...');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oTxsSession.syncDisconnect();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TxsConnectTask(TdTaskBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Class that takes care of connecting to a VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync class TxsConnectTaskVBoxCallback(vbox.VirtualBoxEventHandlerBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Class for looking for IPv4 address changes on interface 0."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, dArgs):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync vbox.VirtualBoxEventHandlerBase.__init__(self, dArgs); # pylint: disable=W0233
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oParentTask = dArgs['oParentTask'];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sMachineId = dArgs['sMachineId'];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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 if sMachineId == self.sMachineId \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and sName == '/VirtualBox/GuestInfo/Net/0/V4/IP':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oParentTask._setIp(sValue); # pylint: disable=W0212
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oSession, cMsTimeout, sIpAddr, sMacAddr, fReversedSetup):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TdTaskBase.__init__(self, utils.getCallerName());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.cMsTimeout = cMsTimeout;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sIpAddr = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sNextIpAddr = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sMacAddr = sMacAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fReversedSetup = fReversedSetup;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBox = oSession.oVBox;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBoxEventHandler = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTxsSession = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fpApiVer = oSession.fpApiVer;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Skip things we don't implement.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sMacAddr is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('TxsConnectTask does not implement sMacAddr yet');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise base.GenError();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('TxsConnectTask: sIpAddr=%s fReversedSetup=%s' % (sIpAddr, fReversedSetup))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fReversedSetup is True:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, fReversedSetup = True);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sIpAddr is not None and sIpAddr.strip() != '':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, cMsIdleFudge = 5000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
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 #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 0. The caller zaps the property before starting the VM.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # oSession.delGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # reporter.logXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 2. Query the guest properties.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = oSession.getGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.errorXcpt('IMachine::getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP") failed');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._deregisterEventHandler();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sIpAddr is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._setIp(sIpAddr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # end __init__
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __del__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Make sure we deregister the callback. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._deregisterEventHandler();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TdTaskBase.__del__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def toString(self):
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _deregisterEventHandler(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Deregisters the event handler."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oVBoxEventHandler is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = self.oVBoxEventHandler.unregister();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBoxEventHandler = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _setIp(self, sIpAddr, fInitCall = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Called when we get an IP. Will create a TXS session and signal the task."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = sIpAddr.strip();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sIpAddr is not None \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and sIpAddr != '':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if vbox.isIpAddrValid(sIpAddr) or fInitCall:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for s in sIpAddr.split('.'):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync i = int(s);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if str(i) != s:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise Exception();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.fatalXcpt();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, cMsIdleFudge = 5000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('TxsConnectTask: Ignoring Bad ip "%s"' % (sIpAddr));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('TxsConnectTask: Ignoring empty ip "%s"' % (sIpAddr));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _openTcpSession(self, sIpAddr, uPort = None, fReversedSetup = False, cMsIdleFudge = 0):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Calls txsclient.openTcpSession and switches our task to reflect the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync state of the subtask.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.acquire();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oTxsSession is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('_openTcpSession: sIpAddr=%s, uPort=%d, fReversedSetup=%s' % \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (sIpAddr, uPort if uPort is not None else 0, fReversedSetup));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sIpAddr = sIpAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTxsSession = txsclient.openTcpSession(self.cMsTimeout, sIpAddr, uPort, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fReversedSetup, cMsIdleFudge);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTxsSession.setTaskOwner(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sNextIpAddr = sIpAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log2('_openTcpSession: sNextIpAddr=%s' % (sIpAddr,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.release();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def notifyAboutReadyTask(self, oTxsSession):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Called by the TXS session task when it's done.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync We'll signal the task completed or retry depending on the result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.acquire();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Disassociate ourselves with the session (avoid cyclic ref)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession.setTaskOwner(None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fSuccess = oTxsSession.isSuccess();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oTxsSession is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not fSuccess:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTxsSession = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fSuccess and self.fReversedSetup:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sIpAddr = oTxsSession.oTransport.sHostname;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fSuccess = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Signal done, or retry?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fSuccess \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or self.fReversedSetup \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or self.getAgeAsMs() >= self.cMsTimeout:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.signalTaskLocked();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sIpAddr = self.sNextIpAddr if self.sNextIpAddr is not None else self.sIpAddr;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._openTcpSession(sIpAddr, cMsIdleFudge = 5000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.release();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Public methods
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getResult(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the connected TXS session object on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None on failure or if the task has not yet completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.acquire();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession = self.oTxsSession;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.release();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oTxsSession is not None and not oTxsSession.isSuccess():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oTxsSession;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def cancelTask(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Cancels the task. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.acquire();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.fSignalled:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession = self.oTxsSession;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oTxsSession is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.release();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession.setTaskOwner(None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession.cancelTask();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTxsSession.waitForTask(1000);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.acquire();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.signalTaskLocked();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCv.release();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync