Changeset 70854 in vbox for trunk/src/VBox/ValidationKit/tests/api/tdMoveMedium1.py
- Timestamp:
- Feb 2, 2018 12:20:34 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/api/tdMoveMedium1.py
r70849 r70854 66 66 # 67 67 68 def setLocation(self, sLocation, a ListOfAttach):69 for attachment in aListOfAttach:68 def setLocation(self, sLocation, aoMediumAttachments): 69 for oAttachment in aoMediumAttachments: 70 70 try: 71 oMedium = attachment.medium72 reporter.log('Move medium ' + oMedium.name + ' to the ' + sLocation)71 oMedium = oAttachment.medium 72 reporter.log('Move medium "%s" to "%s"' % (oMedium.name, sLocation,)) 73 73 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)) 75 75 76 76 try: … … 83 83 if oProgress.logResult() is False: 84 84 return False 85 return True 85 86 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 93 99 94 100 def testMediumMove(self): … … 102 108 assert oVM is not None 103 109 104 # create disk images110 # create hard disk images, one for each file-based backend, using the first applicable extension 105 111 fRc = True 106 c = 0107 112 oSession = self.oTstDrv.openSession(oVM) 108 113 aoDskFmts = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox.systemProperties, 'mediumFormats') 114 asFiles = [] 109 115 for oDskFmt in aoDskFmts: 110 116 aoDskFmtCaps = self.oTstDrv.oVBoxMgr.getArray(oDskFmt, 'capabilities') … … 120 126 fRc = False 121 127 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) 123 130 oHd = oSession.createBaseHd(sHddPath, sFmt=oDskFmt.id, cb=1024*1024) 124 131 if oHd is None: … … 128 135 # attach HDD, IDE controller exists by default, but we use SATA just in case 129 136 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) 131 138 if fRc: 132 c += 1139 asFiles.append(sFile) 133 140 134 141 fRc = fRc and oSession.saveSettings() … … 136 143 #create temporary subdirectory in the current working directory 137 144 sOrigLoc = self.oTstDrv.sScratchPath 138 sNewLoc = os.path.join(sOrigLoc, 'newLocation/') 139 145 sNewLoc = os.path.join(sOrigLoc, 'newLocation') 140 146 os.mkdir(sNewLoc, 0o775) 141 147 142 a ListOfAttach= oVM.getMediumAttachmentsOfController(sController)143 #case 1. Only path without file name 144 sLocation = sNewLoc145 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 146 152 147 #case 2. Only path without file name without '\' or '/' at the end148 sLocation = sOrigLoc149 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 150 156 151 157 #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 154 163 155 164 #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 158 173 159 #case 5. Move snapshot174 #case 5. Move all files from a snapshot 160 175 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 165 181 166 182 fRc = oSession.close() and fRc
Note:
See TracChangeset
for help on using the changeset viewer.