def moveTo(self, sLocation, aoMediumAttachments): for oAttachment in aoMediumAttachments: try: oMedium = oAttachment.medium reporter.log('Move medium "%s" to "%s"' % (oMedium.name, sLocation,)) except: reporter.errorXcpt('failed to get the medium from the IMediumAttachment "%s"' % (oAttachment)) if self.oTstDrv.fpApiVer >= 5.3 and self.oTstDrv.uRevision > 124748: try: oProgress = vboxwrappers.ProgressWrapper(oMedium.moveTo(sLocation), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'move "%s"' % (oMedium.name,)); except: return reporter.errorXcpt('Medium::moveTo("%s") for medium "%s" failed' % (sLocation, oMedium.name,)); else: try: oProgress = vboxwrappers.ProgressWrapper(oMedium.setLocation(sLocation), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'move "%s"' % (oMedium.name,)); except: return reporter.errorXcpt('Medium::setLocation("%s") for medium "%s" failed' % (sLocation, oMedium.name,)); oProgress.wait() if oProgress.logResult() is False: return False return True
def testImportOvaAsOvf(self, sOva): """ Unpacks the OVA into a subdirectory in the scratch area and imports it as an OVF. """ oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox(); sTmpDir = os.path.join(self.oTstDrv.sScratchPath, os.path.split(sOva)[1] + '-ovf'); sOvf = os.path.join(sTmpDir, os.path.splitext(os.path.split(sOva)[1])[0] + '.ovf'); # # Unpack # try: os.mkdir(sTmpDir, 0o755); oTarFile = tarfile.open(sOva, 'r:*'); oTarFile.extractall(sTmpDir); oTarFile.close(); except: return reporter.errorXcpt('Unpacking "%s" to "%s" for OVF style importing failed' % (sOvf, sTmpDir,)); # # Import. # try: oAppliance2 = oVirtualBox.createAppliance(); except: return reporter.errorXcpt('IVirtualBox::createAppliance failed (#2)'); try: oProgress = vboxwrappers.ProgressWrapper(oAppliance2.read(sOvf), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'read "%s"' % (sOvf,)); except: return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOvf,)); oProgress.wait(); if oProgress.logResult() is False: return False; try: oAppliance2.interpret(); except: return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOvf,)); try: oProgress = vboxwrappers.ProgressWrapper(oAppliance2.importMachines([]), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOvf,)); except: return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOvf,)); oProgress.wait(); if oProgress.logResult() is False: return False; return True;
def testImportOva(self, sOva): """ xxx """ oVirtualBox = self.oVBoxMgr.getVirtualBox() # # Import it as OVA. # try: oAppliance = oVirtualBox.createAppliance() except: return reporter.errorXcpt('IVirtualBox::createAppliance failed') print "oAppliance=%s" % (oAppliance, ) try: oProgress = vboxwrappers.ProgressWrapper(oAppliance.read(sOva), self.oVBoxMgr, self, 'read "%s"' % (sOva, )) except: return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOva, )) oProgress.wait() if oProgress.logResult() is False: return False try: oAppliance.interpret() except: return reporter.errorXcpt( 'IAppliance::interpret() failed on "%s"' % (sOva, )) # try: oProgress = vboxwrappers.ProgressWrapper( oAppliance.importMachines([]), self.oVBoxMgr, self, 'importMachines "%s"' % (sOva, )) except: return reporter.errorXcpt( 'IAppliance::importMachines failed on "%s"' % (sOva, )) oProgress.wait() if oProgress.logResult() is False: return False # # Export the # ## @todo do more with this OVA. Like untaring it and loading it as an OVF. Export it and import it again. return True
def deleteVM(self, oVM): try: oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone) except: reporter.logXcpt() if self.fpApiVer >= 4.0: try: if self.fpApiVer >= 4.3: oProgressCom = oVM.deleteConfig([]) else: oProgressCom = oVM.delete(None) except: reporter.logXcpt() else: oProgress = vboxwrappers.ProgressWrapper( oProgressCom, self.oVBoxMgr, self.oVBox.oTstDrv, 'Delete VM %s' % (oVM.name)) oProgress.wait(cMsTimeout=15 * 60 * 1000) # 15 min oProgress.logResult() else: try: oVM.deleteSettings() except: reporter.logXcpt() return None
def resizeMedium(self, oMedium, cbNewSize): if oMedium.deviceType is not vboxcon.DeviceType_HardDisk: return False if oMedium.type is not vboxcon.MediumType_Normal: return False #currently only VDI can be resizable. Medium variant is not checked, because testcase creates disks itself oMediumFormat = oMedium.mediumFormat if oMediumFormat.id != 'VDI': return False cbCurrSize = oMedium.logicalSize # currently reduce is not supported if cbNewSize < cbCurrSize: return False try: oProgressCom = oMedium.resize(cbNewSize) except: reporter.logXcpt('IMedium::resize failed on %s' % (oMedium.name)) return False oProgress = vboxwrappers.ProgressWrapper( oProgressCom, self.oVBoxMgr, self.oVBox.oTstDrv, 'Resize medium %s' % (oMedium.name)) oProgress.wait(cMsTimeout=15 * 60 * 1000) # 15 min oProgress.logResult() return True
def moveVMToLocation(self, sLocation, oVM): fRc = True try: #move machine reporter.log('Moving machine "%s" to the "%s"' % (oVM.name, sLocation)) oType = 'basic' oProgress = vboxwrappers.ProgressWrapper( oVM.moveTo(sLocation, oType), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'moving machine "%s"' % (oVM.name, )) except: return reporter.errorXcpt( 'Machine::moveTo("%s") for machine "%s" failed' % ( sLocation, oVM.name, )) oProgress.wait() if oProgress.logResult() is False: fRc = False reporter.log('Progress object returned False') else: fRc = True return fRc
def moveVMToLocation(self, sLocation, oVM): """ Document me here, not with hashes above. """ fRc = True try: ## @todo r=bird: Too much unncessary crap inside try clause. Only oVM.moveTo needs to be here. ## Though, you could make an argument for oVM.name too, perhaps. # move machine reporter.log('Moving machine "%s" to the "%s"' % (oVM.name, sLocation)) sType = 'basic' oProgress = vboxwrappers.ProgressWrapper( oVM.moveTo(sLocation, sType), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'moving machine "%s"' % (oVM.name, )) except: return reporter.errorXcpt( 'Machine::moveTo("%s") for machine "%s" failed' % ( sLocation, oVM.name, )) oProgress.wait() if oProgress.logResult() is False: fRc = False reporter.log('Progress object returned False') else: fRc = True return fRc
def setLocation(self, sLocation, aListOfAttach): for attachment in aListOfAttach: try: oMedium = attachment.medium reporter.log('Move medium ' + oMedium.name + ' to the ' + sLocation) except: reporter.errorXcpt( 'failed to get the medium from the IMediumAttachment "%s"' % (attachment)) try: oProgress = vboxwrappers.ProgressWrapper( oMedium.setLocation(sLocation), self.oVBoxMgr, self, 'move "%s"' % (oMedium.name, )) except: return reporter.errorXcpt( 'Medium::setLocation("%s") for medium "%s" failed' % ( sLocation, oMedium.name, )) oProgress.wait() if oProgress.logResult() is False: return False
def cloneMedium(self, oSrcHd, oTgtHd): """ Clones medium into target medium. """ try: oProgressCom = oSrcHd.cloneTo(oTgtHd, (vboxcon.MediumVariant_Standard, ), None); except: reporter.errorXcpt('failed to clone medium %s to %s' % (oSrcHd.name, oTgtHd.name)); return False; oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oVBox.oTstDrv, 'clone base disk %s to %s' % (oSrcHd.name, oTgtHd.name)); oProgress.wait(cMsTimeout = 15*60*1000); # 15 min oProgress.logResult(); return True;