1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 |
|
---|
4 | """
|
---|
5 | AUtostart testcase using.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2013-2020 Oracle Corporation
|
---|
11 |
|
---|
12 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | available from http://www.virtualbox.org. This file is free software;
|
---|
14 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | General Public License (GPL) as published by the Free Software
|
---|
16 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 |
|
---|
20 | The contents of this file may alternatively be used under the terms
|
---|
21 | of the Common Development and Distribution License Version 1.0
|
---|
22 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | CDDL are applicable instead of those of the GPL.
|
---|
25 |
|
---|
26 | You may elect to license modified versions of this file under the
|
---|
27 | terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | """
|
---|
29 | __version__ = "$Id: tdAutostart1.py 84699 2020-06-05 15:26:43Z vboxsync $"
|
---|
30 |
|
---|
31 |
|
---|
32 | # Standard Python imports.
|
---|
33 | import os;
|
---|
34 | import sys;
|
---|
35 | import re;
|
---|
36 | import ssl;
|
---|
37 |
|
---|
38 | # Python 3 hacks:
|
---|
39 | if sys.version_info[0] < 3:
|
---|
40 | import urllib2 as urllib; # pylint: disable=import-error,no-name-in-module
|
---|
41 | from urllib2 import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module
|
---|
42 | from urllib2 import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module
|
---|
43 | else:
|
---|
44 | import urllib; # pylint: disable=import-error,no-name-in-module
|
---|
45 | from urllib.request import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module
|
---|
46 | from urllib.request import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module
|
---|
47 |
|
---|
48 |
|
---|
49 | # Only the main script needs to modify the path.
|
---|
50 | try: __file__
|
---|
51 | except: __file__ = sys.argv[0];
|
---|
52 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
---|
53 | sys.path.append(g_ksValidationKitDir);
|
---|
54 |
|
---|
55 | # Validation Kit imports.
|
---|
56 | from testdriver import reporter;
|
---|
57 | from testdriver import base;
|
---|
58 | from testdriver import vbox;
|
---|
59 | from testdriver import vboxcon;
|
---|
60 | from testdriver import vboxwrappers;
|
---|
61 | from common import utils;
|
---|
62 |
|
---|
63 | # Python 3 hacks:
|
---|
64 | if sys.version_info[0] >= 3:
|
---|
65 | long = int # pylint: disable=redefined-builtin,invalid-name
|
---|
66 | xrange = range; # pylint: disable=redefined-builtin,invalid-name
|
---|
67 |
|
---|
68 |
|
---|
69 | class VBoxManageStdOutWrapper(object):
|
---|
70 | """ Parser for VBoxManage list runningvms """
|
---|
71 | def __init__(self):
|
---|
72 | self.sVmRunning = '';
|
---|
73 |
|
---|
74 | def __del__(self):
|
---|
75 | self.close();
|
---|
76 |
|
---|
77 | def close(self):
|
---|
78 | """file.close"""
|
---|
79 | return;
|
---|
80 |
|
---|
81 | def read(self, cb):
|
---|
82 | """file.read"""
|
---|
83 | _ = cb;
|
---|
84 | return "";
|
---|
85 |
|
---|
86 | def write(self, sText):
|
---|
87 | """VBoxManage stdout write"""
|
---|
88 | if sText is None:
|
---|
89 | return None;
|
---|
90 |
|
---|
91 | try: sText = str(sText); # pylint: disable=redefined-variable-type
|
---|
92 | except: pass;
|
---|
93 |
|
---|
94 | asLines = sText.splitlines();
|
---|
95 | for sLine in asLines:
|
---|
96 | sLine = sLine.strip();
|
---|
97 |
|
---|
98 | reporter.log('Logging: ' + sLine);
|
---|
99 |
|
---|
100 | # Extract the value
|
---|
101 | idxVmNameStart = sLine.find('"');
|
---|
102 | if idxVmNameStart == -1:
|
---|
103 | raise Exception('VBoxManageStdOutWrapper: Invalid output');
|
---|
104 |
|
---|
105 | idxVmNameStart += 1;
|
---|
106 | idxVmNameEnd = idxVmNameStart;
|
---|
107 | while sLine[idxVmNameEnd] != '"':
|
---|
108 | idxVmNameEnd += 1;
|
---|
109 |
|
---|
110 | self.sVmRunning = sLine[idxVmNameStart:idxVmNameEnd];
|
---|
111 | reporter.log('Logging: ' + self.sVmRunning);
|
---|
112 |
|
---|
113 | return None;
|
---|
114 |
|
---|
115 |
|
---|
116 | def downloadFile(sUrlFile, sDstFile, sLocalPrefix, fnLog, fnError = None, fNoProxies=True):
|
---|
117 | """
|
---|
118 | Downloads the given file if an URL is given, otherwise assume it's
|
---|
119 | something on the build share and copy it from there.
|
---|
120 |
|
---|
121 | Raises no exceptions, returns log + success indicator instead.
|
---|
122 |
|
---|
123 | Note! This method may use proxies configured on the system and the
|
---|
124 | http_proxy, ftp_proxy, no_proxy environment variables.
|
---|
125 |
|
---|
126 | """
|
---|
127 | if fnError is None:
|
---|
128 | fnError = fnLog;
|
---|
129 |
|
---|
130 | if sUrlFile.startswith('http://') \
|
---|
131 | or sUrlFile.startswith('https://') \
|
---|
132 | or sUrlFile.startswith('ftp://'):
|
---|
133 | # Download the file.
|
---|
134 | fnLog('Downloading "%s" to "%s"...' % (sUrlFile, sDstFile));
|
---|
135 | try:
|
---|
136 | # Disable SSL certificate verification for our servers
|
---|
137 | ssl_ctx = ssl.create_default_context();
|
---|
138 | ssl_ctx.check_hostname = False;
|
---|
139 | ssl_ctx.verify_mode = ssl.CERT_NONE;
|
---|
140 |
|
---|
141 | ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.
|
---|
142 | if not fNoProxies:
|
---|
143 | oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx));
|
---|
144 | else:
|
---|
145 | oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx), urllib_ProxyHandler(proxies = dict()));
|
---|
146 | oSrc = oOpener.open(sUrlFile);
|
---|
147 | oDst = utils.openNoInherit(sDstFile, 'wb');
|
---|
148 | oDst.write(oSrc.read());
|
---|
149 | oDst.close();
|
---|
150 | oSrc.close();
|
---|
151 | except Exception as oXcpt:
|
---|
152 | fnError('Error downloading "%s" to "%s": %s' % (sUrlFile, sDstFile, oXcpt));
|
---|
153 | return False;
|
---|
154 | else:
|
---|
155 | # Assumes file from the build share.
|
---|
156 | sSrcPath = os.path.join(sLocalPrefix, sUrlFile);
|
---|
157 | fnLog('Copying "%s" to "%s"...' % (sSrcPath, sDstFile));
|
---|
158 | try:
|
---|
159 | utils.copyFileSimple(sSrcPath, sDstFile);
|
---|
160 | except Exception as oXcpt:
|
---|
161 | fnError('Error copying "%s" to "%s": %s' % (sSrcPath, sDstFile, oXcpt));
|
---|
162 | return False;
|
---|
163 |
|
---|
164 | return True;
|
---|
165 |
|
---|
166 |
|
---|
167 | class tdAutostartOs(object):
|
---|
168 | """
|
---|
169 | Base autostart helper class to provide common methods.
|
---|
170 | """
|
---|
171 |
|
---|
172 | def __init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso):
|
---|
173 | self.oTestDriver = oTestDriver;
|
---|
174 | self.fpApiVer = fpApiVer;
|
---|
175 | self.sGuestAdditionsIso = sGuestAdditionsIso;
|
---|
176 |
|
---|
177 | def _findFile(self, sRegExp, asTestBuildDirs):
|
---|
178 | """
|
---|
179 | Returns a filepath based on the given regex and paths to look into
|
---|
180 | or None if no matching file is found.
|
---|
181 | """
|
---|
182 |
|
---|
183 | oRegExp = re.compile(sRegExp);
|
---|
184 | for sTestBuildDir in asTestBuildDirs:
|
---|
185 | try:
|
---|
186 | #return most recent file if there are several ones matching the pattern
|
---|
187 | asFiles = [s for s in os.listdir(sTestBuildDir)
|
---|
188 | if os.path.isfile(os.path.join(sTestBuildDir, s))];
|
---|
189 | asFiles = (s for s in asFiles
|
---|
190 | if oRegExp.match(os.path.basename(s))
|
---|
191 | and os.path.exists(sTestBuildDir + '/' + s));
|
---|
192 | asFiles = sorted(asFiles, reverse = True,
|
---|
193 | key = lambda s, sTstBuildDir = sTestBuildDir: os.path.getmtime(os.path.join(sTstBuildDir, s)));
|
---|
194 | if asFiles:
|
---|
195 | return sTestBuildDir + '/' + asFiles[0];
|
---|
196 | except:
|
---|
197 | pass;
|
---|
198 |
|
---|
199 | reporter.error('Failed to find a file matching "%s" in %s.' % (sRegExp, ','.join(asTestBuildDirs)));
|
---|
200 | return None;
|
---|
201 |
|
---|
202 | def _createAutostartCfg(self, sDefaultPolicy = 'allow', asUserAllow = (), asUserDeny = ()):
|
---|
203 | """
|
---|
204 | Creates a autostart config for VirtualBox
|
---|
205 | """
|
---|
206 |
|
---|
207 | sVBoxCfg = 'default_policy=' + sDefaultPolicy + '\n';
|
---|
208 |
|
---|
209 | for sUserAllow in asUserAllow:
|
---|
210 | sVBoxCfg = sVBoxCfg + sUserAllow + ' = {\n allow = true\n }\n';
|
---|
211 |
|
---|
212 | for sUserDeny in asUserDeny:
|
---|
213 | sVBoxCfg = sVBoxCfg + sUserDeny + ' = {\n allow = false\n }\n';
|
---|
214 |
|
---|
215 | return sVBoxCfg;
|
---|
216 |
|
---|
217 | def createSession(self, oSession, sName, sUser, sPassword, cMsTimeout = 10 * 1000, fIsError = True):
|
---|
218 | """
|
---|
219 | Creates (opens) a guest session.
|
---|
220 | Returns (True, IGuestSession) on success or (False, None) on failure.
|
---|
221 | """
|
---|
222 | oGuest = oSession.o.console.guest;
|
---|
223 | if sName is None:
|
---|
224 | sName = "<untitled>";
|
---|
225 |
|
---|
226 | reporter.log('Creating session "%s" ...' % (sName,));
|
---|
227 | try:
|
---|
228 | oGuestSession = oGuest.createSession(sUser, sPassword, '', sName);
|
---|
229 | except:
|
---|
230 | # Just log, don't assume an error here (will be done in the main loop then).
|
---|
231 | reporter.maybeErrXcpt(fIsError, 'Creating a guest session "%s" failed; sUser="%s", pw="%s"'
|
---|
232 | % (sName, sUser, sPassword));
|
---|
233 | return (False, None);
|
---|
234 |
|
---|
235 | reporter.log('Waiting for session "%s" to start within %dms...' % (sName, cMsTimeout));
|
---|
236 | aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start, ];
|
---|
237 | try:
|
---|
238 | waitResult = oGuestSession.waitForArray(aeWaitFor, cMsTimeout);
|
---|
239 |
|
---|
240 | #
|
---|
241 | # Be nice to Guest Additions < 4.3: They don't support session handling and
|
---|
242 | # therefore return WaitFlagNotSupported.
|
---|
243 | #
|
---|
244 | if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported):
|
---|
245 | # Just log, don't assume an error here (will be done in the main loop then).
|
---|
246 | reporter.maybeErr(fIsError, 'Session did not start successfully, returned wait result: %d' % (waitResult,));
|
---|
247 | return (False, None);
|
---|
248 | reporter.log('Session "%s" successfully started' % (sName,));
|
---|
249 | except:
|
---|
250 | # Just log, don't assume an error here (will be done in the main loop then).
|
---|
251 | reporter.maybeErrXcpt(fIsError, 'Waiting for guest session "%s" (usr=%s;pw=%s) to start failed:'
|
---|
252 | % (sName, sUser, sPassword,));
|
---|
253 | return (False, None);
|
---|
254 | return (True, oGuestSession);
|
---|
255 |
|
---|
256 | def closeSession(self, oGuestSession, fIsError = True):
|
---|
257 | """
|
---|
258 | Closes the guest session.
|
---|
259 | """
|
---|
260 | if oGuestSession is not None:
|
---|
261 | try:
|
---|
262 | sName = oGuestSession.name;
|
---|
263 | except:
|
---|
264 | return reporter.errorXcpt();
|
---|
265 |
|
---|
266 | reporter.log('Closing session "%s" ...' % (sName,));
|
---|
267 | try:
|
---|
268 | oGuestSession.close();
|
---|
269 | oGuestSession = None;
|
---|
270 | except:
|
---|
271 | # Just log, don't assume an error here (will be done in the main loop then).
|
---|
272 | reporter.maybeErrXcpt(fIsError, 'Closing guest session "%s" failed:' % (sName,));
|
---|
273 | return False;
|
---|
274 | return True;
|
---|
275 |
|
---|
276 | def guestProcessExecute(self, oGuestSession, sTestName, cMsTimeout, sExecName, asArgs = (),
|
---|
277 | fGetStdOut = True, fIsError = True):
|
---|
278 | """
|
---|
279 | Helper function to execute a program on a guest, specified in the current test.
|
---|
280 | Returns (True, ProcessStatus, ProcessExitCode, ProcessStdOutBuffer) on success or (False, 0, 0, None) on failure.
|
---|
281 | """
|
---|
282 | _ = sTestName;
|
---|
283 | fRc = True; # Be optimistic.
|
---|
284 |
|
---|
285 | reporter.log2('Using session user=%s, name=%s, timeout=%d'
|
---|
286 | % (oGuestSession.user, oGuestSession.name, oGuestSession.timeout,));
|
---|
287 |
|
---|
288 | #
|
---|
289 | # Start the process:
|
---|
290 | #
|
---|
291 | reporter.log2('Executing sCmd=%s, timeoutMS=%d, asArgs=%s'
|
---|
292 | % (sExecName, cMsTimeout, asArgs, ));
|
---|
293 | fTaskFlags = [];
|
---|
294 | if fGetStdOut:
|
---|
295 | fTaskFlags = [vboxcon.ProcessCreateFlag_WaitForStdOut,
|
---|
296 | vboxcon.ProcessCreateFlag_WaitForStdErr];
|
---|
297 | try:
|
---|
298 | oProcess = oGuestSession.processCreate(sExecName,
|
---|
299 | asArgs if self.fpApiVer >= 5.0 else asArgs[1:],
|
---|
300 | [], fTaskFlags, cMsTimeout);
|
---|
301 | except:
|
---|
302 | reporter.maybeErrXcpt(fIsError, 'asArgs=%s' % (asArgs,));
|
---|
303 | return (False, 0, 0, None);
|
---|
304 | if oProcess is None:
|
---|
305 | return (reporter.error('oProcess is None! (%s)' % (asArgs,)), 0, 0, None);
|
---|
306 |
|
---|
307 | #time.sleep(5); # try this if you want to see races here.
|
---|
308 |
|
---|
309 | # Wait for the process to start properly:
|
---|
310 | reporter.log2('Process start requested, waiting for start (%dms) ...' % (cMsTimeout,));
|
---|
311 | iPid = -1;
|
---|
312 | aeWaitFor = [ vboxcon.ProcessWaitForFlag_Start, ];
|
---|
313 | aBuf = None;
|
---|
314 | try:
|
---|
315 | eWaitResult = oProcess.waitForArray(aeWaitFor, cMsTimeout);
|
---|
316 | except:
|
---|
317 | reporter.maybeErrXcpt(fIsError, 'waitforArray failed for asArgs=%s' % (asArgs,));
|
---|
318 | fRc = False;
|
---|
319 | else:
|
---|
320 | try:
|
---|
321 | eStatus = oProcess.status;
|
---|
322 | iPid = oProcess.PID;
|
---|
323 | except:
|
---|
324 | fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,));
|
---|
325 | else:
|
---|
326 | reporter.log2('Wait result returned: %d, current process status is: %d' % (eWaitResult, eStatus,));
|
---|
327 |
|
---|
328 | #
|
---|
329 | # Wait for the process to run to completion if necessary.
|
---|
330 | #
|
---|
331 | # Note! The above eWaitResult return value can be ignored as it will
|
---|
332 | # (mostly) reflect the process status anyway.
|
---|
333 | #
|
---|
334 | if eStatus == vboxcon.ProcessStatus_Started:
|
---|
335 |
|
---|
336 | # What to wait for:
|
---|
337 | aeWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate,
|
---|
338 | vboxcon.ProcessWaitForFlag_StdOut,
|
---|
339 | vboxcon.ProcessWaitForFlag_StdErr];
|
---|
340 |
|
---|
341 | reporter.log2('Process (PID %d) started, waiting for termination (%dms), aeWaitFor=%s ...'
|
---|
342 | % (iPid, cMsTimeout, aeWaitFor));
|
---|
343 | acbFdOut = [0,0,0];
|
---|
344 | while True:
|
---|
345 | try:
|
---|
346 | eWaitResult = oProcess.waitForArray(aeWaitFor, cMsTimeout);
|
---|
347 | except KeyboardInterrupt: # Not sure how helpful this is, but whatever.
|
---|
348 | reporter.error('Process (PID %d) execution interrupted' % (iPid,));
|
---|
349 | try: oProcess.close();
|
---|
350 | except: pass;
|
---|
351 | break;
|
---|
352 | except:
|
---|
353 | fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,));
|
---|
354 | break;
|
---|
355 | reporter.log2('Wait returned: %d' % (eWaitResult,));
|
---|
356 |
|
---|
357 | # Process output:
|
---|
358 | for eFdResult, iFd, sFdNm in [ (vboxcon.ProcessWaitResult_StdOut, 1, 'stdout'),
|
---|
359 | (vboxcon.ProcessWaitResult_StdErr, 2, 'stderr'), ]:
|
---|
360 | if eWaitResult in (eFdResult, vboxcon.ProcessWaitResult_WaitFlagNotSupported):
|
---|
361 | reporter.log2('Reading %s ...' % (sFdNm,));
|
---|
362 | try:
|
---|
363 | abBuf = oProcess.Read(1, 64 * 1024, cMsTimeout);
|
---|
364 | except KeyboardInterrupt: # Not sure how helpful this is, but whatever.
|
---|
365 | reporter.error('Process (PID %d) execution interrupted' % (iPid,));
|
---|
366 | try: oProcess.close();
|
---|
367 | except: pass;
|
---|
368 | except:
|
---|
369 | pass; ## @todo test for timeouts and fail on anything else!
|
---|
370 | else:
|
---|
371 | if abBuf:
|
---|
372 | reporter.log2('Process (PID %d) got %d bytes of %s data' % (iPid, len(abBuf), sFdNm,));
|
---|
373 | acbFdOut[iFd] += len(abBuf);
|
---|
374 | ## @todo Figure out how to uniform + append!
|
---|
375 | if aBuf:
|
---|
376 | aBuf += str(abBuf);
|
---|
377 | else:
|
---|
378 | aBuf = str(abBuf);
|
---|
379 |
|
---|
380 | ## Process input (todo):
|
---|
381 | #if eWaitResult in (vboxcon.ProcessWaitResult_StdIn, vboxcon.ProcessWaitResult_WaitFlagNotSupported):
|
---|
382 | # reporter.log2('Process (PID %d) needs stdin data' % (iPid,));
|
---|
383 |
|
---|
384 | # Termination or error?
|
---|
385 | if eWaitResult in (vboxcon.ProcessWaitResult_Terminate,
|
---|
386 | vboxcon.ProcessWaitResult_Error,
|
---|
387 | vboxcon.ProcessWaitResult_Timeout,):
|
---|
388 | try: eStatus = oProcess.status;
|
---|
389 | except: fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,));
|
---|
390 | reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d'
|
---|
391 | % (iPid, eWaitResult, eStatus,));
|
---|
392 | break;
|
---|
393 |
|
---|
394 | # End of the wait loop.
|
---|
395 | _, cbStdOut, cbStdErr = acbFdOut;
|
---|
396 |
|
---|
397 | try: eStatus = oProcess.status;
|
---|
398 | except: fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,));
|
---|
399 | reporter.log2('Final process status (PID %d) is: %d' % (iPid, eStatus));
|
---|
400 | reporter.log2('Process (PID %d) %d stdout, %d stderr' % (iPid, cbStdOut, cbStdErr));
|
---|
401 |
|
---|
402 | #
|
---|
403 | # Get the final status and exit code of the process.
|
---|
404 | #
|
---|
405 | try:
|
---|
406 | uExitStatus = oProcess.status;
|
---|
407 | iExitCode = oProcess.exitCode;
|
---|
408 | except:
|
---|
409 | fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,));
|
---|
410 | reporter.log2('Process (PID %d) has exit code: %d; status: %d ' % (iPid, iExitCode, uExitStatus));
|
---|
411 |
|
---|
412 | return (fRc, uExitStatus, iExitCode, aBuf);
|
---|
413 |
|
---|
414 | def uploadString(self, oGuestSession, sSrcString, sDst):
|
---|
415 | """
|
---|
416 | Upload the string into guest.
|
---|
417 | """
|
---|
418 | fRc = True;
|
---|
419 | try:
|
---|
420 | oFile = oGuestSession.fileOpenEx(sDst, vboxcon.FileAccessMode_ReadWrite, vboxcon.FileOpenAction_CreateOrReplace,
|
---|
421 | vboxcon.FileSharingMode_All, 0, []);
|
---|
422 | except:
|
---|
423 | fRc = reporter.errorXcpt('Upload string failed. Could not create and open the file %s' % sDst);
|
---|
424 | else:
|
---|
425 | try:
|
---|
426 | oFile.write(bytearray(sSrcString), 60*1000);
|
---|
427 | except:
|
---|
428 | fRc = reporter.errorXcpt('Upload string failed. Could not write the string into the file %s' % sDst);
|
---|
429 | try:
|
---|
430 | oFile.close();
|
---|
431 | except:
|
---|
432 | fRc = reporter.errorXcpt('Upload string failed. Could not close the file %s' % sDst);
|
---|
433 |
|
---|
434 | return fRc;
|
---|
435 |
|
---|
436 | def uploadFile(self, oGuestSession, sSrc, sDst):
|
---|
437 | """
|
---|
438 | Upload the string into guest.
|
---|
439 | """
|
---|
440 | fRc = True;
|
---|
441 | try:
|
---|
442 | if self.fpApiVer >= 5.0:
|
---|
443 | oCurProgress = oGuestSession.fileCopyToGuest(sSrc, sDst, [0]);
|
---|
444 | else:
|
---|
445 | oCurProgress = oGuestSession.copyTo(sSrc, sDst, [0]);
|
---|
446 | except:
|
---|
447 | reporter.maybeErrXcpt(True, 'Upload file exception for sSrc="%s":'
|
---|
448 | % (self.sGuestAdditionsIso,));
|
---|
449 | fRc = False;
|
---|
450 | else:
|
---|
451 | if oCurProgress is not None:
|
---|
452 | oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr,
|
---|
453 | self.oTestDriver, "uploadFile");
|
---|
454 | oWrapperProgress.wait();
|
---|
455 | if not oWrapperProgress.isSuccess():
|
---|
456 | oWrapperProgress.logResult(fIgnoreErrors = False);
|
---|
457 | fRc = False;
|
---|
458 | else:
|
---|
459 | fRc = reporter.error('No progress object returned');
|
---|
460 |
|
---|
461 | return fRc;
|
---|
462 |
|
---|
463 | def downloadFile(self, oGuestSession, sSrc, sDst, fIgnoreErrors = False):
|
---|
464 | """
|
---|
465 | Upload the string into guest.
|
---|
466 | """
|
---|
467 | fRc = True;
|
---|
468 | try:
|
---|
469 | if self.fpApiVer >= 5.0:
|
---|
470 | oCurProgress = oGuestSession.fileCopyFromGuest(sSrc, sDst, [0]);
|
---|
471 | else:
|
---|
472 | oCurProgress = oGuestSession.copyFrom(sSrc, sDst, [0]);
|
---|
473 | except:
|
---|
474 | if not fIgnoreErrors:
|
---|
475 | reporter.errorXcpt('Download file exception for sSrc="%s":' % (self.sGuestAdditionsIso,));
|
---|
476 | else:
|
---|
477 | reporter.log('warning: Download file exception for sSrc="%s":' % (self.sGuestAdditionsIso,));
|
---|
478 | fRc = False;
|
---|
479 | else:
|
---|
480 | if oCurProgress is not None:
|
---|
481 | oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr,
|
---|
482 | self.oTestDriver, "downloadFile");
|
---|
483 | oWrapperProgress.wait();
|
---|
484 | if not oWrapperProgress.isSuccess():
|
---|
485 | oWrapperProgress.logResult(fIgnoreErrors);
|
---|
486 | fRc = False;
|
---|
487 | else:
|
---|
488 | if not fIgnoreErrors:
|
---|
489 | reporter.error('No progress object returned');
|
---|
490 | else:
|
---|
491 | reporter.log('warning: No progress object returned');
|
---|
492 | fRc = False;
|
---|
493 |
|
---|
494 | return fRc;
|
---|
495 |
|
---|
496 | def downloadFiles(self, oGuestSession, asFiles, fIgnoreErrors = False):
|
---|
497 | """
|
---|
498 | Convenience function to get files from the guest and stores it
|
---|
499 | into the scratch directory for later (manual) review.
|
---|
500 |
|
---|
501 | Returns True on success.
|
---|
502 |
|
---|
503 | Returns False on failure, logged.
|
---|
504 | """
|
---|
505 | fRc = True;
|
---|
506 | for sGstFile in asFiles:
|
---|
507 | sTmpFile = os.path.join(self.oTestDriver.sScratchPath, 'tmp-' + os.path.basename(sGstFile));
|
---|
508 | reporter.log2('Downloading file "%s" to "%s" ...' % (sGstFile, sTmpFile));
|
---|
509 | # First try to remove (unlink) an existing temporary file, as we don't truncate the file.
|
---|
510 | try: os.unlink(sTmpFile);
|
---|
511 | except: pass;
|
---|
512 | ## @todo Check for already existing files on the host and create a new
|
---|
513 | # name for the current file to download.
|
---|
514 | fRc = self.downloadFile(oGuestSession, sGstFile, sTmpFile, fIgnoreErrors);
|
---|
515 | if fRc:
|
---|
516 | reporter.addLogFile(sTmpFile, 'misc/other', 'guest - ' + sGstFile);
|
---|
517 | else:
|
---|
518 | if fIgnoreErrors is not True:
|
---|
519 | reporter.error('error downloading file "%s" to "%s"' % (sGstFile, sTmpFile));
|
---|
520 | return fRc;
|
---|
521 | reporter.log('warning: file "%s" was not downloaded, ignoring.' % (sGstFile,));
|
---|
522 | return True;
|
---|
523 |
|
---|
524 |
|
---|
525 | class tdAutostartOsLinux(tdAutostartOs):
|
---|
526 | """
|
---|
527 | Autostart support methods for Linux guests.
|
---|
528 | """
|
---|
529 |
|
---|
530 | def __init__(self, oTestDriver, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):
|
---|
531 | tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
|
---|
532 | self.sTestBuild = self._findFile('^VirtualBox-.*\\.run$', asTestBuildDirs);
|
---|
533 | if not self.sTestBuild:
|
---|
534 | raise base.GenError("VirtualBox install package not found");
|
---|
535 |
|
---|
536 | def waitVMisReady(self, oSession):
|
---|
537 | """
|
---|
538 | Waits the VM is ready after start or reboot.
|
---|
539 | Returns result (true or false) and guest session obtained
|
---|
540 | """
|
---|
541 | # Give the VM a time to reboot
|
---|
542 | self.oTestDriver.sleep(30);
|
---|
543 |
|
---|
544 | # Waiting the VM is ready.
|
---|
545 | # To do it, one will try to open the guest session and start the guest process in loop
|
---|
546 |
|
---|
547 | cAttempt = 0;
|
---|
548 | oGuestSession = None;
|
---|
549 | fRc = False;
|
---|
550 | while cAttempt < 30:
|
---|
551 | fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
|
---|
552 | 'vbox', 'password', 10 * 1000, False);
|
---|
553 | if fRc:
|
---|
554 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process',
|
---|
555 | 30 * 1000, '/sbin/ifconfig',
|
---|
556 | ['ifconfig',],
|
---|
557 | False, False);
|
---|
558 | if fRc:
|
---|
559 | break;
|
---|
560 |
|
---|
561 | self.closeSession(oGuestSession, False);
|
---|
562 |
|
---|
563 | self.oTestDriver.sleep(10);
|
---|
564 | cAttempt += 1;
|
---|
565 |
|
---|
566 | return (fRc, oGuestSession);
|
---|
567 |
|
---|
568 | def rebootVMAndCheckReady(self, oSession, oGuestSession):
|
---|
569 | """
|
---|
570 | Reboot the VM and wait the VM is ready.
|
---|
571 | Returns result and guest session obtained after reboot
|
---|
572 | """
|
---|
573 | reporter.testStart('Reboot VM and wait for readiness');
|
---|
574 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Reboot the VM',
|
---|
575 | 30 * 1000, '/usr/bin/sudo',
|
---|
576 | ['sudo', 'reboot'],
|
---|
577 | False, True);
|
---|
578 | if not fRc:
|
---|
579 | reporter.error('Calling the reboot utility failed');
|
---|
580 | fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
|
---|
581 | if fRc:
|
---|
582 | (fRc, oGuestSession) = self.waitVMisReady(oSession);
|
---|
583 |
|
---|
584 | if not fRc:
|
---|
585 | reporter.error('VM is not ready after reboot');
|
---|
586 | reporter.testDone();
|
---|
587 | return (fRc, oGuestSession);
|
---|
588 |
|
---|
589 | def powerDownVM(self, oGuestSession):
|
---|
590 | """
|
---|
591 | Power down the VM by calling guest process without wating
|
---|
592 | the VM is really powered off. Also, closes the guest session.
|
---|
593 | It helps the terminateBySession to stop the VM without aborting.
|
---|
594 | """
|
---|
595 |
|
---|
596 | if oGuestSession is None:
|
---|
597 | return False;
|
---|
598 |
|
---|
599 | reporter.testStart('Power down the VM');
|
---|
600 |
|
---|
601 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Power down the VM',
|
---|
602 | 30 * 1000, '/usr/bin/sudo',
|
---|
603 | ['sudo', 'poweroff'],
|
---|
604 | False, True);
|
---|
605 | if not fRc:
|
---|
606 | reporter.error('Calling the poweroff utility failed');
|
---|
607 | fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
|
---|
608 |
|
---|
609 | if not fRc:
|
---|
610 | reporter.error('Power down the VM failed');
|
---|
611 | reporter.testDone();
|
---|
612 | return fRc;
|
---|
613 |
|
---|
614 | def installAdditions(self, oSession, oGuestSession, oVM):
|
---|
615 | """
|
---|
616 | Install guest additions in the guest.
|
---|
617 | """
|
---|
618 | reporter.testStart('Install Guest Additions');
|
---|
619 |
|
---|
620 | fRc = False;
|
---|
621 | # Install Kernel headers, which are required for actually installing the Linux Additions.
|
---|
622 | if oVM.OSTypeId.startswith('Debian') \
|
---|
623 | or oVM.OSTypeId.startswith('Ubuntu'):
|
---|
624 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers',
|
---|
625 | 5 * 60 *1000, '/usr/bin/apt-get',
|
---|
626 | ['/usr/bin/apt-get', 'install', '-y',
|
---|
627 | 'linux-headers-generic'],
|
---|
628 | False, True);
|
---|
629 | if not fRc:
|
---|
630 | reporter.error('Error installing Kernel headers');
|
---|
631 | else:
|
---|
632 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Guest Additions depdendencies',
|
---|
633 | 5 * 60 *1000, '/usr/bin/apt-get',
|
---|
634 | ['/usr/bin/apt-get', 'install', '-y', 'build-essential',
|
---|
635 | 'perl'], False, True);
|
---|
636 | if not fRc:
|
---|
637 | reporter.error('Error installing additional installer dependencies');
|
---|
638 |
|
---|
639 | elif oVM.OSTypeId.startswith('OL') \
|
---|
640 | or oVM.OSTypeId.startswith('Oracle') \
|
---|
641 | or oVM.OSTypeId.startswith('RHEL') \
|
---|
642 | or oVM.OSTypeId.startswith('Redhat') \
|
---|
643 | or oVM.OSTypeId.startswith('Cent'):
|
---|
644 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers',
|
---|
645 | 5 * 60 *1000, '/usr/bin/yum',
|
---|
646 | ['/usr/bin/yum', '-y', 'install', 'kernel-headers'],
|
---|
647 | False, True);
|
---|
648 | if not fRc:
|
---|
649 | reporter.error('Error installing Kernel headers');
|
---|
650 | else:
|
---|
651 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Guest Additions depdendencies',
|
---|
652 | 5 * 60 *1000, '/usr/bin/yum',
|
---|
653 | ['/usr/bin/yum', '-y', 'install', 'make', 'automake', 'gcc',
|
---|
654 | 'kernel-devel', 'dkms', 'bzip2', 'perl'], False, True);
|
---|
655 | if not fRc:
|
---|
656 | reporter.error('Error installing additional installer dependencies');
|
---|
657 |
|
---|
658 | else:
|
---|
659 | reporter.error('Installing Linux Additions for the "%s" is not supported yet' % oVM.OSTypeId);
|
---|
660 | fRc = False;
|
---|
661 |
|
---|
662 | if fRc:
|
---|
663 | #
|
---|
664 | # The actual install.
|
---|
665 | # Also tell the installer to produce the appropriate log files.
|
---|
666 | #
|
---|
667 |
|
---|
668 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing guest additions',
|
---|
669 | 10 * 60 *1000, '/usr/bin/sudo',
|
---|
670 | ['/usr/bin/sudo', '/bin/sh',
|
---|
671 | '/media/cdrom/VBoxLinuxAdditions.run'],
|
---|
672 | False, True);
|
---|
673 | if fRc:
|
---|
674 | # Due to the GA updates as separate process the above function returns before
|
---|
675 | # the actual installation finished. So just wait until the GA installed
|
---|
676 | fRc = self.closeSession(oGuestSession);
|
---|
677 | if fRc:
|
---|
678 | (fRc, oGuestSession) = self.waitVMisReady(oSession);
|
---|
679 |
|
---|
680 | # Download log files.
|
---|
681 | # Ignore errors as all files above might not be present for whatever reason.
|
---|
682 | #
|
---|
683 | if fRc:
|
---|
684 | asLogFile = [];
|
---|
685 | asLogFile.append('/var/log/vboxadd-install.log');
|
---|
686 | self.downloadFiles(oGuestSession, asLogFile, fIgnoreErrors = True);
|
---|
687 | else:
|
---|
688 | reporter.error('Installing guest additions failed: Error occured during vbox installer execution')
|
---|
689 |
|
---|
690 | if fRc:
|
---|
691 | (fRc, oGuestSession) = self.rebootVMAndCheckReady(oSession, oGuestSession);
|
---|
692 | if not fRc:
|
---|
693 | reporter.error('Reboot after installing GuestAdditions failed');
|
---|
694 | reporter.testDone();
|
---|
695 | return (fRc, oGuestSession);
|
---|
696 |
|
---|
697 | def installVirtualBox(self, oGuestSession):
|
---|
698 | """
|
---|
699 | Install VirtualBox in the guest.
|
---|
700 | """
|
---|
701 | if self.sTestBuild is None:
|
---|
702 | return False;
|
---|
703 |
|
---|
704 | reporter.testStart('Install Virtualbox into the guest VM');
|
---|
705 |
|
---|
706 | fRc = self.uploadFile(oGuestSession, self.sTestBuild,
|
---|
707 | '/tmp/' + os.path.basename(self.sTestBuild));
|
---|
708 | if not fRc:
|
---|
709 | reporter.error('Upload the vbox installer into guest VM failed');
|
---|
710 | else:
|
---|
711 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession,
|
---|
712 | 'Allowing execution for the vbox installer',
|
---|
713 | 30 * 1000, '/usr/bin/sudo',
|
---|
714 | ['/usr/bin/sudo', '/bin/chmod', '755',
|
---|
715 | '/tmp/' + os.path.basename(self.sTestBuild)],
|
---|
716 | False, True);
|
---|
717 | if not fRc:
|
---|
718 | reporter.error('Allowing execution for the vbox installer failed');
|
---|
719 | if fRc:
|
---|
720 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing VBox',
|
---|
721 | 240 * 1000, '/usr/bin/sudo',
|
---|
722 | ['/usr/bin/sudo',
|
---|
723 | '/tmp/' + os.path.basename(self.sTestBuild),],
|
---|
724 | False, True);
|
---|
725 | if not fRc:
|
---|
726 | reporter.error('Installing VBox failed');
|
---|
727 | reporter.testDone();
|
---|
728 | return fRc;
|
---|
729 |
|
---|
730 | def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow',
|
---|
731 | asUserAllow = (), asUserDeny = ()):
|
---|
732 | """
|
---|
733 | Configures the autostart feature in the guest.
|
---|
734 | """
|
---|
735 | reporter.testStart('Configure autostart');
|
---|
736 | # Create autostart database directory writeable for everyone
|
---|
737 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating autostart database',
|
---|
738 | 30 * 1000, '/usr/bin/sudo',
|
---|
739 | ['/usr/bin/sudo', '/bin/mkdir', '-m', '1777', '/etc/vbox/autostart.d'],
|
---|
740 | False, True);
|
---|
741 | if not fRc:
|
---|
742 | reporter.error('Creating autostart database failed');
|
---|
743 | # Create /etc/default/virtualbox
|
---|
744 | if fRc:
|
---|
745 | sVBoxCfg = 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg\n' \
|
---|
746 | + 'VBOXAUTOSTART_DB=/etc/vbox/autostart.d\n';
|
---|
747 | fRc = self.uploadString(oGuestSession, sVBoxCfg, '/tmp/virtualbox');
|
---|
748 | if not fRc:
|
---|
749 | reporter.error('Upload to /tmp/virtualbox failed');
|
---|
750 | if fRc:
|
---|
751 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Moving to destination',
|
---|
752 | 30 * 1000, '/usr/bin/sudo',
|
---|
753 | ['/usr/bin/sudo', '/bin/mv', '/tmp/virtualbox',
|
---|
754 | '/etc/default/virtualbox'],
|
---|
755 | False, True);
|
---|
756 | if not fRc:
|
---|
757 | reporter.error('Moving the /tmp/virtualbox to destination failed');
|
---|
758 | if fRc:
|
---|
759 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Setting permissions',
|
---|
760 | 30 * 1000, '/usr/bin/sudo',
|
---|
761 | ['/usr/bin/sudo', '/bin/chmod', '644',
|
---|
762 | '/etc/default/virtualbox'],
|
---|
763 | False, True);
|
---|
764 | if not fRc:
|
---|
765 | reporter.error('Setting permissions for the virtualbox failed');
|
---|
766 |
|
---|
767 | if fRc:
|
---|
768 | sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny);
|
---|
769 | fRc = self.uploadString(oGuestSession, sVBoxCfg, '/tmp/autostart.cfg');
|
---|
770 | if not fRc:
|
---|
771 | reporter.error('Upload to /tmp/autostart.cfg failed');
|
---|
772 |
|
---|
773 | if fRc:
|
---|
774 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Moving to destination',
|
---|
775 | 30 * 1000, '/usr/bin/sudo',
|
---|
776 | ['/usr/bin/sudo', '/bin/mv', '/tmp/autostart.cfg',
|
---|
777 | '/etc/vbox/autostart.cfg'],
|
---|
778 | False, True);
|
---|
779 | if not fRc:
|
---|
780 | reporter.error('Moving the /tmp/autostart.cfg to destination failed');
|
---|
781 | if fRc:
|
---|
782 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Setting permissions',
|
---|
783 | 30 * 1000, '/usr/bin/sudo',
|
---|
784 | ['/usr/bin/sudo', '/bin/chmod', '644',
|
---|
785 | '/etc/vbox/autostart.cfg'],
|
---|
786 | False, True);
|
---|
787 | if not fRc:
|
---|
788 | reporter.error('Setting permissions for the autostart.cfg failed');
|
---|
789 | reporter.testDone();
|
---|
790 | return fRc;
|
---|
791 |
|
---|
792 | def createUser(self, oGuestSession, sUser):
|
---|
793 | """
|
---|
794 | Create a new user with the given name
|
---|
795 | """
|
---|
796 | reporter.testStart('Create user %s' % sUser);
|
---|
797 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating new user',
|
---|
798 | 30 * 1000, '/usr/bin/sudo',
|
---|
799 | ['/usr/bin/sudo', '/usr/sbin/useradd', '-m', '-U',
|
---|
800 | sUser], False, True);
|
---|
801 | if not fRc:
|
---|
802 | reporter.error('Create user %s failed' % sUser);
|
---|
803 | reporter.testDone();
|
---|
804 | return fRc;
|
---|
805 |
|
---|
806 | # pylint: enable=too-many-arguments
|
---|
807 |
|
---|
808 | def createTestVM(self, oSession, oGuestSession, sUser, sVmName):
|
---|
809 | """
|
---|
810 | Create a test VM in the guest and enable autostart.
|
---|
811 | Due to the sUser is created whithout password,
|
---|
812 | all calls will be perfomed using 'sudo -u sUser'
|
---|
813 | """
|
---|
814 |
|
---|
815 | _ = oSession;
|
---|
816 |
|
---|
817 | reporter.testStart('Create test VM for user %s' % sUser);
|
---|
818 |
|
---|
819 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Configuring autostart database',
|
---|
820 | 30 * 1000, '/usr/bin/sudo',
|
---|
821 | ['/usr/bin/sudo', '-u', sUser, '-H', '/opt/VirtualBox/VBoxManage',
|
---|
822 | 'setproperty', 'autostartdbpath', '/etc/vbox/autostart.d'],
|
---|
823 | False, True);
|
---|
824 | if not fRc:
|
---|
825 | reporter.error('Configuring autostart database failed');
|
---|
826 | else:
|
---|
827 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Create VM ' + sVmName,
|
---|
828 | 30 * 1000, '/usr/bin/sudo',
|
---|
829 | ['/usr/bin/sudo', '-u', sUser, '-H',
|
---|
830 | '/opt/VirtualBox/VBoxManage', 'createvm',
|
---|
831 | '--name', sVmName, '--register'], False, True);
|
---|
832 | if not fRc:
|
---|
833 | reporter.error('Create VM %s failed' % sVmName);
|
---|
834 | if fRc:
|
---|
835 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Enabling autostart for test VM',
|
---|
836 | 30 * 1000, '/usr/bin/sudo',
|
---|
837 | ['/usr/bin/sudo', '-u', sUser, '-H',
|
---|
838 | '/opt/VirtualBox/VBoxManage', 'modifyvm',
|
---|
839 | sVmName, '--autostart-enabled', 'on'], False, True);
|
---|
840 | if not fRc:
|
---|
841 | reporter.error('Enabling autostart for %s failed' % sVmName);
|
---|
842 | reporter.testDone();
|
---|
843 | return fRc;
|
---|
844 |
|
---|
845 | def checkForRunningVM(self, oSession, oGuestSession, sUser, sVmName):
|
---|
846 | """
|
---|
847 | Check for VM running in the guest after autostart.
|
---|
848 | Due to the sUser is created whithout password,
|
---|
849 | all calls will be perfomed using 'sudo -u sUser'
|
---|
850 | """
|
---|
851 |
|
---|
852 | _ = oSession;
|
---|
853 |
|
---|
854 | reporter.testStart('Check the VM %s is running for user %s' % (sVmName, sUser));
|
---|
855 | (fRc, _, _, aBuf) = self.guestProcessExecute(oGuestSession, 'Check for running VM',
|
---|
856 | 30 * 1000, '/usr/bin/sudo',
|
---|
857 | ['/usr/bin/sudo', '-u', sUser, '-H',
|
---|
858 | '/opt/VirtualBox/VBoxManage',
|
---|
859 | 'list', 'runningvms'], True, True);
|
---|
860 | if not fRc:
|
---|
861 | reporter.error('Checking the VM %s is running for user %s failed' % (sVmName, sUser));
|
---|
862 | else:
|
---|
863 | bufWrapper = VBoxManageStdOutWrapper();
|
---|
864 | bufWrapper.write(aBuf);
|
---|
865 | fRc = bufWrapper.sVmRunning == sVmName;
|
---|
866 |
|
---|
867 | reporter.testDone();
|
---|
868 | return fRc;
|
---|
869 |
|
---|
870 |
|
---|
871 | class tdAutostartOsDarwin(tdAutostartOs):
|
---|
872 | """
|
---|
873 | Autostart support methods for Darwin guests.
|
---|
874 | """
|
---|
875 |
|
---|
876 | def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso):
|
---|
877 | _ = sTestBuildDir;
|
---|
878 | tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
|
---|
879 | raise base.GenError('Testing the autostart functionality for Darwin is not implemented');
|
---|
880 |
|
---|
881 |
|
---|
882 | class tdAutostartOsSolaris(tdAutostartOs):
|
---|
883 | """
|
---|
884 | Autostart support methods for Solaris guests.
|
---|
885 | """
|
---|
886 |
|
---|
887 | def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso):
|
---|
888 | _ = sTestBuildDir;
|
---|
889 | tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
|
---|
890 | raise base.GenError('Testing the autostart functionality for Solaris is not implemented');
|
---|
891 |
|
---|
892 |
|
---|
893 | class tdAutostartOsWin(tdAutostartOs):
|
---|
894 | """
|
---|
895 | Autostart support methods for Windows guests.
|
---|
896 | """
|
---|
897 |
|
---|
898 | def __init__(self, oTestDriver, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):
|
---|
899 | tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
|
---|
900 | self.sTestBuild = self._findFile('^VirtualBox-.*\\.(exe|msi)$', asTestBuildDirs);
|
---|
901 | if not self.sTestBuild:
|
---|
902 | raise base.GenError("VirtualBox install package not found");
|
---|
903 | return;
|
---|
904 |
|
---|
905 | def waitVMisReady(self, oSession):
|
---|
906 | """
|
---|
907 | Waits the VM is ready after start or reboot.
|
---|
908 | """
|
---|
909 | # Give the VM a time to reboot
|
---|
910 | self.oTestDriver.sleep(30);
|
---|
911 |
|
---|
912 | # Waiting the VM is ready.
|
---|
913 | # To do it, one will try to open the guest session and start the guest process in loop
|
---|
914 |
|
---|
915 | cAttempt = 0;
|
---|
916 | oGuestSession = None;
|
---|
917 | while cAttempt < 10:
|
---|
918 | fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
|
---|
919 | 'vbox', 'password', 10 * 1000, False);
|
---|
920 | if fRc:
|
---|
921 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process',
|
---|
922 | 30 * 1000, 'C:\\Windows\\System32\\ipconfig.exe',
|
---|
923 | ['C:\\Windows\\System32\\ipconfig.exe',],
|
---|
924 | False, False);
|
---|
925 | if fRc:
|
---|
926 | break;
|
---|
927 |
|
---|
928 | self.closeSession(oGuestSession, False);
|
---|
929 |
|
---|
930 | self.oTestDriver.sleep(10);
|
---|
931 | cAttempt += 1;
|
---|
932 |
|
---|
933 | return (fRc, oGuestSession);
|
---|
934 |
|
---|
935 | def rebootVMAndCheckReady(self, oSession, oGuestSession):
|
---|
936 | """
|
---|
937 | Reboot the VM and wait the VM is ready.
|
---|
938 | """
|
---|
939 | reporter.testStart('Reboot VM and wait for readiness');
|
---|
940 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Reboot the VM',
|
---|
941 | 30 * 1000, 'C:\\Windows\\System32\\shutdown.exe',
|
---|
942 | ['C:\\Windows\\System32\\shutdown.exe', '/f',
|
---|
943 | '/r', '/t', '0'],
|
---|
944 | False, True);
|
---|
945 | if not fRc:
|
---|
946 | reporter.error('Calling the shutdown utility failed');
|
---|
947 | fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
|
---|
948 | if fRc:
|
---|
949 | (fRc, oGuestSession) = self.waitVMisReady(oSession);
|
---|
950 | if not fRc:
|
---|
951 | reporter.error('VM is not ready after reboot');
|
---|
952 | reporter.testDone();
|
---|
953 | return (fRc, oGuestSession);
|
---|
954 |
|
---|
955 | def powerDownVM(self, oGuestSession):
|
---|
956 | """
|
---|
957 | Power down the VM by calling guest process without wating
|
---|
958 | the VM is really powered off. Also, closes the guest session.
|
---|
959 | It helps the terminateBySession to stop the VM without aborting.
|
---|
960 | """
|
---|
961 |
|
---|
962 | if oGuestSession is None:
|
---|
963 | return False;
|
---|
964 |
|
---|
965 | reporter.testStart('Power down the VM');
|
---|
966 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Power down the VM',
|
---|
967 | 30 * 1000, 'C:\\Windows\\System32\\shutdown.exe',
|
---|
968 | ['C:\\Windows\\System32\\shutdown.exe', '/f',
|
---|
969 | '/s', '/t', '0'],
|
---|
970 | False, True);
|
---|
971 | if not fRc:
|
---|
972 | reporter.error('Calling the shutdown utility failed');
|
---|
973 | fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
|
---|
974 | if not fRc:
|
---|
975 | reporter.error('Power down the VM failed');
|
---|
976 | reporter.testDone();
|
---|
977 | return fRc;
|
---|
978 |
|
---|
979 | def installAdditions(self, oSession, oGuestSession, oVM):
|
---|
980 | """
|
---|
981 | Installs the Windows guest additions using the test execution service.
|
---|
982 | """
|
---|
983 | #
|
---|
984 | # Delete relevant log files.
|
---|
985 | #
|
---|
986 | # Note! On some guests the files in question still can be locked by the OS, so ignore
|
---|
987 | # deletion errors from the guest side (e.g. sharing violations) and just continue.
|
---|
988 | #
|
---|
989 | reporter.testStart('Install Guest Additions');
|
---|
990 | asLogFiles = [];
|
---|
991 | fHaveSetupApiDevLog = False;
|
---|
992 | if oVM.OSTypeId in ('WindowsNT4',):
|
---|
993 | sWinDir = 'C:/WinNT/';
|
---|
994 | else:
|
---|
995 | sWinDir = 'C:/Windows/';
|
---|
996 | asLogFiles = [sWinDir + 'setupapi.log', sWinDir + 'setupact.log', sWinDir + 'setuperr.log'];
|
---|
997 |
|
---|
998 | # Apply The SetupAPI logging level so that we also get the (most verbose) setupapi.dev.log file.
|
---|
999 | ## @todo !!! HACK ALERT !!! Add the value directly into the testing source image. Later.
|
---|
1000 | (fHaveSetupApiDevLog, _, _, _) = \
|
---|
1001 | self.guestProcessExecute(oGuestSession, 'Enabling setupapi.dev.log',
|
---|
1002 | 60 * 1000, 'c:\\Windows\\System32\\reg.exe',
|
---|
1003 | ['c:\\Windows\\System32\\reg.exe', 'add',
|
---|
1004 | '"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Setup"',
|
---|
1005 | '/v', 'LogLevel', '/t', 'REG_DWORD', '/d', '0xFF'],
|
---|
1006 | False, True);
|
---|
1007 | for sFile in asLogFiles:
|
---|
1008 | try: oGuestSession.fsObjRemove(sFile);
|
---|
1009 | except: pass;
|
---|
1010 |
|
---|
1011 | fRc = self.closeSession(oGuestSession, True); # pychecker hack.
|
---|
1012 |
|
---|
1013 | try:
|
---|
1014 | oCurProgress = oSession.o.console.guest.updateGuestAdditions(self.sGuestAdditionsIso, None, None);
|
---|
1015 | except:
|
---|
1016 | reporter.maybeErrXcpt(True, 'Updating Guest Additions exception for sSrc="%s":'
|
---|
1017 | % (self.sGuestAdditionsIso,));
|
---|
1018 | fRc = False;
|
---|
1019 | else:
|
---|
1020 | if oCurProgress is not None:
|
---|
1021 | oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr,
|
---|
1022 | self.oTestDriver, "installAdditions");
|
---|
1023 | oWrapperProgress.wait(cMsTimeout = 10 * 60 * 1000);
|
---|
1024 | if not oWrapperProgress.isSuccess():
|
---|
1025 | oWrapperProgress.logResult(fIgnoreErrors = False);
|
---|
1026 | fRc = False;
|
---|
1027 | else:
|
---|
1028 | fRc = reporter.error('No progress object returned');
|
---|
1029 |
|
---|
1030 | if fRc:
|
---|
1031 | fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
|
---|
1032 | 'vbox', 'password', 10 * 1000, True);
|
---|
1033 | if fRc is True:
|
---|
1034 | (fRc, oGuestSession) = self.rebootVMAndCheckReady(oSession, oGuestSession);
|
---|
1035 | if fRc is True:
|
---|
1036 | # Add the Windows Guest Additions installer files to the files we want to download
|
---|
1037 | # from the guest.
|
---|
1038 | sGuestAddsDir = 'C:/Program Files/Oracle/VirtualBox Guest Additions/';
|
---|
1039 | asLogFiles.append(sGuestAddsDir + 'install.log');
|
---|
1040 | # Note: There won't be a install_ui.log because of the silent installation.
|
---|
1041 | asLogFiles.append(sGuestAddsDir + 'install_drivers.log');
|
---|
1042 | asLogFiles.append('C:/Windows/setupapi.log');
|
---|
1043 |
|
---|
1044 | # Note: setupapi.dev.log only is available since Windows 2000.
|
---|
1045 | if fHaveSetupApiDevLog:
|
---|
1046 | asLogFiles.append('C:/Windows/setupapi.dev.log');
|
---|
1047 |
|
---|
1048 | #
|
---|
1049 | # Download log files.
|
---|
1050 | # Ignore errors as all files above might not be present (or in different locations)
|
---|
1051 | # on different Windows guests.
|
---|
1052 | #
|
---|
1053 | self.downloadFiles(oGuestSession, asLogFiles, fIgnoreErrors = True);
|
---|
1054 | else:
|
---|
1055 | reporter.error('Reboot after installing GuestAdditions failed');
|
---|
1056 | else:
|
---|
1057 | reporter.error('Create session for user vbox after GA updating failed');
|
---|
1058 | reporter.testDone();
|
---|
1059 | return (fRc, oGuestSession);
|
---|
1060 |
|
---|
1061 | def installVirtualBox(self, oGuestSession):
|
---|
1062 | """
|
---|
1063 | Install VirtualBox in the guest.
|
---|
1064 | """
|
---|
1065 |
|
---|
1066 | if self.sTestBuild is None:
|
---|
1067 | return False;
|
---|
1068 | reporter.testStart('Install Virtualbox into the guest VM');
|
---|
1069 | # Used windows image already contains the C:\Temp
|
---|
1070 | fRc = self.uploadFile(oGuestSession, self.sTestBuild,
|
---|
1071 | 'C:\\Temp\\' + os.path.basename(self.sTestBuild));
|
---|
1072 | if not fRc:
|
---|
1073 | reporter.error('Upload the installing into guest VM failed');
|
---|
1074 | else:
|
---|
1075 | if self.sTestBuild.endswith('.msi'):
|
---|
1076 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing VBox',
|
---|
1077 | 240 * 1000, 'C:\\Windows\\System32\\msiexec.exe',
|
---|
1078 | ['msiexec', '/quiet', '/i',
|
---|
1079 | 'C:\\Temp\\' + os.path.basename(self.sTestBuild)],
|
---|
1080 | False, True);
|
---|
1081 | if not fRc:
|
---|
1082 | reporter.error('Installing the VBox from msi installer failed');
|
---|
1083 | else:
|
---|
1084 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing VBox',
|
---|
1085 | 240 * 1000, 'C:\\Temp\\' + os.path.basename(self.sTestBuild),
|
---|
1086 | ['C:\\Temp\\' + os.path.basename(self.sTestBuild), '--silent'],
|
---|
1087 | False, True);
|
---|
1088 | if not fRc:
|
---|
1089 | reporter.error('Installing the VBox failed');
|
---|
1090 | reporter.testDone();
|
---|
1091 | return fRc;
|
---|
1092 |
|
---|
1093 | def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow',
|
---|
1094 | asUserAllow = (), asUserDeny = ()):
|
---|
1095 | """
|
---|
1096 | Configures the autostart feature in the guest.
|
---|
1097 | """
|
---|
1098 | reporter.testStart('Configure autostart');
|
---|
1099 | # Create autostart database directory writeable for everyone
|
---|
1100 | (fRc, _, _, _) = \
|
---|
1101 | self.guestProcessExecute(oGuestSession, 'Setting the autostart environment variable',
|
---|
1102 | 30 * 1000, 'C:\\Windows\\System32\\reg.exe',
|
---|
1103 | ['reg', 'add',
|
---|
1104 | 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',
|
---|
1105 | '/v', 'VBOXAUTOSTART_CONFIG', '/d',
|
---|
1106 | 'C:\\ProgramData\\autostart.cfg', '/f'],
|
---|
1107 | False, True);
|
---|
1108 | if not fRc:
|
---|
1109 | reporter.error('Setting the autostart environment variable failed');
|
---|
1110 |
|
---|
1111 | if fRc:
|
---|
1112 | sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny);
|
---|
1113 | fRc = self.uploadString(oGuestSession, sVBoxCfg, 'C:\\ProgramData\\autostart.cfg');
|
---|
1114 | if not fRc:
|
---|
1115 | reporter.error('Upload the autostart.cfg failed');
|
---|
1116 | reporter.testDone();
|
---|
1117 | return fRc;
|
---|
1118 |
|
---|
1119 | def createTestVM(self, oSession, oGuestSession, sUser, sVmName):
|
---|
1120 | """
|
---|
1121 | Create a test VM in the guest and enable autostart.
|
---|
1122 | """
|
---|
1123 | _ = oGuestSession;
|
---|
1124 |
|
---|
1125 | reporter.testStart('Create test VM for user %s' % sUser);
|
---|
1126 |
|
---|
1127 | fRc, oGuestSession = self.createSession(oSession, 'Session for user: %s' % (sUser,),
|
---|
1128 | sUser, 'password', 10 * 1000, True);
|
---|
1129 | if not fRc:
|
---|
1130 | reporter.error('Create session for user %s failed' % sUser);
|
---|
1131 | else:
|
---|
1132 | (fRc, _, _, _) = \
|
---|
1133 | self.guestProcessExecute(oGuestSession, 'Create VM ' + sVmName,
|
---|
1134 | 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
|
---|
1135 | ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 'createvm',
|
---|
1136 | '--name', sVmName, '--register'], False, True);
|
---|
1137 | if not fRc:
|
---|
1138 | reporter.error('Create VM %s for user %s failed' % (sVmName, sUser));
|
---|
1139 | else:
|
---|
1140 | (fRc, _, _, _) = \
|
---|
1141 | self.guestProcessExecute(oGuestSession, 'Enabling autostart for test VM',
|
---|
1142 | 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
|
---|
1143 | ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
|
---|
1144 | 'modifyvm', sVmName, '--autostart-enabled', 'on'], False, True);
|
---|
1145 | if not fRc:
|
---|
1146 | reporter.error('Enabling autostart for VM %s for user %s failed' % (sVmName, sUser));
|
---|
1147 | if fRc:
|
---|
1148 | fRc = self.uploadString(oGuestSession, 'password', 'C:\\ProgramData\\password.cfg');
|
---|
1149 | if not fRc:
|
---|
1150 | reporter.error('Upload the password.cfg failed');
|
---|
1151 | if fRc:
|
---|
1152 | (fRc, _, _, _) = \
|
---|
1153 | self.guestProcessExecute(oGuestSession, 'Install autostart service for the user',
|
---|
1154 | 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxAutostartSvc.exe',
|
---|
1155 | ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxAutostartSvc.exe',
|
---|
1156 | 'install', '--user=' + sUser,
|
---|
1157 | '--password-file=C:\\ProgramData\\password.cfg'],
|
---|
1158 | False, True);
|
---|
1159 | if not fRc:
|
---|
1160 | reporter.error('Install autostart service for user %s failed' % sUser);
|
---|
1161 | fRc1 = self.closeSession(oGuestSession, True);
|
---|
1162 | if not fRc1:
|
---|
1163 | reporter.error('Closing session for user %s failed' % sUser);
|
---|
1164 | fRc = fRc1 and fRc and True; # pychecker hack.
|
---|
1165 | reporter.testDone();
|
---|
1166 | return fRc;
|
---|
1167 |
|
---|
1168 | def checkForRunningVM(self, oSession, oGuestSession, sUser, sVmName):
|
---|
1169 | """
|
---|
1170 | Check for VM running in the guest after autostart.
|
---|
1171 | """
|
---|
1172 |
|
---|
1173 | _ = oGuestSession;
|
---|
1174 |
|
---|
1175 | reporter.testStart('Check the VM %s is running for user %s' % (sVmName, sUser));
|
---|
1176 |
|
---|
1177 | fRc, oGuestSession = self.createSession(oSession, 'Session for user: %s' % (sUser,),
|
---|
1178 | sUser, 'password', 10 * 1000, True);
|
---|
1179 | if not fRc:
|
---|
1180 | reporter.error('Create session for user %s failed' % sUser);
|
---|
1181 | else:
|
---|
1182 | (fRc, _, _, aBuf) = self.guestProcessExecute(oGuestSession, 'Check for running VM',
|
---|
1183 | 30 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
|
---|
1184 | ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
|
---|
1185 | 'list', 'runningvms'], True, True);
|
---|
1186 | if not fRc:
|
---|
1187 | reporter.error('Checking the VM %s is running for user %s failed' % (sVmName, sUser));
|
---|
1188 | else:
|
---|
1189 | bufWrapper = VBoxManageStdOutWrapper();
|
---|
1190 | bufWrapper.write(aBuf);
|
---|
1191 | fRc = bufWrapper.sVmRunning == sVmName;
|
---|
1192 |
|
---|
1193 | fRc1 = self.closeSession(oGuestSession, True);
|
---|
1194 | if not fRc1:
|
---|
1195 | reporter.error('Closing session for user %s failed' % sUser);
|
---|
1196 | fRc = fRc1 and fRc and True; # pychecker hack.
|
---|
1197 | reporter.testDone();
|
---|
1198 | return fRc;
|
---|
1199 |
|
---|
1200 | def createUser(self, oGuestSession, sUser):
|
---|
1201 | """
|
---|
1202 | Create a new user with the given name
|
---|
1203 | """
|
---|
1204 | reporter.testStart('Create user %s' % sUser);
|
---|
1205 | # Create user
|
---|
1206 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating user %s to run a VM' % sUser,
|
---|
1207 | 30 * 1000, 'C:\\Windows\\System32\\net.exe',
|
---|
1208 | ['net', 'user', sUser, 'password', '/add' ], False, True);
|
---|
1209 | if not fRc:
|
---|
1210 | reporter.error('Creating user %s to run a VM failed' % sUser);
|
---|
1211 | # Add the user to Administrators group
|
---|
1212 | else:
|
---|
1213 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Adding the user %s to Administrators group' % sUser,
|
---|
1214 | 30 * 1000, 'C:\\Windows\\System32\\net.exe',
|
---|
1215 | ['net', 'localgroup', 'Administrators', sUser, '/add' ], False, True);
|
---|
1216 | if not fRc:
|
---|
1217 | reporter.error('Adding the user %s to Administrators group failed' % sUser);
|
---|
1218 |
|
---|
1219 | #Allow the user to logon as service
|
---|
1220 | if fRc:
|
---|
1221 | sSecPolicyEditor = """
|
---|
1222 | ' SetLogonAsAServiceRight.vbs
|
---|
1223 | ' Sample VBScript to set or grant Logon As A Service Right.
|
---|
1224 | ' Author: http://www.morgantechspace.com/
|
---|
1225 | ' ------------------------------------------------------'
|
---|
1226 |
|
---|
1227 | Dim strUserName,ConfigFileName,OrgStr,RepStr,inputFile,strInputFile,outputFile,obj
|
---|
1228 | strUserName = "%s"
|
---|
1229 | Dim oShell
|
---|
1230 | Set oShell = CreateObject ("WScript.Shell")
|
---|
1231 | oShell.Run "secedit /export /cfg config.inf", 0, true
|
---|
1232 | oShell.Run "secedit /import /cfg config.inf /db database.sdb", 0, true
|
---|
1233 |
|
---|
1234 | ConfigFileName = "config.inf"
|
---|
1235 | OrgStr = "SeServiceLogonRight ="
|
---|
1236 | RepStr = "SeServiceLogonRight = " & strUserName & ","
|
---|
1237 | Set inputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf", 1,1,-1)
|
---|
1238 | strInputFile = inputFile.ReadAll
|
---|
1239 | inputFile.Close
|
---|
1240 | Set inputFile = Nothing
|
---|
1241 |
|
---|
1242 | Set outputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf",2,1,-1)
|
---|
1243 | outputFile.Write (Replace(strInputFile,OrgStr,RepStr))
|
---|
1244 | outputFile.Close
|
---|
1245 | Set outputFile = Nothing
|
---|
1246 |
|
---|
1247 | oShell.Run "secedit /configure /db database.sdb /cfg config.inf",0,true
|
---|
1248 | set oShell= Nothing
|
---|
1249 |
|
---|
1250 | Set obj = CreateObject("Scripting.FileSystemObject")
|
---|
1251 | obj.DeleteFile("config.inf")
|
---|
1252 | obj.DeleteFile("database.sdb")
|
---|
1253 |
|
---|
1254 | WScript.Echo "Logon As A Service Right granted to user '"& strUserName &"'"
|
---|
1255 | """ % sUser;
|
---|
1256 | fRc = self.uploadString(oGuestSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.vbs');
|
---|
1257 | if not fRc:
|
---|
1258 | reporter.error('Upload the adjustsec.vbs failed');
|
---|
1259 | if fRc:
|
---|
1260 | (fRc, _, _, _) = self.guestProcessExecute(oGuestSession,
|
---|
1261 | 'Setting the "Logon as service" policy to the user %s' % sUser,
|
---|
1262 | 30 * 1000, 'C:\\Windows\\System32\\cscript.exe',
|
---|
1263 | ['cscript.exe', 'C:\\Temp\\adjustsec.vbs', '//Nologo'], False, True);
|
---|
1264 | if not fRc:
|
---|
1265 | reporter.error('Setting the "Logon as service" policy to the user %s failed' % sUser);
|
---|
1266 | try:
|
---|
1267 | oGuestSession.fsObjRemove('C:\\Temp\\adjustsec.vbs');
|
---|
1268 | except:
|
---|
1269 | fRc = reporter.errorXcpt('Removing policy script failed');
|
---|
1270 | reporter.testDone();
|
---|
1271 | return fRc;
|
---|
1272 |
|
---|
1273 |
|
---|
1274 | class tdAutostart(vbox.TestDriver): # pylint: disable=too-many-instance-attributes
|
---|
1275 | """
|
---|
1276 | Autostart testcase.
|
---|
1277 | """
|
---|
1278 |
|
---|
1279 | ksOsLinux = 'tst-linux'
|
---|
1280 | ksOsWindows = 'tst-win'
|
---|
1281 | ksOsDarwin = 'tst-darwin'
|
---|
1282 | ksOsSolaris = 'tst-solaris'
|
---|
1283 | ksOsFreeBSD = 'tst-freebsd'
|
---|
1284 |
|
---|
1285 | def __init__(self):
|
---|
1286 | vbox.TestDriver.__init__(self);
|
---|
1287 | self.asRsrcs = None;
|
---|
1288 | self.asTestVMsDef = [self.ksOsWindows, self.ksOsLinux]; #[self.ksOsLinux, self.ksOsWindows];
|
---|
1289 | self.asTestVMs = self.asTestVMsDef;
|
---|
1290 | self.asSkipVMs = [];
|
---|
1291 | self.asTestBuildDirs = None; #'D:/AlexD/TestBox/TestAdditionalFiles';
|
---|
1292 | self.sGuestAdditionsIso = None; #'D:/AlexD/TestBox/TestAdditionalFiles/VBoxGuestAdditions_6.1.2.iso';
|
---|
1293 |
|
---|
1294 | #
|
---|
1295 | # Overridden methods.
|
---|
1296 | #
|
---|
1297 | def showUsage(self):
|
---|
1298 | rc = vbox.TestDriver.showUsage(self);
|
---|
1299 | reporter.log('');
|
---|
1300 | reporter.log('tdAutostart Options:');
|
---|
1301 | reporter.log(' --test-build-dirs <path1[,path2[,...]]>');
|
---|
1302 | reporter.log(' The list of directories with VirtualBox distros. The option is mandatory');
|
---|
1303 | reporter.log(' without any default value. The test raises an exception if the');
|
---|
1304 | reporter.log(' option is not specified. At least, one directory should be pointed.');
|
---|
1305 | reporter.log(' --guest-additions-iso <path/to/iso>');
|
---|
1306 | reporter.log(' The path to fresh VirtualBox Guest Additions iso. The option is');
|
---|
1307 | reporter.log(' mandatory without any default value. The test raises an exception');
|
---|
1308 | reporter.log(' if the option is not specified.');
|
---|
1309 | reporter.log(' --test-vms <vm1[:vm2[:...]]>');
|
---|
1310 | reporter.log(' Test the specified VMs in the given order. Use this to change');
|
---|
1311 | reporter.log(' the execution order or limit the choice of VMs');
|
---|
1312 | reporter.log(' Default: %s (all)' % (':'.join(self.asTestVMsDef)));
|
---|
1313 | reporter.log(' --skip-vms <vm1[:vm2[:...]]>');
|
---|
1314 | reporter.log(' Skip the specified VMs when testing.');
|
---|
1315 | return rc;
|
---|
1316 |
|
---|
1317 | def parseOption(self, asArgs, iArg): # pylint: disable=too-many-branches,too-many-statements
|
---|
1318 | if asArgs[iArg] == '--test-build-dirs':
|
---|
1319 | iArg += 1;
|
---|
1320 | if iArg >= len(asArgs): raise base.InvalidOption('The "--test-build-dirs" takes a paths argument');
|
---|
1321 | self.asTestBuildDirs = asArgs[iArg].split(',');
|
---|
1322 | elif asArgs[iArg] == '--guest-additions-iso':
|
---|
1323 | iArg += 1;
|
---|
1324 | if iArg >= len(asArgs): raise base.InvalidOption('The "--guest-additions-iso" takes a path or url to iso argument');
|
---|
1325 | self.sGuestAdditionsIso = asArgs[iArg];
|
---|
1326 | elif asArgs[iArg] == '--test-vms':
|
---|
1327 | iArg += 1;
|
---|
1328 | if iArg >= len(asArgs): raise base.InvalidOption('The "--test-vms" takes colon separated list');
|
---|
1329 | self.asTestVMs = asArgs[iArg].split(':');
|
---|
1330 | for s in self.asTestVMs:
|
---|
1331 | if s not in self.asTestVMsDef:
|
---|
1332 | raise base.InvalidOption('The "--test-vms" value "%s" is not valid; valid values are: %s' \
|
---|
1333 | % (s, ' '.join(self.asTestVMsDef)));
|
---|
1334 | elif asArgs[iArg] == '--skip-vms':
|
---|
1335 | iArg += 1;
|
---|
1336 | if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-vms" takes colon separated list');
|
---|
1337 | self.asSkipVMs = asArgs[iArg].split(':');
|
---|
1338 | for s in self.asSkipVMs:
|
---|
1339 | if s not in self.asTestVMsDef:
|
---|
1340 | reporter.log('warning: The "--test-vms" value "%s" does not specify any of our test VMs.' % (s));
|
---|
1341 | else:
|
---|
1342 | return vbox.TestDriver.parseOption(self, asArgs, iArg);
|
---|
1343 | return iArg + 1;
|
---|
1344 |
|
---|
1345 | def completeOptions(self):
|
---|
1346 | # Remove skipped VMs from the test list.
|
---|
1347 | if self.asTestBuildDirs is None:
|
---|
1348 | raise base.InvalidOption('--test-build-dirs is not specified')
|
---|
1349 | if self.sGuestAdditionsIso is None:
|
---|
1350 | raise base.InvalidOption('--guest-additions-iso is not specified')
|
---|
1351 |
|
---|
1352 | for sVM in self.asSkipVMs:
|
---|
1353 | try: self.asTestVMs.remove(sVM);
|
---|
1354 | except: pass;
|
---|
1355 |
|
---|
1356 | return vbox.TestDriver.completeOptions(self);
|
---|
1357 |
|
---|
1358 | def getResourceSet(self):
|
---|
1359 | # Construct the resource list the first time it's queried.
|
---|
1360 | if self.asRsrcs is None:
|
---|
1361 | self.asRsrcs = [];
|
---|
1362 | if self.ksOsLinux in self.asTestVMs:
|
---|
1363 | self.asRsrcs.append('6.0/ub1804piglit/ub1804piglit.vdi');
|
---|
1364 | if self.ksOsWindows in self.asTestVMs:
|
---|
1365 | self.asRsrcs.append('6.0/windows7piglit/windows7piglit.vdi');
|
---|
1366 | #disabled
|
---|
1367 | #if self.ksOsSolaris in self.asTestVMs:
|
---|
1368 | # self.asRsrcs.append('4.2/autostart/tst-solaris.vdi');
|
---|
1369 |
|
---|
1370 | return self.asRsrcs;
|
---|
1371 |
|
---|
1372 | def actionConfig(self):
|
---|
1373 |
|
---|
1374 | # Make sure vboxapi has been imported so we can use the constants.
|
---|
1375 | if not self.importVBoxApi():
|
---|
1376 | return False;
|
---|
1377 |
|
---|
1378 | # Download VBoxGuestAdditions.iso before work
|
---|
1379 | sDestinationIso = os.path.join(self.sScratchPath, 'VBoxGuestAdditions.iso');
|
---|
1380 | utils.noxcptDeleteFile(sDestinationIso);
|
---|
1381 | if not downloadFile(self.sGuestAdditionsIso, sDestinationIso, '', reporter.log, reporter.error):
|
---|
1382 | raise base.GenError("Could not download VBoxGuestAdditions.iso");
|
---|
1383 | self.sGuestAdditionsIso = sDestinationIso;
|
---|
1384 |
|
---|
1385 | #
|
---|
1386 | # Configure the VMs we're going to use.
|
---|
1387 | #
|
---|
1388 |
|
---|
1389 | fRc = True;
|
---|
1390 |
|
---|
1391 | # Linux VMs
|
---|
1392 | if self.ksOsLinux in self.asTestVMs:
|
---|
1393 | # ub1804piglit is created with 2 CPUs.
|
---|
1394 | oVM = self.createTestVM(self.ksOsLinux, 1, '6.0/ub1804piglit/ub1804piglit.vdi', sKind = 'Ubuntu_64', \
|
---|
1395 | fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
|
---|
1396 | eNic0Type = vboxcon.NetworkAdapterType_Am79C973, cMbRam = 4096, \
|
---|
1397 | cCpus = 2, sDvdImage = self.sGuestAdditionsIso);
|
---|
1398 | if oVM is None:
|
---|
1399 | return False;
|
---|
1400 | # Windows VMs
|
---|
1401 | if self.ksOsWindows in self.asTestVMs:
|
---|
1402 | # windows7piglit is created with PAE enabled and 2 CPUs.
|
---|
1403 | oVM = self.createTestVM(self.ksOsWindows, 1, '6.0/windows7piglit/windows7piglit.vdi', sKind = 'Windows7_64', \
|
---|
1404 | fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
|
---|
1405 | sHddControllerType = "SATA Controller", cMbRam = 4096, fPae = True, cCpus = 2, \
|
---|
1406 | sDvdImage = self.sGuestAdditionsIso);
|
---|
1407 | if oVM is None:
|
---|
1408 | return False;
|
---|
1409 |
|
---|
1410 | # additional options used during the windows7piglit creation
|
---|
1411 | oSession = self.openSession(oVM);
|
---|
1412 | if oSession is not None:
|
---|
1413 | fRc = fRc and oSession.setVRamSize(256);
|
---|
1414 | fRc = fRc and oSession.setVideoControllerType(vboxcon.GraphicsControllerType_VBoxSVGA)
|
---|
1415 | fRc = fRc and oSession.setAccelerate3DEnabled(True);
|
---|
1416 | fRc = fRc and oSession.enableUsbOhci(True);
|
---|
1417 | fRc = fRc and oSession.enableUsbHid(True);
|
---|
1418 | fRc = fRc and oSession.saveSettings();
|
---|
1419 | fRc = oSession.close() and fRc and True; # pychecker hack.
|
---|
1420 | oSession = None;
|
---|
1421 | else:
|
---|
1422 | fRc = False;
|
---|
1423 |
|
---|
1424 | # disabled
|
---|
1425 | # Solaris VMs
|
---|
1426 | #if self.ksOsSolaris in self.asTestVMs:
|
---|
1427 | # oVM = self.createTestVM(self.ksOsSolaris, 1, '4.2/autostart/tst-solaris.vdi', sKind = 'Solaris_64', \
|
---|
1428 | # fIoApic = True, eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
|
---|
1429 | # sHddControllerType = "SATA Controller");
|
---|
1430 | # if oVM is None:
|
---|
1431 | # return False;
|
---|
1432 |
|
---|
1433 | return fRc;
|
---|
1434 |
|
---|
1435 | def actionExecute(self):
|
---|
1436 | """
|
---|
1437 | Execute the testcase.
|
---|
1438 | """
|
---|
1439 | fRc = self.testAutostart();
|
---|
1440 | return fRc;
|
---|
1441 |
|
---|
1442 | #
|
---|
1443 | # Test execution helpers.
|
---|
1444 | #
|
---|
1445 | def testAutostartRunProgs(self, oSession, sVmName, oVM):
|
---|
1446 | """
|
---|
1447 | Test VirtualBoxs autostart feature in a VM.
|
---|
1448 | """
|
---|
1449 | reporter.testStart('Autostart ' + sVmName);
|
---|
1450 |
|
---|
1451 | oGuestOsHlp = None # type: tdAutostartOs
|
---|
1452 | if sVmName == self.ksOsLinux:
|
---|
1453 | oGuestOsHlp = tdAutostartOsLinux(self, self.asTestBuildDirs, self.fpApiVer, # pylint: disable=redefined-variable-type
|
---|
1454 | self.sGuestAdditionsIso);
|
---|
1455 | elif sVmName == self.ksOsSolaris:
|
---|
1456 | oGuestOsHlp = tdAutostartOsSolaris(self, self.asTestBuildDirs, self.fpApiVer, # pylint: disable=redefined-variable-type
|
---|
1457 | self.sGuestAdditionsIso);
|
---|
1458 | elif sVmName == self.ksOsDarwin:
|
---|
1459 | oGuestOsHlp = tdAutostartOsDarwin(self, self.asTestBuildDirs, self.fpApiVer, # pylint: disable=redefined-variable-type
|
---|
1460 | self.sGuestAdditionsIso);
|
---|
1461 | elif sVmName == self.ksOsWindows:
|
---|
1462 | oGuestOsHlp = tdAutostartOsWin(self, self.asTestBuildDirs, self.fpApiVer, # pylint: disable=redefined-variable-type
|
---|
1463 | self.sGuestAdditionsIso);
|
---|
1464 |
|
---|
1465 | sTestUserAllow = 'test1';
|
---|
1466 | sTestUserDeny = 'test2';
|
---|
1467 | sTestVmName = 'TestVM';
|
---|
1468 |
|
---|
1469 | if oGuestOsHlp is not None:
|
---|
1470 | #wait the VM is ready after starting
|
---|
1471 | (fRc, oGuestSession) = oGuestOsHlp.waitVMisReady(oSession);
|
---|
1472 | #install fresh guest additions
|
---|
1473 | if fRc:
|
---|
1474 | (fRc, oGuestSession) = oGuestOsHlp.installAdditions(oSession, oGuestSession, oVM);
|
---|
1475 | # Create two new users
|
---|
1476 | fRc = fRc and oGuestOsHlp.createUser(oGuestSession, sTestUserAllow);
|
---|
1477 | fRc = fRc and oGuestOsHlp.createUser(oGuestSession, sTestUserDeny);
|
---|
1478 | if fRc is True:
|
---|
1479 | # Install VBox first
|
---|
1480 | fRc = oGuestOsHlp.installVirtualBox(oGuestSession);
|
---|
1481 | if fRc is True:
|
---|
1482 | fRc = oGuestOsHlp.configureAutostart(oGuestSession, 'allow', (sTestUserAllow,), (sTestUserDeny,));
|
---|
1483 | if fRc is True:
|
---|
1484 | # Create a VM with autostart enabled in the guest for both users
|
---|
1485 | fRc = oGuestOsHlp.createTestVM(oSession, oGuestSession, sTestUserAllow, sTestVmName);
|
---|
1486 | fRc = fRc and oGuestOsHlp.createTestVM(oSession, oGuestSession, sTestUserDeny, sTestVmName);
|
---|
1487 | if fRc is True:
|
---|
1488 | # Reboot the guest
|
---|
1489 | (fRc, oGuestSession) = oGuestOsHlp.rebootVMAndCheckReady(oSession, oGuestSession);
|
---|
1490 | if fRc is True:
|
---|
1491 | # Fudge factor - Allow the guest to finish starting up.
|
---|
1492 | self.sleep(30);
|
---|
1493 | fRc = oGuestOsHlp.checkForRunningVM(oSession, oGuestSession, sTestUserAllow, sTestVmName);
|
---|
1494 | if fRc is True:
|
---|
1495 | fRc = oGuestOsHlp.checkForRunningVM(oSession, oGuestSession, sTestUserDeny, sTestVmName);
|
---|
1496 | if fRc is True:
|
---|
1497 | reporter.error('Test VM is running inside the guest for denied user');
|
---|
1498 | fRc = not fRc;
|
---|
1499 | else:
|
---|
1500 | reporter.error('Test VM is not running inside the guest for allowed user');
|
---|
1501 | else:
|
---|
1502 | reporter.error('Rebooting the guest failed');
|
---|
1503 | else:
|
---|
1504 | reporter.error('Creating test VM failed');
|
---|
1505 | else:
|
---|
1506 | reporter.error('Configuring autostart in the guest failed');
|
---|
1507 | else:
|
---|
1508 | reporter.error('Installing VirtualBox in the guest failed');
|
---|
1509 | else:
|
---|
1510 | reporter.error('Creating test users failed');
|
---|
1511 |
|
---|
1512 | if oGuestSession is not None:
|
---|
1513 | try: oGuestOsHlp.powerDownVM(oGuestSession);
|
---|
1514 | except: pass;
|
---|
1515 | else:
|
---|
1516 | reporter.error('Guest OS helper not created for VM %s' % (sVmName));
|
---|
1517 | fRc = False;
|
---|
1518 |
|
---|
1519 | reporter.testDone();
|
---|
1520 | return fRc;
|
---|
1521 |
|
---|
1522 | def testAutostartOneCfg(self, sVmName):
|
---|
1523 | """
|
---|
1524 | Runs the specified VM thru test #1.
|
---|
1525 |
|
---|
1526 | Returns a success indicator on the general test execution. This is not
|
---|
1527 | the actual test result.
|
---|
1528 | """
|
---|
1529 | oVM = self.getVmByName(sVmName);
|
---|
1530 |
|
---|
1531 | # Reconfigure the VM
|
---|
1532 | fRc = True;
|
---|
1533 | oSession = self.openSession(oVM);
|
---|
1534 | if oSession is not None:
|
---|
1535 | fRc = fRc and oSession.enableVirtEx(True);
|
---|
1536 | fRc = fRc and oSession.enableNestedPaging(True);
|
---|
1537 | fRc = fRc and oSession.enableNestedHwVirt(True);
|
---|
1538 | # disable 3D until the error is fixed.
|
---|
1539 | fRc = fRc and oSession.setAccelerate3DEnabled(False);
|
---|
1540 | fRc = fRc and oSession.saveSettings();
|
---|
1541 | fRc = oSession.close() and fRc and True; # pychecker hack.
|
---|
1542 | oSession = None;
|
---|
1543 | else:
|
---|
1544 | fRc = False;
|
---|
1545 |
|
---|
1546 | # Start up.
|
---|
1547 | if fRc is True:
|
---|
1548 | self.logVmInfo(oVM);
|
---|
1549 | oSession = self.startVmByName(sVmName);
|
---|
1550 | if oSession is not None:
|
---|
1551 | fRc = self.testAutostartRunProgs(oSession, sVmName, oVM);
|
---|
1552 | try: self.terminateVmBySession(oSession);
|
---|
1553 | except: pass;
|
---|
1554 | else:
|
---|
1555 | fRc = False;
|
---|
1556 | return fRc;
|
---|
1557 |
|
---|
1558 | def testAutostartForOneVM(self, sVmName):
|
---|
1559 | """
|
---|
1560 | Runs one VM thru the various configurations.
|
---|
1561 | """
|
---|
1562 | reporter.testStart(sVmName);
|
---|
1563 | fRc = True;
|
---|
1564 | self.testAutostartOneCfg(sVmName);
|
---|
1565 | reporter.testDone();
|
---|
1566 | return fRc;
|
---|
1567 |
|
---|
1568 | def testAutostart(self):
|
---|
1569 | """
|
---|
1570 | Executes autostart test.
|
---|
1571 | """
|
---|
1572 |
|
---|
1573 | # Loop thru the test VMs.
|
---|
1574 | for sVM in self.asTestVMs:
|
---|
1575 | # run test on the VM.
|
---|
1576 | if not self.testAutostartForOneVM(sVM):
|
---|
1577 | fRc = False;
|
---|
1578 | else:
|
---|
1579 | fRc = True;
|
---|
1580 |
|
---|
1581 | return fRc;
|
---|
1582 |
|
---|
1583 |
|
---|
1584 |
|
---|
1585 | if __name__ == '__main__':
|
---|
1586 | sys.exit(tdAutostart().main(sys.argv));
|
---|
1587 |
|
---|