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