VirtualBox

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

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

validationkit/tests/api: properly report resources, collected from all sub-tests

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