[autotest] passing_experimental.py now files bugs.

Instead of sending emails, passing_experimental.py will now file bugs.

manual_check_passing_experimetnal.py is used to test that
passing_experimental.py correctly submits bug reports that are deduped. It
creates a fake database and then calls passing_experimental.py. It requires
that the user then manually check that the bug is correctly submitted and
deduped.

BUG=chromium:212671
TEST=manual_check_passing_experimetnal.py submits issues using the
passing_experimental.py that are then manually checked. The unittests are also
used for testing.

Change-Id: I8b25fc7e409710dbd783145dec6e33de639c12d7
Reviewed-on: https://gerrit.chromium.org/gerrit/66573
Reviewed-by: Dennis Jeffrey <dennisjeffrey@chromium.org>
Tested-by: Keyar Hood <keyar@chromium.org>
Commit-Queue: Keyar Hood <keyar@chromium.org>
diff --git a/frontend/health/passing_experimental.py b/frontend/health/passing_experimental.py
index 2f975b0..3522310 100755
--- a/frontend/health/passing_experimental.py
+++ b/frontend/health/passing_experimental.py
@@ -8,8 +8,8 @@
 import argparse, datetime, sys
 
 import common
-from autotest_lib.client.common_lib import mail
 from autotest_lib.frontend import setup_django_readonly_environment
+from autotest_lib.server.cros.dynamic_suite import reporting
 
 # Django and the models are only setup after
 # the setup_django_readonly_environment module is imported.
@@ -22,9 +22,6 @@
 # Ignore any tests that have not passed in this many days.
 _MAX_DAYS_SINCE_LAST_PASS = 30
 
-_MAIL_RESULTS_FROM = 'chromeos-test-health@google.com'
-_MAIL_RESULTS_TO = 'chromeos-lab-infrastructure@google.com'
-
 
 def get_experimental_tests():
     """
@@ -69,12 +66,38 @@
     """Parse the command line options."""
 
     description = ('Collects information about which experimental tests '
-                   'have been passing for a long time and creates an email '
-                   'summarizing the results.')
+                   'have been passing for a long time and creates a bug '
+                   'report for each one.')
     parser = argparse.ArgumentParser(description=description)
     parser.parse_args(args)
 
 
+def submit_bug_reports(tests):
+    """
+    Submits bug reports to make the long passing tests as not experimental.
+
+    @param tests: The tests that need to be marked as not experimental.
+    """
+    reporter = reporting.Reporter()
+
+    for test in tests:
+        title = '%s should be promoted to non-experimental.' % test
+        summary = ('This bug has been automatically filed to track the '
+                   'following issue:\n\n'
+                   'Test: %s\n'
+                   'Issue: Promote to non-experimental as it has been passing '
+                   'for at least %d days.\n'
+                   'Suggested Actions: Navigate to the test\'s control file '
+                   'and remove the EXPERIMENTAL flag.\n'
+                   '\tSee http://www.chromium.org/chromium-os/testing/'
+                   'autotest-best-practices#TOC-Control-files' %
+                   (test, _MIN_DAYS_SINCE_FAILURE))
+        search_marker = 'PassingExperimental(%s)' % test
+        bug = reporting.Bug(title=title, summary=summary,
+                            search_marker=search_marker)
+        reporter.report(bug)
+
+
 def main(args=None):
     """
     The script code.
@@ -95,14 +118,7 @@
     long_passers = find_long_passing_tests(pass_times, fail_times,
                                            experimental_tests)
 
-    if long_passers:
-        mail.send(_MAIL_RESULTS_FROM,
-                  [_MAIL_RESULTS_TO],
-                  [],
-                  'Long Passing Experimental Tests',
-                  'The following experimental tests have been passing for at '
-                  'least %i days:\n\n%s'
-                  % (_MIN_DAYS_SINCE_FAILURE, '\n'.join(sorted(long_passers))))
+    submit_bug_reports(long_passers)
 
     return 0