VirtualBox

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

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

tdMoveVM1.py: less confusing output when skipping.

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