VirtualBox

Changeset 99123 in vbox


Ignore:
Timestamp:
Mar 22, 2023 9:40:58 PM (21 months ago)
Author:
vboxsync
Message:

ValidationKit/tests/api/tdTreeDepth1.py: If all of the API tests are
run via tdApi1.py then VMs created before tdTreeDepth1.py which
don't clean up after themselves will have populated the global
IVirtualBox::hardDisks[] array which this test examines for any base
media leftover after calling IMachine::unregister(). The check here
needs smartening up to verify whether any of the base hard disks in the
HardDisks[] array actually belong to this VM.

File:
1 edited

Legend:

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

    r99112 r99123  
    9797                    reporter.log2('parent medium = %s cDisks = %d' % (oParentMedium.location, cDisks));
    9898                    oParentMedium = oParentMedium.parent;
     99        return cDisks;
     100
     101    def getNumOfHDsFromHardDisksArray(self):
     102        """
     103        Helper routine for counting the hard disks that belong to this VM which are
     104        contained in the global IVirtualBox::hardDisks[] array (which contains base media
     105        only).
     106        """
     107        cDisks = 0;
     108        aoHDs = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks');
     109        # Walk the IVirtualBox::hardDisks[] array for hard disks belonging to this VM.
     110        # The array may contain entries from other VMs created by previous API tessts
     111        # which haven't unregistered and deleted their VM's configuration.  The location
     112        # attribute of each disk looks similar to:
     113        # /var/tmp/VBoxTestTmp/VBoxUserHome/Machines/vm 2/tdAppliance1-t2-disk1.vmdk
     114        # So we compare the directory where the disk is located, i.e. the 'basefolder',
     115        # with our VM's basefolder which looks similar to:
     116        # /var/tmp/VBoxTestTmp/VBoxUserHome/Machines/test-medium
     117        # to determine if the disk belongs to us.
     118        for oHD in aoHDs:
     119            sHDBaseFolder = os.path.dirname(oHD.location);
     120            sVMBaseFolder = os.path.join(self.oTstDrv.oVBox.systemProperties.defaultMachineFolder, 'test-medium');
     121            reporter.log2('HDBaseFolder = %s VMBaseFolder = %s' % (sHDBaseFolder, sVMBaseFolder));
     122            if sHDBaseFolder== sVMBaseFolder:
     123                cDisks = cDisks + 1;
    99124        return cDisks;
    100125
     
    209234        oVM = None;
    210235
    211         # If there is no base image (expected) then there are no leftover
    212         # child images either.
    213         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    214         reporter.log('After unregister(DetachAllReturnHardDisksOnly): API reports %d base images' % (cBaseImages));
    215         if cBaseImages != 0:
    216             reporter.error('Got %d initial base images, expected zero (0)' % (cBaseImages));
     236        # If there are no base media belonging to this VM in the global IVirtualBox::hardDisks[]
     237        # array (expected) then there are no leftover child images either.
     238        cNumDisks = self.getNumOfHDsFromHardDisksArray();
     239        reporter.log('After unregister(DetachAllReturnHardDisksOnly): API reports %d base images (should be zero)' % (cNumDisks));
     240        if cNumDisks != 0:
     241            reporter.error('Got %d initial base images, expected zero (0)' % (cNumDisks));
    217242
    218243        # re-register to test loading of settings
     
    251276        time.sleep(3);
    252277
    253         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    254         reporter.log('After unregister(UnregisterOnly): API reports %d base images' % (cBaseImages));
    255         if cBaseImages != 0:
    256             reporter.error('Got %d base images after unregistering, expected zero (0)' % (cBaseImages));
     278        # If there are no base media belonging to this VM in the global IVirtualBox::hardDisks[]
     279        # array (expected) then there are no leftover child images either.
     280        cNumDisks = self.getNumOfHDsFromHardDisksArray();
     281        reporter.log('After unregister(UnregisterOnly): API reports %d base images (should be zero)' % (cNumDisks));
     282        if cNumDisks != 0:
     283            reporter.error('Got %d base images after unregistering, expected zero (0)' % (cNumDisks));
    257284
    258285        return reporter.testDone()[1] == 0;
     
    303330        oVM = None;
    304331
    305         # If there is no base image (expected) then there are no leftover
    306         # child images either.
    307         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    308         reporter.log('After unregister(DetachAllReturnHardDisksOnly): API reports %d base images' % (cBaseImages));
    309         fRc = fRc and cBaseImages == 0
    310         if cBaseImages != 0:
    311             reporter.error('Got %d initial base images, expected zero (0)' % (cBaseImages));
     332        # If there are no base media belonging to this VM in the global IVirtualBox::hardDisks[]
     333        # array (expected) then there are no leftover child images either.
     334        cNumDisks = self.getNumOfHDsFromHardDisksArray();
     335        reporter.log('After unregister(DetachAllReturnHardDisksOnly): API reports %d base images (should be zero)' % (cNumDisks));
     336        fRc = fRc and cNumDisks == 0
     337        if cNumDisks != 0:
     338            reporter.error('Got %d initial base images, expected zero (0)' % (cNumDisks));
    312339
    313340        # re-register to test loading of settings
     
    345372        time.sleep(3);
    346373
    347         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    348         reporter.log('After unregister(UnregisterOnly): API reports %d base images' % (cBaseImages));
    349         if cBaseImages != 0:
    350             reporter.error('Got %d base images after unregistering, expected zero (0)' % (cBaseImages));
     374        # If there are no base media belonging to this VM in the global IVirtualBox::hardDisks[]
     375        # array (expected) then there are no leftover child images either.
     376        cNumDisks = self.getNumOfHDsFromHardDisksArray();
     377        reporter.log('After unregister(UnregisterOnly): API reports %d base images (should be zero)' % (cNumDisks));
     378        if cNumDisks != 0:
     379            reporter.error('Got %d base images after unregistering, expected zero (0)' % (cNumDisks));
    351380
    352381        return reporter.testDone()[1] == 0
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