VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/additions/tdAddBasic1.py@ 83927

Last change on this file since 83927 was 83927, checked in by vboxsync, 5 years ago

Validation Kit/Additions: Don't download and install any dependencies required for installing the Guest Additions anymore; it's now documented and set as a rule that these must be pre-installed with the test VM. Should also speed up testing a lot.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdAddBasic1.py 83927 2020-04-22 14:14:31Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Additions Basics #1.
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2020 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: 83927 $"
31
32# Standard Python imports.
33import os;
34import sys;
35import uuid;
36
37# Only the main script needs to modify the path.
38try: __file__
39except: __file__ = sys.argv[0];
40g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
41sys.path.append(g_ksValidationKitDir);
42
43# Validation Kit imports.
44from testdriver import reporter;
45from testdriver import base;
46from testdriver import vbox;
47from testdriver import vboxcon;
48
49# Sub-test driver imports.
50sys.path.append(os.path.dirname(os.path.abspath(__file__))); # For sub-test drivers.
51from tdAddGuestCtrl import SubTstDrvAddGuestCtrl;
52from tdAddSharedFolders1 import SubTstDrvAddSharedFolders1;
53
54
55class tdAddBasic1(vbox.TestDriver): # pylint: disable=too-many-instance-attributes
56 """
57 Additions Basics #1.
58 """
59 ## @todo
60 # - More of the settings stuff can be and need to be generalized!
61 #
62
63 def __init__(self):
64 vbox.TestDriver.__init__(self);
65 self.oTestVmSet = self.oTestVmManager.getSmokeVmSet('nat');
66 self.asTestsDef = ['install', 'guestprops', 'stdguestprops', 'guestcontrol', 'sharedfolders'];
67 self.asTests = self.asTestsDef;
68 self.asRsrcs = None
69 # The file we're going to use as a beacon to wait if the Guest Additions CD-ROM is ready.
70 self.sFileCdWait = '';
71
72 self.addSubTestDriver(SubTstDrvAddGuestCtrl(self));
73 self.addSubTestDriver(SubTstDrvAddSharedFolders1(self));
74
75 #
76 # Overridden methods.
77 #
78 def showUsage(self):
79 rc = vbox.TestDriver.showUsage(self);
80 reporter.log('');
81 reporter.log('tdAddBasic1 Options:');
82 reporter.log(' --tests <s1[:s2[:]]>');
83 reporter.log(' Default: %s (all)' % (':'.join(self.asTestsDef)));
84 reporter.log(' --quick');
85 reporter.log(' Same as --virt-modes hwvirt --cpu-counts 1.');
86 return rc;
87
88 def parseOption(self, asArgs, iArg): # pylint: disable=too-many-branches,too-many-statements
89 if asArgs[iArg] == '--tests':
90 iArg += 1;
91 if iArg >= len(asArgs): raise base.InvalidOption('The "--tests" takes a colon separated list of tests');
92 self.asTests = asArgs[iArg].split(':');
93 for s in self.asTests:
94 if s not in self.asTestsDef:
95 raise base.InvalidOption('The "--tests" value "%s" is not valid; valid values are: %s'
96 % (s, ' '.join(self.asTestsDef),));
97
98 elif asArgs[iArg] == '--quick':
99 self.parseOption(['--virt-modes', 'hwvirt'], 0);
100 self.parseOption(['--cpu-counts', '1'], 0);
101
102 else:
103 return vbox.TestDriver.parseOption(self, asArgs, iArg);
104 return iArg + 1;
105
106 def getResourceSet(self):
107 if self.asRsrcs is None:
108 self.asRsrcs = []
109 for oSubTstDrv in self.aoSubTstDrvs:
110 self.asRsrcs.extend(oSubTstDrv.asRsrcs)
111 self.asRsrcs.extend(self.oTestVmSet.getResourceSet())
112 return self.asRsrcs
113
114 def actionConfig(self):
115 if not self.importVBoxApi(): # So we can use the constant below.
116 return False;
117
118 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT;
119 sGaIso = self.getGuestAdditionsIso();
120
121 # On 6.0 we merge the GAs with the ValidationKit so we can get at FsPerf.
122 # Note! Not possible to do a dboule import as both images an '/OS2' dir.
123 # So, using same dir as with unattended VISOs for the valkit.
124 if self.fpApiVer >= 6.0 and 'sharedfolders' in self.asTests:
125 sGaViso = os.path.join(self.sScratchPath, 'AdditionsAndValKit.viso');
126 ## @todo encode as bash cmd line:
127 sVisoContent = '--iprt-iso-maker-file-marker-bourne-sh %s ' \
128 '--import-iso \'%s\' ' \
129 '--push-iso \'%s\' ' \
130 '/vboxvalidationkit=/ ' \
131 '--pop ' \
132 % (uuid.uuid4(), sGaIso, self.sVBoxValidationKitIso);
133 reporter.log2('Using VISO combining GAs and ValKit "%s": %s' % (sGaViso, sVisoContent));
134 oGaViso = open(sGaViso, 'w');
135 oGaViso.write(sVisoContent);
136 oGaViso.close();
137 sGaIso = sGaViso;
138
139 return self.oTestVmSet.actionConfig(self, eNic0AttachType = eNic0AttachType, sDvdImage = sGaIso);
140
141 def actionExecute(self):
142 return self.oTestVmSet.actionExecute(self, self.testOneCfg);
143
144
145 #
146 # Test execution helpers.
147 #
148
149 def testOneCfg(self, oVM, oTestVm):
150 """
151 Runs the specified VM thru the tests.
152
153 Returns a success indicator on the general test execution. This is not
154 the actual test result.
155 """
156 fRc = False;
157
158 if oTestVm.isWindows():
159 self.sFileCdWait = 'VBoxWindowsAdditions.exe';
160 elif oTestVm.isLinux():
161 self.sFileCdWait = 'VBoxLinuxAdditions.run';
162
163 self.logVmInfo(oVM);
164 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = True,
165 sFileCdWait = self.sFileCdWait);
166 if oSession is not None:
167 self.addTask(oTxsSession);
168 # Do the testing.
169 fSkip = 'install' not in self.asTests;
170 reporter.testStart('Install');
171 if not fSkip:
172 fRc, oTxsSession = self.testInstallAdditions(oSession, oTxsSession, oTestVm);
173 reporter.testDone(fSkip);
174
175 if not fSkip \
176 and not fRc:
177 reporter.log('Skipping following tests as Guest Additions were not installed successfully');
178 else:
179 fSkip = 'guestprops' not in self.asTests;
180 reporter.testStart('Guest Properties');
181 if not fSkip:
182 fRc = self.testGuestProperties(oSession, oTxsSession, oTestVm) and fRc;
183 reporter.testDone(fSkip);
184
185 fSkip = 'guestcontrol' not in self.asTests;
186 reporter.testStart('Guest Control');
187 if not fSkip:
188 fRc, oTxsSession = self.aoSubTstDrvs[0].testIt(oTestVm, oSession, oTxsSession);
189 reporter.testDone(fSkip);
190
191 fSkip = 'sharedfolders' not in self.asTests and self.fpApiVer >= 6.0;
192 reporter.testStart('Shared Folders');
193 if not fSkip:
194 fRc, oTxsSession = self.aoSubTstDrvs[1].testIt(oTestVm, oSession, oTxsSession);
195 reporter.testDone(fSkip or fRc is None);
196
197 ## @todo Save and restore test.
198
199 ## @todo Reset tests.
200
201 ## @todo Final test: Uninstallation.
202
203 # Cleanup.
204 self.removeTask(oTxsSession);
205 self.terminateVmBySession(oSession)
206 return fRc;
207
208 def testInstallAdditions(self, oSession, oTxsSession, oTestVm):
209 """
210 Tests installing the guest additions
211 """
212 if oTestVm.isWindows():
213 (fRc, oTxsSession) = self.testWindowsInstallAdditions(oSession, oTxsSession, oTestVm);
214 elif oTestVm.isLinux():
215 (fRc, oTxsSession) = self.testLinuxInstallAdditions(oSession, oTxsSession, oTestVm);
216 else:
217 reporter.error('Guest Additions installation not implemented for %s yet! (%s)' %
218 (oTestVm.sKind, oTestVm.sVmName,));
219 fRc = False;
220
221 #
222 # Verify installation of Guest Additions using commmon bits.
223 #
224 if fRc is True:
225 #
226 # Wait for the GAs to come up.
227 #
228
229 ## @todo need to signed up for a OnAdditionsStateChanged and wait runlevel to
230 # at least reach Userland.
231
232 #
233 # Check if the additions are operational.
234 #
235 try: oGuest = oSession.o.console.guest;
236 except:
237 reporter.errorXcpt('Getting IGuest failed.');
238 return (False, oTxsSession);
239
240 # Check the additionsVersion attribute. It must not be empty.
241 reporter.testStart('IGuest::additionsVersion');
242 fRc = self.testIGuest_additionsVersion(oGuest);
243 reporter.testDone();
244
245 reporter.testStart('IGuest::additionsRunLevel');
246 self.testIGuest_additionsRunLevel(oGuest, oTestVm);
247 reporter.testDone();
248
249 ## @todo test IAdditionsFacilities.
250
251 return (fRc, oTxsSession);
252
253 def testWindowsInstallAdditions(self, oSession, oTxsSession, oTestVm):
254 """
255 Installs the Windows guest additions using the test execution service.
256 Since this involves rebooting the guest, we will have to create a new TXS session.
257 """
258
259 #
260 # Install the public signing key.
261 #
262 if oTestVm.sKind not in ('WindowsNT4', 'Windows2000', 'WindowsXP', 'Windows2003'):
263 fRc = self.txsRunTest(oTxsSession, 'VBoxCertUtil.exe', 1 * 60 * 1000, '${CDROM}/cert/VBoxCertUtil.exe',
264 ('${CDROM}/cert/VBoxCertUtil.exe', 'add-trusted-publisher', '${CDROM}/cert/vbox-sha1.cer'),
265 fCheckSessionStatus = True);
266 if not fRc:
267 reporter.error('Error installing SHA1 certificate');
268 else:
269 fRc = self.txsRunTest(oTxsSession, 'VBoxCertUtil.exe', 1 * 60 * 1000, '${CDROM}/cert/VBoxCertUtil.exe',
270 ('${CDROM}/cert/VBoxCertUtil.exe', 'add-trusted-publisher',
271 '${CDROM}/cert/vbox-sha256.cer'), fCheckSessionStatus = True);
272 if not fRc:
273 reporter.error('Error installing SHA256 certificate');
274
275 #
276 # Delete relevant log files.
277 #
278 # Note! On some guests the files in question still can be locked by the OS, so ignore
279 # deletion errors from the guest side (e.g. sharing violations) and just continue.
280 #
281 asLogFiles = [];
282 fHaveSetupApiDevLog = False;
283 if oTestVm.sKind in ('WindowsNT4',):
284 sWinDir = 'C:/WinNT/';
285 else:
286 sWinDir = 'C:/Windows/';
287 asLogFiles = [sWinDir + 'setupapi.log', sWinDir + 'setupact.log', sWinDir + 'setuperr.log'];
288
289 # Apply The SetupAPI logging level so that we also get the (most verbose) setupapi.dev.log file.
290 ## @todo !!! HACK ALERT !!! Add the value directly into the testing source image. Later.
291 fHaveSetupApiDevLog = self.txsRunTest(oTxsSession, 'Enabling setupapi.dev.log', 30 * 1000,
292 'c:\\Windows\\System32\\reg.exe',
293 ('c:\\Windows\\System32\\reg.exe', 'add',
294 '"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Setup"',
295 '/v', 'LogLevel', '/t', 'REG_DWORD', '/d', '0xFF'),
296 fCheckSessionStatus = True);
297
298 for sFile in asLogFiles:
299 self.txsRmFile(oSession, oTxsSession, sFile, 10 * 1000, fIgnoreErrors = True);
300
301 #
302 # The actual install.
303 # Enable installing the optional auto-logon modules (VBoxGINA/VBoxCredProv).
304 # Also tell the installer to produce the appropriate log files.
305 #
306 fRc = self.txsRunTest(oTxsSession, 'VBoxWindowsAdditions.exe', 5 * 60 * 1000, '${CDROM}/VBoxWindowsAdditions.exe',
307 ('${CDROM}/VBoxWindowsAdditions.exe', '/S', '/l', '/with_autologon'), fCheckSessionStatus = True);
308
309 #
310 # Reboot the VM and reconnect the TXS session.
311 #
312 if not fRc \
313 or oTxsSession.getResult() is False:
314 reporter.error('Error installing Windows Guest Additions (installer returned with exit code)')
315 else:
316 (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000);
317 if fRc is True:
318 # Add the Windows Guest Additions installer files to the files we want to download
319 # from the guest.
320 sGuestAddsDir = 'C:/Program Files/Oracle/VirtualBox Guest Additions/';
321 asLogFiles.append(sGuestAddsDir + 'install.log');
322 # Note: There won't be a install_ui.log because of the silent installation.
323 asLogFiles.append(sGuestAddsDir + 'install_drivers.log');
324 asLogFiles.append('C:/Windows/setupapi.log');
325
326 # Note: setupapi.dev.log only is available since Windows 2000.
327 if fHaveSetupApiDevLog:
328 asLogFiles.append('C:/Windows/setupapi.dev.log');
329
330 #
331 # Download log files.
332 # Ignore errors as all files above might not be present (or in different locations)
333 # on different Windows guests.
334 #
335 self.txsDownloadFiles(oSession, oTxsSession, asLogFiles, fIgnoreErrors = True);
336
337 return (fRc, oTxsSession);
338
339 def testLinuxInstallAdditions(self, oSession, oTxsSession, oTestVm):
340 _ = oSession;
341 _ = oTestVm;
342
343 fRc = False;
344
345 #
346 # The actual install.
347 # Also tell the installer to produce the appropriate log files.
348 #
349 # Make sure to add "--nox11" to the makeself wrapper in order to not getting any blocking
350 # xterm window spawned.
351 fRc = self.txsRunTest(oTxsSession, 'VBoxLinuxAdditions.run', 30 * 60 * 1000,
352 '/bin/sh', ('/bin/sh', '${CDROM}/VBoxLinuxAdditions.run', '--nox11'));
353 ## @todo We need to figure out why the result is != 0 when running the .run installer. For now just ignore it.
354 if not fRc:
355 reporter.error('Installing Linux Additions failed (isSuccess=%s, iResult=%d, see log file for details)'
356 % (oTxsSession.isSuccess(), oTxsSession.getResult()));
357
358 #
359 # Download log files.
360 # Ignore errors as all files above might not be present for whatever reason.
361 #
362 asLogFile = [];
363 asLogFile.append('/var/log/vboxadd-install.log');
364 self.txsDownloadFiles(oSession, oTxsSession, asLogFile, fIgnoreErrors = True);
365
366 # Do the final reboot to get the just installed Guest Additions up and running.
367 if fRc:
368 reporter.testStart('Rebooting guest w/ updated Guest Additions active');
369 (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, 15 * 60 * 1000,
370 sFileCdWait = self.sFileCdWait);
371 if fRc:
372 pass
373 else:
374 reporter.testFailure('Rebooting and reconnecting to TXS service failed');
375 reporter.testDone();
376
377 return (fRc, oTxsSession);
378
379 def testIGuest_additionsVersion(self, oGuest):
380 """
381 Returns False if no version string could be obtained, otherwise True
382 even though errors are logged.
383 """
384 try:
385 sVer = oGuest.additionsVersion;
386 except:
387 reporter.errorXcpt('Getting the additions version failed.');
388 return False;
389 reporter.log('IGuest::additionsVersion="%s"' % (sVer,));
390
391 if sVer.strip() == '':
392 reporter.error('IGuest::additionsVersion is empty.');
393 return False;
394
395 if sVer != sVer.strip():
396 reporter.error('IGuest::additionsVersion is contains spaces: "%s".' % (sVer,));
397
398 asBits = sVer.split('.');
399 if len(asBits) < 3:
400 reporter.error('IGuest::additionsVersion does not contain at least tree dot separated fields: "%s" (%d).'
401 % (sVer, len(asBits)));
402
403 ## @todo verify the format.
404 return True;
405
406 def testIGuest_additionsRunLevel(self, oGuest, oTestVm):
407 """
408 Do run level tests.
409 """
410 if oTestVm.isLoggedOntoDesktop():
411 eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Desktop;
412 else:
413 eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Userland;
414
415 ## @todo Insert wait for the desired run level.
416 try:
417 iLevel = oGuest.additionsRunLevel;
418 except:
419 reporter.errorXcpt('Getting the additions run level failed.');
420 return False;
421 reporter.log('IGuest::additionsRunLevel=%s' % (iLevel,));
422
423 if iLevel != eExpectedRunLevel:
424 pass; ## @todo We really need that wait!!
425 #reporter.error('Expected runlevel %d, found %d instead' % (eExpectedRunLevel, iLevel));
426 return True;
427
428
429 def testGuestProperties(self, oSession, oTxsSession, oTestVm):
430 """
431 Test guest properties.
432 """
433 _ = oSession; _ = oTxsSession; _ = oTestVm;
434 return True;
435
436if __name__ == '__main__':
437 sys.exit(tdAddBasic1().main(sys.argv));
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