VirtualBox

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

Last change on this file since 72738 was 72732, checked in by vboxsync, 6 years ago

Valkit: Resource handling regression fix.

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