VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py@ 76776

Last change on this file since 76776 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 26.7 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5AUtostart testcase using.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2013-2019 Oracle Corporation
11
12This file is part of VirtualBox Open Source Edition (OSE), as
13available from http://www.virtualbox.org. This file is free software;
14you can redistribute it and/or modify it under the terms of the GNU
15General Public License (GPL) as published by the Free Software
16Foundation, in version 2 as it comes in the "COPYING" file of the
17VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
20The contents of this file may alternatively be used under the terms
21of the Common Development and Distribution License Version 1.0
22(CDDL) only, as it comes in the "COPYING.CDDL" file of the
23VirtualBox OSE distribution, in which case the provisions of the
24CDDL are applicable instead of those of the GPL.
25
26You may elect to license modified versions of this file under the
27terms and conditions of either the GPL or the CDDL or both.
28"""
29__version__ = "$Id: tdAutostart1.py 76553 2019-01-01 01:45:53Z vboxsync $"
30
31
32# Standard Python imports.
33import os;
34import sys;
35import re;
36import array;
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 reporter;
46from testdriver import base;
47from testdriver import vbox;
48from testdriver import vboxcon;
49
50class VBoxManageStdOutWrapper(object):
51 """ Parser for VBoxManage list runningvms """
52 def __init__(self):
53 self.sVmRunning = '';
54
55 def read(self, cb):
56 """file.read"""
57 _ = cb;
58 return "";
59
60 def write(self, sText):
61 """VBoxManage stdout write"""
62 if isinstance(sText, array.array):
63 sText = sText.tostring();
64
65 asLines = sText.splitlines();
66 for sLine in asLines:
67 sLine = sLine.strip();
68
69 # Extract the value
70 idxVmNameStart = sLine.find('"');
71 if idxVmNameStart == -1:
72 raise Exception('VBoxManageStdOutWrapper: Invalid output');
73
74 idxVmNameStart += 1;
75 idxVmNameEnd = idxVmNameStart;
76 while sLine[idxVmNameEnd] != '"':
77 idxVmNameEnd += 1;
78
79 self.sVmRunning = sLine[idxVmNameStart:idxVmNameEnd];
80 reporter.log('Logging: ' + self.sVmRunning);
81
82 return None;
83
84class tdAutostartOs(object):
85 """
86 Base autostart helper class to provide common methods.
87 """
88
89 def _findFile(self, sRegExp, sTestBuildDir):
90 """
91 Returns a filepath based on the given regex and path to look into
92 or None if no matching file is found.
93 """
94
95 oRegExp = re.compile(sRegExp);
96
97 asFiles = os.listdir(sTestBuildDir);
98
99 for sFile in asFiles:
100 if oRegExp.match(os.path.basename(sFile)) and os.path.exists(sTestBuildDir + '/' + sFile):
101 return sTestBuildDir + '/' + sFile;
102
103 reporter.error('Failed to find a file matching "%s" in %s.' % (sRegExp, sTestBuildDir));
104 return None;
105
106 def _createAutostartCfg(self, sDefaultPolicy = 'allow', asUserAllow = (), asUserDeny = ()):
107 """
108 Creates a autostart config for VirtualBox
109 """
110
111 sVBoxCfg = 'default_policy=' + sDefaultPolicy + '\n';
112
113 for sUserAllow in asUserAllow:
114 sVBoxCfg = sVBoxCfg + sUserAllow + ' = {\n allow = true\n }\n';
115
116 for sUserDeny in asUserDeny:
117 sVBoxCfg = sVBoxCfg + sUserDeny + ' = {\n allow = false\n }\n';
118
119 return sVBoxCfg;
120
121class tdAutostartOsLinux(tdAutostartOs):
122 """
123 Autostart support methods for Linux guests.
124 """
125
126 def __init__(self, oTestDriver, sTestBuildDir):
127 tdAutostartOs.__init__(self);
128 self.sTestBuild = self._findFile('^VirtualBox-.*\\.run$', sTestBuildDir);
129 self.oTestDriver = oTestDriver;
130
131 def installVirtualBox(self, oSession, oTxsSession):
132 """
133 Install VirtualBox in the guest.
134 """
135 fRc = False;
136
137 if self.sTestBuild is not None:
138 fRc = self.oTestDriver.txsUploadFile(oSession, oTxsSession, self.sTestBuild, \
139 '/tmp/' + os.path.basename(self.sTestBuild), \
140 cMsTimeout = 120 * 1000);
141 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Installing VBox', 10 * 1000, \
142 '/bin/chmod',
143 ('chmod', '755', '/tmp/' + os.path.basename(self.sTestBuild)));
144 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Installing VBox', 240 * 1000, \
145 '/tmp/' + os.path.basename(self.sTestBuild));
146
147 return fRc;
148
149 def configureAutostart(self, oSession, oTxsSession, sDefaultPolicy = 'allow',
150 asUserAllow = (), asUserDeny = ()):
151 """
152 Configures the autostart feature in the guest.
153 """
154
155 # Create autostart database directory writeable for everyone
156 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating autostart database', 10 * 1000, \
157 '/bin/mkdir',
158 ('mkdir', '-m', '1777', '/etc/vbox/autostart.d'));
159
160 # Create /etc/default/virtualbox
161 sVBoxCfg = 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg\n' \
162 + 'VBOXAUTOSTART_DB=/etc/vbox/autostart.d\n';
163 fRc = fRc and self.oTestDriver.txsUploadString(oSession, oTxsSession, sVBoxCfg, '/etc/default/virtualbox');
164 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Setting permissions', 10 * 1000, \
165 '/bin/chmod',
166 ('chmod', '644', '/etc/default/virtualbox'));
167
168 sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny);
169 fRc = fRc and self.oTestDriver.txsUploadString(oSession, oTxsSession, sVBoxCfg, '/etc/vbox/autostart.cfg');
170 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Setting permissions', 10 * 1000, \
171 '/bin/chmod',
172 ('chmod', '644', '/etc/vbox/autostart.cfg'));
173
174 return fRc;
175
176 def createUser(self, oTxsSession, sUser):
177 """
178 Create a new user with the given name
179 """
180
181 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating new user', 10 * 1000, \
182 '/usr/sbin/useradd',
183 ('useradd', '-m', '-U', sUser));
184
185 return fRc;
186
187 # pylint: disable=R0913
188
189 def runProgAsUser(self, oTxsSession, sTestName, cMsTimeout, sExecName, sAsUser, asArgs = (),
190 oStdIn = '/dev/null', oStdOut = '/dev/null', oStdErr = '/dev/null', oTestPipe = '/dev/null'):
191 """
192 Runs a program as the specififed user
193 """
194 asNewArgs = ('sudo', '-u', sAsUser, sExecName) + asArgs;
195
196 fRc = self.oTestDriver.txsRunTestRedirectStd(oTxsSession, sTestName, cMsTimeout, '/usr/bin/sudo',
197 asNewArgs, (), "", oStdIn, oStdOut, oStdErr, oTestPipe);
198
199 return fRc;
200
201 # pylint: enable=R0913
202
203 def createTestVM(self, oSession, oTxsSession, sUser, sVmName):
204 """
205 Create a test VM in the guest and enable autostart.
206 """
207
208 _ = oSession;
209
210 fRc = self.runProgAsUser(oTxsSession, 'Configuring autostart database', 10 * 1000, \
211 '/opt/VirtualBox/VBoxManage', sUser,
212 ('setproperty', 'autostartdbpath', '/etc/vbox/autostart.d'));
213 fRc = fRc and self.runProgAsUser(oTxsSession, 'Create VM ' + sVmName, 10 * 1000, \
214 '/opt/VirtualBox/VBoxManage', sUser,
215 ('createvm', '--name', sVmName, '--register'));
216 fRc = fRc and self.runProgAsUser(oTxsSession, 'Enabling autostart for test VM', 10 * 1000, \
217 '/opt/VirtualBox/VBoxManage', sUser,
218 ('modifyvm', sVmName, '--autostart-enabled', 'on'));
219
220 return fRc;
221
222 def checkForRunningVM(self, oSession, oTxsSession, sUser, sVmName):
223 """
224 Check for VM running in the guest after autostart.
225 """
226
227 _ = oSession;
228
229 oStdOut = VBoxManageStdOutWrapper();
230 fRc = self.runProgAsUser(oTxsSession, 'Check for running VM', 20 * 1000, \
231 '/opt/VirtualBox/VBoxManage', sUser, ('list', 'runningvms'),
232 '/dev/null', oStdOut, '/dev/null', '/dev/null');
233
234 fRc = fRc is True and oStdOut.sVmRunning == sVmName;
235
236 return fRc;
237
238class tdAutostartOsDarwin(tdAutostartOs):
239 """
240 Autostart support methods for Darwin guests.
241 """
242
243 def __init__(self, sTestBuildDir):
244 _ = sTestBuildDir;
245 tdAutostartOs.__init__(self);
246
247 def installVirtualBox(self, oSession, oTxsSession):
248 """
249 Install VirtualBox in the guest.
250 """
251 _ = oSession;
252 _ = oTxsSession;
253 return False;
254
255 def configureAutostart(self, oSession, oTxsSession):
256 """
257 Configures the autostart feature in the guest.
258 """
259 _ = oSession;
260 _ = oTxsSession;
261 return False;
262
263 def createTestVM(self, oSession, oTxsSession):
264 """
265 Create a test VM in the guest and enable autostart.
266 """
267 _ = oSession;
268 _ = oTxsSession;
269 return False;
270
271 def checkForRunningVM(self, oSession, oTxsSession):
272 """
273 Check for VM running in the guest after autostart.
274 """
275 _ = oSession;
276 _ = oTxsSession;
277 return False;
278
279class tdAutostartOsSolaris(tdAutostartOs):
280 """
281 Autostart support methods for Solaris guests.
282 """
283
284 def __init__(self, oTestDriver, sTestBuildDir):
285 tdAutostartOs.__init__(self);
286 self.sTestBuildDir = sTestBuildDir;
287 self.sTestBuild = self._findFile('^VirtualBox-.*-SunOS-.*\\.tar.gz$', sTestBuildDir);
288 self.oTestDriver = oTestDriver;
289
290 def installVirtualBox(self, oSession, oTxsSession):
291 """
292 Install VirtualBox in the guest.
293 """
294 fRc = False;
295
296 if self.sTestBuild is not None:
297 reporter.log('Testing build: %s' % (self.sTestBuild));
298 sTestBuildFilename = os.path.basename(self.sTestBuild);
299
300 # Construct the .pkg filename from the tar.gz name.
301 oMatch = re.search(r'\d+.\d+.\d+-SunOS-r\d+', sTestBuildFilename);
302 if oMatch is not None:
303 sPkgFilename = 'VirtualBox-' + oMatch.group() + '.pkg';
304
305 reporter.log('Extracted package filename: %s' % (sPkgFilename));
306
307 fRc = self.oTestDriver.txsUploadFile(oSession, oTxsSession, self.sTestBuild, \
308 '${SCRATCH}/' + sTestBuildFilename, \
309 cMsTimeout = 120 * 1000);
310 fRc = fRc and self.oTestDriver.txsUnpackFile(oSession, oTxsSession, \
311 '${SCRATCH}/' + sTestBuildFilename, \
312 '${SCRATCH}', cMsTimeout = 120 * 1000);
313 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Installing package', 240 * 1000, \
314 '/usr/sbin/pkgadd',
315 ('pkgadd', '-d', '${SCRATCH}/' + sPkgFilename, \
316 '-n', '-a', '${SCRATCH}/autoresponse', 'SUNWvbox'));
317 return fRc;
318
319 def configureAutostart(self, oSession, oTxsSession, sDefaultPolicy = 'allow',
320 asUserAllow = (), asUserDeny = ()):
321 """
322 Configures the autostart feature in the guest.
323 """
324
325 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating /etc/vbox directory', 10 * 1000, \
326 '/usr/bin/mkdir',
327 ('mkdir', '-m', '755', '/etc/vbox'));
328
329 sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny);
330 fRc = fRc and self.oTestDriver.txsUploadString(oSession, oTxsSession, sVBoxCfg, '/etc/vbox/autostart.cfg');
331 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Setting permissions', 10 * 1000, \
332 '/usr/bin/chmod',
333 ('chmod', '644', '/etc/vbox/autostart.cfg'));
334
335
336 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Importing the service', 10 * 1000, \
337 '/usr/sbin/svccfg',
338 ('svccfg', '-s', 'svc:/application/virtualbox/autostart:default', \
339 'setprop', 'config/config=/etc/vbox/autostart.cfg'));
340 fRc = fRc and self.oTestDriver.txsRunTest(oTxsSession, 'Enabling the service', 10 * 1000, \
341 '/usr/sbin/svcadm',
342 ('svcadm', 'enable', 'svc:/application/virtualbox/autostart:default'));
343
344 return fRc;
345
346 def createUser(self, oTxsSession, sUser):
347 """
348 Create a new user with the given name
349 """
350
351 fRc = self.oTestDriver.txsRunTest(oTxsSession, 'Creating new user', 10 * 1000, \
352 '/usr/sbin/useradd',
353 ('useradd', '-m', '-g', 'staff', sUser));
354
355 return fRc;
356
357 # pylint: disable=R0913
358
359 def runProgAsUser(self, oTxsSession, sTestName, cMsTimeout, sExecName, sAsUser, asArgs = (),
360 oStdIn = '/dev/null', oStdOut = '/dev/null', oStdErr = '/dev/null', oTestPipe = '/dev/null'):
361 """
362 Runs a program as the specififed user
363 """
364 asNewArgs = ('sudo', '-u', sAsUser, sExecName) + asArgs;
365
366 fRc = self.oTestDriver.txsRunTestRedirectStd(oTxsSession, sTestName, cMsTimeout, '/usr/bin/sudo',
367 asNewArgs, (), "", oStdIn, oStdOut, oStdErr, oTestPipe);
368
369 return fRc;
370
371 # pylint: enable=R0913
372
373 def createTestVM(self, oSession, oTxsSession, sUser, sVmName):
374 """
375 Create a test VM in the guest and enable autostart.
376 """
377
378 _ = oSession;
379
380 fRc = self.runProgAsUser(oTxsSession, 'Create VM ' + sVmName, 10 * 1000, \
381 '/opt/VirtualBox/VBoxManage', sUser,
382 ('createvm', '--name', sVmName, '--register'));
383 fRc = fRc and self.runProgAsUser(oTxsSession, 'Enabling autostart for test VM', 10 * 1000, \
384 '/opt/VirtualBox/VBoxManage', sUser,
385 ('modifyvm', sVmName, '--autostart-enabled', 'on'));
386
387 return fRc;
388
389 def checkForRunningVM(self, oSession, oTxsSession, sUser, sVmName):
390 """
391 Check for VM running in the guest after autostart.
392 """
393
394 _ = oSession;
395
396 oStdOut = VBoxManageStdOutWrapper();
397 fRc = self.runProgAsUser(oTxsSession, 'Check for running VM', 20 * 1000, \
398 '/opt/VirtualBox/VBoxManage', sUser, ('list', 'runningvms'),
399 '/dev/null', oStdOut, '/dev/null', '/dev/null');
400
401 fRc = fRc is True and oStdOut.sVmRunning == sVmName;
402
403 return fRc;
404
405
406class tdAutostartOsWin(tdAutostartOs):
407 """
408 Autostart support methods for Windows guests.
409 """
410
411 def __init__(self, sTestBuildDir):
412 _ = sTestBuildDir;
413 tdAutostartOs.__init__(self);
414 return;
415
416 def installVirtualBox(self, oSession, oTxsSession):
417 """
418 Install VirtualBox in the guest.
419 """
420 _ = oSession;
421 _ = oTxsSession;
422 return False;
423
424 def configureAutostart(self, oSession, oTxsSession):
425 """
426 Configures the autostart feature in the guest.
427 """
428 _ = oSession;
429 _ = oTxsSession;
430 return False;
431
432 def createTestVM(self, oSession, oTxsSession):
433 """
434 Create a test VM in the guest and enable autostart.
435 """
436 _ = oSession;
437 _ = oTxsSession;
438 return False;
439
440 def checkForRunningVM(self, oSession, oTxsSession):
441 """
442 Check for VM running in the guest after autostart.
443 """
444 _ = oSession;
445 _ = oTxsSession;
446 return False;
447
448class tdAutostart(vbox.TestDriver): # pylint: disable=R0902
449 """
450 Autostart testcase.
451 """
452
453 ksOsLinux = 'tst-debian'
454 ksOsWindows = 'tst-win'
455 ksOsDarwin = 'tst-darwin'
456 ksOsSolaris = 'tst-solaris'
457 ksOsFreeBSD = 'tst-freebsd'
458
459 def __init__(self):
460 vbox.TestDriver.__init__(self);
461 self.asRsrcs = None;
462 self.asTestVMsDef = [self.ksOsLinux, self.ksOsSolaris];
463 self.asTestVMs = self.asTestVMsDef;
464 self.asSkipVMs = [];
465 self.sTestBuildDir = '/home/alexander/Downloads';
466
467 #
468 # Overridden methods.
469 #
470 def showUsage(self):
471 rc = vbox.TestDriver.showUsage(self);
472 reporter.log('');
473 reporter.log('tdAutostart Options:');
474 reporter.log(' --test-build-dir <path>');
475 reporter.log(' Default: %s' % (self.sTestBuildDir));
476 reporter.log(' --test-vms <vm1[:vm2[:...]]>');
477 reporter.log(' Test the specified VMs in the given order. Use this to change');
478 reporter.log(' the execution order or limit the choice of VMs');
479 reporter.log(' Default: %s (all)' % (':'.join(self.asTestVMsDef)));
480 reporter.log(' --skip-vms <vm1[:vm2[:...]]>');
481 reporter.log(' Skip the specified VMs when testing.');
482 return rc;
483
484 def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
485 if asArgs[iArg] == '--test-build-dir':
486 iArg += 1;
487 if iArg >= len(asArgs): raise base.InvalidOption('The "--test-build-dir" takes a path argument');
488 self.sTestBuildDir = asArgs[iArg];
489 elif asArgs[iArg] == '--test-vms':
490 iArg += 1;
491 if iArg >= len(asArgs): raise base.InvalidOption('The "--test-vms" takes colon separated list');
492 self.asTestVMs = asArgs[iArg].split(':');
493 for s in self.asTestVMs:
494 if s not in self.asTestVMsDef:
495 raise base.InvalidOption('The "--test-vms" value "%s" is not valid; valid values are: %s' \
496 % (s, ' '.join(self.asTestVMsDef)));
497 elif asArgs[iArg] == '--skip-vms':
498 iArg += 1;
499 if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-vms" takes colon separated list');
500 self.asSkipVMs = asArgs[iArg].split(':');
501 for s in self.asSkipVMs:
502 if s not in self.asTestVMsDef:
503 reporter.log('warning: The "--test-vms" value "%s" does not specify any of our test VMs.' % (s));
504 else:
505 return vbox.TestDriver.parseOption(self, asArgs, iArg);
506 return iArg + 1;
507
508 def completeOptions(self):
509 # Remove skipped VMs from the test list.
510 for sVM in self.asSkipVMs:
511 try: self.asTestVMs.remove(sVM);
512 except: pass;
513
514 return vbox.TestDriver.completeOptions(self);
515
516 def getResourceSet(self):
517 # Construct the resource list the first time it's queried.
518 if self.asRsrcs is None:
519 self.asRsrcs = [];
520 if self.ksOsLinux in self.asTestVMs:
521 self.asRsrcs.append('4.2/autostart/tst-debian.vdi');
522 if self.ksOsSolaris in self.asTestVMs:
523 self.asRsrcs.append('4.2/autostart/tst-solaris.vdi');
524
525 return self.asRsrcs;
526
527 def actionConfig(self):
528
529 # Make sure vboxapi has been imported so we can use the constants.
530 if not self.importVBoxApi():
531 return False;
532
533 #
534 # Configure the VMs we're going to use.
535 #
536
537 # Linux VMs
538 if self.ksOsLinux in self.asTestVMs:
539 oVM = self.createTestVM(self.ksOsLinux, 1, '4.2/autostart/tst-debian.vdi', sKind = 'Debian_64', \
540 fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
541 eNic0Type = vboxcon.NetworkAdapterType_Am79C973);
542 if oVM is None:
543 return False;
544
545 # Solaris VMs
546 if self.ksOsSolaris in self.asTestVMs:
547 oVM = self.createTestVM(self.ksOsSolaris, 1, '4.2/autostart/tst-solaris.vdi', sKind = 'Solaris_64', \
548 fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
549 sHddControllerType = "SATA Controller");
550 if oVM is None:
551 return False;
552
553 return True;
554
555 def actionExecute(self):
556 """
557 Execute the testcase.
558 """
559 fRc = self.testAutostart();
560 return fRc;
561
562 #
563 # Test execution helpers.
564 #
565 def testAutostartRunProgs(self, oSession, oTxsSession, sVmName):
566 """
567 Test VirtualBoxs autostart feature in a VM.
568 """
569 reporter.testStart('Autostart ' + sVmName);
570
571 oGuestOsHlp = None; # type: tdAutostartOs
572 if sVmName == self.ksOsLinux:
573 oGuestOsHlp = tdAutostartOsLinux(self, self.sTestBuildDir);
574 elif sVmName == self.ksOsSolaris:
575 oGuestOsHlp = tdAutostartOsSolaris(self, self.sTestBuildDir); # annoying - pylint: disable=redefined-variable-type
576 elif sVmName == self.ksOsDarwin:
577 oGuestOsHlp = tdAutostartOsDarwin(self.sTestBuildDir);
578 elif sVmName == self.ksOsWindows:
579 oGuestOsHlp = tdAutostartOsWin(self.sTestBuildDir);
580
581 sTestUserAllow = 'test1';
582 sTestUserDeny = 'test2';
583 sTestVmName = 'TestVM';
584
585 if oGuestOsHlp is not None:
586 # Create two new users
587 fRc = oGuestOsHlp.createUser(oTxsSession, sTestUserAllow);
588 fRc = fRc and oGuestOsHlp.createUser(oTxsSession, sTestUserDeny);
589 if fRc is True:
590 # Install VBox first
591 fRc = oGuestOsHlp.installVirtualBox(oSession, oTxsSession);
592 if fRc is True:
593 fRc = oGuestOsHlp.configureAutostart(oSession, oTxsSession, 'allow',
594 (sTestUserAllow,), (sTestUserDeny,));
595 if fRc is True:
596 # Create a VM with autostart enabled in the guest for both users
597 fRc = oGuestOsHlp.createTestVM(oSession, oTxsSession, sTestUserAllow, sTestVmName);
598 fRc = fRc and oGuestOsHlp.createTestVM(oSession, oTxsSession, sTestUserDeny, sTestVmName);
599 if fRc is True:
600 # Reboot the guest
601 (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000, \
602 fNatForwardingForTxs = True);
603 if fRc is True:
604 # Fudge factor - Allow the guest to finish starting up.
605 self.sleep(5);
606 fRc = oGuestOsHlp.checkForRunningVM(oSession, oTxsSession, sTestUserAllow, sTestVmName);
607 if fRc is False:
608 reporter.error('Test VM is not running inside the guest for allowed user');
609
610 fRc = oGuestOsHlp.checkForRunningVM(oSession, oTxsSession, sTestUserDeny, sTestVmName);
611 if fRc is True:
612 reporter.error('Test VM is running inside the guest for denied user');
613 else:
614 reporter.log('Rebooting the guest failed');
615 else:
616 reporter.log('Creating test VM failed');
617 else:
618 reporter.log('Configuring autostart in the guest failed');
619 else:
620 reporter.log('Installing VirtualBox in the guest failed');
621 else:
622 reporter.log('Creating test users failed');
623 else:
624 reporter.log('Guest OS helper not created for VM %s' % (sVmName));
625 fRc = False;
626
627 reporter.testDone(not fRc);
628 return fRc;
629
630 def testAutostartOneCfg(self, sVmName):
631 """
632 Runs the specified VM thru test #1.
633
634 Returns a success indicator on the general test execution. This is not
635 the actual test result.
636 """
637 oVM = self.getVmByName(sVmName);
638
639 # Reconfigure the VM
640 fRc = True;
641 oSession = self.openSession(oVM);
642 if oSession is not None:
643 fRc = fRc and oSession.enableVirtEx(True);
644 fRc = fRc and oSession.enableNestedPaging(True);
645 fRc = fRc and oSession.saveSettings();
646 fRc = oSession.close() and fRc and True; # pychecker hack.
647 oSession = None;
648 else:
649 fRc = False;
650
651 # Start up.
652 if fRc is True:
653 self.logVmInfo(oVM);
654 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(sVmName, fCdWait = False, fNatForwardingForTxs = True);
655 if oSession is not None:
656 self.addTask(oTxsSession);
657
658 # Fudge factor - Allow the guest to finish starting up.
659 self.sleep(5);
660
661 fRc = self.testAutostartRunProgs(oSession, oTxsSession, sVmName);
662
663 # cleanup.
664 self.removeTask(oTxsSession);
665 self.terminateVmBySession(oSession)
666 else:
667 fRc = False;
668 return fRc;
669
670 def testAutostartForOneVM(self, sVmName):
671 """
672 Runs one VM thru the various configurations.
673 """
674 reporter.testStart(sVmName);
675 fRc = True;
676 self.testAutostartOneCfg(sVmName);
677 reporter.testDone();
678 return fRc;
679
680 def testAutostart(self):
681 """
682 Executes autostart test.
683 """
684
685 # Loop thru the test VMs.
686 for sVM in self.asTestVMs:
687 # run test on the VM.
688 if not self.testAutostartForOneVM(sVM):
689 fRc = False;
690 else:
691 fRc = True;
692
693 return fRc;
694
695
696
697if __name__ == '__main__':
698 sys.exit(tdAutostart().main(sys.argv));
699
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