VirtualBox

Ignore:
Timestamp:
Mar 22, 2018 4:15:14 PM (7 years ago)
Author:
vboxsync
Message:

bugref:8345. Refactoring of the code: splitted up the function testVMMove()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/api/tdMoveVM1.py

    r71458 r71464  
    5656    def __init__(self, oTstDrv):
    5757        base.SubTestDriverBase.__init__(self, 'move-vm', oTstDrv)
    58         self.asRsrcs = self.getResourceSet()
     58        self.asRsrcs = self.__getResourceSet()
    5959
    6060        for oRes in self.asRsrcs:
     
    169169        return False
    170170
    171     def getResourceSet(self):
     171    def __getResourceSet(self):
    172172        # Construct the resource list the first time it's queried.
    173173        if self.oTstDrv.asRsrcs is None:
     
    178178        return self.oTstDrv.asRsrcs
    179179
     180    def __testScenario_4(self, oMachine, sNewLoc, sOldLoc = 0):
     181
     182        #Run VM and get new Session object
     183        oSession = self.oTstDrv.startVm(oMachine)
     184
     185        #some time interval should be here for not closing VM just after start
     186        time.sleep(1)
     187
     188        if oMachine.state != self.oTstDrv.oVBoxMgr.constants.MachineState_Running:
     189            reporter.log("Machine '%s' is not Running" % (oMachine.name))
     190            fRc = False
     191
     192        #call Session::saveState(), already closes session unless it failed
     193        fRc = oSession.saveState()
     194        self.oTstDrv.terminateVmBySession(oSession)
     195
     196        if fRc:
     197            #create a new Session object for moving VM
     198            oSession = self.oTstDrv.openSession(oMachine)
     199            fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc
     200
     201            # cleaning up: get rid of saved state
     202            fRc = fRc and oSession.discardSavedState(True)
     203            if fRc is False:
     204                reporter.log('Failed to discard the saved state of machine')
     205
     206            fRc = oSession.close() and fRc
     207            if fRc is False:
     208                reporter.log('Couldn\'t close machine session')
     209
     210        return fRc
     211
     212    def __testScenario_5(self, oMachine, sNewLoc, sOldLoc = 0):
     213
     214        fRc = True
     215        #create a new Session object
     216        oSession = self.oTstDrv.openSession(oMachine)
     217
     218        sISOLoc = '5.3/isos/tdMoveVM1.iso'
     219        reporter.log("sHost is '%s', sResourcePath is '%s'" % (self.oTstDrv.sHost, self.oTstDrv.sResourcePath))
     220        sISOLoc = self.oTstDrv.getFullResourceName(sISOLoc)
     221
     222        if not os.path.exists(sISOLoc):
     223            reporter.log('ISO file does not exist at "%s"' % (sISOLoc,))
     224            fRc = False
     225
     226        #Copy ISO image from the common resource folder into machine folder
     227        shutil.copy(sISOLoc, sOldLoc)
     228
     229        #attach ISO image to the IDE controller
     230        if fRc is True:
     231            #set actual ISO location
     232            sISOLoc = sOldLoc + os.sep + 'tdMoveVM1.iso'
     233            sController='IDE Controller'
     234            aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
     235            iPort = len(aoMediumAttachments)
     236            reporter.log('sISOLoc "%s", sController "%s", iPort "%s"' % (sISOLoc,sController,iPort))
     237            fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0)
     238
     239        if fRc is True:
     240            fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc
     241
     242        #detach ISO image
     243        fRc = oSession.detachHd(sController, iPort, 0)
     244
     245        fRc = fRc and oSession.saveSettings()
     246        if fRc is False:
     247            reporter.log('Couldn\'t save machine settings after 5th scenario')
     248
     249        fRc = oSession.close() and fRc
     250        if fRc is False:
     251            reporter.log('Couldn\'t close machine session')
     252
     253        return fRc
     254
     255    def __testScenario_6(self, oMachine, sNewLoc, sOldLoc = 0):
     256
     257        fRc = True
     258        #create a new Session object
     259        oSession = self.oTstDrv.openSession(oMachine)
     260
     261        sFloppyLoc = '5.3/floppy/tdMoveVM1.img'
     262        sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc)
     263
     264        if not os.path.exists(sFloppyLoc):
     265            reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,))
     266            fRc = False
     267
     268        #Copy floppy image from the common resource folder into machine folder
     269        shutil.copy(sFloppyLoc, sOldLoc)
     270
     271        # attach floppy image
     272        if fRc is True:
     273            #set actual floppy location
     274            sFloppyLoc = sOldLoc + os.sep + 'tdMoveVM1.img'
     275            sController='Floppy Controller'
     276            reporter.log('sFloppyLoc "%s", sController "%s"' % (sFloppyLoc,sController))
     277            fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0)
     278
     279        if fRc is True:
     280            fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc
     281
     282        #detach floppy image
     283        fRc = oSession.detachHd(sController, 0, 0)
     284
     285        fRc = fRc and oSession.saveSettings()
     286        if fRc is False:
     287            reporter.log('Couldn\'t save machine settings after 6th scenario')
     288
     289        fRc = oSession.close() and fRc
     290        if fRc is False:
     291            reporter.log('Couldn\'t close machine session')
     292
     293        return fRc
     294
    180295    #
    181296    #testVMMove
     
    216331        #
    217332        #7. There are shareable disk and immutable disk attached to the VM.
    218         #
    219         #8. There is "read-only" disk attached to the VM.
    220333
    221334        try:
     
    228341            #create temporary subdirectory in the current working directory
    229342            sOrigLoc = self.oTstDrv.sScratchPath
    230             sNewLoc = os.path.join(sOrigLoc, 'moveFolder')
    231             os.mkdir(sNewLoc, 0o775)
     343            sBaseLoc = os.path.join(sOrigLoc, 'moveFolder')
     344            os.mkdir(sBaseLoc, 0o775)
    232345
    233346            sController='SATA Controller'
     
    239352            fRc = True
    240353
    241             sMoveLoc = sNewLoc + os.sep
     354            sNewLoc = sBaseLoc + os.sep
    242355############# 1 case. ##########################################################################################
    243356            #   All disks attached to VM are located outside the VM's folder.
    244357            #   There are no any snapshots and logs.
    245358            #   In this case only VM setting file should be moved (.vbox file)
    246             fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc
     359            fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc
    247360
    248361            fRc = fRc and oSession.saveSettings()
     
    253366            #   All disks attached to VM are located inside the VM's folder.
    254367            #   There are no any snapshots and logs.
    255             sLoc = sMoveLoc + os.sep + oMachine.name + os.sep
    256             sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario')
    257             os.mkdir(sMoveLoc, 0o775)
     368            sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep
     369            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario')
     370            os.mkdir(sNewLoc, 0o775)
    258371            aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
    259372            oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv)
    260             oSubTstDrvMoveMedium1Instance.setLocation(sLoc, aoMediumAttachments)
     373            oSubTstDrvMoveMedium1Instance.setLocation(sOldLoc, aoMediumAttachments)
    261374
    262375            del oSubTstDrvMoveMedium1Instance
    263376
    264             fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc
     377            fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc
    265378
    266379            fRc = fRc and oSession.saveSettings()
     
    270383############# 3 case. ##########################################################################################
    271384            #   There are snapshots.
    272             sLoc = sMoveLoc + os.sep + oMachine.name + os.sep
    273             sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario')
    274             os.mkdir(sMoveLoc, 0o775)
     385            sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep
     386            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario')
     387            os.mkdir(sNewLoc, 0o775)
    275388
    276389            cSnap = 2
     
    284397            aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
    285398            if fRc is True:
    286                 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc
     399                fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc
    287400
    288401            fRc = fRc and oSession.saveSettings()
     
    296409            #   And next move VM
    297410
     411            sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep
     412            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario')
     413            os.mkdir(sNewLoc, 0o775)
     414
    298415            #Close Session object because after starting VM we get new instance of session
    299416            fRc = oSession.close() and fRc
     
    301418                reporter.log('Couldn\'t close machine session')
    302419
    303             #Run VM and get new Session object
    304             oSession = self.oTstDrv.startVm(oMachine)
    305 
    306             #some time interval should be here for not closing VM just after start
    307             time.sleep(1)
    308 
    309             if oMachine.state != self.oTstDrv.oVBoxMgr.constants.MachineState_Running:
    310                 reporter.log("Machine '%s' is not Running" % (oMachine.name))
    311                 fRc = False
    312 
    313             #call Session::saveState(), already closes session unless it failed
    314             fRc = fRc and oSession.saveState()
    315             self.oTstDrv.terminateVmBySession(oSession)
    316 
    317             if fRc:
    318                 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep
    319                 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario')
    320                 os.mkdir(sMoveLoc, 0o775)
    321 
    322                 #create a new Session object for moving VM
    323                 oSession = self.oTstDrv.openSession(oMachine)
    324                 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc
    325 
    326                 # cleaning up: get rid of saved state
    327                 fRc = fRc and oSession.discardSavedState(True)
    328                 if fRc is False:
    329                     reporter.log('Failed to discard the saved state of machine')
     420            del oSession
     421
     422            self.__testScenario_4(oMachine, sNewLoc)
    330423
    331424############## 5 case. ##########################################################################################
    332425            #There is an ISO image (.iso) attached to the VM.
    333426            #Prerequisites - there is IDE Controller and there are no any images attached to it.
    334             fRc = True
    335             oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
    336             oMachine = oVirtualBox.findMachine('test-vm-move')
    337             if oMachine is None:
    338                 reporter.log("Machine '%s' is unknown" % (oMachine.name))
    339                 return False
    340 
    341             del oVirtualBox
    342 
    343             sLoc = sMoveLoc + os.sep + oMachine.name + os.sep
    344             sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario')
    345             os.mkdir(sMoveLoc, 0o775)
    346             sISOLoc = '5.3/isos/tdMoveVM1.iso'
    347             reporter.log("sHost is '%s', sResourcePath is '%s'" % (self.oTstDrv.sHost, self.oTstDrv.sResourcePath))
    348             sISOLoc = self.oTstDrv.getFullResourceName(sISOLoc)
    349 
    350             if not os.path.exists(sISOLoc):
    351                 reporter.log('ISO file does not exist at "%s"' % (sISOLoc,))
    352                 fRc = False
    353 
    354             #Copy ISO image from the common resource folder into machine folder
    355             shutil.copy(sISOLoc, sLoc)
    356 
    357             #attach ISO image to the IDE controller
    358             if fRc is True:
    359                 #set actual ISO location
    360                 sISOLoc = sLoc + os.sep + 'tdMoveVM1.iso'
    361                 sController='IDE Controller'
    362                 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
    363                 iPort = len(aoMediumAttachments)
    364                 reporter.log('sISOLoc "%s", sController "%s", iPort "%s"' % (sISOLoc,sController,iPort))
    365                 fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0)
    366 
    367             if fRc is True:
    368                 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc
    369 
    370             #detach ISO image
    371             fRc = oSession.detachHd(sController, iPort, 0)
    372 
    373             fRc = fRc and oSession.saveSettings()
    374             if fRc is False:
    375                 reporter.log('Couldn\'t save machine settings after 5th scenario')
     427
     428            sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep
     429            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario')
     430            os.mkdir(sNewLoc, 0o775)
     431            self.__testScenario_5(oMachine, sNewLoc, sOldLoc)
    376432
    377433############# 6 case. ##########################################################################################
    378434            #There is a floppy image (.img) attached to the VM.
    379435            #Prerequisites - there is Floppy Controller and there are no any images attached to it.
    380             fRc = True
    381             sLoc = sMoveLoc + os.sep + oMachine.name + os.sep
    382             sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario')
    383             os.mkdir(sMoveLoc, 0o775)
    384             sFloppyLoc = '5.3/floppy/tdMoveVM1.img'
    385             sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc)
    386 
    387             if not os.path.exists(sFloppyLoc):
    388                 reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,))
    389                 fRc = False
    390 
    391             #Copy floppy image from the common resource folder into machine folder
    392             shutil.copy(sFloppyLoc, sLoc)
    393 
    394             # attach floppy image
    395             if fRc is True:
    396                 #set actual floppy location
    397                 sFloppyLoc = sLoc + os.sep + 'tdMoveVM1.img'
    398                 sController='Floppy Controller'
    399                 reporter.log('sFloppyLoc "%s", sController "%s"' % (sFloppyLoc,sController))
    400                 fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0)
    401 
    402             if fRc is True:
    403                 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc
    404 
    405             #detach floppy image
    406             fRc = oSession.detachHd(sController, 0, 0)
    407 
    408             fRc = fRc and oSession.saveSettings()
    409             if fRc is False:
    410                 reporter.log('Couldn\'t save machine settings after 6th scenario')
     436
     437            sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep
     438            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario')
     439            os.mkdir(sNewLoc, 0o775)
     440            self.__testScenario_6(oMachine, sNewLoc, sOldLoc)
    411441
    412442############# 7 case. ##########################################################################################
     
    419449#
    420450
    421             fRc = oSession.close() and fRc
    422             if fRc is False:
    423                 reporter.log('Couldn\'t close machine session')
    424 
    425451            assert fRc is True
    426452        except:
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette