VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/core/systemchangelog.py@ 65039

Last change on this file since 65039 was 65039, checked in by vboxsync, 8 years ago

testmanager: Simple system wide changelog.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: systemchangelog.py 65039 2016-12-30 15:35:30Z vboxsync $
3
4"""
5Test Manager - System changelog compilation.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2012-2016 Oracle Corporation
11
12This file is part of VirtualBox Open Source Edition (OSE), as
13available from http://www.virtualbox.org. This file is free software;
14you can redistribute it and/or modify it under the terms of the GNU
15General Public License (GPL) as published by the Free Software
16Foundation, in version 2 as it comes in the "COPYING" file of the
17VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
20The contents of this file may alternatively be used under the terms
21of the Common Development and Distribution License Version 1.0
22(CDDL) only, as it comes in the "COPYING.CDDL" file of the
23VirtualBox OSE distribution, in which case the provisions of the
24CDDL are applicable instead of those of the GPL.
25
26You may elect to license modified versions of this file under the
27terms and conditions of either the GPL or the CDDL or both.
28"""
29__version__ = "$Revision: 65039 $"
30
31
32# Validation Kit imports.
33from testmanager.core.base import ModelLogicBase;
34from testmanager.core.useraccount import UserAccountLogic;
35
36
37class SystemChangelogEntry(object): # pylint: disable=R0902
38 """
39 System changelog entry.
40 """
41
42 def __init__(self, tsEffective, oAuthor, sWhat, idWhat, sDesc):
43 self.tsEffective = tsEffective;
44 self.oAuthor = oAuthor;
45 self.sWhat = sWhat;
46 self.idWhat = idWhat;
47 self.sDesc = sDesc;
48
49
50class SystemChangelogLogic(ModelLogicBase):
51 """
52 System changelog compilation logic.
53 """
54
55 ## @name What kind of change.
56 ## @{
57 ksWhat_TestBox = 'TestBox';
58 ksWhat_TestCase = 'TestCase';
59 ksWhat_Blacklisting = 'Blacklisting';
60 ksWhat_Build = 'Build';
61 ksWhat_BuildSource = 'BuildSource';
62 ksWhat_FailureCategory = 'FailureCategory';
63 ksWhat_FailureReason = 'FailureReason';
64 ksWhat_GlobalRsrc = 'GlobalRsrc';
65 ksWhat_SchedGroup = 'SchedGroup';
66 ksWhat_SystemLog = 'SystemLog';
67 ksWhat_TestGroup = 'TestGroup';
68 ksWhat_User = 'User';
69 ksWhat_TestResult = 'TestResult';
70 ## @}
71
72 ## The table key is the effective timestamp.
73 ksClue_TimestampId = 'TimestampId';
74
75 ## Mapping a changelog entry kind to a table, key and clue.
76 kdWhatToTable = {
77 ksWhat_TestBox: ( 'TestBoxes', 'idTestBox', None, ),
78 ksWhat_TestCase: ( 'TestCasees', 'idTestCase', None, ),
79 ksWhat_Blacklisting: ( 'Blacklist', 'idBlacklisting', None, ),
80 ksWhat_Build: ( 'Builds', 'idBuild', None, ),
81 ksWhat_BuildSource: ( 'BuildSources', 'idBuildSrc', None, ),
82 ksWhat_FailureCategory: ( 'FailureCategories', 'idFailureCategory', None, ),
83 ksWhat_FailureReason: ( 'FailureReasons', 'idFailureReason', None, ),
84 ksWhat_GlobalRsrc: ( 'GlobalResources', 'idGlobalRsrc', None, ),
85 ksWhat_SchedGroup: ( 'SchedGroupes', 'idSchedGroup', None, ),
86 ksWhat_SystemLog: ( 'SystemLog', 'tsCreated', ksClue_TimestampId, ),
87 ksWhat_TestGroup: ( 'TestGroupes', 'idTestGroup', None, ),
88 ksWhat_User: ( 'Users', 'idUser', None, ),
89 ksWhat_TestResult: ( 'TestResults', 'idTestResult', None, ),
90 };
91
92 ## @todo move to config.py?
93 ksVSheriffLoginName = 'vsheriff';
94
95
96 ## @name for kaasChangelogTables
97 ## @internal
98 ## @{
99 ksTweak_None = '';
100 ksTweak_NotNullAuthor = 'uidAuthorNotNull';
101 ksTweak_NotNullAuthorOrVSheriff = 'uidAuthorNotNullOrVSheriff';
102 ## @}
103
104 ## @internal
105 kaasChangelogTables = (
106 # [0]: change name, [1]: Table name, [2]: key column, [3]:later, [4]: tweak
107 ( ksWhat_TestBox, 'TestBoxes', 'idTestBox', None, ksTweak_NotNullAuthor, ),
108 ( ksWhat_TestBox, 'TestBoxesInSchedGroups', 'idTestBox', None, ksTweak_None, ),
109 ( ksWhat_TestCase, 'TestCases', 'idTestCase', None, ksTweak_None, ),
110 ( ksWhat_TestCase, 'TestCaseArgs', 'idTestCase', None, ksTweak_None, ),
111 ( ksWhat_TestCase, 'TestCaseDeps', 'idTestCase', None, ksTweak_None, ),
112 ( ksWhat_TestCase, 'TestCaseGlobalRsrcDeps', 'idTestCase', None, ksTweak_None, ),
113 ( ksWhat_Blacklisting, 'BuildBlacklist', 'idBlacklisting', None, ksTweak_None, ),
114 ( ksWhat_Build, 'Builds', 'idBuild', None, ksTweak_NotNullAuthor, ),
115 ( ksWhat_BuildSource, 'BuildSources', 'idBuildSrc', None, ksTweak_None, ),
116 ( ksWhat_FailureCategory, 'FailureCategories', 'idFailureCategory', None, ksTweak_None, ),
117 ( ksWhat_FailureReason, 'FailureReasons', 'idFailureReason', None, ksTweak_None, ),
118 ( ksWhat_GlobalRsrc, 'GlobalResources', 'idGlobalRsrc', None, ksTweak_None, ),
119 ( ksWhat_SchedGroup, 'SchedGroups', 'idSchedGroup', None, ksTweak_None, ),
120 ( ksWhat_SchedGroup, 'SchedGroupMembers', 'idSchedGroup', None, ksTweak_None, ),
121 ( ksWhat_TestGroup, 'TestGroups', 'idTestGroup', None, ksTweak_None, ),
122 ( ksWhat_TestGroup, 'TestGroupMembers', 'idTestGroup', None, ksTweak_None, ),
123 ( ksWhat_User, 'Users', 'uid', None, ksTweak_None, ),
124 ( ksWhat_TestResult, 'TestResultFailures', 'idTestResult', None, ksTweak_NotNullAuthorOrVSheriff, ),
125 );
126
127 def __init__(self, oDb):
128 ModelLogicBase.__init__(self, oDb);
129
130
131 def fetchForListingEx(self, iStart, cMaxRows, tsNow, cDaysBack):
132 """
133 Fetches SystemLog entries.
134
135 Returns an array (list) of SystemLogData items, empty list if none.
136 Raises exception on error.
137 """
138
139 #
140 # Construct the query.
141 #
142 oUserAccountLogic = UserAccountLogic(self._oDb);
143 oVSheriff = oUserAccountLogic.tryFetchAccountByLoginName(self.ksVSheriffLoginName);
144 uidVSheriff = oVSheriff.uid if oVSheriff is not None else -1;
145
146 if tsNow is None:
147 sWhereTime = self._oDb.formatBindArgs(' WHERE tsEffective >= CURRENT_TIMESTAMP - \'%s days\'::interval\n',
148 (cDaysBack,));
149 else:
150 sWhereTime = self._oDb.formatBindArgs(' WHERE tsEffective >= (%s::timestamptz - \'%s days\'::interval)\n'
151 ' AND tsEffective <= %s\n',
152 (tsNow, cDaysBack, tsNow));
153
154 # Special entry for the system log.
155 sQuery = '(\n'
156 sQuery += ' SELECT NULL AS uidAuthor,\n';
157 sQuery += ' tsCreated as tsEffective,\n';
158 sQuery += ' \'' + self.ksWhat_SystemLog + '\' AS sWhat,\n';
159 sQuery += ' NULL AS idWhat,\n';
160 sQuery += ' CONCAT(sEvent, \': \', sLogText) AS sDesc\n';
161 sQuery += ' FROM SystemLog\n';
162 sQuery += sWhereTime.replace('tsEffective', 'tsCreated');
163 sQuery += ' ORDER BY tsCreated DESC\n'
164 sQuery += ')'
165
166 for asEntry in self.kaasChangelogTables:
167 sQuery += ' UNION (\n'
168 sQuery += ' SELECT uidAuthor, tsEffective, \'' + asEntry[0] + '\', ' + asEntry[2] + ', \'\'\n';
169 sQuery += ' FROM ' + asEntry[1] + '\n'
170 sQuery += sWhereTime;
171 if asEntry[4] == self.ksTweak_NotNullAuthor or asEntry[4] == self.ksTweak_NotNullAuthorOrVSheriff:
172 sQuery += ' AND uidAuthor IS NOT NULL\n';
173 if asEntry[4] == self.ksTweak_NotNullAuthorOrVSheriff:
174 sQuery += ' AND uidAuthor <> %u\n' % (uidVSheriff,);
175 sQuery += ' ORDER BY tsEffective DESC\n'
176 sQuery += ')';
177 sQuery += ' ORDER BY 2 DESC\n';
178 sQuery += ' LIMIT %u OFFSET %u\n' % (cMaxRows, iStart, );
179
180
181 #
182 # Execute the query and construct the return data.
183 #
184 self._oDb.execute(sQuery);
185 aoRows = [];
186 for aoRow in self._oDb.fetchAll():
187 aoRows.append(SystemChangelogEntry(aoRow[1], oUserAccountLogic.cachedLookup(aoRow[0]),
188 aoRow[2], aoRow[3], aoRow[4]));
189
190
191 return aoRows;
192
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette