VirtualBox

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

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

bugref:8345. Several small improvements.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 28.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# "$Id: tdMoveVM1.py 71729 2018-04-06 22:07:33Z 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: 71729 $"
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 reporter.log('####### Reference locations: #######')
221 for eachItem in aReferences:
222 reporter.log(' "%s"' % (eachItem))
223
224 if len (intersection) != len (aActuals):
225 reporter.log('Not all items in the right location. Check it.')
226 fRc = False
227
228 return fRc
229
230 #
231 #checkAPIVersion
232 #
233 def checkAPIVersion(self):
234 if self.oTstDrv.fpApiVer >= 5.3:
235 return True
236
237 return False
238
239 def __getStatesFiles(self, oMachine, fPrint = False):
240 asStateFilesList = set()
241 sFolder = oMachine.snapshotFolder
242 for sFile in os.listdir(sFolder):
243 if sFile.endswith(".sav"):
244 sFullPath = os.path.join(sFolder, sFile)
245 asStateFilesList.add(sFullPath)
246 if fPrint is True:
247 reporter.log("State file is %s" % (sFullPath))
248 return asStateFilesList
249
250 def __getSnapshotsFiles(self, oMachine, fPrint = False):
251 asSnapshotsFilesList = set()
252 sFolder = oMachine.snapshotFolder
253 for sFile in os.listdir(sFolder):
254 if sFile.endswith(".sav") is False:
255 sFullPath = os.path.join(sFolder, sFile)
256 asSnapshotsFilesList.add(sFullPath)
257 if fPrint is True:
258 reporter.log("Snapshot file is %s" % (sFullPath))
259 return asSnapshotsFilesList
260
261 def __getLogFiles(self, oMachine, fPrint = False):
262 asLogFilesList = set()
263 sFolder = oMachine.logFolder
264 for sFile in os.listdir(sFolder):
265 if sFile.endswith(".log"):
266 sFullPath = os.path.join(sFolder, sFile)
267 asLogFilesList.add(sFullPath)
268 if fPrint is True:
269 reporter.log("Log file is %s" % (sFullPath))
270 return asLogFilesList
271
272 def __getResourceSet(self):
273 # Construct the resource list the first time it's queried.
274 if self.oTstDrv.asRsrcs is None:
275 self.oTstDrv.asRsrcs = []
276 self.oTstDrv.asRsrcs.append('5.3' + os.sep + 'isos' + os.sep + 'tdMoveVM1.iso')
277 self.oTstDrv.asRsrcs.append('5.3' + os.sep + 'floppy' + os.sep + 'tdMoveVM1.img')
278
279 return self.oTstDrv.asRsrcs
280
281 # All disks attached to VM are located inside the VM's folder.
282 # There are no any snapshots and logs.
283 def __testScenario_2(self, oSession, oMachine, sNewLoc, sOldLoc):
284
285 sController = self.dsKeys['StandardImage']
286 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
287 oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv)
288 oSubTstDrvMoveMedium1Instance.setLocation(sOldLoc, aoMediumAttachments)
289
290 del oSubTstDrvMoveMedium1Instance
291
292 dsReferenceFiles = defaultdict(set)
293
294 for s in self.asImagesNames:
295 reporter.log('"%s"' % (s,))
296 dsReferenceFiles['StandardImage'].add(sNewLoc + os.sep + oMachine.name + os.sep + s)
297
298 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox'))
299 dsReferenceFiles['SettingsFile'].add(sSettingFile)
300
301 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
302
303 if fRc is True:
304 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
305 if fRc is False:
306 reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
307 else:
308 reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
309
310 fRes = oSession.saveSettings()
311 if fRes is False:
312 reporter.log('2nd scenario: Couldn\'t save machine settings')
313
314 return fRc
315
316 # There are snapshots
317 def __testScenario_3(self, oSession, oMachine, sNewLoc):
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 # There are one or more save state files in the snapshots folder
358 # and some files in the logs folder.
359 # Here we run VM, next stop it in the "save" state.
360 # And next move VM
361 def __testScenario_4(self, oMachine, sNewLoc):
362
363 #Run VM and get new Session object
364 oSession = self.oTstDrv.startVm(oMachine)
365
366 #some time interval should be here for not closing VM just after start
367 time.sleep(1)
368
369 if oMachine.state != self.oTstDrv.oVBoxMgr.constants.MachineState_Running:
370 reporter.log("Machine '%s' is not Running" % (oMachine.name))
371 fRc = False
372
373 #call Session::saveState(), already closes session unless it failed
374 fRc = oSession.saveState()
375 if fRc is True:
376 reporter.log("Machine is in saved state")
377
378 fRc = self.oTstDrv.terminateVmBySession(oSession)
379
380 if fRc is True or False:
381 #create a new Session object for moving VM
382 oSession = self.oTstDrv.openSession(oMachine)
383
384 #always clear before each scenario
385 dsReferenceFiles = defaultdict(set)
386
387 asLogs = self.__getLogFiles(oMachine)
388 for sFile in asLogs:
389 sRes = sFile.rpartition(os.sep)
390 dsReferenceFiles['LogFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Logs' + os.sep + sRes[2])
391
392 asStates = self.__getStatesFiles(oMachine)
393 for sFile in asStates:
394 sRes = sFile.rpartition(os.sep)
395 dsReferenceFiles['SavedStateFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Snapshots' + os.sep + sRes[2])
396
397 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
398
399 if fRc is True:
400 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
401 if fRc is False:
402 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
403 else:
404 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
405
406 # cleaning up: get rid of saved state
407 fRes = oSession.discardSavedState(True)
408 if fRes is False:
409 reporter.log('4th scenario: Failed to discard the saved state of machine')
410
411 fRes = oSession.close()
412 if fRes is False:
413 reporter.log('4th scenario: Couldn\'t close machine session')
414 else:
415 reporter.testFailure('!!!!!!!!!!!!!!!!!! 4th scenario: Terminate machine by session failed... !!!!!!!!!!!!!!!!!!')
416
417 return fRc
418
419 # There is an ISO image (.iso) attached to the VM.
420 # Prerequisites - there is IDE Controller and there are no any images attached to it.
421 def __testScenario_5(self, oMachine, sNewLoc, sOldLoc):
422
423 fRc = True
424 sISOImageName = 'tdMoveVM1.iso'
425
426 #always clear before each scenario
427 dsReferenceFiles = defaultdict(set)
428
429 #create a new Session object
430 oSession = self.oTstDrv.openSession(oMachine)
431
432 sISOLoc = self.asRsrcs[0]#'5.3/isos/tdMoveVM1.iso'
433 reporter.log("sHost is '%s', sResourcePath is '%s'" % (self.oTstDrv.sHost, self.oTstDrv.sResourcePath))
434 sISOLoc = self.oTstDrv.getFullResourceName(sISOLoc)
435 reporter.log("sISOLoc is '%s'" % (sISOLoc,))
436
437 if not os.path.exists(sISOLoc):
438 reporter.log('ISO file does not exist at "%s"' % (sISOLoc,))
439 fRc = False
440
441 #Copy ISO image from the common resource folder into machine folder
442 shutil.copy(sISOLoc, sOldLoc)
443
444 #attach ISO image to the IDE controller
445 if fRc is True:
446 #set actual ISO location
447 sISOLoc = sOldLoc + os.sep + sISOImageName
448 reporter.log("sISOLoc is '%s'" % (sISOLoc,))
449 if not os.path.exists(sISOLoc):
450 reporter.log('ISO file does not exist at "%s"' % (sISOLoc,))
451 fRc = False
452
453 sController=self.dsKeys['ISOImage']
454 aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
455 iPort = len(aoMediumAttachments)
456 fRc = oSession.attachDvd(sISOLoc, sController, iPort, iDevice = 0)
457 dsReferenceFiles['ISOImage'].add(os.path.join(os.path.join(sNewLoc, oMachine.name), sISOImageName))
458
459 if fRc is True:
460 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
461 if fRc is True:
462 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
463 if fRc is False:
464 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
465 else:
466 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
467 else:
468 reporter.testFailure('!!!!!!!!!!!!!!!!!! 5th scenario: Attach ISO image failed... !!!!!!!!!!!!!!!!!!')
469
470 #detach ISO image
471 fRes = oSession.detachHd(sController, iPort, 0)
472 if fRes is False:
473 reporter.log('5th scenario: Couldn\'t detach image from the controller %s '
474 'port %s device %s' % (sController, iPort, 0))
475
476 fRes = oSession.saveSettings()
477 if fRes is False:
478 reporter.log('5th scenario: Couldn\'t save machine settings')
479
480 fRes = oSession.close()
481 if fRes is False:
482 reporter.log('5th scenario: Couldn\'t close machine session')
483
484 return fRc
485
486 # There is a floppy image (.img) attached to the VM.
487 # Prerequisites - there is Floppy Controller and there are no any images attached to it.
488 def __testScenario_6(self, oMachine, sNewLoc, sOldLoc):
489
490 fRc = True
491
492 #always clear before each scenario
493 dsReferenceFiles = defaultdict(set)
494
495 #create a new Session object
496 oSession = self.oTstDrv.openSession(oMachine)
497
498 sFloppyLoc = self.asRsrcs[1]#'5.3/floppy/tdMoveVM1.img'
499 sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc)
500
501 if not os.path.exists(sFloppyLoc):
502 reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,))
503 fRc = False
504
505 #Copy floppy image from the common resource folder into machine folder
506 shutil.copy(sFloppyLoc, sOldLoc)
507
508 #attach floppy image
509 if fRc is True:
510 #set actual floppy location
511 sFloppyImageName = 'tdMoveVM1.img'
512 sFloppyLoc = sOldLoc + os.sep + sFloppyImageName
513 sController=self.dsKeys['FloppyImage']
514 fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0)
515 dsReferenceFiles['FloppyImage'].add(os.path.join(os.path.join(sNewLoc, oMachine.name), sFloppyImageName))
516
517 if fRc is True:
518 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
519 if fRc is True:
520 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
521 if fRc is False:
522 reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
523 else:
524 reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
525 else:
526 reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Attach floppy image failed... !!!!!!!!!!!!!!!!!!')
527
528 #detach floppy image
529 fRes = oSession.detachHd(sController, 0, 0)
530 if fRes is False:
531 reporter.log('6th scenario: Couldn\'t detach image from the controller %s port %s device %s' % (sController, 0, 0))
532
533 fRes = oSession.saveSettings()
534 if fRes is False:
535 reporter.testFailure('6th scenario: Couldn\'t save machine settings')
536
537 fRes = oSession.close()
538 if fRes is False:
539 reporter.log('6th scenario: Couldn\'t close machine session')
540 return fRc
541
542 #
543 #testVMMove
544 #
545 def testVMMove(self):
546 """
547 Test machine moving.
548 """
549 reporter.testStart('machine moving')
550
551 if not self.oTstDrv.importVBoxApi():
552 return False
553
554 fSupported = self.checkAPIVersion()
555
556 if fSupported is False:
557 reporter.log('API version %s is too old. Just skip this test.' % (self.oTstDrv.fpApiVer))
558 return reporter.testDone()[1] == 0
559 else:
560 reporter.log('API version is "%s".' % (self.oTstDrv.fpApiVer))
561
562 #Scenarios
563 #1. All disks attached to VM are located outside the VM's folder.
564 # There are no any snapshots and logs.
565 # In this case only VM setting file should be moved (.vbox file)
566 #
567 #2. All disks attached to VM are located inside the VM's folder.
568 # There are no any snapshots and logs.
569 #
570 #3. There are snapshots.
571 #
572 #4. There are one or more save state files in the snapshots folder
573 # and some files in the logs folder.
574 #
575 #5. There is an ISO image (.iso) attached to the VM.
576 #
577 #6. There is a floppy image (.img) attached to the VM.
578 #
579 #7. There are shareable disk and immutable disk attached to the VM.
580
581 try:
582 #create test machine
583 oMachine = self.createTestMachine()
584
585 if oMachine is None:
586 reporter.error('Failed to create test machine')
587
588 #create temporary subdirectory in the current working directory
589 sOrigLoc = self.oTstDrv.sScratchPath
590 sBaseLoc = os.path.join(sOrigLoc, 'moveFolder')
591 os.mkdir(sBaseLoc, 0o775)
592
593 #lock machine
594 #get session machine
595 oSession = self.oTstDrv.openSession(oMachine)
596 fRc = True
597
598 sNewLoc = sBaseLoc + os.sep
599
600 dsReferenceFiles = defaultdict(set)
601
602############# 1 case. ##########################################################################################
603 # All disks attached to VM are located outside the VM's folder.
604 # There are no any snapshots and logs.
605 # In this case only VM setting file should be moved (.vbox file)
606 for s in self.asImagesNames:
607 reporter.log('"%s"' % (s,))
608 dsReferenceFiles['StandardImage'].add(os.path.join(sOrigLoc, s))
609
610 sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox'))
611 dsReferenceFiles['SettingsFile'].add(sSettingFile)
612
613 fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine)
614
615 if fRc is True:
616 fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles)
617 if fRc is False:
618 reporter.testFailure('!!!!!!!!!!!!!!!!!! 1st scenario: Check locations failed... !!!!!!!!!!!!!!!!!!')
619 return reporter.testDone()[1] == 0
620 else:
621 reporter.testFailure('!!!!!!!!!!!!!!!!!! 1st scenario: Move VM failed... !!!!!!!!!!!!!!!!!!')
622 return reporter.testDone()[1] == 0
623
624 fRc = oSession.saveSettings()
625 if fRc is False:
626 reporter.testFailure('1st scenario: Couldn\'t save machine settings')
627
628############# 2 case. ##########################################################################################
629 # All disks attached to VM are located inside the VM's folder.
630 # There are no any snapshots and logs.
631 sOldLoc = sNewLoc + oMachine.name + os.sep
632 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario')
633 os.mkdir(sNewLoc, 0o775)
634
635 fRc = self.__testScenario_2(oSession, oMachine, sNewLoc, sOldLoc)
636 if fRc is False:
637 return reporter.testDone()[1] == 0
638
639############# 3 case. ##########################################################################################
640 # There are snapshots.
641 sOldLoc = sNewLoc + oMachine.name + os.sep
642 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario')
643 os.mkdir(sNewLoc, 0o775)
644
645 fRc = self.__testScenario_3(oSession, oMachine, sNewLoc)
646 if fRc is False:
647 return reporter.testDone()[1] == 0
648
649############# 4 case. ##########################################################################################
650 # There are one or more save state files in the snapshots folder
651 # and some files in the logs folder.
652 # Here we run VM, next stop it in the "save" state.
653 # And next move VM
654
655 sOldLoc = sNewLoc + oMachine.name + os.sep
656 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario')
657 os.mkdir(sNewLoc, 0o775)
658
659 #Close Session object because after starting VM we get new instance of session
660 fRc = oSession.close() and fRc
661 if fRc is False:
662 reporter.log('Couldn\'t close machine session')
663
664 del oSession
665
666 fRc = self.__testScenario_4(oMachine, sNewLoc)
667 if fRc is False:
668 return reporter.testDone()[1] == 0
669
670############## 5 case. ##########################################################################################
671 # There is an ISO image (.iso) attached to the VM.
672 # Prerequisites - there is IDE Controller and there are no any images attached to it.
673
674 sOldLoc = sNewLoc + os.sep + oMachine.name
675 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario')
676 os.mkdir(sNewLoc, 0o775)
677 fRc = self.__testScenario_5(oMachine, sNewLoc, sOldLoc)
678 if fRc is False:
679 return reporter.testDone()[1] == 0
680
681############# 6 case. ##########################################################################################
682 # There is a floppy image (.img) attached to the VM.
683 # Prerequisites - there is Floppy Controller and there are no any images attached to it.
684
685 sOldLoc = sNewLoc + os.sep + oMachine.name
686 sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario')
687 os.mkdir(sNewLoc, 0o775)
688 fRc = self.__testScenario_6(oMachine, sNewLoc, sOldLoc)
689 if fRc is False:
690 return reporter.testDone()[1] == 0
691
692############# 7 case. ##########################################################################################
693# # There are shareable disk and immutable disk attached to the VM.
694# #
695#
696# fRc = fRc and oSession.saveSettings()
697# if fRc is False:
698# reporter.log('Couldn\'t save machine settings')
699#
700
701 assert fRc is True
702 except:
703 reporter.errorXcpt()
704
705 return reporter.testDone()[1] == 0
706
707
708if __name__ == '__main__':
709 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
710 from tdApi1 import tdApi1
711 sys.exit(tdApi1([SubTstDrvMoveVM1]).main(sys.argv))
712
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