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