コード例 #1
0
 def testValidCache(self):
   """Test valid cache."""
   osutils.WriteFile(self.token_cache_file, json.dumps(self.FAKE_CACHE))
   msg = alerts.CreateEmail('fake subject', 'fake@localhost', 'fake msg')
   server = alerts.GmailServer(token_cache_file=self.token_cache_file)
   ret = server.Send(msg)
   self.assertTrue(ret)
コード例 #2
0
 def testCacheNotExistsTokenNotExists(self):
   """Test cache not exists, token not exists."""
   msg = alerts.CreateEmail('fake subject', 'fake@localhost', 'fake msg')
   server = alerts.GmailServer(token_cache_file=self.token_cache_file,
                               token_json_file=self.token_json_file)
   ret = server.Send(msg)
   self.assertFalse(ret)
コード例 #3
0
 def testGmail(self):
     """Gmail sanity check."""
     send_mock = self.PatchObject(alerts.GmailServer, 'Send')
     alerts.SendEmailLog(
         'mail',
         'root@localhost',
         server=alerts.GmailServer(token_cache_file='fakefile'))
     self.assertEqual(send_mock.call_count, 1)
コード例 #4
0
 def testCacheNotExistsTokenExists(self):
   """Test cache not exists, token exists"""
   osutils.WriteFile(self.token_json_file, json.dumps(self.FAKE_TOKEN_JSON))
   msg = alerts.CreateEmail('fake subject', 'fake@localhost', 'fake msg')
   server = alerts.GmailServer(token_cache_file=self.token_cache_file,
                               token_json_file=self.token_json_file)
   ret = server.Send(msg)
   self.assertTrue(ret)
   # Cache file should be auto-generated.
   self.assertExists(self.token_cache_file)
コード例 #5
0
 def testCacheInvalidTokenNotExists(self):
   """Test cache exists but invalid, token not exists."""
   invalid_cache = self.FAKE_CACHE.copy()
   invalid_cache['invalid'] = True
   osutils.WriteFile(self.token_cache_file, json.dumps(invalid_cache))
   msg = alerts.CreateEmail('fake subject', 'fake@localhost', 'fake msg')
   server = alerts.GmailServer(token_cache_file=self.token_cache_file,
                               token_json_file=self.token_json_file)
   ret = server.Send(msg)
   self.assertFalse(ret)
   invalid_cache = json.loads(osutils.ReadFile(self.token_cache_file))
   self.assertTrue(invalid_cache['invalid'])
コード例 #6
0
ファイル: tree_status.py プロジェクト: sjg20/chromite
def SendHealthAlert(builder_run, subject, body, extra_fields=None):
    """Send a health alert.

  Health alerts are only sent for regular buildbots and Pre-CQ buildbots.

  Args:
    builder_run: BuilderRun for the main cbuildbot run.
    subject: The subject of the health alert email.
    body: The body of the health alert email.
    extra_fields: (optional) A dictionary of additional message header fields
                  to be added to the message. Custom field names should begin
                  with the prefix 'X-'.
  """
    if builder_run.InEmailReportingEnvironment():
        server = alerts.GmailServer(
            token_cache_file=constants.GMAIL_TOKEN_CACHE_FILE,
            token_json_file=constants.GMAIL_TOKEN_JSON_FILE)
        alerts.SendEmail(subject,
                         GetHealthAlertRecipients(builder_run),
                         server=server,
                         message=body,
                         extra_fields=extra_fields)