VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdMoveVm1.py@ 83432

Last change on this file since 83432 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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

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