Ejemplo n.º 1
0
    def testMostSpecificMatchingPattern_Duplicate(self):
        test_key = utils.TestKey('Does/Not/Match/Something')

        result = utils.MostSpecificMatchingPattern(test_key,
                                                   [('Does/Not/Match/*', 1),
                                                    ('Does/Not/Match/*', 2)])
        self.assertEqual(1, result)
Ejemplo n.º 2
0
    def _pre_put_hook(self):
        """This method is called before a TestMetadata is put into the datastore.

    Here, we check the key to make sure it is valid and check the sheriffs and
    anomaly configs to make sure they are current. We also update the monitored
    list of the test suite.
    """
        # Check to make sure the key is valid.
        # TestMetadata should not be an ancestor, so key.pairs() should have length
        # of 1. The id should have at least 3 slashes to represent master/bot/suite.
        assert len(self.key.pairs()) == 1
        path_parts = self.key.id().split('/')
        assert len(path_parts) >= 3

        # Set the sheriff to the first sheriff (alphabetically by sheriff name)
        # that has a test pattern that matches this test.
        old_sheriff = self.sheriff
        self.sheriff = None
        for sheriff_entity in sheriff_module.Sheriff.query().fetch():
            for pattern in sheriff_entity.patterns:
                if utils.TestMatchesPattern(self, pattern):
                    self.sheriff = sheriff_entity.key
            if self.sheriff:
                break

        # TODO(simonhatch): Remove this logging. Trying to track down alerts being
        # generated for tests that seemingly have no sheriff.
        # https://github.com/catapult-project/catapult/issues/3903
        if old_sheriff != self.sheriff:
            logging.info('Sheriff Modified')
            logging.info(' Test: %s', self.test_path)
            logging.info(' Old Sheriff: %s', old_sheriff)
            logging.info(' New Sheriff: %s', self.sheriff)

        # If this test is monitored, add it to the monitored list of its test suite.
        # A test is be monitored iff it has a sheriff, and monitored tests are
        # tracked in the monitored list of a test suite TestMetadata entity.
        test_suite = ndb.Key('TestMetadata', '/'.join(path_parts[:3])).get()
        if self.sheriff:
            if test_suite and self.key not in test_suite.monitored:
                test_suite.monitored.append(self.key)
                test_suite.put()
        elif test_suite and self.key in test_suite.monitored:
            test_suite.monitored.remove(self.key)
            test_suite.put()

        # Set the anomaly threshold config to the first one that has a test pattern
        # that matches this test, if there is one. Anomaly configs with a pattern
        # that more specifically matches the test are given higher priority.
        # ie. */*/*/foo is chosen over */*/*/*
        self.overridden_anomaly_config = None
        anomaly_configs = anomaly_config.AnomalyConfig.query().fetch()
        anomaly_data_list = []
        for e in anomaly_configs:
            for p in e.patterns:
                anomaly_data_list.append((p, e))
        anomaly_config_to_use = utils.MostSpecificMatchingPattern(
            self, anomaly_data_list)
        if anomaly_config_to_use:
            self.overridden_anomaly_config = anomaly_config_to_use.key
Ejemplo n.º 3
0
  def testMostSpecificMatchingPattern_TopLevelSpecificOverLowerSpecific(self):
    test_key = utils.TestKey('M/B/S/Total')

    result = utils.MostSpecificMatchingPattern(test_key, [('*/*/S/*', 1),
                                                          ('*/*/*/Total', 2),
                                                          ('*/*/*/Foo', 3)])
    self.assertEqual(2, result)
Ejemplo n.º 4
0
  def testMostSpecificMatchingPattern_PartialVsGeneral(self):
    test_key = utils.TestKey('M/B/S/Total')

    result = utils.MostSpecificMatchingPattern(test_key, [('*/*/*/*', 1),
                                                          ('*/*/*/To*al', 2),
                                                          ('*/*/*/Foo', 3)])
    self.assertEqual(2, result)
Ejemplo n.º 5
0
    def UpdateSheriffAsync(self, anomaly_configs=None):
        """This method is called before a TestMetadata is put into the datastore.

    Here, we check the key to make sure it is valid and check the sheriffs and
    anomaly configs to make sure they are current.
    """
        # Check to make sure the key is valid.
        # TestMetadata should not be an ancestor, so key.pairs() should have length
        # of 1. The id should have at least 3 slashes to represent master/bot/suite.
        assert len(self.key.pairs()) == 1
        path_parts = self.key.id().split('/')
        assert len(path_parts) >= 3

        # Set the anomaly threshold config to the first one that has a test pattern
        # that matches this test, if there is one. Anomaly configs with a pattern
        # that more specifically matches the test are given higher priority.
        # ie. */*/*/foo is chosen over */*/*/*
        old_anomaly_config = self.overridden_anomaly_config
        self.overridden_anomaly_config = None
        if not anomaly_configs:
            anomaly_configs = yield anomaly_config.AnomalyConfig.query(
            ).fetch_async()
        anomaly_data_list = []
        for e in anomaly_configs:
            for p in e.patterns:
                anomaly_data_list.append((p, e))
        anomaly_config_to_use = utils.MostSpecificMatchingPattern(
            self, anomaly_data_list)
        if anomaly_config_to_use:
            self.overridden_anomaly_config = anomaly_config_to_use.key

        raise ndb.Return(self.overridden_anomaly_config != old_anomaly_config)
Ejemplo n.º 6
0
    def _pre_put_hook(self):
        """This method is called before a TestMetadata is put into the datastore.

    Here, we check the key to make sure it is valid and check the sheriffs and
    anomaly configs to make sure they are current.
    """
        # Check to make sure the key is valid.
        # TestMetadata should not be an ancestor, so key.pairs() should have length
        # of 1. The id should have at least 3 slashes to represent master/bot/suite.
        assert len(self.key.pairs()) == 1
        path_parts = self.key.id().split('/')
        assert len(path_parts) >= 3

        # Set the sheriff to the first sheriff (alphabetically by sheriff name)
        # that has a test pattern that matches this test.
        self.sheriff = None
        for sheriff_entity in sheriff_module.Sheriff.query().fetch():
            for pattern in sheriff_entity.patterns:
                if utils.TestMatchesPattern(self, pattern):
                    self.sheriff = sheriff_entity.key
            if self.sheriff:
                break

        # Set the anomaly threshold config to the first one that has a test pattern
        # that matches this test, if there is one. Anomaly configs with a pattern
        # that more specifically matches the test are given higher priority.
        # ie. */*/*/foo is chosen over */*/*/*
        self.overridden_anomaly_config = None
        anomaly_configs = anomaly_config.AnomalyConfig.query().fetch()
        anomaly_data_list = []
        for e in anomaly_configs:
            for p in e.patterns:
                anomaly_data_list.append((p, e))
        anomaly_config_to_use = utils.MostSpecificMatchingPattern(
            self, anomaly_data_list)
        if anomaly_config_to_use:
            self.overridden_anomaly_config = anomaly_config_to_use.key