VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/core/buildblacklist.py

最後變更 在這個檔案是 106061,由 vboxsync 提交於 6 月 前

Copyright year updates by scm.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 12.4 KB
 
1# -*- coding: utf-8 -*-
2# $Id: buildblacklist.py 106061 2024-09-16 14:03:52Z vboxsync $
3
4"""
5Test Manager - Builds Blacklist.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2012-2024 Oracle and/or its affiliates.
11
12This file is part of VirtualBox base platform packages, as
13available from https://www.alldomusa.eu.org.
14
15This program is free software; you can redistribute it and/or
16modify it under the terms of the GNU General Public License
17as published by the Free Software Foundation, in version 3 of the
18License.
19
20This program is distributed in the hope that it will be useful, but
21WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program; if not, see <https://www.gnu.org/licenses>.
27
28The contents of this file may alternatively be used under the terms
29of the Common Development and Distribution License Version 1.0
30(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
31in the VirtualBox distribution, in which case the provisions of the
32CDDL are applicable instead of those of the GPL.
33
34You may elect to license modified versions of this file under the
35terms and conditions of either the GPL or the CDDL or both.
36
37SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
38"""
39__version__ = "$Revision: 106061 $"
40
41
42# Validation Kit imports.
43from testmanager.core.base import ModelDataBase, ModelLogicBase, TMInvalidData, TMRowNotFound;
44
45
46class BuildBlacklistData(ModelDataBase):
47 """
48 Build Blacklist Data.
49 """
50
51 ksIdAttr = 'idBlacklisting';
52
53 ksParam_idBlacklisting = 'BuildBlacklist_idBlacklisting'
54 ksParam_tsEffective = 'BuildBlacklist_tsEffective'
55 ksParam_tsExpire = 'BuildBlacklist_tsExpire'
56 ksParam_uidAuthor = 'BuildBlacklist_uidAuthor'
57 ksParam_idFailureReason = 'BuildBlacklist_idFailureReason'
58 ksParam_sProduct = 'BuildBlacklist_sProduct'
59 ksParam_sBranch = 'BuildBlacklist_sBranch'
60 ksParam_asTypes = 'BuildBlacklist_asTypes'
61 ksParam_asOsArches = 'BuildBlacklist_asOsArches'
62 ksParam_iFirstRevision = 'BuildBlacklist_iFirstRevision'
63 ksParam_iLastRevision = 'BuildBlacklist_iLastRevision'
64
65 kasAllowNullAttributes = [ 'idBlacklisting',
66 'tsEffective',
67 'tsExpire',
68 'uidAuthor',
69 'asTypes',
70 'asOsArches' ];
71
72 def __init__(self):
73 ModelDataBase.__init__(self);
74
75 #
76 # Initialize with defaults.
77 # See the database for explanations of each of these fields.
78 #
79 self.idBlacklisting = None
80 self.tsEffective = None
81 self.tsExpire = None
82 self.uidAuthor = None
83 self.idFailureReason = None
84 self.sProduct = None
85 self.sBranch = None
86 self.asTypes = None
87 self.asOsArches = None
88 self.iFirstRevision = None
89 self.iLastRevision = None
90
91 def initFromDbRow(self, aoRow):
92 """
93 Re-initializes the data with a row from a SELECT * FROM BuildBlacklist.
94
95 Returns self. Raises exception if the row is None or otherwise invalid.
96 """
97
98 if aoRow is None:
99 raise TMRowNotFound('Build Blacklist item not found.')
100
101 self.idBlacklisting = aoRow[0]
102 self.tsEffective = aoRow[1]
103 self.tsExpire = aoRow[2]
104 self.uidAuthor = aoRow[3]
105 self.idFailureReason = aoRow[4]
106 self.sProduct = aoRow[5]
107 self.sBranch = aoRow[6]
108 self.asTypes = aoRow[7]
109 self.asOsArches = aoRow[8]
110 self.iFirstRevision = aoRow[9]
111 self.iLastRevision = aoRow[10]
112
113 return self;
114
115 def initFromDbWithId(self, oDb, idBlacklisting, tsNow = None, sPeriodBack = None):
116 """
117 Initialize the object from the database.
118 """
119 oDb.execute(self.formatSimpleNowAndPeriodQuery(oDb,
120 'SELECT *\n'
121 'FROM BuildBlacklist\n'
122 'WHERE idBlacklisting = %s\n'
123 , ( idBlacklisting,), tsNow, sPeriodBack));
124 aoRow = oDb.fetchOne()
125 if aoRow is None:
126 raise TMRowNotFound('idBlacklisting=%s not found (tsNow=%s sPeriodBack=%s)'
127 % (idBlacklisting, tsNow, sPeriodBack,));
128 return self.initFromDbRow(aoRow);
129
130
131class BuildBlacklistLogic(ModelLogicBase): # pylint: disable=too-few-public-methods
132 """
133 Build Back List logic.
134 """
135
136 def __init__(self, oDb):
137 ModelLogicBase.__init__(self, oDb)
138 self.dCache = None;
139
140 def fetchForListing(self, iStart, cMaxRows, tsNow, aiSortColumns = None):
141 """
142 Fetches Build Blacklist records.
143
144 Returns an array (list) of BuildBlacklistData items, empty list if none.
145 Raises exception on error.
146 """
147 _ = aiSortColumns;
148
149 if tsNow is None:
150 self._oDb.execute('SELECT *\n'
151 'FROM BuildBlacklist\n'
152 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
153 'ORDER BY idBlacklisting DESC\n'
154 'LIMIT %s OFFSET %s\n'
155 , (cMaxRows, iStart,));
156 else:
157 self._oDb.execute('SELECT *\n'
158 'FROM BuildBlacklist\n'
159 'WHERE tsExpire > %s\n'
160 ' AND tsEffective <= %s\n'
161 'ORDER BY idBlacklisting DESC\n'
162 'LIMIT %s OFFSET %s\n'
163 , (tsNow, tsNow, cMaxRows, iStart,));
164
165 aoRows = []
166 for aoRow in self._oDb.fetchAll():
167 aoRows.append(BuildBlacklistData().initFromDbRow(aoRow))
168 return aoRows
169
170 def addEntry(self, oData, uidAuthor, fCommit = False):
171 """
172 Adds a blacklisting to the database.
173 """
174 self._oDb.execute('INSERT INTO BuildBlacklist (\n'
175 ' uidAuthor,\n'
176 ' idFailureReason,\n'
177 ' sProduct,\n'
178 ' sBranch,\n'
179 ' asTypes,\n'
180 ' asOsArches,\n'
181 ' iFirstRevision,\n'
182 ' iLastRevision)\n'
183 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)'
184 , ( uidAuthor,
185 oData.idFailureReason,
186 oData.sProduct,
187 oData.sBranch,
188 oData.asTypes,
189 oData.asOsArches,
190 oData.iFirstRevision,
191 oData.iLastRevision,) );
192 self._oDb.maybeCommit(fCommit);
193 return True
194
195 def editEntry(self, oData, uidAuthor, fCommit = False):
196 """
197 Modifies a blacklisting.
198 """
199
200 #
201 # Validate inputs and read in the old(/current) data.
202 #
203 assert isinstance(oData, BuildBlacklistData);
204 dErrors = oData.validateAndConvert(self._oDb, oData.ksValidateFor_Edit);
205 if dErrors:
206 raise TMInvalidData('editEntry invalid input: %s' % (dErrors,));
207
208 oOldData = BuildBlacklistData().initFromDbWithId(self._oDb, oData.idBlacklisting);
209
210 #
211 # Update the data that needs updating.
212 #
213 if not oData.isEqualEx(oOldData, [ 'tsEffective', 'tsExpire', 'uidAuthor', ]):
214 self._historizeEntry(oData.idBlacklisting, None);
215 self._readdEntry(uidAuthor, oData, None);
216 self._oDb.maybeCommit(fCommit);
217 return True;
218
219
220 def removeEntry(self, uidAuthor, idBlacklisting, fCascade = False, fCommit = False):
221 """
222 Deletes a test group.
223 """
224 _ = fCascade; # Not applicable.
225
226 oData = BuildBlacklistData().initFromDbWithId(self._oDb, idBlacklisting);
227
228 (tsCur, tsCurMinusOne) = self._oDb.getCurrentTimestamps();
229 if oData.tsEffective not in (tsCur, tsCurMinusOne):
230 self._historizeEntry(idBlacklisting, tsCurMinusOne);
231 self._readdEntry(uidAuthor, oData, tsCurMinusOne);
232 self._historizeEntry(idBlacklisting);
233 self._oDb.execute('UPDATE BuildBlacklist\n'
234 'SET tsExpire = CURRENT_TIMESTAMP\n'
235 'WHERE idBlacklisting = %s\n'
236 ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
237 , (idBlacklisting,));
238 self._oDb.maybeCommit(fCommit);
239 return True;
240
241
242 def cachedLookup(self, idBlacklisting):
243 """
244 Looks up the most recent BuildBlacklistData object for idBlacklisting
245 via an object cache.
246
247 Returns a shared BuildBlacklistData object. None if not found.
248 Raises exception on DB error.
249 """
250 if self.dCache is None:
251 self.dCache = self._oDb.getCache('BuildBlacklistData');
252 oEntry = self.dCache.get(idBlacklisting, None);
253 if oEntry is None:
254 self._oDb.execute('SELECT *\n'
255 'FROM BuildBlacklist\n'
256 'WHERE idBlacklisting = %s\n'
257 ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
258 , (idBlacklisting, ));
259 if self._oDb.getRowCount() == 0:
260 # Maybe it was deleted, try get the last entry.
261 self._oDb.execute('SELECT *\n'
262 'FROM BuildBlacklist\n'
263 'WHERE idBlacklisting = %s\n'
264 'ORDER BY tsExpire DESC\n'
265 'LIMIT 1\n'
266 , (idBlacklisting, ));
267 elif self._oDb.getRowCount() > 1:
268 raise self._oDb.integrityException('%s infinity rows for %s' % (self._oDb.getRowCount(), idBlacklisting));
269
270 if self._oDb.getRowCount() == 1:
271 aaoRow = self._oDb.fetchOne();
272 oEntry = BuildBlacklistData();
273 oEntry.initFromDbRow(aaoRow);
274 self.dCache[idBlacklisting] = oEntry;
275 return oEntry;
276
277
278 #
279 # Helpers.
280 #
281
282 def _historizeEntry(self, idBlacklisting, tsExpire = None):
283 """
284 Historizes the current entry for the given backlisting.
285 """
286 if tsExpire is None:
287 tsExpire = self._oDb.getCurrentTimestamp();
288 self._oDb.execute('UPDATE BuildBlacklist\n'
289 'SET tsExpire = %s\n'
290 'WHERE idBlacklisting = %s\n'
291 ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
292 , ( tsExpire, idBlacklisting, ));
293 return True;
294
295 def _readdEntry(self, uidAuthor, oData, tsEffective = None):
296 """
297 Re-adds the BuildBlacklist entry. Used by editEntry and removeEntry.
298 """
299 if tsEffective is None:
300 tsEffective = self._oDb.getCurrentTimestamp();
301 self._oDb.execute('INSERT INTO BuildBlacklist (\n'
302 ' uidAuthor,\n'
303 ' tsEffective,\n'
304 ' idBlacklisting,\n'
305 ' idFailureReason,\n'
306 ' sProduct,\n'
307 ' sBranch,\n'
308 ' asTypes,\n'
309 ' asOsArches,\n'
310 ' iFirstRevision,\n'
311 ' iLastRevision)\n'
312 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n'
313 , ( uidAuthor,
314 tsEffective,
315 oData.idBlacklisting,
316 oData.idFailureReason,
317 oData.sProduct,
318 oData.sBranch,
319 oData.asTypes,
320 oData.asOsArches,
321 oData.iFirstRevision,
322 oData.iLastRevision,) );
323 return True;
324
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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