VirtualBox

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

Last change on this file since 78994 was 78460, checked in by vboxsync, 6 years ago

tdMoveVM1.py: must put os.listdir in a try/catch so it won't croak if the directory does not exist.

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