Changeset 61282 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- May 29, 2016 7:49:31 PM (9 years ago)
- Location:
- trunk/src/VBox/ValidationKit/testmanager
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testmanager/core/base.py
r61280 r61282 89 89 """ 90 90 Database row is in use and cannot be deleted. 91 Used by ModelLogicBase decendants. 92 """ 93 pass; 94 95 96 class TMInFligthCollision(TMExceptionBase): 97 """ 98 Database update failed because someone else had already made changes to 99 the data there. 91 100 Used by ModelLogicBase decendants. 92 101 """ … … 1159 1168 return self._oDb; 1160 1169 1170 def _dbRowsToModelDataList(self, oModelDataType, aaoRows = None): 1171 """ 1172 Helper for conerting a simple fetch into a list of ModelDataType python objects. 1173 1174 If aaoRows is None, we'll fetchAll from the database ourselves. 1175 1176 The oModelDataType must be a class derived from ModelDataBase and implement 1177 the initFormDbRow method. 1178 1179 Returns a list of oModelDataType instances. 1180 """ 1181 assert issubclass(oModelDataType, ModelDataBase); 1182 aoRet = []; 1183 if aaoRows is None: 1184 aaoRows = self._oDb.fetchAll(); 1185 for aoRow in aaoRows: 1186 aoRet.append(oModelDataType().initFromDbRow(aoRow)); 1187 return aoRet; 1188 1189 1161 1190 1162 1191 class AttributeChangeEntry(object): # pylint: disable=R0903 -
trunk/src/VBox/ValidationKit/testmanager/core/testbox.py
r61221 r61282 34 34 35 35 # Validation Kit imports. 36 from testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase, \36 from testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase, TMInFligthCollision, \ 37 37 TMInvalidData, TMTooManyRows, TMRowNotFound, ChangeLogEntry, AttributeChangeEntry; 38 38 … … 731 731 return idGenTestBox; 732 732 733 def setCommand(self, idTestBox, sOldCommand, sNewCommand, uidAuthor = None, fCommit = False): 733 def setCommand(self, idTestBox, sOldCommand, sNewCommand, uidAuthor = None, fCommit = False, sComment = None, 734 fNoRollbackOnInFlightCollision = False): 734 735 """ 735 736 Sets or resets the pending command on a testbox. 736 737 Returns (idGenTestBox, tsEffective) of the new row. 737 738 """ 739 _ = sComment; 738 740 try: 739 741 # Would be easier to do this using an insert or update hook, I think. Much easier. … … 745 747 'RETURNING tsExpire\n', 746 748 (idTestBox, sOldCommand,)); 749 if self._oDb.getRowCount() == 0: 750 raise TMInFligthCollision(); 747 751 tsEffective = self._oDb.fetchOne()[0]; 748 752 … … 825 829 if fCommit is True: 826 830 self._oDb.commit(); 831 832 except TMInFligthCollision: # This is pretty stupid, but don't want to touch testboxcontroller.py now. 833 if not fNoRollbackOnInFlightCollision: 834 self._oDb.rollback(); 835 raise; 827 836 except: 828 837 self._oDb.rollback(); … … 879 888 880 889 890 # 891 # The virtual test sheriff interface. 892 # 893 894 def hasTestBoxRecentlyBeenRebooted(self, idTestBox, cHoursBack = 2, tsNow = None): 895 """ 896 Checks if the testbox has been rebooted in the specified time period. 897 898 This does not include already pending reboots, though under some 899 circumstances it may. These being the test box entry being edited for 900 other reasons. 901 902 Returns True / False. 903 """ 904 if tsNow is None: 905 tsNow = self._oDb.getCurrentTimestamp(); 906 self._oDb.execute('SELECT COUNT(idTestBox)\n' 907 'FROM TestBoxes\n' 908 'WHERE idTestBox = %s\n' 909 ' AND tsExpire < %s\n' 910 ' AND tsExpire >= %s - interval \'%u hours\'\n' 911 ' AND enmPendingCmd IN (%s, %s)\n' 912 , ( idTestBox, tsNow, tsNow, cHoursBack, 913 TestBoxData.ksTestBoxCmd_Reboot, TestBoxData.ksTestBoxCmd_UpgradeAndReboot, )); 914 return self._oDb.fetchOne()[0] > 0; 915 916 917 def rebootTestBox(self, idTestBox, uidAuthor, sComment, sOldCommand = TestBoxData.ksTestBoxCmd_None, fCommit = False): 918 """ 919 Issues a reboot command for the given test box. 920 Return True on succes, False on in-flight collision. 921 May raise DB exception with rollback on other trouble. 922 """ 923 try: 924 self.setCommand(idTestBox, sOldCommand, TestBoxData.ksTestBoxCmd_Reboot, 925 uidAuthor = uidAuthor, fCommit = fCommit, sComment = sComment, 926 fNoRollbackOnInFlightCollision = True); 927 except TMInFligthCollision: 928 return False; 929 except: 930 raise; 931 return True; 932 933 934 def disableTestBox(self, idTestBox, uidAuthor, sComment, fCommit = False): 935 """ 936 Disables the given test box. 937 938 Raises exception on trouble, without rollback. 939 """ 940 oTestBox = TestBoxData().initFromDbWithId(self._oDb, idTestBox); 941 if oTestBox.fEnabled: 942 oTestBox.fEnabled = False; 943 if sComment is not None: 944 _ = sComment; # oTestBox.sComment = sComment; 945 self.editEntry(oTestBox, uidAuthor = uidAuthor, fCommit = fCommit); 946 return None; 947 948 881 949 # 882 950 # Unit testing. -
trunk/src/VBox/ValidationKit/testmanager/core/testresults.py
r61278 r61282 1857 1857 1858 1858 1859 1860 1859 1861 # 1860 1862 # Unit testing. -
trunk/src/VBox/ValidationKit/testmanager/core/testset.py
r61220 r61282 229 229 return oFile; 230 230 231 232 231 233 class TestSetLogic(ModelLogicBase): 232 234 """ … … 637 639 638 640 641 # 642 # The virtual test sheriff interface. 643 # 644 645 def fetchBadTestBoxIds(self, cHoursBack = 2, tsNow = None): 646 """ 647 Fetches a list of test box IDs which returned bad-testbox statuses in the 648 given period (tsDone). 649 """ 650 if tsNow is None: 651 tsNow = self._oDb.getCurrentTimestamp(); 652 self._oDb.execute('SELECT DISTINCT idTestBox\n' 653 'FROM TestSets\n' 654 'WHERE TestSets.enmStatus = \'bad-testbox\'\n' 655 ' AND tsDone <= %s\n' 656 ' AND tsDone > (%s - interval \'%s hours\')\n' 657 , ( tsNow, tsNow, cHoursBack,)); 658 return [aoRow[0] for aoRow in self._oDb.fetchAll()]; 659 660 def fetchResultForTestBox(self, idTestBox, cHoursBack = 2, tsNow = None): 661 """ 662 Fetches the TestSet rows for idTestBox for the given period (tsDone), w/o running ones. 663 664 Returns list of TestSetData sorted by tsDone in descending order. 665 """ 666 if tsNow is None: 667 tsNow = self._oDb.getCurrentTimestamp(); 668 self._oDb.execute('SELECT *\n' 669 'FROM TestSets\n' 670 'WHERE TestSets.idTestBox = %s\n' 671 ' AND tsDone IS NOT NULL\n' 672 ' AND tsDone <= %s\n' 673 ' AND tsDone > (%s - interval \'%s hours\')\n' 674 'ORDER by tsDone DESC\n' 675 , ( idTestBox, tsNow, tsNow, cHoursBack,)); 676 return self._dbRowsToModelDataList(TestSetData); 677 678 679 639 680 # 640 681 # Unit testing.
Note:
See TracChangeset
for help on using the changeset viewer.