[autotest] test failure send email via a different gmail account
Test failures notification emails sometimes causing quota issues
when a huge amount of notifications are sent out around the same time.
Move it to a different gmail account to gurantee that more
critical emails like inventory emails can be sent out on time.
Also, add support for a "creds" dir.
TEST=send email using the new gmail account:
- with gmail_api_credentials_test_failure and creds dir set.
confirm using new credentials.
- without gmail_api_credentials_test_failure and creds dir set.
confirm using the default credentials.
BUG=chromium:541824;chromium:567882
Change-Id: I191e14303cdead164147d188ac495da6f7c18ba6
Reviewed-on: https://chromium-review.googlesource.com/316680
Commit-Ready: Fang Deng <fdeng@chromium.org>
Tested-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Fang Deng <fdeng@chromium.org>
diff --git a/server/cros/dynamic_suite/reporting.py b/server/cros/dynamic_suite/reporting.py
index b8298a8..9a88ff3 100644
--- a/server/cros/dynamic_suite/reporting.py
+++ b/server/cros/dynamic_suite/reporting.py
@@ -38,6 +38,8 @@
CHROMIUM_EMAIL_ADDRESS = global_config.global_config.get_config_value(
BUG_CONFIG_SECTION, 'chromium_email_address', default='')
+EMAIL_CREDS_FILE = global_config.global_config.get_config_value(
+ 'NOTIFICATIONS', 'gmail_api_credentials_test_failure', default=None)
class Bug(object):
@@ -912,8 +914,9 @@
to_set.add(bug_template.get('owner'))
recipients = ', '.join(to_set)
try:
- gmail_lib.send_email(recipients, bug.title(), bug.summary(),
- retry=False)
+ gmail_lib.send_email(
+ recipients, bug.title(), bug.summary(), retry=False,
+ creds_path=site_utils.get_creds_abspath(EMAIL_CREDS_FILE))
except Exception:
autotest_stats.Counter(EMAIL_COUNT_KEY % 'fail').increment()
raise
diff --git a/server/site_utils.py b/server/site_utils.py
index 1ebff49..6d44467 100644
--- a/server/site_utils.py
+++ b/server/site_utils.py
@@ -691,3 +691,24 @@
return (machine['hostname'], machine['host_attributes'])
else:
return (machine, {})
+
+
+def get_creds_abspath(creds_file):
+ """Returns the abspath of the credentials file.
+
+ If creds_file is already an absolute path, just return it.
+ Otherwise, assume it is located in the creds directory
+ specified in global_config and return the absolute path.
+
+ @param: creds_path, a path to the credentials.
+ @return: An absolute path to the credentials file.
+ """
+ if not creds_file:
+ return None
+ if os.path.isabs(creds_file):
+ return creds_file
+ creds_dir = global_config.global_config.get_config_value(
+ 'SERVER', 'creds_dir', default='')
+ if not creds_dir or not os.path.exists(creds_dir):
+ creds_dir = common.autotest_dir
+ return os.path.join(creds_dir, creds_file)