def getById(self, idTestGroup, tsNow=None): """Get Test Group data by its ID""" if tsNow is None: self._oDb.execute( 'SELECT *\n' 'FROM TestGroups\n' 'WHERE tsExpire = \'infinity\'::timestamp\n' ' AND idTestGroup = %s\n' 'ORDER BY idTestGroup ASC;', (idTestGroup, )) else: self._oDb.execute( 'SELECT *\n' 'FROM TestGroups\n' 'WHERE tsExpire > %s\n' ' AND tsEffective <= %s\n' ' AND idTestGroup = %s\n' 'ORDER BY idTestGroup ASC;', (tsNow, tsNow, idTestGroup)) aRows = self._oDb.fetchAll() if len(aRows) not in (0, 1): raise TMTooManyRows( 'Found more than one test groups with the same credentials. Database structure is corrupted.' ) try: return TestGroupData().initFromDbRow(aRows[0]) except IndexError: return None
def tryFetchStatusAndConfig(self, idTestBox, sTestBoxUuid, sTestBoxAddr): """ 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. """ self._oDb.execute( 'SELECT TestBoxStatuses.*,\n' ' TestBoxesWithStrings.*\n' 'FROM TestBoxStatuses,\n' ' TestBoxesWithStrings\n' 'WHERE TestBoxStatuses.idTestBox = %s\n' ' AND TestBoxesWithStrings.idTestBox = %s\n' ' AND TestBoxesWithStrings.tsExpire = \'infinity\'::TIMESTAMP\n' ' AND TestBoxesWithStrings.uuidSystem = %s\n' ' AND TestBoxesWithStrings.ip = %s\n', ( idTestBox, idTestBox, sTestBoxUuid, sTestBoxAddr, )) cRows = self._oDb.getRowCount() if cRows != 1: if cRows != 0: raise TMTooManyRows( 'tryFetchStatusForCommandReq got %s rows for idTestBox=%s' % (cRows, idTestBox)) return (None, None) aoRow = self._oDb.fetchOne() return (TestBoxStatusData().initFromDbRow( aoRow[:TestBoxStatusData.kcDbColumns]), TestBoxData().initFromDbRow( aoRow[TestBoxStatusData.kcDbColumns:]))
def getById(self, idTestSet): """ Get TestSet table record by its id """ self._oDb.execute('SELECT *\n' 'FROM TestSets\n' 'WHERE idTestSet=%s\n', (idTestSet,)) aRows = self._oDb.fetchAll() if len(aRows) not in (0, 1): raise TMTooManyRows('Found more than one test sets with the same credentials. Database structure is corrupted.') try: return TestSetData().initFromDbRow(aRows[0]) except IndexError: return None
def getById(self, idBuild): """ Get build record by its id """ self._oDb.execute('SELECT Builds.*, BuildCategories.*\n' 'FROM Builds, BuildCategories\n' 'WHERE Builds.idBuild=%s\n' ' AND Builds.idBuildCategory=BuildCategories.idBuildCategory\n' ' AND Builds.tsExpire = \'infinity\'::TIMESTAMP\n', (idBuild,)) aRows = self._oDb.fetchAll() if len(aRows) not in (0, 1): raise TMTooManyRows('Found more than one build with the same credentials. Database structure is corrupted.') try: return BuildDataEx().initFromDbRow(aRows[0]) except IndexError: return None
def tryFetchTestBoxByUuid(self, sTestBoxUuid): """ Tries to fetch a testbox by its UUID alone. """ self._oDb.execute('SELECT TestBoxesWithStrings.*\n' 'FROM TestBoxesWithStrings\n' 'WHERE uuidSystem = %s\n' ' AND tsExpire = \'infinity\'::timestamp\n' 'ORDER BY tsEffective DESC\n', (sTestBoxUuid,)); if self._oDb.getRowCount() == 0: return None; if self._oDb.getRowCount() != 1: raise TMTooManyRows('Database integrity error: %u hits' % (self._oDb.getRowCount(),)); oData = TestBoxData(); oData.initFromDbRow(self._oDb.fetchOne()); return oData;
def _getByField(self, sField, sValue): """ Get user account record by its field value """ self._oDb.execute('SELECT *\n' 'FROM Users\n' 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n' ' AND ' + sField + ' = %s' , (sValue,)) aRows = self._oDb.fetchAll() if len(aRows) not in (0, 1): raise TMTooManyRows('Found more than one user account with the same credentials. Database structure is corrupted.') try: return aRows[0] except IndexError: return []