cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager - Test Case Arguments Variations.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2012-2014 Oracle Corporation
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.
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.
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# Standard python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.testcase import TestCaseData, TestCaseDependencyLogic, TestCaseGlobalRsrcDepLogic;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Python 3 hacks:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test case argument variation.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idTestCaseArgs = 'TestCaseArgs_idTestCaseArgs';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idGenTestCaseArgs = 'TestCaseArgs_idGenTestCaseArgs';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sTestBoxReqExpr = 'TestCaseArgs_sTestBoxReqExpr';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sBuildReqExpr = 'TestCaseArgs_sBuildReqExpr';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_cGangMembers = 'TestCaseArgs_cGangMembers';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = [ 'idTestCase', 'idTestCaseArgs', 'tsEffective', 'tsExpire', 'uidAuthor', 'idGenTestCaseArgs',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cSecTimeout', 'sTestBoxReqExpr', 'sBuildReqExpr', ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Re-initializes the object from a SELECT * FROM TestCaseArgs row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if aoRow is None.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idTestCaseArgs, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize from the database.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute(self.formatSimpleNowAndPeriodQuery(oDb,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCaseArgs = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('idTestCaseArgs=%s not found (tsNow=%s sPeriodBack=%s)'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithGenId(self, oDb, idGenTestCaseArgs):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize from the database, given the generation ID of a row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute('SELECT * FROM TestCaseArgs WHERE idGenTestCaseArgs = %s', (idGenTestCaseArgs,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromValues(self, sArgs, cSecTimeout = None, sTestBoxReqExpr = None, sBuildReqExpr = None, # pylint: disable=R0913
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cGangMembers = 1, idTestCase = None, idTestCaseArgs = None, tsEffective = None, tsExpire = None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize from values.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.cSecTimeout = utils.parseIntervalSeconds(cSecTimeout);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNilValues = ModelDataBase.getAttributeParamNullValues(self, sAttr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNilValues.insert(0, ''); # Prettier NULL value for cSecTimeout.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr == 'cSecTimeout' and oValue not in aoNilValues: # Allow human readable interval formats.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (oValue, sError) = ModelDataBase._validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sError = TestCaseData.validateTestBoxReqExpr(oValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sError = TestCaseData.validateBuildReqExpr(oValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Complete data set.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Do not call me: %s' % (aoRow,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idTestCaseArgs, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = oDb; _ = idTestCaseArgs; _ = tsNow; _ = sPeriodBack;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithGenId(self, oDb, idGenTestCaseArgs):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithGenIdEx(self, oDb, idGenTestCaseArgs, tsConfigEff = None, tsRsrcEff = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize from the database, given the ID of a row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute('SELECT *, CURRENT_TIMESTAMP FROM TestCaseArgs WHERE idGenTestCaseArgs = %s', (idGenTestCaseArgs,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oTestCase = TestCaseData().initFromDbWithId(oDb, self.idTestCase, tsConfigEff);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoTestCasePreReqs = TestCaseDependencyLogic(oDb).getTestCaseDeps(self.idTestCase, tsConfigEff);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoGlobalRsrc = TestCaseGlobalRsrcDepLogic(oDb).getTestCaseDeps(self.idTestCase, tsRsrcEff);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the all of the testbox related test requirements matches the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync given testbox.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True or False according to the expression, None on exception or
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync non-boolean expression result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData.matchesTestBoxPropsEx(oTestBoxData, self.oTestCase.sTestBoxReqExpr) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and TestCaseData.matchesTestBoxPropsEx(oTestBoxData, self.sTestBoxReqExpr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the all of the build related test requirements matches the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync given build.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True or False according to the expression, None on exception or
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync non-boolean expression result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData.matchesBuildPropsEx(oBuildDataEx, self.oTestCase.sBuildReqExpr) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and TestCaseData.matchesBuildPropsEx(oBuildDataEx, self.sBuildReqExpr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestCaseArgs database logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if all global resources are currently still in existance and free.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True/False. May raise exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Create a set of global resource IDs.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asIdRsrcs = [str(oDep.idGlobalRsrc) for oDep, _ in oDataEx.aoGlobalRsrc];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # A record in the resource status table means it's allocated.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM GlobalResourceStatuses\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE GlobalResourceStatuses.idGlobalRsrc IN (' + ', '.join(asIdRsrcs) + ')\n');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check for disabled or deleted resources (we cannot allocate them).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM GlobalResources\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE GlobalResources.idGlobalRsrc IN (' + ', '.join(asIdRsrcs) + ')\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.fEnabled = TRUE\n');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self._oDb.fetchOne()[0] == len(oDataEx.aoGlobalRsrc):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Get list of objects of type TestCaseArgsData"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(TestCaseArgsData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getTestCaseArgs(self, idTestCase, tsNow = None, aiWhiteList = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Get list of testcase's arguments variations"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sWhiteList = ','.join((str(x) for x in aiWhiteList));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(TestCaseArgsData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Add Test Case Args record into DB"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Unit testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0111
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseArgsDataTestCase(ModelDataBaseTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # not reached.