1#!/usr/bin/python
2#
3# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import argparse, datetime, sys
8
9import common
10# This must come before the import of complete_failures in order to use the
11# in memory database.
12from autotest_lib.frontend import setup_django_readonly_environment
13from autotest_lib.frontend import setup_test_environment
14from autotest_lib.frontend.afe import models as afe_models
15from autotest_lib.frontend.health import passing_experimental
16from autotest_lib.frontend.tko import models as tko_models
17
18GOOD_STATUS_IDX = 6
19
20
21def parse_options(args):
22    """Parse the command line options."""
23    description = ('Sets up a fake database and then runs '
24                   'passing_experimental.py main() function to simulate '
25                   'running the script to test bug filing. Manually checking '
26                   'will be required to verify that bugs have been submitted '
27                   'correctly. Remember to set up the shadow_config.ini file '
28                   'to point to the autotest-bug-filing-test dummy project.')
29    parser = argparse.ArgumentParser(description=description)
30    parser.parse_args(args)
31
32
33def main(args):
34    """
35    Run passing_experimental.py to check bug filing for it.
36
37    This sets the fake database up so a bug is guranteed to be filed. However,
38    it requires manually verifying that the bug was filed and deduped.
39
40    @param args: The arguments passed in from the commandline.
41
42    """
43    args = [] if args is None else args
44    parse_options(args)
45
46    setup_test_environment.set_up()
47
48    afe_models.Test(name='test_dedupe', test_type=0, path='test_dedupe',
49                    experimental=True).save()
50
51    tko_models.Status(status_idx=6, word='GOOD').save()
52
53    job = tko_models.Job(job_idx=1)
54    kernel = tko_models.Kernel(kernel_idx=1)
55    machine = tko_models.Machine(machine_idx=1)
56    success_status = tko_models.Status(status_idx=GOOD_STATUS_IDX)
57
58    tko_dedupe = tko_models.Test(job=job, status=success_status,
59                                 kernel=kernel, machine=machine,
60                                 test='test_dedupe',
61                                 started_time=datetime.datetime.today())
62    tko_dedupe.save()
63
64    passing_experimental.main()
65
66    # We assume that the user is using the dummy tracker when using this script.
67    print ('Now check the bug tracker to make sure this was properly deduped.\n'
68           'https://code.google.com/p/autotest-bug-filing-test/issues/list?'
69           'q=PassingExperimental')
70
71
72if __name__ == '__main__':
73    sys.exit(main(sys.argv[1:]))
74