VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/core/testcaseargs.py@ 59687

最後變更 在這個檔案從59687是 56295,由 vboxsync 提交於 10 年 前

ValidationKit: Updated (C) year.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 14.2 KB
 
1# -*- coding: utf-8 -*-
2# $Id: testcaseargs.py 56295 2015-06-09 14:29:55Z vboxsync $
3
4"""
5Test Manager - Test Case Arguments Variations.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2012-2015 Oracle Corporation
11
12This file is part of VirtualBox Open Source Edition (OSE), as
13available from http://www.alldomusa.eu.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: 56295 $"
30
31
32# Standard python imports.
33import unittest;
34import sys;
35
36# Validation Kit imports.
37from common import utils;
38from testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase;
39from testmanager.core.testcase import TestCaseData, TestCaseDependencyLogic, TestCaseGlobalRsrcDepLogic;
40
41# Python 3 hacks:
42if sys.version_info[0] >= 3:
43 long = int; # pylint: disable=W0622,C0103
44
45
46class TestCaseArgsData(ModelDataBase):
47 """
48 Test case argument variation.
49 """
50
51 ksIdAttr = 'idTestCaseArgs';
52 ksIdGenAttr = 'idGenTestCaseArgs';
53
54 ksParam_idTestCase = 'TestCaseArgs_idTestCase';
55 ksParam_idTestCaseArgs = 'TestCaseArgs_idTestCaseArgs';
56 ksParam_tsEffective = 'TestCaseArgs_tsEffective';
57 ksParam_tsExpire = 'TestCaseArgs_tsExpire';
58 ksParam_uidAuthor = 'TestCaseArgs_uidAuthor';
59 ksParam_idGenTestCaseArgs = 'TestCaseArgs_idGenTestCaseArgs';
60 ksParam_sArgs = 'TestCaseArgs_sArgs';
61 ksParam_cSecTimeout = 'TestCaseArgs_cSecTimeout';
62 ksParam_sTestBoxReqExpr = 'TestCaseArgs_sTestBoxReqExpr';
63 ksParam_sBuildReqExpr = 'TestCaseArgs_sBuildReqExpr';
64 ksParam_cGangMembers = 'TestCaseArgs_cGangMembers';
65
66 kasAllowNullAttributes = [ 'idTestCase', 'idTestCaseArgs', 'tsEffective', 'tsExpire', 'uidAuthor', 'idGenTestCaseArgs',
67 'cSecTimeout', 'sTestBoxReqExpr', 'sBuildReqExpr', ];
68
69 def __init__(self):
70 ModelDataBase.__init__(self);
71
72 #
73 # Initialize with defaults.
74 # See the database for explanations of each of these fields.
75 #
76 self.idTestCase = None;
77 self.idTestCaseArgs = None;
78 self.tsEffective = None;
79 self.tsExpire = None;
80 self.uidAuthor = None;
81 self.idGenTestCaseArgs = None;
82 self.sArgs = '';
83 self.cSecTimeout = None;
84 self.sTestBoxReqExpr = None;
85 self.sBuildReqExpr = None;
86 self.cGangMembers = 1;
87
88 def initFromDbRow(self, aoRow):
89 """
90 Re-initializes the object from a SELECT * FROM TestCaseArgs row.
91 Returns self. Raises exception if aoRow is None.
92 """
93 if aoRow is None:
94 raise TMExceptionBase('TestBoxStatus not found.');
95
96 self.idTestCase = aoRow[0];
97 self.idTestCaseArgs = aoRow[1];
98 self.tsEffective = aoRow[2];
99 self.tsExpire = aoRow[3];
100 self.uidAuthor = aoRow[4];
101 self.idGenTestCaseArgs = aoRow[5];
102 self.sArgs = aoRow[6];
103 self.cSecTimeout = aoRow[7];
104 self.sTestBoxReqExpr = aoRow[8];
105 self.sBuildReqExpr = aoRow[9];
106 self.cGangMembers = aoRow[10];
107 return self;
108
109 def initFromDbWithId(self, oDb, idTestCaseArgs, tsNow = None, sPeriodBack = None):
110 """
111 Initialize from the database.
112 """
113 oDb.execute(self.formatSimpleNowAndPeriodQuery(oDb,
114 'SELECT *\n'
115 'FROM TestCaseArgs\n'
116 'WHERE idTestCaseArgs = %s\n'
117 , ( idTestCaseArgs,), tsNow, sPeriodBack));
118 aoRow = oDb.fetchOne()
119 if aoRow is None:
120 raise TMExceptionBase('idTestCaseArgs=%s not found (tsNow=%s sPeriodBack=%s)'
121 % (idTestCaseArgs, tsNow, sPeriodBack,));
122 return self.initFromDbRow(aoRow);
123
124 def initFromDbWithGenId(self, oDb, idGenTestCaseArgs):
125 """
126 Initialize from the database, given the generation ID of a row.
127 """
128 oDb.execute('SELECT * FROM TestCaseArgs WHERE idGenTestCaseArgs = %s', (idGenTestCaseArgs,));
129 return self.initFromDbRow(oDb.fetchOne());
130
131 def initFromValues(self, sArgs, cSecTimeout = None, sTestBoxReqExpr = None, sBuildReqExpr = None, # pylint: disable=R0913
132 cGangMembers = 1, idTestCase = None, idTestCaseArgs = None, tsEffective = None, tsExpire = None,
133 uidAuthor = None, idGenTestCaseArgs = None):
134 """
135 Reinitialize from values.
136 Returns self.
137 """
138 self.idTestCase = idTestCase;
139 self.idTestCaseArgs = idTestCaseArgs;
140 self.tsEffective = tsEffective;
141 self.tsExpire = tsExpire;
142 self.uidAuthor = uidAuthor;
143 self.idGenTestCaseArgs = idGenTestCaseArgs;
144 self.sArgs = sArgs;
145 self.cSecTimeout = utils.parseIntervalSeconds(cSecTimeout);
146 self.sTestBoxReqExpr = sTestBoxReqExpr;
147 self.sBuildReqExpr = sBuildReqExpr;
148 self.cGangMembers = cGangMembers;
149 return self;
150
151 def getAttributeParamNullValues(self, sAttr):
152 aoNilValues = ModelDataBase.getAttributeParamNullValues(self, sAttr);
153 if sAttr == 'cSecTimeout':
154 aoNilValues.insert(0, ''); # Prettier NULL value for cSecTimeout.
155 elif sAttr == 'sArgs':
156 aoNilValues = []; # No NULL value here, thank you.
157 return aoNilValues;
158
159 def _validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb):
160 if sAttr == 'cSecTimeout' and oValue not in aoNilValues: # Allow human readable interval formats.
161 return utils.parseIntervalSeconds(oValue);
162
163 (oValue, sError) = ModelDataBase._validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb);
164 if sError is None:
165 if sAttr == 'sTestBoxReqExpr':
166 sError = TestCaseData.validateTestBoxReqExpr(oValue);
167 elif sAttr == 'sBuildReqExpr':
168 sError = TestCaseData.validateBuildReqExpr(oValue);
169 return (oValue, sError);
170
171
172
173
174class TestCaseArgsDataEx(TestCaseArgsData):
175 """
176 Complete data set.
177 """
178
179 def __init__(self):
180 TestCaseArgsData.__init__(self);
181 self.oTestCase = None;
182 self.aoTestCasePreReqs = [];
183 self.aoGlobalRsrc = [];
184
185 def initFromDbRow(self, aoRow):
186 raise TMExceptionBase('Do not call me: %s' % (aoRow,))
187
188 def initFromDbWithId(self, oDb, idTestCaseArgs, tsNow = None, sPeriodBack = None):
189 _ = oDb; _ = idTestCaseArgs; _ = tsNow; _ = sPeriodBack;
190 raise Exception('Not supported.');
191
192 def initFromDbWithGenId(self, oDb, idGenTestCaseArgs):
193 _ = oDb; _ = idGenTestCaseArgs;
194 raise Exception('Use initFromDbWithGenIdEx...');
195
196 def initFromDbWithGenIdEx(self, oDb, idGenTestCaseArgs, tsConfigEff = None, tsRsrcEff = None):
197 """
198 Initialize from the database, given the ID of a row.
199 """
200
201 oDb.execute('SELECT *, CURRENT_TIMESTAMP FROM TestCaseArgs WHERE idGenTestCaseArgs = %s', (idGenTestCaseArgs,));
202 aoRow = oDb.fetchOne();
203 TestCaseArgsData.initFromDbRow(self, aoRow);
204
205 tsNow = aoRow[11];
206 if tsConfigEff is None: tsConfigEff = tsNow;
207 if tsRsrcEff is None: tsRsrcEff = tsNow;
208
209 self.oTestCase = TestCaseData().initFromDbWithId(oDb, self.idTestCase, tsConfigEff);
210 self.aoTestCasePreReqs = TestCaseDependencyLogic(oDb).getTestCaseDeps(self.idTestCase, tsConfigEff);
211 self.aoGlobalRsrc = TestCaseGlobalRsrcDepLogic(oDb).getTestCaseDeps(self.idTestCase, tsRsrcEff);
212
213 return self;
214
215 def convertFromParamNull(self):
216 raise TMExceptionBase('Not implemented');
217
218 def convertToParamNull(self):
219 raise TMExceptionBase('Not implemented');
220
221 def isEqual(self, oOther):
222 raise TMExceptionBase('Not implemented');
223
224 def matchesTestBoxProps(self, oTestBoxData):
225 """
226 Checks if the all of the testbox related test requirements matches the
227 given testbox.
228
229 Returns True or False according to the expression, None on exception or
230 non-boolean expression result.
231 """
232 return TestCaseData.matchesTestBoxPropsEx(oTestBoxData, self.oTestCase.sTestBoxReqExpr) \
233 and TestCaseData.matchesTestBoxPropsEx(oTestBoxData, self.sTestBoxReqExpr);
234
235 def matchesBuildProps(self, oBuildDataEx):
236 """
237 Checks if the all of the build related test requirements matches the
238 given build.
239
240 Returns True or False according to the expression, None on exception or
241 non-boolean expression result.
242 """
243 return TestCaseData.matchesBuildPropsEx(oBuildDataEx, self.oTestCase.sBuildReqExpr) \
244 and TestCaseData.matchesBuildPropsEx(oBuildDataEx, self.sBuildReqExpr);
245
246
247class TestCaseArgsLogic(ModelLogicBase):
248 """
249 TestCaseArgs database logic.
250 """
251
252 def __init__(self, oDb):
253 ModelLogicBase.__init__(self, oDb);
254
255
256 def areResourcesFree(self, oDataEx):
257 """
258 Checks if all global resources are currently still in existance and free.
259 Returns True/False. May raise exception on database error.
260 """
261
262 # Create a set of global resource IDs.
263 if len(oDataEx.aoGlobalRsrc) == 0:
264 return True;
265 asIdRsrcs = [str(oDep.idGlobalRsrc) for oDep, _ in oDataEx.aoGlobalRsrc];
266
267 # A record in the resource status table means it's allocated.
268 self._oDb.execute('SELECT COUNT(*)\n'
269 'FROM GlobalResourceStatuses\n'
270 'WHERE GlobalResourceStatuses.idGlobalRsrc IN (' + ', '.join(asIdRsrcs) + ')\n');
271 if self._oDb.fetchOne()[0] == 0:
272 # Check for disabled or deleted resources (we cannot allocate them).
273 self._oDb.execute('SELECT COUNT(*)\n'
274 'FROM GlobalResources\n'
275 'WHERE GlobalResources.idGlobalRsrc IN (' + ', '.join(asIdRsrcs) + ')\n'
276 ' AND GlobalResources.tsExpire = \'infinity\'::TIMESTAMP\n'
277 ' AND GlobalResources.fEnabled = TRUE\n');
278 if self._oDb.fetchOne()[0] == len(oDataEx.aoGlobalRsrc):
279 return True;
280 return False;
281
282 def getAll(self):
283 """Get list of objects of type TestCaseArgsData"""
284 self._oDb.execute('SELECT *\n'
285 'FROM TestCaseArgs\n'
286 'WHERE tsExpire = \'infinity\'::TIMESTAMP')
287 aaoRows = self._oDb.fetchAll()
288 aoRet = []
289 for aoRow in aaoRows:
290 aoRet.append(TestCaseArgsData().initFromDbRow(aoRow))
291
292 return aoRet
293
294 def getTestCaseArgs(self, idTestCase, tsNow = None, aiWhiteList = None):
295 """Get list of testcase's arguments variations"""
296 if aiWhiteList is None:
297 if tsNow is None:
298 self._oDb.execute('SELECT *\n'
299 'FROM TestCaseArgs\n'
300 'WHERE idTestCase = %s\n'
301 ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
302 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
303 , (idTestCase,));
304 else:
305 self._oDb.execute('SELECT *\n'
306 'FROM TestCaseArgs\n'
307 'WHERE idTestCase = %s\n'
308 ' AND tsExpire > %s\n'
309 ' AND tsEffective <= %s\n'
310 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
311 , (idTestCase, tsNow, tsNow));
312 else:
313 sWhiteList = ','.join((str(x) for x in aiWhiteList));
314 if tsNow is None:
315 self._oDb.execute('SELECT *\n'
316 'FROM TestCaseArgs\n'
317 'WHERE idTestCase = %s\n'
318 ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
319 ' AND idTestCaseArgs IN (' + sWhiteList + ')\n'
320 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
321 , (idTestCase,));
322 else:
323 self._oDb.execute('SELECT *\n'
324 'FROM TestCaseArgs\n'
325 'WHERE idTestCase = %s\n'
326 ' AND tsExpire > %s\n'
327 ' AND tsEffective <= %s\n'
328 ' AND idTestCaseArgs IN (' + sWhiteList + ')\n'
329 'ORDER BY TestCaseArgs.idTestCaseArgs\n'
330 , (idTestCase, tsNow, tsNow));
331
332 aaoRows = self._oDb.fetchAll()
333 aoRet = []
334 for aoRow in aaoRows:
335 aoRet.append(TestCaseArgsData().initFromDbRow(aoRow))
336
337 return aoRet
338
339 def addTestCaseArgs(self, oTestCaseArgsData):
340 """Add Test Case Args record into DB"""
341 pass
342
343
344#
345# Unit testing.
346#
347
348# pylint: disable=C0111
349class TestCaseArgsDataTestCase(ModelDataBaseTestCase):
350 def setUp(self):
351 self.aoSamples = [TestCaseArgsData(),];
352
353if __name__ == '__main__':
354 unittest.main();
355 # not reached.
356
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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