VirtualBox

Ignore:
Timestamp:
Aug 4, 2016 8:31:09 PM (8 years ago)
Author:
vboxsync
Message:

ValidationKit/tests/storage: Add a method to cleanup leftover volumes and pools from a failed previous run (only implemented on Solaris so far)

Location:
trunk/src/VBox/ValidationKit/tests/storage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/storage/storagecfg.py

    r62190 r63008  
    9595        StorageConfigOs.__init__(self);
    9696
     97    def _getActivePoolsStartingWith(self, oExec, sPoolIdStart):
     98        """
     99        Returns a list of pools starting with the given ID or None on failure.
     100        """
     101        lstPools = None;
     102        fRc, sOutput = oExec.execBinary('zpool', ('list', '-H'));
     103        if fRc:
     104            lstPools = [];
     105            asPools = sOutput.splitlines();
     106            for sPool in asPools:
     107                if sPool.startswith(sPoolIdStart):
     108                    # Extract the whole name and add it to the list.
     109                    asItems = sPool.split(' ');
     110                    lstPools.append(asItems[0]);
     111        return lstPools;
     112
     113    def _getActiveVolumesInPoolStartingWith(self, oExec, sPool, sVolumeIdStart):
     114        """
     115        Returns a list of active volumes for the given pool starting with the given
     116        identifier or None on failure.
     117        """
     118        lstVolumes = None;
     119        fRc, sOutput = oExec.execBinary('zfs', ('list', '-H'));
     120        if fRc:
     121            lstVolumes = [];
     122            asVolumes = sOutput.splitlines();
     123            for sVolume in asVolumes:
     124                if sVolume.startswith(sPool + '/' + sVolumeIdStart):
     125                    # Extract the whole name and add it to the list.
     126                    asItems = sVolume.split(' ');
     127                    lstVolumes.append(asItems[0]);
     128        return lstVolumes;
     129
    97130    def getDisksMatchingRegExp(self, sRegExp):
    98131        """
     
    148181        """
    149182        fRc, _ = oExec.execBinary('zpool', ('destroy', sPool));
     183        return fRc;
     184
     185    def cleanupPoolsAndVolumes(self, oExec, sPoolIdStart, sVolIdStart):
     186        """
     187        Cleans up any pools and volumes starting with the name in the given
     188        parameters.
     189        """
     190        fRc = True;
     191        lstPools = self._getActivePoolsStartingWith(oExec, sPoolIdStart);
     192        if lstPools is not None:
     193            for sPool in lstPools:
     194                lstVolumes = self._getActiveVolumesInPoolStartingWith(oExec, sPool, sVolIdStart);
     195                if lstVolumes is not None:
     196                    # Destroy all the volumes first
     197                    for sVolume in lstVolumes:
     198                        fRc2 = oExec.execBinaryNoStdOut('zfs', ('destroy', sVolume));
     199                        if not fRc2:
     200                            fRc = fRc2;
     201
     202                    # Destroy the pool
     203                    fRc2 = self.destroyPool(oExec, sPool);
     204                    if not fRc2:
     205                        fRc = fRc2;
     206                else:
     207                    fRc = False;
     208        else:
     209            fRc = False;
     210
    150211        return fRc;
    151212
     
    279340        return fRc;
    280341
     342    def cleanupPoolsAndVolumes(self, oExec, sPoolIdStart, sVolIdStart):
     343        """
     344        Cleans up any pools and volumes starting with the name in the given
     345        parameters.
     346        """
     347        # @todo: Needs implementation, for LVM based configs a similar approach can be used
     348        #        as for Solaris.
     349        _ = oExec;
     350        _ = sPoolIdStart;
     351        _ = sVolIdStart;
     352        return True;
     353
    281354class StorageCfg(object):
    282355    """
     
    459532        return self.oExec.mkDir(sMountPoint + '/' + sDir, fMode);
    460533
     534    def cleanupLeftovers(self):
     535        """
     536        Tries to cleanup any leftover pools and volumes from a failed previous run.
     537        """
     538        return self.oStorOs.cleanupPoolsAndVolumes('pool', 'vol');
     539
  • trunk/src/VBox/ValidationKit/tests/storage/tdStorageBenchmark1.py

    r63000 r63008  
    791791            self.oStorCfg = storagecfg.StorageCfg(oExecutor, utils.getHostOs(), oDiskCfg);
    792792
     793            # Try to cleanup any leftovers from a previous run first.
     794            fRc = self.oStorCfg.cleanupLeftovers();
     795            if not fRc:
     796                reporter.error('Failed to cleanup any leftovers from a previous run');
     797
    793798            if self.fTestHost:
    794799                reporter.testStart('Host');
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