failurereason.py revision cf22150eaeeb72431bf1cf65c309a431454fb22b
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager - Failure Reasons.
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# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.base import ModelDataBase, ModelLogicBase, TMExceptionBase
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Failure Reason Data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idFailureReason = 'FailureReasonData_idFailureReason'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsEffective = 'FailureReasonData_tsEffective'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idFailureCategory = 'FailureReasonData_idFailureCategory'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = [ 'idFailureReason', 'tsEffective', 'tsExpire',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Re-initializes the data with a row from a SELECT * FROM FailureReasons.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if the row is None or otherwise invalid.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Failure Reason not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass FailureReasonLogic(ModelLogicBase): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Failure Reason logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForListing(self, iStart, cMaxRows, tsNow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches Failure Category records.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array (list) of FailureReasonData items, empty list if none.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows.append(FailureReasonData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of Failure Reasons for a combo box.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of (value [idFailureReason], drop-down-name [sShort],
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync hover-text [sFull]) tuples.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureReason, sShort, sFull\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sShort')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureReason, sShort, sFull\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sShort'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Get Failure Reason data by idFailureReason"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::timestamp\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Found more than one failure reasons with the same credentials. Database structure is corrupted.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getIdsByCategory(self, idFailureCategory, tsEffective=None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of Failure Ressons IDs,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync all the items belong to @param idFailureCategory
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND idFailureCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND idFailureCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of all Failure Reasons.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of FailureReasonData instances.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(FailureReasonData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addEntry(self, oFailureReasonData, uidAuthor, fCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Add record to database"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if record with the same sShort fiels is already exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND sShort = %s\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor, idFailureCategory,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sShort, sFull, iTicket, asUrls'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s)',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def remove(self, uidAuthor, idFailureReason, fNeedCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Historize record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idFailureReason = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Also historize Black List records
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idFailureReason = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def editEntry(self, oFailureReasonData, uidAuthor, fCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Modify database record"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if record exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonDataOld = self.getById(oFailureReasonData.idFailureReason)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Failure Reason (id: %d) does not exist'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if anything has been changed
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oFailureReasonData.isEqual(oFailureReasonDataOld):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Historize record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uidAuthor, oFailureReasonData.idFailureReason, fNeedCommit=False)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add new record (keeping its ID)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idFailureReason,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idFailureCategory,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' iTicket,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s, %s)',