cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager - Failure Categories.
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
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.failurereason import FailureReasonLogic
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Failure Category Data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idFailureCategory = 'FailureCategory_idFailureCategory'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsEffective = 'FailureCategory_tsEffective'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = [ 'idFailureCategory', 'tsEffective', 'tsExpire', 'uidAuthor' ]
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 FailureCategoryes.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if the row is None or otherwise invalid.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Failure Category not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass FailureCategoryLogic(ModelLogicBase): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Failure Category logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForListing(self, iStart, cMaxRows, tsNow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches Failure Category records.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array (list) of FailureCategoryData items, empty list if none.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureCategory ASC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureCategory ASC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows.append(FailureCategoryData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getFailureCategoriesForCombo(self, tsEffective = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of Failure Categories for a combo box.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of (value [idFailureCategory], drop-down-name [sShort],
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync hover-text [sFull]) tuples.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureCategory, sShort, sFull\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sShort')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureCategory, sShort, sFull\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sShort'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Get Failure Category data by idFailureCategory"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::timestamp\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND idFailureCategory = %s;', (idFailureCategory,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Found more than one failure categories with the same credentials. Database structure is corrupted.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return FailureCategoryData().initFromDbRow(aRows[0])
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addEntry(self, oFailureCategoryData, uidAuthor, fCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Add Failure Category record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if record with the same sShort fiels is already exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND sShort = %s\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO FailureCategories (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor, sShort, sFull'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s)',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def remove(self, uidAuthor, idFailureCategory, fNeedCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Historize record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Historize Failure Reasons records first
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idFailureCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idFailureCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def editEntry(self, oFailureCategoryData, uidAuthor, fCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Modify database record"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if record exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureCategoryDataOld = self.getById(oFailureCategoryData.idFailureCategory)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Failure Category (id: %d) does not exist'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if anything has been changed
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oFailureCategoryData.isEqual(oFailureCategoryDataOld):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Historize record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uidAuthor, oFailureCategoryData.idFailureCategory, fNeedCommit=False)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO FailureCategories (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idFailureCategory, uidAuthor, sShort, sFull'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s)',