# -*- coding: utf-8 -*-
# $Id$
"""
Test Manager - Failure Reasons.
"""
__copyright__ = \
"""
Copyright (C) 2012-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Validation Kit imports.
"""
Failure Reason Data.
"""
'uidAuthor', 'iTicket', 'asUrls' ]
#
# Initialize with defaults.
# See the database for explanations of each of these fields.
#
self.idFailureReason = None
self.tsEffective = None
self.idFailureCategory = None
"""
Re-initializes the data with a row from a SELECT * FROM FailureReasons.
Returns self. Raises exception if the row is None or otherwise invalid.
"""
if aoRow is None:
raise TMExceptionBase('Failure Reason not found.');
return self
"""
Failure Reason logic.
"""
"""
Fetches Failure Category records.
Returns an array (list) of FailureReasonData items, empty list if none.
Raises exception on error.
"""
if tsNow is None:
'FROM FailureReasons\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
'ORDER BY idFailureReason DESC\n'
'LIMIT %s OFFSET %s\n'
else:
'FROM FailureReasons\n'
'WHERE tsExpire > %s\n'
' AND tsEffective <= %s\n'
'ORDER BY idFailureReason DESC\n'
'LIMIT %s OFFSET %s\n'
aoRows = []
return aoRows
"""
Gets the list of Failure Reasons for a combo box.
Returns an array of (value [idFailureReason], drop-down-name [sShort],
hover-text [sFull]) tuples.
"""
if tsEffective is None:
'FROM FailureReasons\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
'ORDER BY sShort')
else:
'FROM FailureReasons\n'
'WHERE tsExpire > %s\n'
' AND tsEffective <= %s\n'
'ORDER BY sShort'
, (tsEffective, tsEffective))
"""Get Failure Reason data by idFailureReason"""
'FROM FailureReasons\n'
'WHERE tsExpire = \'infinity\'::timestamp\n'
' AND idFailureReason = %s;', (idFailureReason,))
'Found more than one failure reasons with the same credentials. Database structure is corrupted.')
try:
except IndexError:
return None
"""
Gets the list of Failure Ressons IDs,
all the items belong to @param idFailureCategory
"""
if tsEffective is None:
'FROM FailureReasons\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
' AND idFailureCategory = %s\n'
'ORDER BY idFailureReason DESC'
, (idFailureCategory,))
else:
'FROM FailureReasons\n'
'WHERE tsExpire > %s\n'
' AND tsEffective <= %s\n'
' AND idFailureCategory = %s\n'
'ORDER BY idFailureReason DESC'
"""
Gets the list of all Failure Reasons.
Returns an array of FailureReasonData instances.
"""
if tsEffective is None:
'FROM FailureReasons\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
'ORDER BY idFailureReason DESC')
else:
'FROM FailureReasons\n'
'WHERE tsExpire > %s\n'
' AND tsEffective <= %s\n'
'ORDER BY idFailureReason DESC'
, (tsEffective, tsEffective))
aoRet = []
return aoRet
"""Add record to database"""
# Check if record with the same sShort fiels is already exists
'FROM FailureReasons\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
' AND sShort = %s\n',
raise Exception('Record already exist')
# Add record
' uidAuthor, idFailureCategory,'
' sShort, sFull, iTicket, asUrls'
')\n'
'VALUES (%s, %s, %s, %s, %s, %s)',
if fCommit:
return True
"""
Historize record
"""
'SET tsExpire = CURRENT_TIMESTAMP,\n'
' uidAuthor = %s\n'
'WHERE idFailureReason = %s\n'
' AND tsExpire = \'infinity\'::TIMESTAMP\n',
# Also historize Black List records
'SET tsExpire = CURRENT_TIMESTAMP,\n'
' uidAuthor = %s\n'
'WHERE idFailureReason = %s\n'
' AND tsExpire = \'infinity\'::TIMESTAMP\n',
if fNeedCommit:
return True
"""Modify database record"""
# Check if record exists
if oFailureReasonDataOld is None:
raise TMExceptionBase(
'Failure Reason (id: %d) does not exist'
# Check if anything has been changed
return True
# Historize record
# Add new record (keeping its ID)
' idFailureReason,'
' uidAuthor,'
' idFailureCategory,'
' sShort,'
' sFull,'
' iTicket,'
' asUrls'
')\n'
'VALUES (%s, %s, %s, %s, %s, %s, %s)',
))
if fCommit:
return True