Пример #1
0
 def __init__(self,
              aoEntries,
              iPage,
              cItemsPerPage,
              tsEffective,
              fnDPrint,
              oDisp,
              cDaysBack,
              aiSelectedSortColumns=None):
     WuiListContentBase.__init__(
         self,
         aoEntries,
         iPage,
         cItemsPerPage,
         tsEffective,
         'System Changelog',
         fnDPrint=fnDPrint,
         oDisp=oDisp,
         aiSelectedSortColumns=aiSelectedSortColumns)
     self._asColumnHeaders = ['When', 'User', 'Event', 'Details']
     self._asColumnAttribs = ['align="center"', 'align="center"', '', '']
     self._oBuildBlacklistLogic = BuildBlacklistLogic(oDisp.getDb())
     self._oBuildLogic = BuildLogic(oDisp.getDb())
     self._oBuildSourceLogic = BuildSourceLogic(oDisp.getDb())
     self._oFailureCategoryLogic = FailureCategoryLogic(oDisp.getDb())
     self._oFailureReasonLogic = FailureReasonLogic(oDisp.getDb())
     self._oGlobalResourceLogic = GlobalResourceLogic(oDisp.getDb())
     self._oSchedGroupLogic = SchedGroupLogic(oDisp.getDb())
     self._oTestBoxLogic = TestBoxLogic(oDisp.getDb())
     self._oTestCaseLogic = TestCaseLogic(oDisp.getDb())
     self._oTestGroupLogic = TestGroupLogic(oDisp.getDb())
     self._oUserAccountLogic = UserAccountLogic(oDisp.getDb())
     self._sPrevDate = ''
     _ = cDaysBack
Пример #2
0
    def __init__(self, oSrvGlue, sScriptName):
        self._oSrvGlue          = oSrvGlue;
        self._oDb               = TMDatabaseConnection(self.dprint if config.g_kfWebUiSqlDebug else None, oSrvGlue = oSrvGlue);
        self._asCheckedParams   = [];
        self._dParams           = None;  # Set by dispatchRequest.
        self._sAction           = None;  # Set by dispatchRequest.
        self._dDispatch         = { self.ksActionDefault: self._actionDefault, };

        # Template bits.
        self._sTemplate         = 'template-default.html';
        self._sPageTitle        = '$$TODO$$';   # The page title.
        self._aaoMenus          = [];           # List of [sName, sLink, [ [sSideName, sLink], .. ] tuples.
        self._sPageBody         = '$$TODO$$';   # The body text.
        self._sRedirectTo       = None;
        self._sDebug            = '';

        # Debugger bits.
        self._fDbgSqlTrace      = False;
        self._fDbgSqlExplain    = False;
        self._dDbgParams        = dict();
        for sKey, sValue in oSrvGlue.getParameters().iteritems():
            if sKey in self.kasDbgParams:
                self._dDbgParams[sKey] = sValue;
        if len(self._dDbgParams) > 0:
            from testmanager.webui.wuicontentbase import WuiTmLink;
            WuiTmLink.kdDbgParams = self._dDbgParams;

        # Determine currently logged in user credentials
        self._oCurUser          = UserAccountLogic(self._oDb).tryFetchAccountByLoginName(oSrvGlue.getLoginName());

        # Calc a couple of URL base strings for this dispatcher.
        self._sUrlBase          = sScriptName + '?';
        if len(self._dDbgParams) > 0:
            self._sUrlBase     += webutils.encodeUrlParams(self._dDbgParams) + '&';
        self._sActionUrlBase    = self._sUrlBase + self.ksParamAction + '=';
Пример #3
0
 def _ensureCachesPresent(self):
     """ Ensures we've got the cache references resolved. """
     if self.oCategoryLogic is None:
         from testmanager.core.failurecategory import FailureCategoryLogic
         self.oCategoryLogic = FailureCategoryLogic(self._oDb)
     if self.oUserAccountLogic is None:
         self.oUserAccountLogic = UserAccountLogic(self._oDb)
     return True
Пример #4
0
    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)
Пример #5
0
    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)
Пример #7
0
    def fetchForListingEx(self,
                          iStart,
                          cMaxRows,
                          tsNow,
                          cDaysBack,
                          aiSortColumns=None):
        """
        Fetches SystemLog entries.

        Returns an array (list) of SystemLogData items, empty list if none.
        Raises exception on error.
        """
        _ = aiSortColumns

        #
        # Construct the query.
        #
        oUserAccountLogic = UserAccountLogic(self._oDb)
        oVSheriff = oUserAccountLogic.tryFetchAccountByLoginName(
            self.ksVSheriffLoginName)
        uidVSheriff = oVSheriff.uid if oVSheriff is not None else -1

        if tsNow is None:
            sWhereTime = self._oDb.formatBindArgs(
                '    WHERE  tsEffective >= CURRENT_TIMESTAMP - \'%s days\'::interval\n',
                (cDaysBack, ))
        else:
            sWhereTime = self._oDb.formatBindArgs(
                '    WHERE  tsEffective >= (%s::timestamptz - \'%s days\'::interval)\n'
                '       AND tsEffective <= %s\n', (tsNow, cDaysBack, tsNow))

        # Special entry for the system log.
        sQuery = '(\n'
        sQuery += '    SELECT NULL AS uidAuthor,\n'
        sQuery += '           tsCreated AS tsEffective,\n'
        sQuery += '           sEvent    AS sEvent,\n'
        sQuery += '           NULL      AS idWhat,\n'
        sQuery += '           sLogText  AS sDesc\n'
        sQuery += '    FROM   SystemLog\n'
        sQuery += sWhereTime.replace('tsEffective', 'tsCreated')
        sQuery += '    ORDER BY tsCreated DESC\n'
        sQuery += ')'

        for asEntry in self.kaasChangelogTables:
            sQuery += ' UNION (\n'
            sQuery += '    SELECT uidAuthor, tsEffective, \'' + asEntry[
                0] + '\', ' + asEntry[2] + ', \'\'\n'
            sQuery += '    FROM   ' + asEntry[1] + '\n'
            sQuery += sWhereTime
            if asEntry[4] == self.ksTweak_NotNullAuthor or asEntry[
                    4] == self.ksTweak_NotNullAuthorOrVSheriff:
                sQuery += '      AND uidAuthor IS NOT NULL\n'
                if asEntry[4] == self.ksTweak_NotNullAuthorOrVSheriff:
                    sQuery += '      AND uidAuthor <> %u\n' % (uidVSheriff, )
            sQuery += '    ORDER BY tsEffective DESC\n'
            sQuery += ')'
        sQuery += ' ORDER BY 2 DESC\n'
        sQuery += '  LIMIT %u OFFSET %u\n' % (
            cMaxRows,
            iStart,
        )

        #
        # Execute the query and construct the return data.
        #
        self._oDb.execute(sQuery)
        aoRows = []
        for aoRow in self._oDb.fetchAll():
            aoRows.append(
                SystemChangelogEntry(aoRow[1],
                                     oUserAccountLogic.cachedLookup(aoRow[0]),
                                     aoRow[2], aoRow[3], aoRow[4]))

        return aoRows