def _AddAdditionalDetailsToBug(self, bug_id, alerts): """Adds additional data to the bug as a comment. Adds the link to /group_report and bug_id as well as the names of the bots that triggered the alerts, and a milestone label. Args: bug_id: Bug ID number. alerts: The Alert entities being associated with this bug. """ base_url = '%s/group_report' % _GetServerURL() bug_page_url = '%s?bug_id=%s' % (base_url, bug_id) alerts_url = '%s?keys=%s' % (base_url, _UrlsafeKeys(alerts)) comment = 'All graphs for this bug:\n %s\n\n' % bug_page_url comment += 'Original alerts at time of bug-filing:\n %s\n' % alerts_url bot_names = alert.GetBotNamesFromAlerts(alerts) if bot_names: comment += '\n\nBot(s) for this bug\'s original alert(s):\n\n' comment += '\n'.join(sorted(bot_names)) else: comment += '\nCould not extract bot names from the list of alerts.' http = oauth2_decorator.decorator.http() service = issue_tracker_service.IssueTrackerService(http=http) service.AddBugComment(bug_id, comment)
def testGetBotNamesFromAlerts_RemovesDuplicates(self): testing_common.AddTests(['SuperGPU'], ['Bot1'], {'foo': {'bar': {}}}) anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot1/foo/bar')).put() anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot1/foo/bar')).put() anomalies = anomaly.Anomaly.query().fetch() bot_names = alert.GetBotNamesFromAlerts(anomalies) self.assertEqual(2, len(anomalies)) self.assertEqual(1, len(bot_names))
def testGetBotNamesFromAlerts_ReturnsBotNames(self): testing_common.AddTests(['SuperGPU'], ['Bot1', 'Bot2', 'Bot3'], {'foo': { 'bar': {} }}) anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot1/foo/bar')).put() anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot2/foo/bar')).put() anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot3/foo/bar')).put() anomalies = anomaly.Anomaly.query().fetch() bot_names = alert.GetBotNamesFromAlerts(anomalies) self.assertEqual({'Bot1', 'Bot2', 'Bot3'}, bot_names)
def testGetBotNamesFromAlerts_TypicalCase(self): """Tests that we can get the name of the bots for a list of anomalies.""" testing_common.AddTests(['SuperGPU'], ['Bot1', 'Bot2', 'Bot3'], {'foo': { 'bar': {} }}) anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot1/foo/bar')).put() anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot2/foo/bar')).put() anomaly.Anomaly(test=utils.TestKey('SuperGPU/Bot3/foo/bar')).put() anomalies = anomaly.Anomaly.query().fetch() bot_names = alert.GetBotNamesFromAlerts(anomalies) self.assertEqual({'Bot1', 'Bot2', 'Bot3'}, bot_names)
def _AdditionalDetails(bug_id, alerts): """Returns a message with additional information to add to a bug.""" base_url = '%s/group_report' % _GetServerURL() bug_page_url = '%s?bug_id=%s' % (base_url, bug_id) alerts_url = '%s?keys=%s' % (base_url, _UrlsafeKeys(alerts)) comment = 'All graphs for this bug:\n %s\n\n' % bug_page_url comment += 'Original alerts at time of bug-filing:\n %s\n' % alerts_url bot_names = alert.GetBotNamesFromAlerts(alerts) if bot_names: comment += '\n\nBot(s) for this bug\'s original alert(s):\n\n' comment += '\n'.join(sorted(bot_names)) else: comment += '\nCould not extract bot names from the list of alerts.' return comment
def testGetBotNamesFromAlerts_EmptyList_ReturnsEmptySet(self): self.assertEqual(set(), alert.GetBotNamesFromAlerts([]))
def testGetBotNamesFromAlerts_EmptyList_ReturnsEmptySet(self): """Tests that an empty set is returned when nothing is passed.""" self.assertEqual(set(), alert.GetBotNamesFromAlerts([]))