testboxstatus.py revision cf22150eaeeb72431bf1cf65c309a431454fb22b
# -*- coding: utf-8 -*-
# $Id$
"""
Test Manager - TestBoxStatus.
"""
__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.
"""
__version__ = "$Revision$"
# Standard python imports.
import unittest;
# Validation Kit imports.
from testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase;
class TestBoxStatusData(ModelDataBase):
"""
TestBoxStatus Data.
"""
## @name TestBoxState_T
# @{
ksTestBoxState_Idle = 'idle';
ksTestBoxState_Testing = 'testing';
ksTestBoxState_GangGathering = 'gang-gathering';
ksTestBoxState_GangGatheringTimedOut = 'gang-gathering-timedout';
ksTestBoxState_GangTesting = 'gang-testing';
ksTestBoxState_GangCleanup = 'gang-cleanup';
ksTestBoxState_Rebooting = 'rebooting';
ksTestBoxState_Upgrading = 'upgrading';
ksTestBoxState_UpgradingAndRebooting = 'upgrading-and-rebooting';
ksTestBoxState_DoingSpecialCmd = 'doing-special-cmd';
## @}
ksParam_idTestBox = 'TestBoxStatus_idTestBox';
ksParam_idGenTestBox = 'TestBoxStatus_idGenTestBox'
ksParam_tsUpdated = 'TestBoxStatus_tsUpdated';
ksParam_enmState = 'TestBoxStatus_enmState';
ksParam_idTestSet = 'TestBoxStatus_idTestSet';
kasAllowNullAttributes = ['idTestSet', ];
[
];
#
# Initialize with defaults.
# See the database for explanations of each of these fields.
#
self.idGenTestBox = None;
"""
Internal worker for initFromDbWithId and initFromDbWithGenId as well as
TestBoxStatusLogic.
"""
if aoRow is None:
raise TMExceptionBase('TestBoxStatus not found.');
return self;
"""
Initialize the object from the database.
"""
'FROM TestBoxStatuses\n'
'WHERE idTestBox = %s\n'
, (idTestBox, ) );
"""
Initialize the object from the database.
"""
'FROM TestBoxStatuses\n'
'WHERE idGenTestBox = %s\n'
, (idGenTestBox, ) );
class TestBoxStatusLogic(ModelLogicBase):
"""
TestBoxStatus logic.
"""
## The number of seconds between each time to call touchStatus() when
# returning CMD_IDLE.
kcSecIdleTouchStatus = 120;
"""
Attempts to fetch the status of the given testbox.
Returns a TestBoxStatusData object on success.
Returns None if no status was found.
Raises exception on other errors.
"""
'FROM TestBoxStatuses\n'
'WHERE idTestBox = %s\n',
(idTestBox,));
return None;
oStatus = TestBoxStatusData();
"""
Tries to fetch the testbox status and current testbox config.
Returns (TestBoxStatusData, TestBoxData) on success, (None, None) if
not found. May throw an exception on database error.
"""
'FROM TestBoxStatuses, TestBoxes\n'
'WHERE TestBoxStatuses.idTestBox = %s\n'
' AND TestBoxes.idTestBox = %s\n'
' AND TestBoxes.tsExpire = \'infinity\'::timestamp\n'
' AND TestBoxes.uuidSystem = %s\n'
' AND TestBoxes.ip = %s\n'
, (idTestBox,
));
if cRows != 1:
if cRows != 0:
raise TMExceptionBase('tryFetchStatusForCommandReq got %s rows for idTestBox=%s' % (cRows, idTestBox));
return (None, None);
"""
Inserts an idle status for the specified testbox.
"""
' idTestBox,\n'
' idGenTestBox,\n'
' enmState,\n'
' idTestSet)\n'
'VALUES ( %s,\n'
' %s,\n'
' \'idle\'::TestBoxState_T,\n'
' NULL)\n',
(idTestBox, idGenTestBox) );
return True;
"""
Touches the testbox status row, i.e. sets tsUpdated to the current time.
"""
'SET tsUpdated = CURRENT_TIMESTAMP\n'
'WHERE idTestBox = %s\n'
, (idTestBox,));
return True;
"""
Updates the testbox state.
"""
'SET enmState = %s,\n'
' idTestSet = %s,\n'
' tsUpdated = CURRENT_TIMESTAMP\n'
'WHERE idTestBox = %s\n',
return True;
"""
Update the state of all members of a gang.
"""
'SET enmState = %s,\n'
' tsUpdated = CURRENT_TIMESTAMP\n'
'WHERE idTestBox IN (SELECT idTestBox\n'
' FROM TestSets\n'
' WHERE idTestSetGangLeader = %s)\n'
, (sNewState, idTestSetGangLeader,) );
return True;
"""
Checks if the whole gang is done testing.
"""
'FROM TestBoxStatuses, TestSets\n'
'WHERE TestBoxStatuses.idTestSet = TestSets.idTestSet\n'
' AND TestSets.idTestSetGangLeader = %s\n'
' AND TestBoxStatuses.enmState IN (%s, %s)\n'
, ( idTestSetGangLeader,
"""
Checks if the whole gang is done testing.
"""
'FROM TestBoxStatuses, TestSets\n'
'WHERE TestBoxStatuses.idTestSet = TestSets.idTestSet\n'
' AND TestSets.idTestSetGangLeader = %s\n'
' AND TestBoxStatuses.enmState IN (%s, %s)\n'
, ( idTestSetGangLeader,
"""
Figures the time since the last status change.
"""
#
# Unit testing.
#
# pylint: disable=C0111
if __name__ == '__main__':
# not reached.