VirtualBox

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

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

testmanager: More details in the system wide changelog.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: systemchangelog.py 65040 2016-12-31 02:29:50Z 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: 65040 $"
30
31
32# Validation Kit imports.
33from testmanager.core.base import ModelLogicBase;
34from testmanager.core.useraccount import UserAccountLogic;
35from testmanager.core.systemlog import SystemLogData;
36
37
38class SystemChangelogEntry(object): # pylint: disable=R0902
39 """
40 System changelog entry.
41 """
42
43 def __init__(self, tsEffective, oAuthor, sEvent, idWhat, sDesc):
44 self.tsEffective = tsEffective;
45 self.oAuthor = oAuthor;
46 self.sEvent = sEvent;
47 self.idWhat = idWhat;
48 self.sDesc = sDesc;
49
50
51class SystemChangelogLogic(ModelLogicBase):
52 """
53 System changelog compilation logic.
54 """
55
56 ## @name What kind of change.
57 ## @{
58 ksWhat_TestBox = 'chlog::TestBox';
59 ksWhat_TestCase = 'chlog::TestCase';
60 ksWhat_Blacklisting = 'chlog::Blacklisting';
61 ksWhat_Build = 'chlog::Build';
62 ksWhat_BuildSource = 'chlog::BuildSource';
63 ksWhat_FailureCategory = 'chlog::FailureCategory';
64 ksWhat_FailureReason = 'chlog::FailureReason';
65 ksWhat_GlobalRsrc = 'chlog::GlobalRsrc';
66 ksWhat_SchedGroup = 'chlog::SchedGroup';
67 ksWhat_TestGroup = 'chlog::TestGroup';
68 ksWhat_User = 'chlog::User';
69 ksWhat_TestResult = 'chlog::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_TestGroup: ( 'TestGroupes', 'idTestGroup', None, ),
87 ksWhat_User: ( 'Users', 'idUser', None, ),
88 ksWhat_TestResult: ( 'TestResults', 'idTestResult', None, ),
89 };
90 for sEvent in SystemLogData.kasEvents:
91 kdWhatToTable[sEvent] = ( 'SystemLog', 'tsCreated', ksClue_TimestampId, );
92
93 ## @todo move to config.py?
94 ksVSheriffLoginName = 'vsheriff';
95
96
97 ## @name for kaasChangelogTables
98 ## @internal
99 ## @{
100 ksTweak_None = '';
101 ksTweak_NotNullAuthor = 'uidAuthorNotNull';
102 ksTweak_NotNullAuthorOrVSheriff = 'uidAuthorNotNullOrVSheriff';
103 ## @}
104
105 ## @internal
106 kaasChangelogTables = (
107 # [0]: change name, [1]: Table name, [2]: key column, [3]:later, [4]: tweak
108 ( ksWhat_TestBox, 'TestBoxes', 'idTestBox', None, ksTweak_NotNullAuthor, ),
109 ( ksWhat_TestBox, 'TestBoxesInSchedGroups', 'idTestBox', None, ksTweak_None, ),
110 ( ksWhat_TestCase, 'TestCases', 'idTestCase', None, ksTweak_None, ),
111 ( ksWhat_TestCase, 'TestCaseArgs', 'idTestCase', None, ksTweak_None, ),
112 ( ksWhat_TestCase, 'TestCaseDeps', 'idTestCase', None, ksTweak_None, ),
113 ( ksWhat_TestCase, 'TestCaseGlobalRsrcDeps', 'idTestCase', None, ksTweak_None, ),
114 ( ksWhat_Blacklisting, 'BuildBlacklist', 'idBlacklisting', None, ksTweak_None, ),
115 ( ksWhat_Build, 'Builds', 'idBuild', None, ksTweak_NotNullAuthor, ),
116 ( ksWhat_BuildSource, 'BuildSources', 'idBuildSrc', None, ksTweak_None, ),
117 ( ksWhat_FailureCategory, 'FailureCategories', 'idFailureCategory', None, ksTweak_None, ),
118 ( ksWhat_FailureReason, 'FailureReasons', 'idFailureReason', None, ksTweak_None, ),
119 ( ksWhat_GlobalRsrc, 'GlobalResources', 'idGlobalRsrc', None, ksTweak_None, ),
120 ( ksWhat_SchedGroup, 'SchedGroups', 'idSchedGroup', None, ksTweak_None, ),
121 ( ksWhat_SchedGroup, 'SchedGroupMembers', 'idSchedGroup', None, ksTweak_None, ),
122 ( ksWhat_TestGroup, 'TestGroups', 'idTestGroup', None, ksTweak_None, ),
123 ( ksWhat_TestGroup, 'TestGroupMembers', 'idTestGroup', None, ksTweak_None, ),
124 ( ksWhat_User, 'Users', 'uid', None, ksTweak_None, ),
125 ( ksWhat_TestResult, 'TestResultFailures', 'idTestResult', None, ksTweak_NotNullAuthorOrVSheriff, ),
126 );
127
128 def __init__(self, oDb):
129 ModelLogicBase.__init__(self, oDb);
130
131
132 def fetchForListingEx(self, iStart, cMaxRows, tsNow, cDaysBack):
133 """
134 Fetches SystemLog entries.
135
136 Returns an array (list) of SystemLogData items, empty list if none.
137 Raises exception on error.
138 """
139
140 #
141 # Construct the query.
142 #
143 oUserAccountLogic = UserAccountLogic(self._oDb);
144 oVSheriff = oUserAccountLogic.tryFetchAccountByLoginName(self.ksVSheriffLoginName);
145 uidVSheriff = oVSheriff.uid if oVSheriff is not None else -1;
146
147 if tsNow is None:
148 sWhereTime = self._oDb.formatBindArgs(' WHERE tsEffective >= CURRENT_TIMESTAMP - \'%s days\'::interval\n',
149 (cDaysBack,));
150 else:
151 sWhereTime = self._oDb.formatBindArgs(' WHERE tsEffective >= (%s::timestamptz - \'%s days\'::interval)\n'
152 ' AND tsEffective <= %s\n',
153 (tsNow, cDaysBack, tsNow));
154
155 # Special entry for the system log.
156 sQuery = '(\n'
157 sQuery += ' SELECT NULL AS uidAuthor,\n';
158 sQuery += ' tsCreated AS tsEffective,\n';
159 sQuery += ' sEvent AS sEvent,\n';
160 sQuery += ' NULL AS idWhat,\n';
161 sQuery += ' sLogText AS sDesc\n';
162 sQuery += ' FROM SystemLog\n';
163 sQuery += sWhereTime.replace('tsEffective', 'tsCreated');
164 sQuery += ' ORDER BY tsCreated DESC\n'
165 sQuery += ')'
166
167 for asEntry in self.kaasChangelogTables:
168 sQuery += ' UNION (\n'
169 sQuery += ' SELECT uidAuthor, tsEffective, \'' + asEntry[0] + '\', ' + asEntry[2] + ', \'\'\n';
170 sQuery += ' FROM ' + asEntry[1] + '\n'
171 sQuery += sWhereTime;
172 if asEntry[4] == self.ksTweak_NotNullAuthor or asEntry[4] == self.ksTweak_NotNullAuthorOrVSheriff:
173 sQuery += ' AND uidAuthor IS NOT NULL\n';
174 if asEntry[4] == self.ksTweak_NotNullAuthorOrVSheriff:
175 sQuery += ' AND uidAuthor <> %u\n' % (uidVSheriff,);
176 sQuery += ' ORDER BY tsEffective DESC\n'
177 sQuery += ')';
178 sQuery += ' ORDER BY 2 DESC\n';
179 sQuery += ' LIMIT %u OFFSET %u\n' % (cMaxRows, iStart, );
180
181
182 #
183 # Execute the query and construct the return data.
184 #
185 self._oDb.execute(sQuery);
186 aoRows = [];
187 for aoRow in self._oDb.fetchAll():
188 aoRows.append(SystemChangelogEntry(aoRow[1], oUserAccountLogic.cachedLookup(aoRow[0]),
189 aoRow[2], aoRow[3], aoRow[4]));
190
191
192 return aoRows;
193
Note: See TracBrowser for help on using the repository browser.

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