VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdMoveVM1.py@ 71546

Last change on this file since 71546 was 71546, checked in by vboxsync, 7 years ago

bugref:8345. Coding style fixes.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 27.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# "$Id: tdMoveVM1.py 71546 2018-03-28 15:43:50Z vboxsync $"
4
5"""
6VirtualBox Validation Kit - VM Move Test #1
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2018 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 71546 $"
31
32# Standard Python imports.
33import os
34import sys
35import time
36import shutil
37from collections import defaultdict
38
39# Only the main script needs to modify the path.
40try: __file__
41except: __file__ = sys.argv[0]
42g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
43sys.path.append(g_ksValidationKitDir)
44
45# Validation Kit imports.
46from testdriver import base
47from testdriver import reporter
48from testdriver import vboxcon
49from testdriver import vboxwrappers
50from tdMoveMedium1 import SubTstDrvMoveMedium1
51
52class SubTstDrvMoveVM1(base.SubTestDriverBase):
53 """
54 Sub-test driver for VM Move Test #1.
55 """
56
57 def __init__(self, oTstDrv):
58 base.SubTestDriverBase.__init__(self, 'move-vm', oTstDrv)
59 self.asRsrcs = self.__getResourceSet()
60 self.asImagesNames = []
61 self.dsKeys = dict (StandardImage = 'SATA Controller',
62 ISOImage = 'IDE Controller',
63 FloppyImage = 'Floppy Controller',
64 SettingsFile = 'Settings File',
65 LogFile = 'Log File',
66 SavedStateFile = 'Saved State File',
67 SnapshotFile = 'Snapshot File')
68
69 def testIt(self):
70 """
71 Execute the sub-testcase.
72 """
73 reporter.log('ValidationKit folder is "%s"' % (g_ksValidationKitDir,))
74 return self.testVMMove()
75
76 #
77 # Test execution helpers.
78 #
79
80 #
81 #createTestMachine
82 #
83 def createTestMachine(self):
84 oVM = self.oTstDrv.createTestVM('test-vm-move', 1, None, 4)
85 if oVM is None:
86 return None
87
88 # create hard disk images, one for each file-based backend, using the first applicable extension
89 fRc = True
90 oSession = self.oTstDrv.openSession(oVM)
91 aoDskFmts = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox.systemProperties, 'mediumFormats')
92
93 for oDskFmt in aoDskFmts:
94 aoDskFmtCaps = self.oTstDrv.oVBoxMgr.getArray(oDskFmt, 'capabilities')
95 if vboxcon.MediumFormatCapabilities_File not in aoDskFmtCaps \
96 or vboxcon.MediumFormatCapabilities_CreateDynamic not in aoDskFmtCaps:
97 continue
98 (asExts, aTypes) = oDskFmt.describeFileExtensions()
99 for i in range(0, len(asExts)):
100 if aTypes[i] is vboxcon.DeviceType_HardDisk:
101 sExt = '.' + asExts[i]
102 break
103 if sExt is None:
104 fRc = False
105 break
106 sFile = 'test-vm-move' + str(len(self.asImagesNames)) + sExt
107 sHddPath = os.path.join(self.oTstDrv.sScratchPath, sFile)
108 oHd = oSession.createBaseHd(sHddPath, sFmt=oDskFmt.id, cb=1024*1024)
109 if oHd is None:
110 fRc = False
111 break
112
113 # attach HDD, IDE controller exists by default, but we use SATA just in case
114 sController=self.dsKeys['StandardImage']
115 fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = len(self.asImagesNames),
116 fImmutable=False, fForceResource=False)
117 if fRc:
118 self.asImagesNames.append(sFile)
119
120 fRc = fRc and oSession.saveSettings()
121 fRc = oSession.close() and fRc
122
123 if fRc is False:
124 oVM = None
125
126 return oVM
127
128 #
129 #moveVMToLocation
130 #
131 def moveVMToLocation(self, sLocation, oVM):
132 fRc = True
133 try:
134 #move machine
135 reporter.log('Moving machine "%s" to the "%s"' % (oVM.name, sLocation))
136 oType = 'basic'
137 oProgress = vboxwrappers.ProgressWrapper(oVM.moveTo(sLocation, oType), self.oTstDrv.oVBoxMgr, self.oTstDrv,
138 'moving machine "%s"' % (oVM.name,))
139
140 except:
141 return reporter.errorXcpt('Machine::moveTo("%s") for machine "%s" failed' % (sLocation, oVM.name,))
142
143 oProgress.wait()
144 if oProgress.logResult() is False:
145 fRc = False
146 reporter.log('Progress object returned False')
147 else:
148 fRc = True
149
150 return fRc
151
152 #
153 #checkLocation
154 #
155 #Prerequisites:
156 #1. All standard images are attached to SATA controller
157 #2. All ISO images are attached to IDE controller
158 #3. All floppy images are attached to Floppy controller
159 #4. The type defaultdict from collection is used here (some sort of multimap data structure)
160 #5. The dsReferenceFiles parameter here is the structure defaultdict(set):
161 # [
162 # ('StandardImage': ['somedisk.vdi', 'somedisk.vmdk',...]),
163 # ('ISOImage': ['somedisk_1.iso','somedisk_2.iso',...]),
164 # ('FloppyImage': ['somedisk_1.img','somedisk_2.img',...]),
165 # ('SnapshotFile': ['snapshot file 1','snapshot file 2', ...]),
166 # ('SettingsFile', ['setting file',...]),
167 # ('SavedStateFile': ['state file 1','state file 2',...]),
168 # ('LogFile': ['log file 1','log file 2',...]),
169 # ]
170 #
171 def checkLocation(self, oMachine, dsReferenceFiles):
172
173 fRc = True
174 iLen = 0
175
176 for key, value in self.dsKeys.iteritems():
177 aActuals = set()
178 aReferences = set()
179
180 #Check standard images locations, ISO files locations, floppy images locations, snapshots files locations
181 if key == 'StandardImage' or key == 'ISOImage' or key == 'FloppyImage':
182 aReferences = dsReferenceFiles[key]
183 if len (aReferences) > 0:
184 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(value)
185 for oAttachment in aoMediumAttachments:
186 aActuals.add(oAttachment.medium.location)
187
188 elif key == 'SnapshotFile':
189 aReferences = dsReferenceFiles[key]
190 if len (aReferences) > 0:
191 aActuals = self.__getSnapshotsFiles(oMachine)
192
193 #Check setting file location
194 elif key == 'SettingsFile':
195 aReferences = dsReferenceFiles[key]
196 if len (aReferences) > 0:
197 aActuals.add(oMachine.settingsFilePath)
198
199 #Check saved state files location
200 elif key == 'SavedStateFile':
201 aReferences = dsReferenceFiles[key]
202 if len (aReferences) > 0:
203 aActuals = self.__getStatesFiles(oMachine)
204
205 #Check log files location
206 elif key == 'LogFile':
207 aReferences = dsReferenceFiles[key]
208 if len (aReferences) > 0:
209 aActuals = self.__getLogFiles(oMachine)
210
211 if len(aActuals) > 0:
212 reporter.log('Check %s' % (key))
213 intersection = aReferences.intersection(aActuals)
214 for eachItem in intersection:
215 reporter.log('Item location "%s" is correct' % (eachItem))
216
217 difference = aReferences.difference(aActuals)
218 for eachItem in difference:
219 reporter.log('Item location "%s" isn\'t correct' % (eachItem))
220
221 if len (intersection) != len (aActuals):
222 reporter.log('Not all items in the right location. Check it.')
223 fRc = False
224
225 return fRc
226
227 #
228 #checkAPIVersion
229 #
230 def checkAPIVersion(self):
231 if self.oTstDrv.fpApiVer >= 5.3:
232 return True
233
234 return False
235
236 def __getStatesFiles(self, oMachine, fPrint = False):
237 asStateFilesList = set()
238 sFolder = oMachine.snapshotFolder
239 for file in os.listdir(sFolder):
240 if file.endswith(".sav"):
241 sFile = os.path.join(sFolder, file)
242 asStateFilesList.add(sFile)
243 if fPrint is True:
244 reporter.log("State file is %s" % (sFile))
245 return asStateFilesList
246
247 def __getSnapshotsFiles(self, oMachine, fPrint = False):
248 asSnapshotsFilesList = set()
249 sFolder = oMachine.snapshotFolder
250 for file in os.listdir(sFolder):
251 if file.endswith(".sav") is False:
252 sFile = os.path.join(sFolder, file)
253 asSnapshotsFilesList.add(sFile)
254 if fPrint is True:
255 reporter.log("Snapshot file is %s" % (sFile))
256 return asSnapshotsFilesList
257
258 def __getLogFiles(self, oMachine, fPrint = False):
259 asLogFilesList = set()
260 sFolder = oMachine.logFolder
261 for file in os.listdir(sFolder):
262 if file.endswith(".log"):
263 sFile = os.path.join(sFolder, file)
264 asLogFilesList.add(sFile)
265 if fPrint is True:
266 reporter.log("Log file is %s" % (sFile))
267 return asLogFilesList
268
269 def __getResourceSet(self):
270 # Construct the resource list the first time it's queried.
271 if self.oTstDrv.asRsrcs is None:
272 self.oTstDrv.asRsrcs = []
273 self.oTstDrv.asRsrcs.append('5.3/isos/tdMoveVM.iso')
274 self.oTstDrv.asRsrcs.append('5.3/floppy/tdMoveVM.img')
275
276 return self.oTstDrv.asRsrcs
277
278 def __testScenario_4(self, oMachine, sNewLoc):
279
280 #Run VM and get new Session object
281 oSession = self.oTstDrv.startVm(oMachine)
282
283 #some time interval should be here for not closing VM just after start
284 time.sleep(1)
285
286 if oMachine.state != self.oTstDrv.oVBoxMgr.constants.MachineState_Running:
287 reporter.log("Machine '%s' is not Running" % (oMachine.name))
288 fRc = False
289
290 #call Session::saveState(), already closes session unless it failed
291 fRc = oSession.saveState()
292 self.oTstDrv.terminateVmBySession(oSession)
293
294 if fRc:
295 #create a new Session object for moving VM
296 oSession = self.oTstDrv.openSession(oMachine)
297
298 #always clear before each scenario
299 dsReferenceFiles = defaultdict(set)
300
301 asLogs = self.__getLogFiles(oMachine)
302 for sFile in asLogs:
303 sRes = sFile.rpartition(os.sep)
304 dsReferenceFiles['LogFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Logs' + os.sep + sRes[2])
305
306 asStates = self.__getStatesFiles(oMachine)
307 for sFile in asStates:
308 sRes = sFile.rpartition(os.sep)
309 dsReferenceFiles['SavedStateFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Snapshots' + os.sep + sRes[2])
310
311 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
312
313 if fRc is True:
314 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
315 if fRc is False:
316 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
317 else:
318 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
319
320 # cleaning up: get rid of saved state
321 fRes = oSession.discardSavedState(True)
322 if fRes is False:
323 reporter.log('4th scenario: Failed to discard the saved state of machine')
324
325 fRes = oSession.close()
326 if fRes is False:
327 reporter.log('4th scenario: Couldn\'t close machine session')
328 else:
329 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Terminate machine by session failed... !!!!!!!!!!!!!!!!!!')
330
331 return fRc
332
333 def __testScenario_5(self, oMachine, sNewLoc, sOldLoc):
334
335 fRc = True
336 sISOImageName = 'tdMoveVM1.iso'
337
338 #always clear before each scenario
339 dsReferenceFiles = defaultdict(set)
340
341 #create a new Session object
342 oSession = self.oTstDrv.openSession(oMachine)
343
344 sISOLoc = '5.3/isos/tdMoveVM1.iso'
345 reporter.log("sHost is '%s', sResourcePath is '%s'" % (self.oTstDrv.sHost, self.oTstDrv.sResourcePath))
346 sISOLoc = self.oTstDrv.getFullResourceName(sISOLoc)
347
348 if not os.path.exists(sISOLoc):
349 reporter.log('ISO file does not exist at "%s"' % (sISOLoc,))
350 fRc = False
351
352 #Copy ISO image from the common resource folder into machine folder
353 shutil.copy(sISOLoc, sOldLoc)
354
355 #attach ISO image to the IDE controller
356 if fRc is True:
357 #set actual ISO location
358 sISOLoc = sOldLoc + os.sep + sISOImageName
359 sController=self.dsKeys['ISOImage']
360 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
361 iPort = len(aoMediumAttachments)
362 fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0)
363 dsReferenceFiles['ISOImage'].add(os.path.join(os.path.join(sNewLoc, oMachine.name), sISOImageName))
364
365 if fRc is True:
366 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
367 if fRc is True:
368 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
369 if fRc is False:
370 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
371 else:
372 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
373 else:
374 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Attach ISO image failed... !!!!!!!!!!!!!!!!!!')
375
376 #detach ISO image
377 fRes = oSession.detachHd(sController, iPort, 0)
378 if fRes is False:
379 reporter.log('5th scenario: Couldn\'t detach image from the controller %s
380 port %s device %s' % (sController, iPort, 0))
381
382 fRes = oSession.saveSettings()
383 if fRes is False:
384 reporter.log('5th scenario: Couldn\'t save machine settings')
385
386 fRes = oSession.close()
387 if fRes is False:
388 reporter.log('5th scenario: Couldn\'t close machine session')
389
390 return fRc
391
392 def __testScenario_6(self, oMachine, sNewLoc, sOldLoc):
393
394 fRc = True
395
396 #always clear before each scenario
397 dsReferenceFiles = defaultdict(set)
398
399 #create a new Session object
400 oSession = self.oTstDrv.openSession(oMachine)
401
402 sFloppyLoc = '5.3/floppy/tdMoveVM1.img'
403 sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc)
404
405 if not os.path.exists(sFloppyLoc):
406 reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,))
407 fRc = False
408
409 #Copy floppy image from the common resource folder into machine folder
410 shutil.copy(sFloppyLoc, sOldLoc)
411
412 # attach floppy image
413 if fRc is True:
414 #set actual floppy location
415 sFloppyImageName = 'tdMoveVM1.img'
416 sFloppyLoc = sOldLoc + os.sep + sFloppyImageName
417 sController=self.dsKeys['FloppyImage']
418 fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0)
419 dsReferenceFiles['FloppyImage'].add(os.path.join(os.path.join(sNewLoc, oMachine.name), sFloppyImageName))
420
421 if fRc is True:
422 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
423 if fRc is True:
424 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
425 if fRc is False:
426 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
427 else:
428 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
429 else:
430 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Attach floppy image failed... !!!!!!!!!!!!!!!!!!')
431
432 #detach floppy image
433 fRes = oSession.detachHd(sController, 0, 0)
434 if fRes is False:
435 reporter.log('6th scenario: Couldn\'t detach image from the controller %s port %s device %s' % (sController, 0, 0))
436
437 fRes = oSession.saveSettings()
438 if fRes is False:
439 reporter.testFailure('6th scenario: Couldn\'t save machine settings')
440
441 fRes = oSession.close()
442 if fRes is False:
443 reporter.log('6th scenario: Couldn\'t close machine session')
444 return fRc
445
446 #
447 #testVMMove
448 #
449 def testVMMove(self):
450 """
451 Test machine moving.
452 """
453 reporter.testStart('machine moving')
454
455 if not self.oTstDrv.importVBoxApi():
456 return False
457
458 fSupported = self.checkAPIVersion()
459
460 if fSupported is False:
461 reporter.log('API version is below "%s". Just skip this test.' % (self.oTstDrv.fpApiVer))
462 return reporter.testDone()[1] == 0
463 else:
464 reporter.log('API version is "%s". Continuing the test.' % (self.oTstDrv.fpApiVer))
465
466 #Scenarios
467 #1. All disks attached to VM are located outside the VM's folder.
468 # There are no any snapshots and logs.
469 # In this case only VM setting file should be moved (.vbox file)
470 #
471 #2. All disks attached to VM are located inside the VM's folder.
472 # There are no any snapshots and logs.
473 #
474 #3. There are snapshots.
475 #
476 #4. There are one or more save state files in the snapshots folder
477 # and some files in the logs folder.
478 #
479 #5. There is an ISO image (.iso) attached to the VM.
480 #
481 #6. There is a floppy image (.img) attached to the VM.
482 #
483 #7. There are shareable disk and immutable disk attached to the VM.
484
485 try:
486 #create test machine
487 oMachine = self.createTestMachine()
488
489 if oMachine is None:
490 reporter.error('Failed to create test machine')
491
492 #create temporary subdirectory in the current working directory
493 sOrigLoc = self.oTstDrv.sScratchPath
494 sBaseLoc = os.path.join(sOrigLoc, 'moveFolder')
495 os.mkdir(sBaseLoc, 0o775)
496
497 sController=self.dsKeys['StandardImage']
498 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
499
500 #lock machine
501 #get session machine
502 oSession = self.oTstDrv.openSession(oMachine)
503 fRc = True
504
505 sNewLoc = sBaseLoc + os.sep
506
507 dsReferenceFiles = defaultdict(set)
508
509############# 1 case. ##########################################################################################
510 # All disks attached to VM are located outside the VM's folder.
511 # There are no any snapshots and logs.
512 # In this case only VM setting file should be moved (.vbox file)
513 for s in self.asImagesNames:
514 reporter.log('"%s"' % (s,))
515 dsReferenceFiles['StandardImage'].add(os.path.join(sOrigLoc, s))
516
517 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox'))
518 dsReferenceFiles['SettingsFile'].add(sSettingFile)
519
520 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
521
522 if fRc is True:
523 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
524 if fRc is False:
525 reporter.testFailure('!!!!!!!!!!!!!!!!!! 1st scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
526 return reporter.testDone()[1] == 0
527 else:
528 reporter.testFailure('!!!!!!!!!!!!!!!!!! 1st scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
529 return reporter.testDone()[1] == 0
530
531 fRc = oSession.saveSettings()
532 if fRc is False:
533 reporter.testFailure('1st scenario: Couldn\'t save machine settings')
534
535############# 2 case. ##########################################################################################
536 # All disks attached to VM are located inside the VM's folder.
537 # There are no any snapshots and logs.
538 sOldLoc = sNewLoc + oMachine.name + os.sep
539 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario')
540 os.mkdir(sNewLoc, 0o775)
541 sController = self.dsKeys['StandardImage']
542 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
543 oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv)
544 oSubTstDrvMoveMedium1Instance.setLocation(sOldLoc, aoMediumAttachments)
545
546 del oSubTstDrvMoveMedium1Instance
547
548 #always clear before each scenario
549 dsReferenceFiles.clear()
550
551 for s in self.asImagesNames:
552 reporter.log('"%s"' % (s,))
553 dsReferenceFiles['StandardImage'].add(sNewLoc + os.sep + oMachine.name + os.sep + s)
554
555 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox'))
556 dsReferenceFiles['SettingsFile'].add(sSettingFile)
557
558 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
559
560 if fRc is True:
561 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
562 if fRc is False:
563 reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
564 return reporter.testDone()[1] == 0
565 else:
566 reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
567 return reporter.testDone()[1] == 0
568
569 fRc = oSession.saveSettings()
570 if fRc is False:
571 reporter.testFailure('2nd scenario: Couldn\'t save machine settings')
572
573############# 3 case. ##########################################################################################
574 # There are snapshots.
575 sOldLoc = sNewLoc + oMachine.name + os.sep
576 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario')
577 os.mkdir(sNewLoc, 0o775)
578
579 #At moment, it's used only one snapshot due to the difficulty to get
580 #all attachments of the machine (i.e. not only attached at moment)
581 cSnap = 1
582
583 for counter in range(1,cSnap+1):
584 strSnapshot = 'Snapshot' + str(counter)
585 fRc = fRc and oSession.takeSnapshot(strSnapshot)
586 if fRc is False:
587 reporter.testFailure('3rd scenario: Can\'t take snapshot "%s"' % (strSnapshot,))
588 return reporter.testDone()[1] == 0
589
590 #always clear before each scenario
591 dsReferenceFiles.clear()
592
593 sController = self.dsKeys['StandardImage']
594 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
595 if fRc is True:
596 for oAttachment in aoMediumAttachments:
597 sRes = oAttachment.medium.location.rpartition(os.sep)
598 dsReferenceFiles['SnapshotFile'].add(sNewLoc + os.sep + oMachine.name + os.sep +
599 'Snapshots' + os.sep + sRes[2])
600
601 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox'))
602 dsReferenceFiles['SettingsFile'].add(sSettingFile)
603
604 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
605
606 if fRc is True:
607 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
608 if fRc is False:
609 reporter.testFailure('!!!!!!!!!!!!!!!!!! 3rd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
610 return reporter.testDone()[1] == 0
611 else:
612 reporter.testFailure('!!!!!!!!!!!!!!!!!! 3rd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
613 return reporter.testDone()[1] == 0
614
615 fRc = oSession.saveSettings()
616 if fRc is False:
617 reporter.testFailure('3d scenario: Couldn\'t save machine settings')
618
619############# 4 case. ##########################################################################################
620 # There are one or more save state files in the snapshots folder
621 # and some files in the logs folder.
622 # Here we run VM, next stop it in the "save" state.
623 # And next move VM
624
625 sOldLoc = sNewLoc + oMachine.name + os.sep
626 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario')
627 os.mkdir(sNewLoc, 0o775)
628
629 #Close Session object because after starting VM we get new instance of session
630 fRc = oSession.close() and fRc
631 if fRc is False:
632 reporter.log('Couldn\'t close machine session')
633
634 del oSession
635
636 fRc = self.__testScenario_4(oMachine, sNewLoc)
637 if fRc is False:
638 return reporter.testDone()[1] == 0
639
640############## 5 case. ##########################################################################################
641 #There is an ISO image (.iso) attached to the VM.
642 #Prerequisites - there is IDE Controller and there are no any images attached to it.
643
644 sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep
645 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario')
646 os.mkdir(sNewLoc, 0o775)
647 fRc = self.__testScenario_5(oMachine, sNewLoc, sOldLoc)
648 if fRc is False:
649 return reporter.testDone()[1] == 0
650
651############# 6 case. ##########################################################################################
652 #There is a floppy image (.img) attached to the VM.
653 #Prerequisites - there is Floppy Controller and there are no any images attached to it.
654
655 sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep
656 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario')
657 os.mkdir(sNewLoc, 0o775)
658 fRc = self.__testScenario_6(oMachine, sNewLoc, sOldLoc)
659 if fRc is False:
660 return reporter.testDone()[1] == 0
661
662############# 7 case. ##########################################################################################
663# # There are shareable disk and immutable disk attached to the VM.
664# #
665#
666# fRc = fRc and oSession.saveSettings()
667# if fRc is False:
668# reporter.log('Couldn\'t save machine settings')
669#
670
671 assert fRc is True
672 except:
673 reporter.errorXcpt()
674
675 return reporter.testDone()[1] == 0
676
677
678if __name__ == '__main__':
679 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
680 from tdApi1 import tdApi1
681 sys.exit(tdApi1([SubTstDrvMoveVM1]).main(sys.argv))
682
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette