VirtualBox

Changeset 61282 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
May 29, 2016 7:49:31 PM (9 years ago)
Author:
vboxsync
Message:

virtual test sheriff: Kick-off and the bad-testbox rebooting and disabling. (completely untested)

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  
    8989    """
    9090    Database row is in use and cannot be deleted.
     91    Used by ModelLogicBase decendants.
     92    """
     93    pass;
     94
     95
     96class TMInFligthCollision(TMExceptionBase):
     97    """
     98    Database update failed because someone else had already made changes to
     99    the data there.
    91100    Used by ModelLogicBase decendants.
    92101    """
     
    11591168        return self._oDb;
    11601169
     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
    11611190
    11621191class AttributeChangeEntry(object): # pylint: disable=R0903
  • trunk/src/VBox/ValidationKit/testmanager/core/testbox.py

    r61221 r61282  
    3434
    3535# Validation Kit imports.
    36 from testmanager.core.base  import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase, \
     36from testmanager.core.base  import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase, TMInFligthCollision, \
    3737                                   TMInvalidData, TMTooManyRows, TMRowNotFound, ChangeLogEntry, AttributeChangeEntry;
    3838
     
    731731        return idGenTestBox;
    732732
    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):
    734735        """
    735736        Sets or resets the pending command on a testbox.
    736737        Returns (idGenTestBox, tsEffective) of the new row.
    737738        """
     739        _ = sComment;
    738740        try:
    739741            # Would be easier to do this using an insert or update hook, I think. Much easier.
     
    745747                              'RETURNING tsExpire\n',
    746748                              (idTestBox, sOldCommand,));
     749            if self._oDb.getRowCount() == 0:
     750                raise TMInFligthCollision();
    747751            tsEffective = self._oDb.fetchOne()[0];
    748752
     
    825829            if fCommit is True:
    826830                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;
    827836        except:
    828837            self._oDb.rollback();
     
    879888
    880889
     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
    881949#
    882950# Unit testing.
  • trunk/src/VBox/ValidationKit/testmanager/core/testresults.py

    r61278 r61282  
    18571857
    18581858
     1859
     1860
    18591861#
    18601862# Unit testing.
  • trunk/src/VBox/ValidationKit/testmanager/core/testset.py

    r61220 r61282  
    229229        return oFile;
    230230
     231
     232
    231233class TestSetLogic(ModelLogicBase):
    232234    """
     
    637639
    638640
     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
    639680#
    640681# Unit testing.
Note: See TracChangeset for help on using the changeset viewer.

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