Changeset 71464 in vbox for trunk/src/VBox/ValidationKit/tests
- Timestamp:
- Mar 22, 2018 4:15:14 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/api/tdMoveVM1.py
r71458 r71464 56 56 def __init__(self, oTstDrv): 57 57 base.SubTestDriverBase.__init__(self, 'move-vm', oTstDrv) 58 self.asRsrcs = self. getResourceSet()58 self.asRsrcs = self.__getResourceSet() 59 59 60 60 for oRes in self.asRsrcs: … … 169 169 return False 170 170 171 def getResourceSet(self):171 def __getResourceSet(self): 172 172 # Construct the resource list the first time it's queried. 173 173 if self.oTstDrv.asRsrcs is None: … … 178 178 return self.oTstDrv.asRsrcs 179 179 180 def __testScenario_4(self, oMachine, sNewLoc, sOldLoc = 0): 181 182 #Run VM and get new Session object 183 oSession = self.oTstDrv.startVm(oMachine) 184 185 #some time interval should be here for not closing VM just after start 186 time.sleep(1) 187 188 if oMachine.state != self.oTstDrv.oVBoxMgr.constants.MachineState_Running: 189 reporter.log("Machine '%s' is not Running" % (oMachine.name)) 190 fRc = False 191 192 #call Session::saveState(), already closes session unless it failed 193 fRc = oSession.saveState() 194 self.oTstDrv.terminateVmBySession(oSession) 195 196 if fRc: 197 #create a new Session object for moving VM 198 oSession = self.oTstDrv.openSession(oMachine) 199 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 200 201 # 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') 209 210 return fRc 211 212 def __testScenario_5(self, oMachine, sNewLoc, sOldLoc = 0): 213 214 fRc = True 215 #create a new Session object 216 oSession = self.oTstDrv.openSession(oMachine) 217 218 sISOLoc = '5.3/isos/tdMoveVM1.iso' 219 reporter.log("sHost is '%s', sResourcePath is '%s'" % (self.oTstDrv.sHost, self.oTstDrv.sResourcePath)) 220 sISOLoc = self.oTstDrv.getFullResourceName(sISOLoc) 221 222 if not os.path.exists(sISOLoc): 223 reporter.log('ISO file does not exist at "%s"' % (sISOLoc,)) 224 fRc = False 225 226 #Copy ISO image from the common resource folder into machine folder 227 shutil.copy(sISOLoc, sOldLoc) 228 229 #attach ISO image to the IDE controller 230 if fRc is True: 231 #set actual ISO location 232 sISOLoc = sOldLoc + os.sep + 'tdMoveVM1.iso' 233 sController='IDE Controller' 234 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 235 iPort = len(aoMediumAttachments) 236 reporter.log('sISOLoc "%s", sController "%s", iPort "%s"' % (sISOLoc,sController,iPort)) 237 fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0) 238 239 if fRc is True: 240 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 241 242 #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') 252 253 return fRc 254 255 def __testScenario_6(self, oMachine, sNewLoc, sOldLoc = 0): 256 257 fRc = True 258 #create a new Session object 259 oSession = self.oTstDrv.openSession(oMachine) 260 261 sFloppyLoc = '5.3/floppy/tdMoveVM1.img' 262 sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc) 263 264 if not os.path.exists(sFloppyLoc): 265 reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,)) 266 fRc = False 267 268 #Copy floppy image from the common resource folder into machine folder 269 shutil.copy(sFloppyLoc, sOldLoc) 270 271 # attach floppy image 272 if fRc is True: 273 #set actual floppy location 274 sFloppyLoc = sOldLoc + os.sep + 'tdMoveVM1.img' 275 sController='Floppy Controller' 276 reporter.log('sFloppyLoc "%s", sController "%s"' % (sFloppyLoc,sController)) 277 fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0) 278 279 if fRc is True: 280 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 281 282 #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 293 return fRc 294 180 295 # 181 296 #testVMMove … … 216 331 # 217 332 #7. There are shareable disk and immutable disk attached to the VM. 218 #219 #8. There is "read-only" disk attached to the VM.220 333 221 334 try: … … 228 341 #create temporary subdirectory in the current working directory 229 342 sOrigLoc = self.oTstDrv.sScratchPath 230 s NewLoc = os.path.join(sOrigLoc, 'moveFolder')231 os.mkdir(s NewLoc, 0o775)343 sBaseLoc = os.path.join(sOrigLoc, 'moveFolder') 344 os.mkdir(sBaseLoc, 0o775) 232 345 233 346 sController='SATA Controller' … … 239 352 fRc = True 240 353 241 s MoveLoc = sNewLoc + os.sep354 sNewLoc = sBaseLoc + os.sep 242 355 ############# 1 case. ########################################################################################## 243 356 # All disks attached to VM are located outside the VM's folder. 244 357 # There are no any snapshots and logs. 245 358 # In this case only VM setting file should be moved (.vbox file) 246 fRc = self.moveVMToLocation(s MoveLoc, oSession.o.machine) and fRc359 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 247 360 248 361 fRc = fRc and oSession.saveSettings() … … 253 366 # All disks attached to VM are located inside the VM's folder. 254 367 # There are no any snapshots and logs. 255 s Loc = sMoveLoc + os.sep + oMachine.name + os.sep256 s MoveLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario')257 os.mkdir(s MoveLoc, 0o775)368 sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep 369 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario') 370 os.mkdir(sNewLoc, 0o775) 258 371 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 259 372 oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) 260 oSubTstDrvMoveMedium1Instance.setLocation(s Loc, aoMediumAttachments)373 oSubTstDrvMoveMedium1Instance.setLocation(sOldLoc, aoMediumAttachments) 261 374 262 375 del oSubTstDrvMoveMedium1Instance 263 376 264 fRc = self.moveVMToLocation(s MoveLoc, oSession.o.machine) and fRc377 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 265 378 266 379 fRc = fRc and oSession.saveSettings() … … 270 383 ############# 3 case. ########################################################################################## 271 384 # There are snapshots. 272 s Loc = sMoveLoc + os.sep + oMachine.name + os.sep273 s MoveLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario')274 os.mkdir(s MoveLoc, 0o775)385 sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep 386 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario') 387 os.mkdir(sNewLoc, 0o775) 275 388 276 389 cSnap = 2 … … 284 397 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 285 398 if fRc is True: 286 fRc = self.moveVMToLocation(s MoveLoc, oSession.o.machine) and fRc399 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc 287 400 288 401 fRc = fRc and oSession.saveSettings() … … 296 409 # And next move VM 297 410 411 sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep 412 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario') 413 os.mkdir(sNewLoc, 0o775) 414 298 415 #Close Session object because after starting VM we get new instance of session 299 416 fRc = oSession.close() and fRc … … 301 418 reporter.log('Couldn\'t close machine session') 302 419 303 #Run VM and get new Session object 304 oSession = self.oTstDrv.startVm(oMachine) 305 306 #some time interval should be here for not closing VM just after start 307 time.sleep(1) 308 309 if oMachine.state != self.oTstDrv.oVBoxMgr.constants.MachineState_Running: 310 reporter.log("Machine '%s' is not Running" % (oMachine.name)) 311 fRc = False 312 313 #call Session::saveState(), already closes session unless it failed 314 fRc = fRc and oSession.saveState() 315 self.oTstDrv.terminateVmBySession(oSession) 316 317 if fRc: 318 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 319 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario') 320 os.mkdir(sMoveLoc, 0o775) 321 322 #create a new Session object for moving VM 323 oSession = self.oTstDrv.openSession(oMachine) 324 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc 325 326 # cleaning up: get rid of saved state 327 fRc = fRc and oSession.discardSavedState(True) 328 if fRc is False: 329 reporter.log('Failed to discard the saved state of machine') 420 del oSession 421 422 self.__testScenario_4(oMachine, sNewLoc) 330 423 331 424 ############## 5 case. ########################################################################################## 332 425 #There is an ISO image (.iso) attached to the VM. 333 426 #Prerequisites - there is IDE Controller and there are no any images attached to it. 334 fRc = True 335 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox() 336 oMachine = oVirtualBox.findMachine('test-vm-move') 337 if oMachine is None: 338 reporter.log("Machine '%s' is unknown" % (oMachine.name)) 339 return False 340 341 del oVirtualBox 342 343 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 344 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario') 345 os.mkdir(sMoveLoc, 0o775) 346 sISOLoc = '5.3/isos/tdMoveVM1.iso' 347 reporter.log("sHost is '%s', sResourcePath is '%s'" % (self.oTstDrv.sHost, self.oTstDrv.sResourcePath)) 348 sISOLoc = self.oTstDrv.getFullResourceName(sISOLoc) 349 350 if not os.path.exists(sISOLoc): 351 reporter.log('ISO file does not exist at "%s"' % (sISOLoc,)) 352 fRc = False 353 354 #Copy ISO image from the common resource folder into machine folder 355 shutil.copy(sISOLoc, sLoc) 356 357 #attach ISO image to the IDE controller 358 if fRc is True: 359 #set actual ISO location 360 sISOLoc = sLoc + os.sep + 'tdMoveVM1.iso' 361 sController='IDE Controller' 362 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) 363 iPort = len(aoMediumAttachments) 364 reporter.log('sISOLoc "%s", sController "%s", iPort "%s"' % (sISOLoc,sController,iPort)) 365 fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0) 366 367 if fRc is True: 368 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc 369 370 #detach ISO image 371 fRc = oSession.detachHd(sController, iPort, 0) 372 373 fRc = fRc and oSession.saveSettings() 374 if fRc is False: 375 reporter.log('Couldn\'t save machine settings after 5th scenario') 427 428 sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep 429 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario') 430 os.mkdir(sNewLoc, 0o775) 431 self.__testScenario_5(oMachine, sNewLoc, sOldLoc) 376 432 377 433 ############# 6 case. ########################################################################################## 378 434 #There is a floppy image (.img) attached to the VM. 379 435 #Prerequisites - there is Floppy Controller and there are no any images attached to it. 380 fRc = True 381 sLoc = sMoveLoc + os.sep + oMachine.name + os.sep 382 sMoveLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario') 383 os.mkdir(sMoveLoc, 0o775) 384 sFloppyLoc = '5.3/floppy/tdMoveVM1.img' 385 sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc) 386 387 if not os.path.exists(sFloppyLoc): 388 reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,)) 389 fRc = False 390 391 #Copy floppy image from the common resource folder into machine folder 392 shutil.copy(sFloppyLoc, sLoc) 393 394 # attach floppy image 395 if fRc is True: 396 #set actual floppy location 397 sFloppyLoc = sLoc + os.sep + 'tdMoveVM1.img' 398 sController='Floppy Controller' 399 reporter.log('sFloppyLoc "%s", sController "%s"' % (sFloppyLoc,sController)) 400 fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0) 401 402 if fRc is True: 403 fRc = self.moveVMToLocation(sMoveLoc, oSession.o.machine) and fRc 404 405 #detach floppy image 406 fRc = oSession.detachHd(sController, 0, 0) 407 408 fRc = fRc and oSession.saveSettings() 409 if fRc is False: 410 reporter.log('Couldn\'t save machine settings after 6th scenario') 436 437 sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep 438 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario') 439 os.mkdir(sNewLoc, 0o775) 440 self.__testScenario_6(oMachine, sNewLoc, sOldLoc) 411 441 412 442 ############# 7 case. ########################################################################################## … … 419 449 # 420 450 421 fRc = oSession.close() and fRc422 if fRc is False:423 reporter.log('Couldn\'t close machine session')424 425 451 assert fRc is True 426 452 except:
Note:
See TracChangeset
for help on using the changeset viewer.