Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Fakes for dynamic_suite-related unit tests.""" |
| 6 | |
Chris Masone | f63576d | 2012-06-29 11:13:31 -0700 | [diff] [blame] | 7 | import datetime |
| 8 | from autotest_lib.server.cros import job_status |
| 9 | |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 10 | |
| 11 | class FakeControlData(object): |
| 12 | """A fake parsed control file data structure.""" |
| 13 | def __init__(self, suite, data, expr=False): |
| 14 | self.string = 'text-' + data |
| 15 | self.name = 'name-' + data |
| 16 | self.data = data |
| 17 | self.suite = suite |
| 18 | self.test_type = 'Client' |
| 19 | self.experimental = expr |
Chris Masone | 517ef48 | 2012-07-23 15:36:36 -0700 | [diff] [blame] | 20 | self.dependencies = [] |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class FakeJob(object): |
| 24 | """Faked out RPC-client-side Job object.""" |
Chris Masone | 517ef48 | 2012-07-23 15:36:36 -0700 | [diff] [blame] | 25 | def __init__(self, id=0, statuses=[], hostnames=[]): |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 26 | self.id = id |
Chris Masone | 517ef48 | 2012-07-23 15:36:36 -0700 | [diff] [blame] | 27 | self.hostnames = hostnames if hostnames else ['host%d' % id] |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 28 | self.owner = 'tester' |
| 29 | self.name = 'Fake Job %d' % self.id |
| 30 | self.statuses = statuses |
| 31 | |
| 32 | |
| 33 | class FakeHost(object): |
| 34 | """Faked out RPC-client-side Host object.""" |
Chris Masone | 275ec90 | 2012-07-10 15:28:34 -0700 | [diff] [blame] | 35 | def __init__(self, hostname='', status='Ready'): |
| 36 | self.hostname = hostname |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 37 | self.status = status |
| 38 | |
Chris Masone | 275ec90 | 2012-07-10 15:28:34 -0700 | [diff] [blame] | 39 | |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 40 | class FakeLabel(object): |
| 41 | """Faked out RPC-client-side Label object.""" |
| 42 | def __init__(self, id=0): |
| 43 | self.id = id |
| 44 | |
| 45 | |
| 46 | class FakeStatus(object): |
| 47 | """Fake replacement for server-side job status objects. |
| 48 | |
| 49 | @var status: 'GOOD', 'FAIL', 'ERROR', etc. |
| 50 | @var test_name: name of the test this is status for |
| 51 | @var reason: reason for failure, if any |
| 52 | @var aborted: present and True if the job was aborted. Optional. |
| 53 | """ |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 54 | def __init__(self, code, name, reason, aborted=None, hostname=None): |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 55 | self.status = code |
| 56 | self.test_name = name |
| 57 | self.reason = reason |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 58 | self.hostname = hostname if hostname else 'hostless' |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 59 | self.entry = {} |
| 60 | self.test_started_time = '2012-11-11 11:11:11' |
| 61 | self.test_finished_time = '2012-11-11 12:12:12' |
| 62 | if aborted: |
| 63 | self.entry['aborted'] = True |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 64 | if hostname: |
| 65 | self.entry['host'] = {'hostname': hostname} |
| 66 | |
Chris Masone | e3dcadb | 2012-07-31 12:16:19 -0700 | [diff] [blame] | 67 | |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 68 | def __repr__(self): |
| 69 | return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason, |
| 70 | self.hostname) |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 71 | |
Chris Masone | e3dcadb | 2012-07-31 12:16:19 -0700 | [diff] [blame] | 72 | |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 73 | def equals_record(self, status): |
| 74 | """Compares this object to a recorded status.""" |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 75 | if 'aborted' in self.entry and self.entry['aborted']: |
Chris Masone | e3dcadb | 2012-07-31 12:16:19 -0700 | [diff] [blame] | 76 | return status._status == 'ABORT' |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 77 | return (self.status == status._status and |
Chris Masone | e71a515 | 2012-07-31 12:16:19 -0700 | [diff] [blame^] | 78 | status._test_name.endswith(self.test_name) and |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 79 | self.reason == status._reason) |
Chris Masone | f63576d | 2012-06-29 11:13:31 -0700 | [diff] [blame] | 80 | |
Chris Masone | e3dcadb | 2012-07-31 12:16:19 -0700 | [diff] [blame] | 81 | |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 82 | def equals_hostname_record(self, status): |
| 83 | """Compares this object to a recorded status. |
Chris Masone | f63576d | 2012-06-29 11:13:31 -0700 | [diff] [blame] | 84 | |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame] | 85 | Expects the test name field of |status| to contain |self.hostname|. |
| 86 | """ |
| 87 | return (self.status == status._status and |
| 88 | self.hostname in status._test_name and |
| 89 | self.reason == status._reason) |