cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager - TestBoxStatus.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2012-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport unittest;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.testbox import TestBoxData;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestBoxStatusData(ModelDataBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestBoxStatus Data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @name TestBoxState_T
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # @{
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_Idle = 'idle';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_Testing = 'testing';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_GangGathering = 'gang-gathering';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_GangGatheringTimedOut = 'gang-gathering-timedout';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_GangTesting = 'gang-testing';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_GangCleanup = 'gang-cleanup';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_Rebooting = 'rebooting';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_Upgrading = 'upgrading';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_UpgradingAndRebooting = 'upgrading-and-rebooting';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_DoingSpecialCmd = 'doing-special-cmd';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @}
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idTestBox = 'TestBoxStatus_idTestBox';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idGenTestBox = 'TestBoxStatus_idGenTestBox'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsUpdated = 'TestBoxStatus_tsUpdated';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_enmState = 'TestBoxStatus_enmState';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idTestSet = 'TestBoxStatus_idTestSet';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = ['idTestSet', ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasValidValues_enmState = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync [
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_Idle, ksTestBoxState_Testing, ksTestBoxState_GangGathering,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_GangGatheringTimedOut, ksTestBoxState_GangTesting, ksTestBoxState_GangCleanup,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_Rebooting, ksTestBoxState_Upgrading, ksTestBoxState_UpgradingAndRebooting,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksTestBoxState_DoingSpecialCmd,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelDataBase.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestBox = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idGenTestBox = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsUpdated = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.enmState = self.ksTestBoxState_Idle;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestSet = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Internal worker for initFromDbWithId and initFromDbWithGenId as well as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestBoxStatusLogic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('TestBoxStatus not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestBox = aoRow[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idGenTestBox = aoRow[1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsUpdated = aoRow[2];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.enmState = aoRow[3];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestSet = aoRow[4];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idTestBox):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize the object from the database.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestBoxStatuses\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestBox = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestBox, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.initFromDbRow(oDb.fetchOne());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithGenId(self, oDb, idGenTestBox):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize the object from the database.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestBoxStatuses\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idGenTestBox = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idGenTestBox, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.initFromDbRow(oDb.fetchOne());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestBoxStatusLogic(ModelLogicBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestBoxStatus logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## The number of seconds between each time to call touchStatus() when
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # returning CMD_IDLE.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kcSecIdleTouchStatus = 120;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oDb):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelLogicBase.__init__(self, oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def tryFetchStatus(self, idTestBox):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attempts to fetch the status of the given testbox.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a TestBoxStatusData object on success.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None if no status was found.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on other errors.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestBoxStatuses\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestBox = %s\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (idTestBox,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self._oDb.getRowCount() == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oStatus = TestBoxStatusData();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oStatus.initFromDbRow(self._oDb.fetchOne());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def tryFetchStatusAndConfig(self, idTestBox, sTestBoxUuid, sTestBoxAddr):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Tries to fetch the testbox status and current testbox config.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns (TestBoxStatusData, TestBoxData) on success, (None, None) if
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync not found. May throw an exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestBoxStatuses, TestBoxes\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestBoxStatuses.idTestBox = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestBoxes.idTestBox = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestBoxes.tsExpire = \'infinity\'::timestamp\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestBoxes.uuidSystem = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestBoxes.ip = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestBox,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync idTestBox,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sTestBoxUuid,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sTestBoxAddr,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cRows = self._oDb.getRowCount();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cRows != 1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cRows != 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('tryFetchStatusForCommandReq got %s rows for idTestBox=%s' % (cRows, idTestBox));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (None, None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRow = self._oDb.fetchOne();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (TestBoxStatusData().initFromDbRow(aoRow[0:5]), TestBoxData().initFromDbRow(aoRow[5:]));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def insertIdleStatus(self, idTestBox, idGenTestBox, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Inserts an idle status for the specified testbox.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestBoxStatuses (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idTestBox,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idGenTestBox,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' enmState,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idTestSet)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES ( %s,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' %s,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' \'idle\'::TestBoxState_T,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' NULL)\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (idTestBox, idGenTestBox) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def touchStatus(self, idTestBox, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Touches the testbox status row, i.e. sets tsUpdated to the current time.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE TestBoxStatuses\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsUpdated = CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestBox = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestBox,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def updateState(self, idTestBox, sNewState, idTestSet = None, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Updates the testbox state.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE TestBoxStatuses\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET enmState = %s,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idTestSet = %s,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' tsUpdated = CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestBox = %s\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (sNewState, idTestSet, idTestBox));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def updateGangStatus(self, idTestSetGangLeader, sNewState, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Update the state of all members of a gang.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE TestBoxStatuses\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET enmState = %s,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' tsUpdated = CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestBox IN (SELECT idTestBox\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' FROM TestSets\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' WHERE idTestSetGangLeader = %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (sNewState, idTestSetGangLeader,) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isWholeGangDoneTesting(self, idTestSetGangLeader):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the whole gang is done testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT COUNT(*)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestBoxStatuses, TestSets\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestBoxStatuses.idTestSet = TestSets.idTestSet\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestSets.idTestSetGangLeader = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestBoxStatuses.enmState IN (%s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( idTestSetGangLeader,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestBoxStatusData.ksTestBoxState_GangGathering,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestBoxStatusData.ksTestBoxState_GangTesting));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._oDb.fetchOne()[0] == 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isTheWholeGangThere(self, idTestSetGangLeader):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the whole gang is done testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT COUNT(*)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestBoxStatuses, TestSets\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestBoxStatuses.idTestSet = TestSets.idTestSet\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestSets.idTestSetGangLeader = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestBoxStatuses.enmState IN (%s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( idTestSetGangLeader,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestBoxStatusData.ksTestBoxState_GangGathering,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestBoxStatusData.ksTestBoxState_GangTesting));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._oDb.fetchOne()[0] == 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def timeSinceLastChangeInSecs(self, oStatusData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Figures the time since the last status change.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync tsNow = self._oDb.getCurrentTimestamp();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDelta = tsNow - oStatusData.tsUpdated;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oDelta.seconds + oDelta.days * 24 * 3600;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Unit testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0111
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestBoxStatusDataTestCase(ModelDataBaseTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setUp(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSamples = [TestBoxStatusData(),];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncif __name__ == '__main__':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync unittest.main();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # not reached.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync