VirtualBox

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

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

vkit/tdMoveVM1: pylint fix and cleanups. untested, hope it still works.

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

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