def __testScenario_2(self, oSession, oMachine, sNewLoc, sOldLoc): """ All disks attached to VM are located inside the VM's folder. There are no any snapshots and logs. """ sController = self.dsKeys['StandardImage'] aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) oSubTstDrvMoveMedium1Instance.moveTo(sOldLoc, aoMediumAttachments) del oSubTstDrvMoveMedium1Instance dsReferenceFiles = defaultdict(set) for s in self.asImagesNames: reporter.log('"%s"' % (s, )) dsReferenceFiles['StandardImage'].add( os.path.normcase(sNewLoc + os.sep + oMachine.name + os.sep + s)) sSettingFile = os.path.join( sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) dsReferenceFiles['SettingsFile'].add(os.path.normcase(sSettingFile)) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 2nd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!' ) else: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 2nd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!' ) fRes = oSession.saveSettings() if fRes is False: reporter.log('2nd scenario: Couldn\'t save machine settings') return fRc
def testVMMove(self): """ Test machine moving. """ reporter.testStart('machine moving') if not self.oTstDrv.importVBoxApi(): return False isSupported = self.checkAPIVersion() if isSupported is False: reporter.log('API version is below "%s". Just skip this test.' % (self.oTstDrv.fpApiVer)) return reporter.testDone()[1] == 0 else: reporter.log('API version is "%s". Continuing the test.' % (self.oTstDrv.fpApiVer)) #Scenarios #1. All disks attached to VM are located outside the VM's folder. # There are no any snapshots and logs. # In this case only VM setting file should be moved (.vbox file) # #2. All disks attached to VM are located inside the VM's folder. # There are no any snapshots and logs. # #3. There are snapshots. # #4. There are one or more save state files in the snapshots folder # and some files in the logs folder. # #5. There is an ISO image (.iso) attached to the VM. # #6. There is a floppy image (.img) attached to the VM. # #7. There are shareable disk and immutable disk attached to the VM. try: #create test machine oMachine = self.createTestMachine() if oMachine is None: reporter.error('Failed to create test machine') #create temporary subdirectory in the current working directory sOrigLoc = self.oTstDrv.sScratchPath sBaseLoc = os.path.join(sOrigLoc, 'moveFolder') os.mkdir(sBaseLoc, 0o775) sController = 'SATA Controller' aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) #lock machine #get session machine oSession = self.oTstDrv.openSession(oMachine) fRc = True sNewLoc = sBaseLoc + os.sep ############# 1 case. ########################################################################################## # All disks attached to VM are located outside the VM's folder. # There are no any snapshots and logs. # In this case only VM setting file should be moved (.vbox file) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc fRc = fRc and oSession.saveSettings() if fRc is False: reporter.log( 'Couldn\'t save machine settings after 1t scenario') ############# 2 case. ########################################################################################## # All disks attached to VM are located inside the VM's folder. # There are no any snapshots and logs. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario') os.mkdir(sNewLoc, 0o775) aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) oSubTstDrvMoveMedium1Instance.setLocation(sOldLoc, aoMediumAttachments) del oSubTstDrvMoveMedium1Instance fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc fRc = fRc and oSession.saveSettings() if fRc is False: reporter.log( 'Couldn\'t save machine settings after 2nd scenario') ############# 3 case. ########################################################################################## # There are snapshots. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario') os.mkdir(sNewLoc, 0o775) cSnap = 2 for counter in range(1, cSnap + 1): strSnapshot = 'Snapshot' + str(counter) fRc = fRc and oSession.takeSnapshot(strSnapshot) if fRc is False: reporter.error('Error: Can\'t take snapshot "%s".' % (strSnapshot, )) reporter.testFailure('Error: Can\'t take snapshot "%s".' % (strSnapshot, )) aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) if fRc is True: fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc fRc = fRc and oSession.saveSettings() if fRc is False: reporter.log( 'Couldn\'t save machine settings after 3d scenario') ############# 4 case. ########################################################################################## # There are one or more save state files in the snapshots folder # and some files in the logs folder. # Here we run VM, next stop it in the "save" state. # And next move VM sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario') os.mkdir(sNewLoc, 0o775) #Close Session object because after starting VM we get new instance of session fRc = oSession.close() and fRc if fRc is False: reporter.log('Couldn\'t close machine session') del oSession self.__testScenario_4(oMachine, sNewLoc) ############## 5 case. ########################################################################################## #There is an ISO image (.iso) attached to the VM. #Prerequisites - there is IDE Controller and there are no any images attached to it. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario') os.mkdir(sNewLoc, 0o775) self.__testScenario_5(oMachine, sNewLoc, sOldLoc) ############# 6 case. ########################################################################################## #There is a floppy image (.img) attached to the VM. #Prerequisites - there is Floppy Controller and there are no any images attached to it. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario') os.mkdir(sNewLoc, 0o775) self.__testScenario_6(oMachine, sNewLoc, sOldLoc) ############# 7 case. ########################################################################################## # # There are shareable disk and immutable disk attached to the VM. # # # # fRc = fRc and oSession.saveSettings() # if fRc is False: # reporter.log('Couldn\'t save machine settings') # assert fRc is True except: reporter.errorXcpt() return reporter.testDone()[1] == 0