VirtualBox

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

Last change on this file since 78351 was 77777, checked in by vboxsync, 6 years ago

bugref:9312. The command 'VBoxManage cloudprofile' was implemented. It uses new style of help and documentation.

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