VirtualBox

Ignore:
Timestamp:
May 10, 2019 2:27:02 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
130489
Message:

tdMoveVM1.py: must put os.listdir in a try/catch so it won't croak if the directory does not exist.

File:
1 edited

Legend:

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

    r77777 r78460  
    8181        """
    8282        reporter.log('ValidationKit folder is "%s"' % (g_ksValidationKitDir,))
    83         return  self.testVMMove()
     83        return self.testVMMove()
    8484
    8585    #
     
    244244        return self.oTstDrv.fpApiVer >= 5.3;
    245245
     246    @staticmethod
     247    def __safeListDir(sDir):
     248        """ Wrapper around os.listdir that returns empty array instead of exceptions. """
     249        try:
     250            return os.listdir(sDir);
     251        except:
     252            return [];
     253
    246254    def __getStatesFiles(self, oMachine, fPrint = False):
    247255        asStateFilesList = set()
    248256        sFolder = oMachine.snapshotFolder
    249         for sFile in os.listdir(sFolder):
     257        for sFile in self.__safeListDir(sFolder):
    250258            if sFile.endswith(".sav"):
    251259                sFullPath = os.path.join(sFolder, sFile)
     
    258266        asSnapshotsFilesList = set()
    259267        sFolder = oMachine.snapshotFolder
    260         for sFile in os.listdir(sFolder):
     268        for sFile in self.__safeListDir(sFolder):
    261269            if sFile.endswith(".sav") is False:
    262270                sFullPath = os.path.join(sFolder, sFile)
     
    269277        asLogFilesList = set()
    270278        sFolder = oMachine.logFolder
    271         for sFile in os.listdir(sFolder):
     279        for sFile in self.__safeListDir(sFolder):
    272280            if sFile.endswith(".log"):
    273281                sFullPath = os.path.join(sFolder, sFile)
     
    354362        fRes = oSession.saveSettings()
    355363        if fRes is False:
    356             reporter.log('3d scenario: Couldn\'t save machine settings')
     364            reporter.log('3rd scenario: Couldn\'t save machine settings')
    357365
    358366        return fRc
     
    587595        # 7. There are shareable disk and immutable disk attached to the VM.
    588596
    589         try:
     597        try: ## @todo r=bird: Would be nice to use sub-tests here for each scenario, however
     598             ##               this try/catch as well as lots of return points makes that very hard.
     599             ##               Big try/catch stuff like this should be avoided.
    590600            # Create test machine.
    591601            oMachine = self.createTestMachine()
     
    614624            # In this case only VM setting file should be moved (.vbox file)
    615625            #
     626            reporter.log("Scenario #1:");
    616627            for s in self.asImagesNames:
    617628                reporter.log('"%s"' % (s,))
     
    642653            # There are no any snapshots and logs.
    643654            #
     655            reporter.log("Scenario #2:");
    644656            sOldLoc = sNewLoc + oMachine.name + os.sep
    645             sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario')
     657            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2nd_scenario')
    646658            os.mkdir(sNewLoc, 0o775)
    647659
     
    655667            # There are snapshots.
    656668            #
     669            reporter.log("Scenario #3:");
    657670            sOldLoc = sNewLoc + oMachine.name + os.sep
    658             sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario')
     671            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3rd_scenario')
    659672            os.mkdir(sNewLoc, 0o775)
    660673
     
    671684            # And next move VM
    672685            #
     686            reporter.log("Scenario #4:");
    673687            sOldLoc = sNewLoc + oMachine.name + os.sep
    674688            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario')
     
    692706            # Prerequisites - there is IDE Controller and there are no any images attached to it.
    693707            #
     708            reporter.log("Scenario #5:");
    694709            sOldLoc = sNewLoc + os.sep + oMachine.name
    695710            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario')
     
    705720            # Prerequisites - there is Floppy Controller and there are no any images attached to it.
    706721            #
     722            reporter.log("Scenario #6:");
    707723            sOldLoc = sNewLoc + os.sep + oMachine.name
    708724            sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario')
     
    712728                return reporter.testDone()[1] == 0
    713729
    714 #           #
    715 #           # 7. case:
    716 #           #
    717 #           # There are shareable disk and immutable disk attached to the VM.
    718 #           #
    719 #           fRc = fRc and oSession.saveSettings()
    720 #           if fRc is False:
    721 #               reporter.log('Couldn\'t save machine settings')
     730#            #
     731#            # 7. case:
     732#            #
     733#            # There are shareable disk and immutable disk attached to the VM.
     734#            #
     735#            reporter.log("Scenario #7:");
     736#            fRc = fRc and oSession.saveSettings()
     737#            if fRc is False:
     738#                reporter.log('Couldn\'t save machine settings')
    722739#
    723740
Note: See TracChangeset for help on using the changeset viewer.

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