Changeset 71543 in vbox for trunk/src/VBox/ValidationKit/tests/api/tdMoveVM1.py
- Timestamp:
- Mar 28, 2018 3:34:21 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/api/tdMoveVM1.py
r71465 r71543 35 35 import time 36 36 import shutil 37 from collections import defaultdict 37 38 38 39 # Only the main script needs to modify the path. … … 49 50 from tdMoveMedium1 import SubTstDrvMoveMedium1 50 51 52 class SubTstDrvMoveVM1Error(Exception): 53 def __init__(self, desc): 54 self.desc = desc 55 def __str__(self): 56 return repr(self.desc) 57 51 58 class SubTstDrvMoveVM1(base.SubTestDriverBase): 52 59 """ … … 57 64 base.SubTestDriverBase.__init__(self, 'move-vm', oTstDrv) 58 65 self.asRsrcs = self.__getResourceSet() 59 60 for oRes in self.asRsrcs: 61 reporter.log('Resource is "%s"' % (oRes,)) 66 self.asImagesNames = [] 67 self.dsKeys = dict (StandardImage = 'SATA Controller', 68 ISOImage = 'IDE Controller', 69 FloppyImage = 'Floppy Controller', 70 SettingsFile = 'Settings File', 71 LogFile = 'Log File', 72 SavedStateFile = 'Saved State File', 73 SnapshotFile = 'Snapshot File') 62 74 63 75 def testIt(self): … … 84 96 oSession = self.oTstDrv.openSession(oVM) 85 97 aoDskFmts = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox.systemProperties, 'mediumFormats') 86 asFiles = [] 98 87 99 for oDskFmt in aoDskFmts: 88 100 aoDskFmtCaps = self.oTstDrv.oVBoxMgr.getArray(oDskFmt, 'capabilities') … … 98 110 fRc = False 99 111 break 100 sFile = 'test-vm-move' + str(len( asFiles)) + sExt112 sFile = 'test-vm-move' + str(len(self.asImagesNames)) + sExt 101 113 sHddPath = os.path.join(self.oTstDrv.sScratchPath, sFile) 102 114 oHd = oSession.createBaseHd(sHddPath, sFmt=oDskFmt.id, cb=1024*1024) … … 106 118 107 119 # attach HDD, IDE controller exists by default, but we use SATA just in case 108 sController= 'SATA Controller'109 fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = len( asFiles),120 sController=self.dsKeys['StandardImage'] 121 fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = len(self.asImagesNames), 110 122 fImmutable=False, fForceResource=False) 111 123 if fRc: 112 asFiles.append(sFile)124 self.asImagesNames.append(sFile) 113 125 114 126 fRc = fRc and oSession.saveSettings() … … 147 159 #checkLocation 148 160 # 149 def checkLocation(self, sLocation, aoMediumAttachments, asFiles): 161 #Prerequisites: 162 #1. All standard images are attached to SATA controller 163 #2. All ISO images are attached to IDE controller 164 #3. All floppy images are attached to Floppy controller 165 #4. The type defaultdict from collection is used here (some sort of multimap data structure) 166 #5. The dsReferenceFiles parameter here is the structure defaultdict(set): 167 # [ 168 # ('StandardImage': ['somedisk.vdi', 'somedisk.vmdk',...]), 169 # ('ISOImage': ['somedisk_1.iso','somedisk_2.iso',...]), 170 # ('FloppyImage': ['somedisk_1.img','somedisk_2.img',...]), 171 # ('SnapshotFile': ['snapshot file 1','snapshot file 2', ...]), 172 # ('SettingsFile', ['setting file',...]), 173 # ('SavedStateFile': ['state file 1','state file 2',...]), 174 # ('LogFile': ['log file 1','log file 2',...]), 175 # ] 176 # 177 def checkLocation(self, oMachine, dsReferenceFiles): 178 150 179 fRc = True 151 for oAttachment in aoMediumAttachments: 152 sFilePath = os.path.join(sLocation, asFiles[oAttachment.port]) 153 sActualFilePath = oAttachment.medium.location 154 if os.path.abspath(sFilePath) != os.path.abspath(sActualFilePath): 155 reporter.log('medium location expected to be "%s" but is "%s"' % (sFilePath, sActualFilePath)) 156 fRc = False 157 if not os.path.exists(sFilePath): 158 reporter.log('medium file does not exist at "%s"' % (sFilePath,)) 159 fRc = False 180 iLen = 0 181 182 for key, value in self.dsKeys.iteritems(): 183 aActuals = set() 184 aReferences = set() 185 186 #Check standard images locations, ISO files locations, floppy images locations, snapshots files locations 187 if key == 'StandardImage' or key == 'ISOImage' or key == 'FloppyImage': 188 aReferences = dsReferenceFiles[key] 189 if len (aReferences) > 0: 190 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(value) 191 for oAttachment in aoMediumAttachments: 192 aActuals.add(oAttachment.medium.location) 193 194 elif key == 'SnapshotFile': 195 aReferences = dsReferenceFiles[key] 196 if len (aReferences) > 0: 197 aActuals = self.__getSnapshotsFiles(oMachine) 198 199 #Check setting file location 200 elif key == 'SettingsFile': 201 aReferences = dsReferenceFiles[key] 202 if len (aReferences) > 0: 203 aActuals.add(oMachine.settingsFilePath) 204 205 #Check saved state files location 206 elif key == 'SavedStateFile': 207 aReferences = dsReferenceFiles[key] 208 if len (aReferences) > 0: 209 aActuals = self.__getStatesFiles(oMachine) 210 211 #Check log files location 212 elif key == 'LogFile': 213 aReferences = dsReferenceFiles[key] 214 if len (aReferences) > 0: 215 aActuals = self.__getLogFiles(oMachine) 216 217 if len(aActuals) > 0: 218 reporter.log('Check %s' % (key)) 219 intersection = aReferences.intersection(aActuals) 220 for eachItem in intersection: 221 reporter.log('Item location "%s" is correct' % (eachItem)) 222 223 difference = aReferences.difference(aActuals) 224 for eachItem in difference: 225 reporter.log('Item location "%s" isn\'t correct' % (eachItem)) 226 227 if len (intersection) != len (aActuals): 228 reporter.log('Not all items in the right location. Check it.') 229 fRc = False 230 160 231 return fRc 161 232 … … 168 239 169 240 return False 241 242 def __getStatesFiles(self, oMachine, fPrint = False): 243 asStateFilesList = set() 244 sFolder = oMachine.snapshotFolder 245 for file in os.listdir(sFolder): 246 if file.endswith(".sav"): 247 sFile = os.path.join(sFolder, file) 248 asStateFilesList.add(sFile) 249 if fPrint is True: 250 reporter.log("State file is %s" % (sFile)) 251 return asStateFilesList 252 253 def __getSnapshotsFiles(self, oMachine, fPrint = False): 254 asSnapshotsFilesList = set() 255 sFolder = oMachine.snapshotFolder 256 for file in os.listdir(sFolder): 257 if file.endswith(".sav") is False: 258 sFile = os.path.join(sFolder, file) 259 asSnapshotsFilesList.add(sFile) 260 if fPrint is True: 261 reporter.log("Snapshot file is %s" % (sFile)) 262 return asSnapshotsFilesList 263 264 def __getLogFiles(self, oMachine, fPrint = False): 265 asLogFilesList = set() 266 sFolder = oMachine.logFolder 267 for file in os.listdir(sFolder): 268 if file.endswith(".log"): 269 sFile = os.path.join(sFolder, file) 270 asLogFilesList.add(sFile) 271 if fPrint is True: 272 reporter.log("Log file is %s" % (sFile)) 273 return asLogFilesList 170 274 171 275 def __getResourceSet(self): … … 197 301 #create a new Session object for moving VM 198 302 oSession = self.oTstDrv.openSession(oMachine) 199 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 303 304 #always clear before each scenario 305 dsReferenceFiles = defaultdict(set) 306 307 asLogs = self.__getLogFiles(oMachine) 308 for sFile in asLogs: 309 sRes = sFile.rpartition(os.sep) 310 dsReferenceFiles['LogFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Logs' + os.sep + sRes[2]) 311 312 asStates = self.__getStatesFiles(oMachine) 313 for sFile in asStates: 314 sRes = sFile.rpartition(os.sep) 315 dsReferenceFiles['SavedStateFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Snapshots' + os.sep + sRes[2]) 316 317 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) 318 319 if fRc is True: 320 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) 321 if fRc is False: 322 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') 323 else: 324 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') 200 325 201 326 # cleaning up: get rid of saved state 202 fRc = fRc and oSession.discardSavedState(True) 203 if fRc is False: 204 reporter.log('Failed to discard the saved state of machine') 205 206 fRc = oSession.close() and fRc 207 if fRc is False: 208 reporter.log('Couldn\'t close machine session') 327 fRes = oSession.discardSavedState(True) 328 if fRes is False: 329 reporter.log('4th scenario: Failed to discard the saved state of machine') 330 331 fRes = oSession.close() 332 if fRes is False: 333 reporter.log('4th scenario: Couldn\'t close machine session') 334 else: 335 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Terminate machine by session failed... !!!!!!!!!!!!!!!!!!') 209 336 210 337 return fRc … … 213 340 214 341 fRc = True 342 sISOImageName = 'tdMoveVM1.iso' 343 344 #always clear before each scenario 345 dsReferenceFiles = defaultdict(set) 346 215 347 #create a new Session object 216 348 oSession = self.oTstDrv.openSession(oMachine) … … 230 362 if fRc is True: 231 363 #set actual ISO location 232 sISOLoc = sOldLoc + os.sep + 'tdMoveVM1.iso'233 sController= 'IDE Controller'364 sISOLoc = sOldLoc + os.sep + sISOImageName 365 sController=self.dsKeys['ISOImage'] 234 366 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 235 367 iPort = len(aoMediumAttachments) 236 reporter.log('sISOLoc "%s", sController "%s", iPort "%s"' % (sISOLoc,sController,iPort))237 368 fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0) 369 dsReferenceFiles['ISOImage'].add(os.path.join(os.path.join(sNewLoc, oMachine.name), sISOImageName)) 238 370 239 371 if fRc is True: 240 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 372 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) 373 if fRc is True: 374 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) 375 if fRc is False: 376 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') 377 else: 378 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') 379 else: 380 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Attach ISO image failed... !!!!!!!!!!!!!!!!!!') 241 381 242 382 #detach ISO image 243 fRc = oSession.detachHd(sController, iPort, 0) 244 245 fRc = fRc and oSession.saveSettings() 246 if fRc is False: 247 reporter.log('Couldn\'t save machine settings after 5th scenario') 248 249 fRc = oSession.close() and fRc 250 if fRc is False: 251 reporter.log('Couldn\'t close machine session') 383 fRes = oSession.detachHd(sController, iPort, 0) 384 if fRes is False: 385 reporter.log('5th scenario: Couldn\'t detach image from the controller %s port %s device %s' % (sController, iPort, 0)) 386 387 fRes = oSession.saveSettings() 388 if fRes is False: 389 reporter.log('5th scenario: Couldn\'t save machine settings') 390 391 fRes = oSession.close() 392 if fRes is False: 393 reporter.log('5th scenario: Couldn\'t close machine session') 252 394 253 395 return fRc … … 256 398 257 399 fRc = True 400 401 #always clear before each scenario 402 dsReferenceFiles = defaultdict(set) 403 258 404 #create a new Session object 259 405 oSession = self.oTstDrv.openSession(oMachine) … … 272 418 if fRc is True: 273 419 #set actual floppy location 274 sFloppy Loc = sOldLoc + os.sep +'tdMoveVM1.img'275 s Controller='Floppy Controller'276 reporter.log('sFloppyLoc "%s", sController "%s"' % (sFloppyLoc,sController))420 sFloppyImageName = 'tdMoveVM1.img' 421 sFloppyLoc = sOldLoc + os.sep + sFloppyImageName 422 sController=self.dsKeys['FloppyImage'] 277 423 fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0) 424 dsReferenceFiles['FloppyImage'].add(os.path.join(os.path.join(sNewLoc, oMachine.name), sFloppyImageName)) 278 425 279 426 if fRc is True: 280 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 427 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) 428 if fRc is True: 429 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) 430 if fRc is False: 431 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') 432 else: 433 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') 434 else: 435 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Attach floppy image failed... !!!!!!!!!!!!!!!!!!') 281 436 282 437 #detach floppy image 283 fRc = oSession.detachHd(sController, 0, 0) 284 285 fRc = fRc and oSession.saveSettings() 286 if fRc is False: 287 reporter.log('Couldn\'t save machine settings after 6th scenario') 288 289 fRc = oSession.close() and fRc 290 if fRc is False: 291 reporter.log('Couldn\'t close machine session') 292 438 fRes = oSession.detachHd(sController, 0, 0) 439 if fRes is False: 440 reporter.log('6th scenario: Couldn\'t detach image from the controller %s port %s device %s' % (sController, 0, 0)) 441 442 fRes = oSession.saveSettings() 443 if fRes is False: 444 reporter.testFailure('6th scenario: Couldn\'t save machine settings') 445 446 fRes = oSession.close() 447 if fRes is False: 448 reporter.log('6th scenario: Couldn\'t close machine session') 293 449 return fRc 294 450 … … 305 461 return False 306 462 307 isSupported = self.checkAPIVersion()308 309 if isSupported is False:463 fSupported = self.checkAPIVersion() 464 465 if fSupported is False: 310 466 reporter.log('API version is below "%s". Just skip this test.' % (self.oTstDrv.fpApiVer)) 311 467 return reporter.testDone()[1] == 0 … … 344 500 os.mkdir(sBaseLoc, 0o775) 345 501 346 sController= 'SATA Controller'502 sController=self.dsKeys['StandardImage'] 347 503 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 348 504 … … 353 509 354 510 sNewLoc = sBaseLoc + os.sep 511 512 dsReferenceFiles = defaultdict(set) 513 355 514 ############# 1 case. ########################################################################################## 356 515 # All disks attached to VM are located outside the VM's folder. 357 516 # There are no any snapshots and logs. 358 517 # In this case only VM setting file should be moved (.vbox file) 359 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 360 361 fRc = fRc and oSession.saveSettings() 518 for s in self.asImagesNames: 519 reporter.log('"%s"' % (s,)) 520 dsReferenceFiles['StandardImage'].add(os.path.join(sOrigLoc, s)) 521 522 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) 523 dsReferenceFiles['SettingsFile'].add(sSettingFile) 524 525 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) 526 527 if fRc is True: 528 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) 529 if fRc is False: 530 reporter.testFailure('!!!!!!!!!!!!!!!!!! 1st scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') 531 return reporter.testDone()[1] == 0 532 else: 533 reporter.testFailure('!!!!!!!!!!!!!!!!!! 1st scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') 534 return reporter.testDone()[1] == 0 535 536 fRc = oSession.saveSettings() 362 537 if fRc is False: 363 reporter. log('Couldn\'t save machine settings after 1t scenario')538 reporter.testFailure('1st scenario: Couldn\'t save machine settings') 364 539 365 540 ############# 2 case. ########################################################################################## 366 541 # All disks attached to VM are located inside the VM's folder. 367 542 # There are no any snapshots and logs. 368 sOldLoc = sNewLoc + o s.sep + oMachine.name + os.sep543 sOldLoc = sNewLoc + oMachine.name + os.sep 369 544 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario') 370 545 os.mkdir(sNewLoc, 0o775) 546 sController = self.dsKeys['StandardImage'] 371 547 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 372 548 oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) … … 375 551 del oSubTstDrvMoveMedium1Instance 376 552 377 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 378 379 fRc = fRc and oSession.saveSettings() 553 #always clear before each scenario 554 dsReferenceFiles.clear() 555 556 for s in self.asImagesNames: 557 reporter.log('"%s"' % (s,)) 558 dsReferenceFiles['StandardImage'].add(sNewLoc + os.sep + oMachine.name + os.sep + s) 559 560 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) 561 dsReferenceFiles['SettingsFile'].add(sSettingFile) 562 563 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) 564 565 if fRc is True: 566 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) 567 if fRc is False: 568 reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') 569 return reporter.testDone()[1] == 0 570 else: 571 reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') 572 return reporter.testDone()[1] == 0 573 574 fRc = oSession.saveSettings() 380 575 if fRc is False: 381 reporter. log('Couldn\'t save machine settings after 2nd scenario')576 reporter.testFailure('2nd scenario: Couldn\'t save machine settings') 382 577 383 578 ############# 3 case. ########################################################################################## 384 579 # There are snapshots. 385 sOldLoc = sNewLoc + o s.sep + oMachine.name + os.sep580 sOldLoc = sNewLoc + oMachine.name + os.sep 386 581 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario') 387 582 os.mkdir(sNewLoc, 0o775) 388 583 389 cSnap = 2 584 #At moment, it's used only one snapshot due to the difficulty to get 585 #all attachments of the machine (i.e. not only attached at moment) 586 cSnap = 1 587 390 588 for counter in range(1,cSnap+1): 391 589 strSnapshot = 'Snapshot' + str(counter) 392 590 fRc = fRc and oSession.takeSnapshot(strSnapshot) 393 591 if fRc is False: 394 reporter.error('Error: Can\'t take snapshot "%s".' % (strSnapshot,)) 395 reporter.testFailure('Error: Can\'t take snapshot "%s".' % (strSnapshot,)) 396 592 reporter.testFailure('3rd scenario: Can\'t take snapshot "%s"' % (strSnapshot,)) 593 return reporter.testDone()[1] == 0 594 595 #always clear before each scenario 596 dsReferenceFiles.clear() 597 598 sController = self.dsKeys['StandardImage'] 397 599 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 398 600 if fRc is True: 399 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 400 401 fRc = fRc and oSession.saveSettings() 601 for oAttachment in aoMediumAttachments: 602 sRes = oAttachment.medium.location.rpartition(os.sep) 603 dsReferenceFiles['SnapshotFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Snapshots' + os.sep + sRes[2]) 604 605 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) 606 dsReferenceFiles['SettingsFile'].add(sSettingFile) 607 608 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) 609 610 if fRc is True: 611 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) 612 if fRc is False: 613 reporter.testFailure('!!!!!!!!!!!!!!!!!! 3rd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') 614 return reporter.testDone()[1] == 0 615 else: 616 reporter.testFailure('!!!!!!!!!!!!!!!!!! 3rd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') 617 return reporter.testDone()[1] == 0 618 619 fRc = oSession.saveSettings() 402 620 if fRc is False: 403 reporter. log('Couldn\'t save machine settings after 3d scenario')621 reporter.testFailure('3d scenario: Couldn\'t save machine settings') 404 622 405 623 ############# 4 case. ########################################################################################## … … 409 627 # And next move VM 410 628 411 sOldLoc = sNewLoc + o s.sep + oMachine.name + os.sep629 sOldLoc = sNewLoc + oMachine.name + os.sep 412 630 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario') 413 631 os.mkdir(sNewLoc, 0o775) … … 420 638 del oSession 421 639 422 self.__testScenario_4(oMachine, sNewLoc) 640 fRc = self.__testScenario_4(oMachine, sNewLoc) 641 if fRc is False: 642 return reporter.testDone()[1] == 0 423 643 424 644 ############## 5 case. ########################################################################################## … … 429 649 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario') 430 650 os.mkdir(sNewLoc, 0o775) 431 self.__testScenario_5(oMachine, sNewLoc, sOldLoc) 651 fRc = self.__testScenario_5(oMachine, sNewLoc, sOldLoc) 652 if fRc is False: 653 return reporter.testDone()[1] == 0 432 654 433 655 ############# 6 case. ########################################################################################## … … 438 660 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario') 439 661 os.mkdir(sNewLoc, 0o775) 440 self.__testScenario_6(oMachine, sNewLoc, sOldLoc) 662 fRc = self.__testScenario_6(oMachine, sNewLoc, sOldLoc) 663 if fRc is False: 664 return reporter.testDone()[1] == 0 441 665 442 666 ############# 7 case. ##########################################################################################
Note:
See TracChangeset
for help on using the changeset viewer.