def fetchForChangeLog(self, idFailureCategory, iStart, cMaxRows, tsNow): # pylint: disable=R0914 """ Fetches change log entries for a failure reason. Returns an array of ChangeLogEntry instance and an indicator whether there are more entries. Raises exception on error. """ if tsNow is None: tsNow = self._oDb.getCurrentTimestamp() # 1. Get a list of the relevant changes. self._oDb.execute( 'SELECT * FROM FailureCategories WHERE idFailureCategory = %s AND tsEffective <= %s\n' 'ORDER BY tsEffective DESC\n' 'LIMIT %s OFFSET %s\n', ( idFailureCategory, tsNow, cMaxRows + 1, iStart, )) aoRows = [] for aoChange in self._oDb.fetchAll(): aoRows.append(FailureCategoryData().initFromDbRow(aoChange)) # 2. Calculate the changes. aoEntries = [] for i in xrange(0, len(aoRows) - 1): oNew = aoRows[i] oOld = aoRows[i + 1] aoChanges = [] for sAttr in oNew.getDataAttributes(): if sAttr not in [ 'tsEffective', 'tsExpire', 'uidAuthor', ]: oOldAttr = getattr(oOld, sAttr) oNewAttr = getattr(oNew, sAttr) if oOldAttr != oNewAttr: aoChanges.append( AttributeChangeEntry(sAttr, oNewAttr, oOldAttr, str(oNewAttr), str(oOldAttr))) aoEntries.append( ChangeLogEntry(oNew.uidAuthor, None, oNew.tsEffective, oNew.tsExpire, oNew, oOld, aoChanges)) # If we're at the end of the log, add the initial entry. if len(aoRows) <= cMaxRows and aoRows: oNew = aoRows[-1] aoEntries.append( ChangeLogEntry(oNew.uidAuthor, None, oNew.tsEffective, oNew.tsExpire, oNew, None, [])) return (UserAccountLogic(self._oDb).resolveChangeLogAuthors(aoEntries), len(aoRows) > cMaxRows)
def fetchForChangeLog(self, idTestBox, iStart, cMaxRows, tsNow): # pylint: disable=R0914 """ Fetches change log entries for a testbox. Returns an array of ChangeLogEntry instance and an indicator whether there are more entries. Raises exception on error. """ if tsNow is None: tsNow = self._oDb.getCurrentTimestamp(); self._oDb.execute('SELECT TestBoxes.*, Users.sUsername\n' 'FROM TestBoxes\n' 'LEFT OUTER JOIN Users \n' ' ON ( TestBoxes.uidAuthor = Users.uid\n' ' AND Users.tsEffective <= TestBoxes.tsEffective\n' ' AND Users.tsExpire > TestBoxes.tsEffective)\n' 'WHERE TestBoxes.tsEffective <= %s\n' ' AND TestBoxes.idTestBox = %s\n' 'ORDER BY TestBoxes.tsExpire DESC\n' 'LIMIT %s OFFSET %s\n' , (tsNow, idTestBox, cMaxRows + 1, iStart,)); aoRows = []; for _ in range(self._oDb.getRowCount()): oRow = self._oDb.fetchOne(); aoRows.append([TestBoxData().initFromDbRow(oRow), oRow[-1],]); # Calculate the changes. aoEntries = []; for i in range(0, len(aoRows) - 1): (oNew, sAuthor) = aoRows[i]; (oOld, _ ) = aoRows[i + 1]; aoChanges = []; for sAttr in oNew.getDataAttributes(): if sAttr not in [ 'tsEffective', 'tsExpire', 'uidAuthor']: oOldAttr = getattr(oOld, sAttr); oNewAttr = getattr(oNew, sAttr); if oOldAttr != oNewAttr: aoChanges.append(AttributeChangeEntry(sAttr, oNewAttr, oOldAttr, str(oNewAttr), str(oOldAttr))); aoEntries.append(ChangeLogEntry(oNew.uidAuthor, sAuthor, oNew.tsEffective, oNew.tsExpire, oNew, oOld, aoChanges)); # If we're at the end of the log, add the initial entry. if len(aoRows) <= cMaxRows and len(aoRows) > 0: (oNew, sAuthor) = aoRows[-1]; aoEntries.append(ChangeLogEntry(oNew.uidAuthor, aoRows[-1][1], oNew.tsEffective, oNew.tsExpire, oNew, None, [])); return (aoEntries, len(aoRows) > cMaxRows);
def fetchForChangeLog(self, idTestBox, iStart, cMaxRows, tsNow): # pylint: disable=R0914 """ Fetches change log entries for a testbox. Returns an array of ChangeLogEntry instance and an indicator whether there are more entries. Raises exception on error. """ ## @todo calc changes to scheduler group! if tsNow is None: tsNow = self._oDb.getCurrentTimestamp(); self._oDb.execute('SELECT TestBoxesWithStrings.*\n' 'FROM TestBoxesWithStrings\n' 'WHERE TestBoxesWithStrings.tsEffective <= %s\n' ' AND TestBoxesWithStrings.idTestBox = %s\n' 'ORDER BY TestBoxesWithStrings.tsExpire DESC\n' 'LIMIT %s OFFSET %s\n' , (tsNow, idTestBox, cMaxRows + 1, iStart,)); aoRows = []; for aoDbRow in self._oDb.fetchAll(): aoRows.append(TestBoxData().initFromDbRow(aoDbRow)); # Calculate the changes. aoEntries = []; for i in xrange(0, len(aoRows) - 1): oNew = aoRows[i]; oOld = aoRows[i + 1]; aoChanges = []; for sAttr in oNew.getDataAttributes(): if sAttr not in [ 'tsEffective', 'tsExpire', 'uidAuthor', ]: oOldAttr = getattr(oOld, sAttr); oNewAttr = getattr(oNew, sAttr); if oOldAttr != oNewAttr: aoChanges.append(AttributeChangeEntry(sAttr, oNewAttr, oOldAttr, str(oNewAttr), str(oOldAttr))); aoEntries.append(ChangeLogEntry(oNew.uidAuthor, None, oNew.tsEffective, oNew.tsExpire, oNew, oOld, aoChanges)); # If we're at the end of the log, add the initial entry. if len(aoRows) <= cMaxRows and len(aoRows) > 0: oNew = aoRows[-1]; aoEntries.append(ChangeLogEntry(oNew.uidAuthor, None, oNew.tsEffective, oNew.tsExpire, oNew, None, [])); UserAccountLogic(self._oDb).resolveChangeLogAuthors(aoEntries); return (aoEntries, len(aoRows) > cMaxRows);
def fetchForChangeLog(self, idTestResult, iStart, cMaxRows, tsNow): # pylint: disable=R0914 """ Fetches change log entries for a failure reason. Returns an array of ChangeLogEntry instance and an indicator whether there are more entries. Raises exception on error. """ if tsNow is None: tsNow = self._oDb.getCurrentTimestamp() # 1. Get a list of the changes from both TestResultFailures and assoicated # FailureReasons. The latter is useful since the failure reason # description may evolve along side the invidiual failure analysis. self._oDb.execute( '( SELECT trf.tsEffective AS tsEffectiveChangeLog,\n' ' trf.uidAuthor AS uidAuthorChangeLog,\n' ' trf.*,\n' ' fr.*\n' ' FROM TestResultFailures trf,\n' ' FailureReasons fr\n' ' WHERE trf.idTestResult = %s\n' ' AND trf.tsEffective <= %s\n' ' AND trf.idFailureReason = fr.idFailureReason\n' ' AND fr.tsEffective <= trf.tsEffective\n' ' AND fr.tsExpire > trf.tsEffective\n' ')\n' 'UNION\n' '( SELECT fr.tsEffective AS tsEffectiveChangeLog,\n' ' fr.uidAuthor AS uidAuthorChangeLog,\n' ' trf.*,\n' ' fr.*\n' ' FROM TestResultFailures trf,\n' ' FailureReasons fr\n' ' WHERE trf.idTestResult = %s\n' ' AND trf.tsEffective <= %s\n' ' AND trf.idFailureReason = fr.idFailureReason\n' ' AND fr.tsEffective > trf.tsEffective\n' ' AND fr.tsEffective < trf.tsExpire\n' ')\n' 'ORDER BY tsEffectiveChangeLog DESC\n' 'LIMIT %s OFFSET %s\n', ( idTestResult, tsNow, idTestResult, tsNow, cMaxRows + 1, iStart, )) aaoRows = [] for aoChange in self._oDb.fetchAll(): oTrf = TestResultFailureDataEx().initFromDbRow(aoChange[2:]) oFr = FailureReasonData().initFromDbRow( aoChange[(2 + TestResultFailureData.kcDbColumns):]) oTrf.oFailureReason = oFr aaoRows.append([aoChange[0], aoChange[1], oTrf, oFr]) # 2. Calculate the changes. oFailureCategoryLogic = None aoEntries = [] for i in xrange(0, len(aaoRows) - 1): aoNew = aaoRows[i] aoOld = aaoRows[i + 1] aoChanges = [] oNew = aoNew[2] oOld = aoOld[2] for sAttr in oNew.getDataAttributes(): if sAttr not in [ 'tsEffective', 'tsExpire', 'uidAuthor', 'oFailureReason', 'oAuthor' ]: oOldAttr = getattr(oOld, sAttr) oNewAttr = getattr(oNew, sAttr) if oOldAttr != oNewAttr: if sAttr == 'idFailureReason': oNewAttr = '%s (%s)' % ( oNewAttr, oNew.oFailureReason.sShort, ) oOldAttr = '%s (%s)' % ( oOldAttr, oOld.oFailureReason.sShort, ) aoChanges.append( AttributeChangeEntry(sAttr, oNewAttr, oOldAttr, str(oNewAttr), str(oOldAttr))) if oOld.idFailureReason == oNew.idFailureReason: oNew = aoNew[3] oOld = aoOld[3] for sAttr in oNew.getDataAttributes(): if sAttr not in [ 'tsEffective', 'tsExpire', 'uidAuthor', ]: oOldAttr = getattr(oOld, sAttr) oNewAttr = getattr(oNew, sAttr) if oOldAttr != oNewAttr: if sAttr == 'idFailureCategory': if oFailureCategoryLogic is None: from testmanager.core.failurecategory import FailureCategoryLogic oFailureCategoryLogic = FailureCategoryLogic( self._oDb) oCat = oFailureCategoryLogic.cachedLookup( oNewAttr) if oCat is not None: oNewAttr = '%s (%s)' % ( oNewAttr, oCat.sShort, ) oCat = oFailureCategoryLogic.cachedLookup( oOldAttr) if oCat is not None: oOldAttr = '%s (%s)' % ( oOldAttr, oCat.sShort, ) aoChanges.append( AttributeChangeEntry(sAttr, oNewAttr, oOldAttr, str(oNewAttr), str(oOldAttr))) tsExpire = aaoRows[i - 1][0] if i > 0 else aoNew[2].tsExpire aoEntries.append( ChangeLogEntry(aoNew[1], None, aoNew[0], tsExpire, aoNew[2], aoOld[2], aoChanges)) # If we're at the end of the log, add the initial entry. if len(aaoRows) <= cMaxRows and len(aaoRows) > 0: aoNew = aaoRows[-1] tsExpire = aaoRows[-1 - 1][0] if len(aaoRows) > 1 else aoNew[2].tsExpire aoEntries.append( ChangeLogEntry(aoNew[1], None, aoNew[0], tsExpire, aoNew[2], None, [])) return (UserAccountLogic(self._oDb).resolveChangeLogAuthors(aoEntries), len(aaoRows) > cMaxRows)