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