# -*- coding: utf-8 -*-
# $Id$
"""
TestBox Script - Command Processor.
"""
__copyright__ = \
"""
Copyright (C) 2012-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Standard python imports.
import os;
import sys;
import threading;
# Validation Kit imports.
import testboxcommons;
# Figure where we are.
try: __file__
"""
Implementation of Test Box command.
"""
## The time to wait on the current task to abort.
## The time to wait on the current task to abort before rebooting.
"""
Class instance init
"""
# List of available commands and their handlers
self._dfnCommands = \
{
}
"""
Idle response, no ACK.
"""
# The dispatch loop will delay for us, so nothing to do here.
_ = oConnection; # Leave the connection open.
return True;
"""
Gang scheduling wait response, no ACK.
"""
# The dispatch loop will delay for us, so nothing to do here.
_ = oConnection; # Leave the connection open.
return True;
"""
Execute incoming command
"""
# Check if required parameters given and make a little sense.
if sScriptFile is None:
# One task at the time.
raise TestBoxException('Already running other command');
# Don't bother running the task without the shares mounted.
# Kick off the task and ACK the command.
try:
self._oCurTask = TestBoxExecTask(self._oTestBoxScript, idResult = idResult, sScriptZips = sScriptZips,
finally:
return True;
"""
Abort background task
"""
if oCurTask is not None:
oConnection.close();
return True;
"""
Worker common to _cmdReboot and _doUpgrade that performs a system reboot.
"""
# !! Not more exceptions beyond this point !!
# Stop anything that might be executing at this point.
if oCurTask is not None:
# Invoke shutdown command line utility.
asCmd2 = None;
if sOs == 'win':
elif sOs == 'os2':
elif sOs in ('solaris',):
asCmd2 = ['/usr/sbin/reboot']; # Hack! S10 doesn't have -p, but don't know how to reliably detect S10.
else:
try:
if asCmd2 is not None:
try:
testboxcommons.log('Error executing reboot command "%s" as well as "%s": %s' % (asCmd, asCmd2, oXcpt));
return False;
return False;
# Quit the script.
while True:
return True;
"""
Reboot Test Box
"""
"""
Common worker for _cmdUpgrade and _cmdUpgradeAndReboot.
Will sys.exit on success!
"""
#
# The server specifies a ZIP archive with the new scripts. It's ASSUMED
# that the zip is of selected files at g_ksValidationKitDir in SVN. It's
# further ASSUMED that we're executing from
#
if utils.isRunningFromCheckout():
raise TestBoxException('Cannot upgrade when running from the tree!');
oConnection.sendAckAndClose(constants.tbresp.CMD_UPGRADE_AND_REBOOT if fReboot else constants.tbresp.CMD_UPGRADE);
#
# Download the file and install it.
#
fRc = webutils.downloadFile(sZipUrl, sDstFile, self._oTestBoxScript.getPathBuilds(), testboxcommons.log);
return False;
return False;
#
# Restart the system or the script (we have a parent script which
# respawns us when we quit).
#
if fReboot:
"""
Upgrade Test Box Script
"""
"""
Upgrade Test Box Script
"""
"""
Reserved for future fun.
"""
return False;
"""
Handles a command from the test manager.
Some commands will close the connection, others (generally the simple
ones) wont, leaving the caller the option to use it for log flushing.
Returns success indicator.
Raises no exception.
"""
try:
oConnection.close();
return False;
# Do we know the command?
try:
# Execute the handler.
# NACK the command if an exception is raised during parameter validation.
if oConnection.isConnected():
try:
else:
# NOTSUP the unknown command.
try:
return fRc;
"""
Resumes an incomplete command at startup.
The EXEC commands saves essential state information in the scratch area
so we can resume them in case the testbox panics or is rebooted.
Current "resume" means doing cleanups, but we may need to implement
test scenarios involving rebooting the testbox later.
Returns (idTestBox, sTestBoxName, True) if a command was resumed,
otherwise (-1, '', False). Raises no exceptions.
"""
try:
except:
"""
Check if we're running a task or not.
"""
"""
Flushes the log of any running task with a log buffer.
"""
return None;
""" Gets the current task in a paranoidly safe manny. """
return oCurTask;