Changeset 71377 in vbox for trunk/src/VBox
- Timestamp:
- Mar 19, 2018 5:26:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/api/tdMoveVM.py
r71228 r71377 33 33 import os 34 34 import sys 35 import time 35 36 36 37 # Only the main script needs to modify the path. … … 59 60 Execute the sub-testcase. 60 61 """ 62 reporter.log('ValidationKit folder is "%s"' % (g_ksValidationKitDir,)) 61 63 return self.testVMMove() 62 64 … … 111 113 oVM = None 112 114 115 # del oSession 116 113 117 return oVM 114 118 … … 205 209 try: 206 210 #create test machine 207 aMachine = self.createTestMachine()208 209 if aMachine is None:211 oMachine = self.createTestMachine() 212 213 if oMachine is None: 210 214 reporter.error('Failed to create test machine') 211 215 … … 216 220 217 221 sController='SATA Controller' 218 aoMediumAttachments = aMachine.getMediumAttachmentsOfController(sController)222 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 219 223 220 224 #lock machine 221 225 #get session machine 222 oSession = self.oTstDrv.openSession( aMachine)226 oSession = self.oTstDrv.openSession(oMachine) 223 227 fRc = True 224 228 225 229 sMoveLoc = sNewLoc + os.sep 226 #1 case. 230 ############# 1 case. ########################################################################################## 227 231 # All disks attached to VM are located outside the VM's folder. 228 232 # There are no any snapshots and logs. … … 234 238 reporter.log('Couldn\'t save machine settings') 235 239 236 #2 case. 240 ############# 2 case. ########################################################################################## 237 241 # All disks attached to VM are located inside the VM's folder. 238 242 # There are no any snapshots and logs. 239 sLoc = sMoveLoc + aMachine.name + os.sep243 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 240 244 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario') 241 245 os.mkdir(sMoveLoc, 0o775) 242 aoMediumAttachments = aMachine.getMediumAttachmentsOfController(sController)246 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 243 247 oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) 244 248 oSubTstDrvMoveMedium1Instance.setLocation(sLoc, aoMediumAttachments) 249 250 del oSubTstDrvMoveMedium1Instance 251 245 252 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc 246 253 … … 249 256 reporter.log('Couldn\'t save machine settings') 250 257 251 #3 case. 258 ############# 3 case. ########################################################################################## 252 259 # There are snapshots. 253 sLoc = sMoveLoc + aMachine.name + os.sep260 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 254 261 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario') 255 262 os.mkdir(sMoveLoc, 0o775) 256 263 257 cSnap = 5264 cSnap = 2 258 265 for counter in range(1,cSnap+1): 259 266 strSnapshot = 'Snapshot' + str(counter) … … 263 270 reporter.testFailure('Error: Can\'t take snapshot "%s".' % (strSnapshot,)) 264 271 265 aoMediumAttachments = aMachine.getMediumAttachmentsOfController(sController)272 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 266 273 if fRc is True: 267 274 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc … … 270 277 if fRc is False: 271 278 reporter.log('Couldn\'t save machine settings') 279 280 ############# 4 case. ########################################################################################## 281 # There are one or more save state files in the snapshots folder 282 # and some files in the logs folder. 283 # Here we run VM, next stop it in the "save" state. 284 # And next move VM 285 286 #Close and delete Session object because after starting VM we get new instance of session 287 # fRc = oSession.close() and fRc 288 # if fRc is False: 289 # reporter.log('Couldn\'t close machine session') 290 # 291 # del oSession 292 # 293 # #Run VM and get new Session object 294 # oSession = self.oTstDrv.startVm(oMachine) 295 # 296 # #some time interval should be here for not closing VM just after start 297 # time.sleep(1) 298 # 299 # if oMachine.state != self.oTstDrv.oVBoxMgr.constants.MachineState_Running: 300 # reporter.log("Machine '%s' is not Running" % (oMachine.name)) 301 # fRc = False 302 # 303 # oConsole = oSession.o.console 304 # 305 # #logic comes from handleControlVM() 306 # #Pause VM using console object 307 # fRc = oConsole.pause() and fRc 308 # 309 # #Check VM state 310 # if oMachine.state == self.oTstDrv.oVBoxMgr.constants.MachineState_Paused: 311 # reporter.log("Machine '%s' is Paused" % (oMachine.name)) 312 # fRc = True 313 # 314 # #call Session::saveState() 315 # if fRc is True: 316 # oProgress = oSession.o.machine.saveState() 317 # rc = self.oTstDrv.waitOnProgress(oProgress,1000) 318 # self.oTstDrv.sleep(2) 319 # 320 # #Close and delete Session object because this session hasn't been locked 321 # #but locking is needed to run moveVMToLocation(). 322 # #if to use the current session object we'll get the error "The session is not locked (session state: Unlocked)" 323 # fRc = oSession.close() and fRc 324 # if fRc is False: 325 # reporter.log('Couldn\'t close machine session') 326 # 327 # del oSession 328 # del oConsole 329 # 330 # sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 331 # sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario') 332 # os.mkdir(sMoveLoc, 0o775) 333 # 334 # #Create a new Session object 335 # #It seems that it's possible to lock VM only via creating a pure Session object (not SessionWrapper as it was before) 336 # #and call Machine::lockMachine() 337 # oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox() 338 # oNewSession = self.oTstDrv.oVBoxMgr.mgr.getSessionObject(oVirtualBox) 339 # 340 # oMachine.lockMachine(oNewSession, self.oTstDrv.oVBoxMgr.constants.LockType_Write) 341 # fRc = self.moveVMToLocation(sMoveLoc, oNewSession.machine) and fRc 342 # oNewSession.unlockMachine() 343 # 344 # del oNewSession 345 # 346 # #call Session::discardSavedState() 347 # #for this we delete oNewSession object earlier and creating SessionWrapper object here 348 # oSession = self.oTstDrv.openSession(oMachine) 349 # fRc = oSession.o.machine.discardSavedState(True) 350 # reporter.log('Discard save machine state') 351 # 352 # del oMachine 353 # del oVirtualBox 354 # 355 # if fRc is False: 356 # reporter.log('Failed to discard the saved state of machine') 357 358 ############## 5 case. ########################################################################################## 359 #There is an ISO image (.iso) attached to the VM. 360 #Prerequisites - there is IDE Controller and there are no any images attached to it. 361 fRc = True 362 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox() 363 oMachine = oVirtualBox.findMachine('test-vm-move') 364 if oMachine == None: 365 reporter.log("Machine '%s' is unknown" % (oMachine.name)) 366 return False 367 368 del oVirtualBox 369 370 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 371 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario') 372 os.mkdir(sMoveLoc, 0o775) 373 sISOLoc = os.path.join(g_ksValidationKitDir + os.sep, 'tests' + os.sep + 'api' + os.sep + 'tdMoveVM.iso') 374 if not os.path.exists(sISOLoc): 375 reporter.log('ISO file does not exist at "%s"' % (sISOLoc,)) 376 fRc = False 377 378 #attach ISO image to the IDE controller 379 if fRc is True: 380 sController='IDE Controller' 381 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 382 iPort = len(aoMediumAttachments) 383 reporter.log('sISOLoc "%s", sController "%s", iPort "%s"' % (sISOLoc,sController,iPort)) 384 fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0) 385 386 fRc = fRc and oSession.saveSettings() 387 if fRc is False: 388 reporter.log('Couldn\'t save machine settings') 389 390 reporter.log('fRc after oSession.attachDvd "%s"' % (fRc)) 391 392 #move ISO image to the VM settings folder 393 if fRc is True: 394 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 395 reporter.log('number of attachments on IDE Controller is "%s"' % (len(aoMediumAttachments))) 396 for oAttachment in aoMediumAttachments: 397 sActualFilePath = oAttachment.medium.location 398 reporter.log('medium location is "%s"' % (sActualFilePath)) 399 400 oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) 401 oSubTstDrvMoveMedium1Instance.setLocation(sLoc, aoMediumAttachments) 402 403 if fRc is True: 404 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc 405 406 fRc = fRc and oSession.saveSettings() 407 if fRc is False: 408 reporter.log('Couldn\'t save machine settings') 409 410 #back ISO image to the original destination 411 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 412 oSubTstDrvMoveMedium1Instance.setLocation(sActualFilePath, aoMediumAttachments) 413 del oSubTstDrvMoveMedium1Instance 414 415 #detach ISO image 416 fRc = oSession.detachHd(sController, iPort, 0) 417 418 fRc = fRc and oSession.saveSettings() 419 if fRc is False: 420 reporter.log('Couldn\'t save machine settings') 421 422 ############# 6 case. ########################################################################################## 423 #There is a floppy image (.img) attached to the VM. 424 #Prerequisites - there is Floppy Controller and there are no any images attached to it. 425 fRc = True 426 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 427 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario') 428 os.mkdir(sMoveLoc, 0o775) 429 sFloppyLoc = os.path.join(g_ksValidationKitDir + os.sep, 'tests' + os.sep + 'api' + os.sep + 'tdMoveVM.img') 430 if not os.path.exists(sISOLoc): 431 reporter.log('Floppy disk does not exist at "%s"' % (sISOLoc,)) 432 fRc = False 433 434 # attach floppy image 435 if fRc is True: 436 sController='Floppy Controller' 437 reporter.log('sFloppyLoc "%s", sController "%s"' % (sFloppyLoc,sController)) 438 fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0) 439 440 fRc = fRc and oSession.saveSettings() 441 if fRc is False: 442 reporter.log('Couldn\'t save machine settings') 443 444 reporter.log('fRc after oSession.attachFloppy "%s"' % (fRc)) 445 446 #move Floppy image to the VM settings folder 447 if fRc is True: 448 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 449 reporter.log('number of attachments on Floppy Controller is "%s"' % (len(aoMediumAttachments))) 450 for oAttachment in aoMediumAttachments: 451 sActualFilePath = oAttachment.medium.location 452 reporter.log('medium location is "%s"' % (sActualFilePath)) 453 454 oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) 455 oSubTstDrvMoveMedium1Instance.setLocation(sLoc, aoMediumAttachments) 456 457 if fRc is True: 458 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc 459 460 #back Floppy image to the original destination 461 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 462 oSubTstDrvMoveMedium1Instance.setLocation(sActualFilePath, aoMediumAttachments) 463 del oSubTstDrvMoveMedium1Instance 464 465 #detach Floppy image 466 fRc = oSession.detachHd(sController, 0, 0) 467 468 fRc = fRc and oSession.saveSettings() 469 if fRc is False: 470 reporter.log('Couldn\'t save machine settings') 471 # 472 ############# 7 case. ########################################################################################## 473 # # There are shareable disk and immutable disk attached to the VM. 474 # # 475 # 476 # fRc = fRc and oSession.saveSettings() 477 # if fRc is False: 478 # reporter.log('Couldn\'t save machine settings') 479 # 480 ############# 8 case. ########################################################################################## 481 # # There is "read-only" disk attached to the VM. 482 # # 483 # 484 # fRc = fRc and oSession.saveSettings() 485 # if fRc is False: 486 # reporter.log('Couldn\'t save machine settings') 487 272 488 273 489 fRc = oSession.close() and fRc
Note:
See TracChangeset
for help on using the changeset viewer.