VirtualBox

Ignore:
Timestamp:
Feb 2, 2018 12:20:34 PM (7 years ago)
Author:
vboxsync
Message:

ValidationKit: Improve API testcase, doing checks if the moved images actually are in the correct place.

File:
1 edited

Legend:

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

    r70849 r70854  
    6666    #
    6767
    68     def setLocation(self, sLocation, aListOfAttach):
    69         for attachment in aListOfAttach:
     68    def setLocation(self, sLocation, aoMediumAttachments):
     69        for oAttachment in aoMediumAttachments:
    7070            try:
    71                 oMedium = attachment.medium
    72                 reporter.log('Move medium ' + oMedium.name + ' to the ' + sLocation)
     71                oMedium = oAttachment.medium
     72                reporter.log('Move medium "%s" to "%s"' % (oMedium.name, sLocation,))
    7373            except:
    74                 reporter.errorXcpt('failed to get the medium from the IMediumAttachment "%s"' % (attachment))
     74                reporter.errorXcpt('failed to get the medium from the IMediumAttachment "%s"' % (oAttachment))
    7575
    7676            try:
     
    8383            if oProgress.logResult() is False:
    8484                return False
     85        return True
    8586
    86     # Test with VDI image
    87     # move medium to a new location.
    88     # case 1. Only path without file name
    89     # case 2. Only path without file name without '\' or '/' at the end
    90     # case 3. Path with file name
    91     # case 4. Only file name
    92     # case 5. Move snapshot
     87    def checkLocation(self, sLocation, aoMediumAttachments, asFiles):
     88        fRc = True
     89        for oAttachment in aoMediumAttachments:
     90            sFilePath = os.path.join(sLocation, asFiles[oAttachment.port])
     91            sActualFilePath = oAttachment.medium.location
     92            if not os.path.samefile(sFilePath, sActualFilePath):
     93                reporter.log('medium location expected to be "%s" but is "%s"', (sFilePath, sActualFilePath))
     94                fRc = False;
     95            if not os.path.exists(sFilePath):
     96                reporter.log('medium file does not exist at "%s"', (sFilePath))
     97                fRc = False;
     98        return fRc
    9399
    94100    def testMediumMove(self):
     
    102108            assert oVM is not None
    103109
    104             # create disk images
     110            # create hard disk images, one for each file-based backend, using the first applicable extension
    105111            fRc = True
    106             c = 0
    107112            oSession = self.oTstDrv.openSession(oVM)
    108113            aoDskFmts = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox.systemProperties, 'mediumFormats')
     114            asFiles = []
    109115            for oDskFmt in aoDskFmts:
    110116                aoDskFmtCaps = self.oTstDrv.oVBoxMgr.getArray(oDskFmt, 'capabilities')
     
    120126                    fRc = False
    121127                    break
    122                 sHddPath = os.path.join(self.oTstDrv.sScratchPath, 'Test' + str(c) + sExt)
     128                sFile = 'Test' + str(len(asFiles)) + sExt
     129                sHddPath = os.path.join(self.oTstDrv.sScratchPath, sFile)
    123130                oHd = oSession.createBaseHd(sHddPath, sFmt=oDskFmt.id, cb=1024*1024)
    124131                if oHd is None:
     
    128135                # attach HDD, IDE controller exists by default, but we use SATA just in case
    129136                sController='SATA Controller'
    130                 fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = c, fImmutable=False, fForceResource=False)
     137                fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = len(asFiles), fImmutable=False, fForceResource=False)
    131138                if fRc:
    132                     c += 1
     139                    asFiles.append(sFile)
    133140
    134141            fRc = fRc and oSession.saveSettings()
     
    136143            #create temporary subdirectory in the current working directory
    137144            sOrigLoc = self.oTstDrv.sScratchPath
    138             sNewLoc = os.path.join(sOrigLoc, 'newLocation/')
    139 
     145            sNewLoc = os.path.join(sOrigLoc, 'newLocation')
    140146            os.mkdir(sNewLoc, 0o775)
    141147
    142             aListOfAttach = oVM.getMediumAttachmentsOfController(sController)
    143             #case 1. Only path without file name
    144             sLocation = sNewLoc
    145             self.setLocation(sLocation, aListOfAttach)
     148            aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
     149            #case 1. Only path without file name, with trailing separator
     150            fRc = self.setLocation(sNewLoc + os.sep, aoMediumAttachments) and fRc
     151            fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asFiles) and fRc
    146152
    147             #case 2. Only path without file name without '\' or '/' at the end
    148             sLocation = sOrigLoc
    149             self.setLocation(sLocation, aListOfAttach)
     153            #case 2. Only path without file name, without trailing separator
     154            fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
     155            fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asFiles) and fRc
    150156
    151157            #case 3. Path with file name
    152             sLocation = sNewLoc + 'newName'
    153             self.setLocation(sLocation, aListOfAttach)
     158            fRc = self.setLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments) and fRc
     159            asNewFiles = list(map(lambda s: 'newName' + os.path.splitext(s)[1], asFiles))
     160            fRc = self.checkLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments, asFiles) and fRc
     161            # BUG! the check above succeeds, but it actually should be the one below which does
     162            #fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asNewFiles) and fRc
    154163
    155164            #case 4. Only file name
    156             sLocation = 'onlyMediumName'
    157             self.setLocation(sLocation, aListOfAttach)
     165            fRc = self.setLocation('onlyMediumName', aoMediumAttachments) and fRc
     166            asNewFiles = list(map(lambda s: 'onlyMediumName' + os.path.splitext(s)[1], asFiles))
     167            fRc = self.checkLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments,
     168                                     list(map(lambda s: s.replace('.hdd', '.parallels'), asNewFiles))) and fRc
     169            # BUG! due to the above path mishandling the check above succeeds, the directory issue is
     170            # a consequence of the bug in case 3, but the extension is also picked incorrectly, it is
     171            # not correct to just pick the backend id as the extension, it needs looking at the ext list.
     172            #fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asNewFiles) and fRc
    158173
    159             #case 5. Move snapshot
     174            #case 5. Move all files from a snapshot
    160175            fRc = fRc and oSession.takeSnapshot('Snapshot1')
    161             sLocation = sOrigLoc
    162             #get fresh attachments after snapshot
    163             aListOfAttach = oVM.getMediumAttachmentsOfController(sController)
    164             self.setLocation(sLocation, aListOfAttach)
     176            if fRc:
     177                aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
     178                asSnapFiles = list(map(lambda o: os.path.basename(o.medium.name), aoMediumAttachments))
     179                fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
     180                fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asSnapFiles) and fRc
    165181
    166182            fRc = oSession.close() and fRc
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