Changeset 75373 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Nov 9, 2018 6:12:30 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/storage/tdStorageSnapshotMerging1.py
r69111 r75373 28 28 terms and conditions of either the GPL or the CDDL or both. 29 29 """ 30 __version__ = "$Id$" 31 30 __version__ = "$Revision$" 32 31 33 32 # Standard Python imports. … … 35 34 import sys; 36 35 import uuid; 36 import zlib; 37 37 38 38 # Only the main script needs to modify the path. … … 47 47 from testdriver import vbox; 48 48 from testdriver import vboxcon; 49 from testdriver import vboxwrappers; 49 50 50 51 def _ControllerTypeToName(eControllerType): … … 62 63 return sType; 63 64 65 def crc32_of_file(filepath): 66 fileobj = open(filepath,'rb'); 67 current = 0; 68 69 while True: 70 buf = fileobj.read(1024 * 1024); 71 if not buf: 72 break 73 current = zlib.crc32(buf, current); 74 75 fileobj.close(); 76 return current % 2**32; 77 64 78 class tdStorageSnapshot(vbox.TestDriver): # pylint: disable=R0902 65 79 """ 66 80 Storage benchmark. 67 81 """ 68 69 82 def __init__(self): 70 83 vbox.TestDriver.__init__(self); … … 73 86 self.oGuestToGuestSess = None; 74 87 self.oGuestToGuestTxs = None; 75 self.asTestVMsDef = ['tst-win7-vhd', 'tst-debian-vhd', 'tst-debian-vdi'];76 self.asTestVMs = self.asTestVMsDef;77 self.asSkipVMs = [];78 88 self.asStorageCtrlsDef = ['AHCI', 'IDE', 'LsiLogicSAS', 'LsiLogic', 'BusLogic']; 79 89 self.asStorageCtrls = self.asStorageCtrlsDef; 80 self.asDiskFormatsDef = ['VDI', 'VMDK', 'VHD', 'QED', 'Parallels', 'QCOW', 'iSCSI']; 90 #self.asDiskFormatsDef = ['VDI', 'VMDK', 'VHD', 'QED', 'Parallels', 'QCOW', 'iSCSI']; 91 self.asDiskFormatsDef = ['VDI', 'VMDK', 'VHD']; 81 92 self.asDiskFormats = self.asDiskFormatsDef; 82 93 self.sRndData = os.urandom(100*1024*1024); … … 93 104 reporter.log(' --disk-formats <type1[:type2[:...]]>'); 94 105 reporter.log(' Default: %s' % (':'.join(self.asDiskFormats))); 95 reporter.log(' --test-vms <vm1[:vm2[:...]]>');96 reporter.log(' Test the specified VMs in the given order. Use this to change');97 reporter.log(' the execution order or limit the choice of VMs');98 reporter.log(' Default: %s (all)' % (':'.join(self.asTestVMsDef)));99 reporter.log(' --skip-vms <vm1[:vm2[:...]]>');100 reporter.log(' Skip the specified VMs when testing.');101 106 return rc; 102 107 … … 111 116 if iArg >= len(asArgs): raise base.InvalidOption('The "--disk-formats" takes a colon separated list of disk formats'); 112 117 self.asDiskFormats = asArgs[iArg].split(':'); 113 elif asArgs[iArg] == '--test-vms':114 iArg += 1;115 if iArg >= len(asArgs): raise base.InvalidOption('The "--test-vms" takes colon separated list');116 self.asTestVMs = asArgs[iArg].split(':');117 for s in self.asTestVMs:118 if s not in self.asTestVMsDef:119 raise base.InvalidOption('The "--test-vms" value "%s" is not valid; valid values are: %s' \120 % (s, ' '.join(self.asTestVMsDef)));121 elif asArgs[iArg] == '--skip-vms':122 iArg += 1;123 if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-vms" takes colon separated list');124 self.asSkipVMs = asArgs[iArg].split(':');125 for s in self.asSkipVMs:126 if s not in self.asTestVMsDef:127 reporter.log('warning: The "--test-vms" value "%s" does not specify any of our test VMs.' % (s));128 118 else: 129 119 return vbox.TestDriver.parseOption(self, asArgs, iArg); 130 120 return iArg + 1; 131 121 132 def completeOptions(self):133 # Remove skipped VMs from the test list.134 for sVM in self.asSkipVMs:135 try: self.asTestVMs.remove(sVM);136 except: pass;137 138 return vbox.TestDriver.completeOptions(self);139 140 122 def getResourceSet(self): 141 123 # Construct the resource list the first time it's queried. 142 124 if self.asRsrcs is None: 143 self.asRsrcs = []; 144 if 'tst-win7-vhd' in self.asTestVMs: 145 self.asRsrcs.append('4.2/storage/win7.vhd'); 146 147 if 'tst-debian-vhd' in self.asTestVMs: 148 self.asRsrcs.append('4.2/storage/debian.vhd'); 149 150 if 'tst-debian-vdi' in self.asTestVMs: 151 self.asRsrcs.append('4.2/storage/debian.vdi'); 152 125 self.asRsrcs = ['5.3/storage/mergeMedium/t-orig.vdi', '5.3/storage/mergeMedium/t-fixed.vdi', '5.3/storage/mergeMedium/t-resized.vdi']; 153 126 return self.asRsrcs; 154 155 def actionConfig(self):156 157 # Make sure vboxapi has been imported so we can use the constants.158 if not self.importVBoxApi():159 return False;160 161 #162 # Configure the VMs we're going to use.163 #164 165 # Windows VMs166 if 'tst-win7-vhd' in self.asTestVMs:167 oVM = self.createTestVM('tst-win7-vhd', 1, '4.2/storage/win7.vhd', sKind = 'Windows7', fIoApic = True, \168 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \169 eNic0Type = vboxcon.NetworkAdapterType_Am79C973);170 if oVM is None:171 return False;172 173 # Linux VMs174 if 'tst-debian-vhd' in self.asTestVMs:175 oVM = self.createTestVM('tst-debian-vhd', 1, '4.2/storage/debian.vhd', sKind = 'Debian_64', fIoApic = True, \176 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \177 eNic0Type = vboxcon.NetworkAdapterType_Am79C973);178 if oVM is None:179 return False;180 181 if 'tst-debian-vdi' in self.asTestVMs:182 oVM = self.createTestVM('tst-debian-vdi', 1, '4.2/storage/debian.vdi', sKind = 'Debian_64', fIoApic = True, \183 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \184 eNic0Type = vboxcon.NetworkAdapterType_Am79C973);185 if oVM is None:186 return False;187 188 return True;189 127 190 128 def actionExecute(self): … … 194 132 fRc = self.test1(); 195 133 return fRc; 196 197 134 135 def resizeMedium(self, oMedium, cbNewSize): 136 if oMedium.deviceType is not vboxcon.DeviceType_HardDisk: 137 return False; 138 139 if oMedium.type is not vboxcon.MediumType_Normal: 140 return False; 141 142 #currently only VDI can be resizable. Medium variant is not checked, because testcase creates disks itself 143 oMediumFormat = oMedium.mediumFormat; 144 if oMediumFormat.id != 'VDI': 145 return False; 146 147 cbCurrSize = oMedium.logicalSize; 148 # currently reduce is not supported 149 if cbNewSize < cbCurrSize: 150 return False; 151 152 try: 153 oProgressCom = oMedium.resize(cbNewSize); 154 oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oVBox.oTstDrv, 'Resize medium %s' % (oMedium.name)); 155 oProgress.wait(cMsTimeout = 60 * 1000); 156 oProgress.logResult(); 157 except: 158 reporter.logXcpt('IMedium::resize failed on %s' % (oMedium.name)); 159 return False; 160 161 return True; 162 163 def getMedium(self, oVM, sController): 164 oMediumAttachments = oVM.getMediumAttachmentsOfController(sController); 165 166 for oAttachment in oMediumAttachments: 167 oMedium = oAttachment.medium; 168 if oMedium.deviceType is not vboxcon.DeviceType_HardDisk: 169 continue; 170 if oMedium.type is not vboxcon.MediumType_Normal: 171 continue; 172 return oMedium; 173 174 return None; 175 176 def getSnapshotMedium(self, oSnapshot, sController): 177 oVM = oSnapshot.machine; 178 oMedium = self.getMedium(oVM, sController); 179 180 for oChildMedium in oMedium.children: 181 for uSnapshotId in oChildMedium.getSnapshotIds(oVM.id): 182 if uSnapshotId == oVM.id: 183 return oChildMedium; 184 185 return None; 186 187 def openMedium(self, sHd, fImmutable = False): 188 """ 189 Opens medium in readonly mode. 190 Returns Medium object on success and None on failure. Error information is logged. 191 """ 192 sFullName = self.oVBox.oTstDrv.getFullResourceName(sHd); 193 try: 194 oHd = self.oVBox.findHardDisk(sFullName); 195 except: 196 try: 197 if self.fpApiVer >= 4.1: 198 oHd = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_HardDisk, vboxcon.AccessMode_ReadOnly, False); 199 elif self.fpApiVer >= 4.0: 200 oHd = self.oVBox.openMedium(sFullName, vboxcon.DeviceType_HardDisk, vboxcon.AccessMode_ReadOnly); 201 else: 202 oHd = self.oVBox.openHardDisk(sFullName, vboxcon.AccessMode_ReadOnly, False, "", False, ""); 203 204 except: 205 reporter.errorXcpt('failed to open hd "%s"' % (sFullName)); 206 return False; 207 208 try: 209 if fImmutable: 210 oHd.type = vboxcon.MediumType_Immutable; 211 else: 212 oHd.type = vboxcon.MediumType_Normal; 213 214 except: 215 if fImmutable: 216 reporter.errorXcpt('failed to set hd "%s" immutable' % (sHd)); 217 else: 218 reporter.errorXcpt('failed to set hd "%s" normal' % (sHd)); 219 220 return None; 221 222 return oHd; 223 224 def cloneMedium(self, oSrcHd, oTgtHd): 225 """ 226 Clones medium into target medium. 227 """ 228 try: 229 oProgressCom = oSrcHd.cloneTo(oTgtHd, (vboxcon.MediumVariant_Standard, ), None); 230 oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oVBoxMgr, self.oVBox.oTstDrv, 'clone base disk %s to %s' % (oSrcHd.name, oTgtHd.name)); 231 oProgress.wait(cMsTimeout = 60 * 1000); 232 oProgress.logResult(); 233 except: 234 reporter.errorXcpt('failed to clone medium %s to %s' % (oSrcHd.name, oTgtHd.name)); 235 return False; 236 237 return True; 238 239 def deleteVM(self, oVM): 240 try: 241 oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone); 242 except: 243 reporter.logXcpt(); 244 pass; 245 246 if self.fpApiVer >= 4.0: 247 try: 248 if self.fpApiVer >= 4.3: 249 oProgress = oVM.deleteConfig([]); 250 else: 251 oProgress = oVM.delete(None); 252 self.waitOnProgress(oProgress); 253 254 except: 255 reporter.logXcpt(); 256 257 else: 258 try: oVM.deleteSettings(); 259 except: reporter.logXcpt(); 260 261 return None; 262 198 263 # 199 264 # Test execution helpers. 200 265 # 201 266 202 def test1UploadFile(self, oSession, oTxsSession): 203 """ 204 Uploads a test file to the test machine. 205 """ 206 reporter.testStart('Upload file'); 207 208 fRc = self.txsUploadString(oSession, oTxsSession, self.sRndData, '${SCRATCH}/' + str(uuid.uuid4()), \ 209 cMsTimeout = 3600 * 1000); 210 211 reporter.testDone(not fRc); 212 return fRc; 213 214 def test1OneCfg(self, sVmName, eStorageController, sDiskFormat): 267 def test1OneCfg(self, eStorageController, oDskFmt): 215 268 """ 216 269 Runs the specified VM thru test #1. … … 219 272 the actual test result. 220 273 """ 221 oVM = self.getVmByName(sVmName); 222 223 # @ŧodo: Implement support for different formats. 224 _ = sDiskFormat; 225 274 275 (asExts, aTypes) = oDskFmt.describeFileExtensions() 276 for i in range(0, len(asExts)): #pylint: disable=consider-using-enumerate 277 if aTypes[i] is vboxcon.DeviceType_HardDisk: 278 sExt = '.' + asExts[i] 279 break 280 281 if sExt is None: 282 return False; 283 284 oOrigBaseHd = self.openMedium('5.3/storage/mergeMedium/t-orig.vdi'); 285 if oOrigBaseHd is None: 286 return False; 287 288 #currently only VDI can be resizable. Medium variant is not checked, because testcase creates disks itself 289 fFmtDynamic = oDskFmt.id == 'VDI'; 290 sOrigWithDiffHd = '5.3/storage/mergeMedium/t-fixed.vdi' 291 uOrigCrc = 0x7a417cbb; 292 293 if fFmtDynamic: 294 sOrigWithDiffHd = '5.3/storage/mergeMedium/t-resized.vdi'; 295 uOrigCrc = 0xa8f5daa3; 296 297 oOrigWithDiffHd = self.openMedium(sOrigWithDiffHd); 298 if oOrigWithDiffHd is None: 299 return False; 300 301 oVM = self.createTestVM('testvm', 1, None); 302 if oVM is None: 303 return False; 304 305 sController = _ControllerTypeToName(eStorageController); 306 226 307 # Reconfigure the VM 308 oSession = self.openSession(oVM); 309 if oSession is None: 310 return False; 311 # Attach HD 312 227 313 fRc = True; 228 oSession = self.openSession(oVM); 314 sFile = 't-base' + sExt; 315 sHddPath = os.path.join(self.oVBox.oTstDrv.sScratchPath, sFile); 316 oHd = oSession.createBaseHd(sHddPath, sFmt=oDskFmt.id, cb=oOrigBaseHd.logicalSize); 317 #if oSession.createBaseHd can't create disk because it exists, oHd will point to some stub object anyway 318 fRc = fRc and oHd is not None and oHd.logicalSize == oOrigBaseHd.logicalSize; 319 fRc = fRc and self.cloneMedium(oOrigBaseHd, oHd); 320 321 fRc = fRc and oSession.ensureControllerAttached(sController); 322 fRc = fRc and oSession.setStorageControllerType(eStorageController, sController); 323 fRc = fRc and oSession.saveSettings(); 324 fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = 0, fImmutable=False, fForceResource=False) 325 326 if fRc: 327 oSession.takeSnapshot('Base snapshot'); 328 oSnapshot = oSession.findSnapshot('Base snapshot'); 329 330 if oSnapshot is not None: 331 oSnapshotMedium = self.getSnapshotMedium(oSnapshot, sController); 332 fRc = oSnapshotMedium is not None; 333 334 if fFmtDynamic: 335 fRc = fRc and self.resizeMedium(oSnapshotMedium, oOrigWithDiffHd.logicalSize); 336 fRc = fRc and self.cloneMedium(oOrigWithDiffHd, oSnapshotMedium); 337 fRc = fRc and oSession.deleteSnapshot(oSnapshot.id, cMsTimeout = 120 * 1000); 338 339 if fRc: 340 # disk for result test by checksum 341 sResFilePath = os.path.join(self.oVBox.oTstDrv.sScratchPath, 't_res.vmdk'); 342 sResFilePathRaw = os.path.join(self.oVBox.oTstDrv.sScratchPath, 't_res-flat.vmdk'); 343 oResHd = oSession.createBaseHd(sResFilePath, sFmt='VMDK', cb=oOrigWithDiffHd.logicalSize, tMediumVariant = (vboxcon.MediumVariant_Fixed, )); 344 fRc = oResHd is not None; 345 fRc = fRc and self.cloneMedium(oHd, oResHd); 346 347 uResCrc32 = 0; 348 if fRc: 349 uResCrc32 = crc32_of_file(sResFilePathRaw); 350 if uResCrc32 == uOrigCrc: 351 reporter.log('Snapshot merged successfully. Data of the result medium are correspond to data of the original medium'); 352 fRc = True; 353 else: 354 reporter.error('Snapshot merging failed. Data of the result medium not correspond to data of the original medium'); 355 fRc = False; 356 357 self.oVBox.deleteHdByMedium(oResHd); 358 229 359 if oSession is not None: 230 # Attach HD 231 fRc = oSession.ensureControllerAttached(_ControllerTypeToName(eStorageController)); 232 fRc = fRc and oSession.setStorageControllerType(eStorageController, _ControllerTypeToName(eStorageController)); 233 fRc = fRc and oSession.saveSettings(); 234 fRc = oSession.close() and fRc and True; # pychecker hack. 235 oSession = None; 236 else: 237 fRc = False; 238 239 # Start up. 240 if fRc is True: 241 self.logVmInfo(oVM); 242 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(sVmName, fCdWait = False, fNatForwardingForTxs = True); 243 if oSession is not None: 244 self.addTask(oTxsSession); 245 246 # Fudge factor - Allow the guest to finish starting up. 247 self.sleep(5); 248 249 # Do a snapshot first. 250 oSession.takeSnapshot('Base snapshot'); 251 252 for i in range(0, 10): 253 oSession.takeSnapshot('Snapshot ' + str(i)); 254 self.test1UploadFile(oSession, oTxsSession); 255 msNow = base.timestampMilli(); 256 oSnapshot = oSession.findSnapshot('Snapshot ' + str(i)); 257 oSession.deleteSnapshot(oSnapshot.id, cMsTimeout = 60 * 1000); 258 msElapsed = base.timestampMilli() - msNow; 259 reporter.log('Deleting snapshot %d took %d ms' % (i, msElapsed)); 260 261 # cleanup. 262 self.removeTask(oTxsSession); 263 self.terminateVmBySession(oSession) 264 else: 265 fRc = False; 360 if oHd is not None: 361 oSession.detachHd(sController, iPort = 0, iDevice = 0); 362 363 oSession.saveSettings(fClose = True); 364 if oHd is not None: 365 self.oVBox.deleteHdByMedium(oHd); 366 367 self.deleteVM(oVM); 266 368 return fRc; 267 369 268 def test1OneVM(self, sVmName): 269 """ 270 Runs one VM thru the various configurations. 271 """ 370 def test1(self): 371 """ 372 Executes test #1 thru the various configurations. 373 """ 374 if not self.importVBoxApi(): 375 return False; 376 377 sVmName = 'testvm'; 272 378 reporter.testStart(sVmName); 379 380 aoDskFmts = self.oVBoxMgr.getArray(self.oVBox.systemProperties, 'mediumFormats') 381 if aoDskFmts is None or len(aoDskFmts) < 1: 382 return False; 383 273 384 fRc = True; 274 385 for sStorageCtrl in self.asStorageCtrls: 275 386 reporter.testStart(sStorageCtrl); 276 277 387 if sStorageCtrl == 'AHCI': 278 388 eStorageCtrl = vboxcon.StorageControllerType_IntelAhci; … … 287 397 else: 288 398 eStorageCtrl = None; 289 290 for sDiskFormat in self.asDiskFormats: 291 reporter.testStart('%s' % (sDiskFormat)); 292 self.test1OneCfg(sVmName, eStorageCtrl, sDiskFormat); 293 reporter.testDone(); 399 400 for oDskFmt in aoDskFmts: 401 if (oDskFmt.id in self.asDiskFormats): 402 reporter.testStart('%s' % (oDskFmt.id)); 403 fRc = self.test1OneCfg(eStorageCtrl, oDskFmt); 404 reporter.testDone(); 405 if not fRc: 406 break; 407 294 408 reporter.testDone(); 409 if not fRc: 410 break; 411 295 412 reporter.testDone(); 296 413 return fRc; 297 414 298 def test1(self):299 """300 Executes test #1.301 """302 303 # Loop thru the test VMs.304 for sVM in self.asTestVMs:305 # run test on the VM.306 if not self.test1OneVM(sVM):307 fRc = False;308 else:309 fRc = True;310 311 return fRc;312 313 314 315 415 if __name__ == '__main__': 316 416 sys.exit(tdStorageSnapshot().main(sys.argv));
Note:
See TracChangeset
for help on using the changeset viewer.