VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/installation/tdGuestOsUnattendedInst1.py@ 79021

Last change on this file since 79021 was 78830, checked in by vboxsync, 6 years ago

tdGuestOsUnattendedInst1.py: Work in progress

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 14.8 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdGuestOsUnattendedInst1.py 78830 2019-05-28 16:11:23Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Guest OS unattended installation tests.
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2019 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 78830 $"
31
32
33# Standard Python imports.
34import os
35import sys
36
37
38# Only the main script needs to modify the path.
39try: __file__
40except: __file__ = sys.argv[0]
41g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
42sys.path.append(g_ksValidationKitDir)
43
44# Validation Kit imports.
45from testdriver import vbox;
46from testdriver import base;
47from testdriver import reporter;
48from testdriver import vboxcon;
49from testdriver import vboxtestvms;
50
51
52class UnattendedVm(vboxtestvms.TestVm):
53 """ Unattended Installation test VM. """
54
55 ## @name VM option flags (OR together).
56 ## @{
57 kfIdeIrqDelay = 0x1;
58 kfUbuntuNewAmdBug = 0x2;
59 kfNoWin81Paravirt = 0x4;
60 ## @}
61
62 ## IRQ delay extra data config for win2k VMs.
63 kasIdeIrqDelay = [ 'VBoxInternal/Devices/piix3ide/0/Config/IRQDelay:1', ];
64
65 ## Install ISO paths relative to the testrsrc root.
66 kasIosPathBases = [ os.path.join('6.0', 'isos'), os.path.join('6.1', 'isos'), ];
67
68 def __init__(self, oSet, sVmName, sKind, sInstallIso, fFlags = 0):
69 vboxtestvms.TestVm.__init__(self, sVmName, oSet = oSet, sKind = sKind,
70 fRandomPvPMode = False, sFirmwareType = None, sChipsetType = None,
71 sHddControllerType = None, sDvdControllerType = None);
72 self.sInstallIso = sInstallIso;
73 self.fInstVmFlags = fFlags;
74
75 # Adjustments over the defaults.
76 self.iOptRamAdjust = 0;
77 self.fOptIoApic = None;
78 self.fOptPae = None;
79 self.asExtraData = [];
80 if fFlags & self.kfIdeIrqDelay:
81 self.asOptExtraData = self.kasIdeIrqDelay;
82
83 ## @todo split TestVm.
84 def createVmInner(self, oTestDrv, eNic0AttachType, sDvdImage):
85 """ Overloaded from TestVm to create using defaults rather than a set complicated config properties. """
86
87
88 def detatchAndDeleteHd(self, oTestDrv):
89 """
90 Detaches and deletes the HD.
91 Returns success indicator, error info logged.
92 """
93 fRc = False;
94 oVM = oTestDrv.getVmByName(self.sVmName);
95 if oVM is not None:
96 oSession = oTestDrv.openSession(oVM);
97 if oSession is not None:
98 (fRc, oHd) = oSession.detachHd(self.sHddControllerType, iPort = 0, iDevice = 0);
99 if fRc is True and oHd is not None:
100 fRc = oSession.saveSettings();
101 fRc = fRc and oTestDrv.oVBox.deleteHdByMedium(oHd);
102 fRc = fRc and oSession.saveSettings(); # Necessary for media reg?
103 fRc = oSession.close() and fRc;
104 return fRc;
105
106 def getReconfiguredVm(self, oTestDrv, cCpus, sVirtMode, sParavirtMode = None):
107 #
108 # Do the standard reconfig in the base class first, it'll figure out
109 # if we can run the VM as requested.
110 #
111 (fRc, oVM) = vboxtestvms.TestVm.getReconfiguredVm(self, oTestDrv, cCpus, sVirtMode, sParavirtMode);
112
113 #
114 # Make sure there is no HD from the previous run attached nor taking
115 # up storage on the host.
116 #
117 if fRc is True:
118 fRc = self.detatchAndDeleteHd(oTestDrv);
119
120 #
121 # Check for ubuntu installer vs. AMD host CPU.
122 #
123 if fRc is True and (self.fInstVmFlags & self.kfUbuntuNewAmdBug):
124 if self.isHostCpuAffectedByUbuntuNewAmdBug(oTestDrv):
125 return (None, None); # (skip)
126
127 #
128 # Make adjustments to the default config, and adding a fresh HD.
129 #
130 if fRc is True:
131 oSession = oTestDrv.openSession(oVM);
132 if oSession is not None:
133 if self.sHddControllerType == self.ksSataController:
134 fRc = fRc and oSession.setStorageControllerType(vboxcon.StorageControllerType_IntelAhci,
135 self.sHddControllerType);
136 fRc = fRc and oSession.setStorageControllerPortCount(self.sHddControllerType, 1);
137 elif self.sHddControllerType == self.ksScsiController:
138 fRc = fRc and oSession.setStorageControllerType(vboxcon.StorageControllerType_LsiLogic,
139 self.sHddControllerType);
140 try:
141 sHddPath = os.path.join(os.path.dirname(oVM.settingsFilePath),
142 '%s-%s-%s.vdi' % (self.sVmName, sVirtMode, cCpus,));
143 except:
144 reporter.errorXcpt();
145 sHddPath = None;
146 fRc = False;
147
148 fRc = fRc and oSession.createAndAttachHd(sHddPath,
149 cb = self.cGbHdd * 1024*1024*1024,
150 sController = self.sHddControllerType,
151 iPort = 0,
152 fImmutable = False);
153
154 # Set proper boot order
155 fRc = fRc and oSession.setBootOrder(1, vboxcon.DeviceType_HardDisk)
156 fRc = fRc and oSession.setBootOrder(2, vboxcon.DeviceType_DVD)
157
158 # Adjust memory if requested.
159 if self.iOptRamAdjust != 0:
160 fRc = fRc and oSession.setRamSize(oSession.o.machine.memorySize + self.iOptRamAdjust);
161
162 # Set extra data
163 for sExtraData in self.asOptExtraData:
164 try:
165 sKey, sValue = sExtraData.split(':')
166 except ValueError:
167 raise base.InvalidOption('Invalid extradata specified: %s' % sExtraData)
168 reporter.log('Set extradata: %s => %s' % (sKey, sValue))
169 fRc = fRc and oSession.setExtraData(sKey, sValue)
170
171 # Other variations?
172
173 # Save the settings.
174 fRc = fRc and oSession.saveSettings()
175 fRc = oSession.close() and fRc;
176 else:
177 fRc = False;
178 if fRc is not True:
179 oVM = None;
180
181 # Done.
182 return (fRc, oVM)
183
184
185
186
187class tdGuestOsInstTest1(vbox.TestDriver):
188 """
189 Guest OS installation tests.
190
191 Scenario:
192 - Create new VM that corresponds specified installation ISO image.
193 - Create HDD that corresponds to OS type that will be installed.
194 - Boot VM from ISO image (i.e. install guest OS).
195 - Wait for incomming TCP connection (guest should initiate such a
196 connection in case installation has been completed successfully).
197 """
198
199
200 def __init__(self):
201 """
202 Reinitialize child class instance.
203 """
204 vbox.TestDriver.__init__(self)
205 self.fLegacyOptions = False;
206 assert self.fEnableVrdp; # in parent driver.
207
208 #
209 # Our install test VM set.
210 #
211 oSet = vboxtestvms.TestVmSet(self.oTestVmManager, fIgnoreSkippedVm = True);
212 oSet.aoTestVms.extend([
213 # pylint: disable=C0301
214 UnattendedVm(oSet, 'tst-w7-32', 'Windows7', 'en_windows_7_enterprise_x86_dvd_x15-70745.iso'),
215 # pylint: enable=C0301
216 ]);
217 self.oTestVmSet = oSet;
218
219 # For option parsing:
220 self.aoSelectedVms = oSet.aoTestVms # type: list(UnattendedVm)
221
222 # Number of VMs to test in parallel:
223 self.cInParallel = 1;
224
225 #
226 # Overridden methods.
227 #
228
229 def showUsage(self):
230 """
231 Extend usage info
232 """
233 rc = vbox.TestDriver.showUsage(self)
234 reporter.log('');
235 reporter.log('tdGuestOsUnattendedInst1 options:');
236 reporter.log(' --parallel <num>');
237 reporter.log(' Number of VMs to test in parallel.');
238 reporter.log(' Default: 1');
239 reporter.log('');
240 reporter.log(' Options for working on selected test VMs:');
241 reporter.log(' --select <vm1[:vm2[:..]]>');
242 reporter.log(' Selects a test VM for the following configuration alterations.');
243 reporter.log(' Default: All possible test VMs');
244 reporter.log(' --copy <old-vm>=<new-vm>');
245 reporter.log(' Creates and selects <new-vm> as a copy of <old-vm>.');
246 reporter.log(' --guest-type <guest-os-type>');
247 reporter.log(' Sets the guest-os type of the currently selected test VM.');
248 reporter.log(' --install-iso <ISO file name>');
249 reporter.log(' Sets ISO image to use for the selected test VM.');
250 reporter.log(' --ram-adjust <MBs>');
251 reporter.log(' Adjust the VM ram size by the given delta. Both negative and positive');
252 reporter.log(' values are accepted.');
253 reporter.log(' --max-cpus <# CPUs>');
254 reporter.log(' Sets the maximum number of guest CPUs for the selected VM.');
255 reporter.log(' --set-extradata <key>:value');
256 reporter.log(' Set VM extra data for the selected VM. Can be repeated.');
257 reporter.log(' --ioapic, --no-ioapic');
258 reporter.log(' Enable or disable the I/O apic for the selected VM.');
259 reporter.log(' --pae, --no-pae');
260 reporter.log(' Enable or disable PAE support (32-bit guests only) for the selected VM.');
261 return rc
262
263 def parseOption(self, asArgs, iArg):
264 """
265 Extend standard options set
266 """
267
268 if asArgs[iArg] == '--parallel':
269 iArg = self.requireMoreArgs(1, asArgs, iArg);
270 self.cInParallel = int(asArgs[iArg]);
271 if self.cInParallel <= 0:
272 self.cInParallel = 1;
273 elif asArgs[iArg] == '--select':
274 iArg = self.requireMoreArgs(1, asArgs, iArg);
275 self.aoSelectedVms = [];
276 for sTestVm in asArgs[iArg].split(':'):
277 oTestVm = self.oTestVmSet.findTestVmByName(sTestVm);
278 if not oTestVm:
279 raise base.InvalidOption('Unknown test VM: %s' % (sTestVm,));
280 self.aoSelectedVms.append(oTestVm);
281 elif asArgs[iArg] == '--copy':
282 iArg = self.requireMoreArgs(1, asArgs, iArg);
283 asNames = asArgs[iArg].split('=');
284 if len(asNames) != 2 or len(asNames[0]) == 0 or len(asNames[1]) == 0:
285 raise base.InvalidOption('The --copy option expects value on the form "old=new": %s' % (asArgs[iArg],));
286 oOldTestVm = self.oTestVmSet.findTestVmByName(asNames[0]);
287 if not oOldTestVm:
288 raise base.InvalidOption('Unknown test VM: %s' % (asNames[0],));
289 oNewTestVm = copy.deepcopy(oOldTestVm);
290 oNewTestVm.sVmName = asNames[1];
291 self.oTestVmSet.aoTestVms.append(oNewTestVm);
292 self.aoSelectedVms = [oNewTestVm];
293 elif asArgs[iArg] == '--guest-type':
294 iArg = self.requireMoreArgs(1, asArgs, iArg);
295 for oTestVm in self.aoSelectedVms:
296 oTestVm.sKind = asArgs[iArg];
297 elif asArgs[iArg] == '--install-iso':
298 iArg = self.requireMoreArgs(1, asArgs, iArg);
299 for oTestVm in self.aoSelectedVms:
300 oTestVm.sInstallIso = asArgs[iArg];
301 elif asArgs[iArg] == '--ram-adjust':
302 iArg = self.requireMoreArgs(1, asArgs, iArg);
303 for oTestVm in self.aoSelectedVms:
304 oTestVm.iOptRamAdjust = int(asArgs[iArg]);
305 elif asArgs[iArg] == '--max-cpus':
306 iArg = self.requireMoreArgs(1, asArgs, iArg);
307 for oTestVm in self.aoSelectedVms:
308 oTestVm.iOptMaxCpus = int(asArgs[iArg]);
309 elif asArgs[iArg] == '--set-extradata':
310 iArg = self.requireMoreArgs(1, asArgs, iArg)
311 for oTestVm in self.aoSelectedVms:
312 oTestVm.asOptExtraData.append(asArgs[iArg]);
313 elif asArgs[iArg] == '--ioapic':
314 for oTestVm in self.aoSelectedVms:
315 oTestVm.fOptIoApic = True;
316 elif asArgs[iArg] == '--no-ioapic':
317 for oTestVm in self.aoSelectedVms:
318 oTestVm.fOptIoApic = False;
319 elif asArgs[iArg] == '--pae':
320 for oTestVm in self.aoSelectedVms:
321 oTestVm.fOptPae = True;
322 elif asArgs[iArg] == '--no-pae':
323 for oTestVm in self.aoSelectedVms:
324 oTestVm.fOptPae = False;
325 else:
326 return vbox.TestDriver.parseOption(self, asArgs, iArg);
327 return iArg + 1;
328
329 def actionConfig(self):
330 if not self.importVBoxApi(): # So we can use the constant below.
331 return False;
332 return self.oTestVmSet.actionConfig(self, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT);
333
334 def actionExecute(self):
335 """
336 Execute the testcase.
337 """
338 return self.oTestVmSet.actionExecute(self, self.testOneVmConfig)
339
340 def testOneVmConfig(self, oVM, oTestVm):
341 """
342 Install guest OS and wait for result
343 """
344
345 self.logVmInfo(oVM)
346 reporter.testStart('Installing %s' % (oTestVm.sVmName,))
347
348 cMsTimeout = 40*60000;
349 if not reporter.isLocal(): ## @todo need to figure a better way of handling timeouts on the testboxes ...
350 cMsTimeout = 180 * 60000; # will be adjusted down.
351
352 oSession, _ = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = False, cMsTimeout = cMsTimeout);
353 if oSession is not None:
354 # The guest has connected to TXS, so we're done (for now anyways).
355 reporter.log('Guest reported success')
356 ## @todo Do save + restore.
357
358 reporter.testDone()
359 fRc = self.terminateVmBySession(oSession)
360 return fRc is True
361
362 reporter.error('Installation of %s has failed' % (oTestVm.sVmName,))
363 oTestVm.detatchAndDeleteHd(self); # Save space.
364 reporter.testDone()
365 return False
366
367if __name__ == '__main__':
368 sys.exit(tdGuestOsInstTest1().main(sys.argv))
369
Note: See TracBrowser for help on using the repository browser.

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