blob: 67d0ac09960147e41443b572429e047495925dc9 [file] [log] [blame]
Chris Masone8d6e6412012-06-28 11:20:56 -07001# 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 Masonef63576d2012-06-29 11:13:31 -07007import datetime
Chris Masoneb4935552012-08-14 12:05:54 -07008from autotest_lib.server.cros.dynamic_suite import job_status
Chris Masonef63576d2012-06-29 11:13:31 -07009
Chris Masone8d6e6412012-06-28 11:20:56 -070010
11class 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
Chris Masone8906ab12012-07-23 15:37:56 -070016 self.path = None # Will be set during 'parsing'.
Chris Masone8d6e6412012-06-28 11:20:56 -070017 self.data = data
18 self.suite = suite
19 self.test_type = 'Client'
20 self.experimental = expr
Chris Masone517ef482012-07-23 15:36:36 -070021 self.dependencies = []
Chris Masone8d6e6412012-06-28 11:20:56 -070022
23
24class FakeJob(object):
25 """Faked out RPC-client-side Job object."""
Chris Masone517ef482012-07-23 15:36:36 -070026 def __init__(self, id=0, statuses=[], hostnames=[]):
Chris Masone8d6e6412012-06-28 11:20:56 -070027 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070028 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070029 self.owner = 'tester'
30 self.name = 'Fake Job %d' % self.id
31 self.statuses = statuses
32
33
34class FakeHost(object):
35 """Faked out RPC-client-side Host object."""
Chris Masonee99bcf22012-08-17 15:09:49 -070036 def __init__(self, hostname='', status='Ready', locked=False, locked_by=''):
Chris Masone275ec902012-07-10 15:28:34 -070037 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070038 self.status = status
Chris Masonee99bcf22012-08-17 15:09:49 -070039 self.locked = locked
40 self.locked_by = locked_by
Chris Masone8d6e6412012-06-28 11:20:56 -070041
Chris Masone275ec902012-07-10 15:28:34 -070042
Chris Masone8906ab12012-07-23 15:37:56 -070043 def __str__(self):
44 return '%s: %s. %s%s' % (
45 self.hostname, self.status,
46 'Locked' if self.locked else 'Unlocked',
47 ' by %s' % self.locked_by if self.locked else '')
48
49
Chris Masone8d6e6412012-06-28 11:20:56 -070050class FakeLabel(object):
51 """Faked out RPC-client-side Label object."""
52 def __init__(self, id=0):
53 self.id = id
54
55
56class FakeStatus(object):
57 """Fake replacement for server-side job status objects.
58
59 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
60 @var test_name: name of the test this is status for
61 @var reason: reason for failure, if any
62 @var aborted: present and True if the job was aborted. Optional.
63 """
Chris Masone6ea0cad2012-07-02 09:43:36 -070064 def __init__(self, code, name, reason, aborted=None, hostname=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070065 self.status = code
66 self.test_name = name
67 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070068 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070069 self.entry = {}
70 self.test_started_time = '2012-11-11 11:11:11'
71 self.test_finished_time = '2012-11-11 12:12:12'
72 if aborted:
73 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070074 if hostname:
75 self.entry['host'] = {'hostname': hostname}
76
Chris Masonee3dcadb2012-07-31 12:16:19 -070077
Chris Masone6ea0cad2012-07-02 09:43:36 -070078 def __repr__(self):
79 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
80 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070081
Chris Masonee3dcadb2012-07-31 12:16:19 -070082
Chris Masone8d6e6412012-06-28 11:20:56 -070083 def equals_record(self, status):
84 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070085 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -070086 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070087 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -070088 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -070089 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -070090
Chris Masonee3dcadb2012-07-31 12:16:19 -070091
Chris Masone6ea0cad2012-07-02 09:43:36 -070092 def equals_hostname_record(self, status):
93 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -070094
Chris Masone6ea0cad2012-07-02 09:43:36 -070095 Expects the test name field of |status| to contain |self.hostname|.
96 """
97 return (self.status == status._status and
98 self.hostname in status._test_name and
99 self.reason == status._reason)
Alex Miller176a29f2012-07-30 14:03:55 -0700100
101
102 def record_all(self, record):
103 pass
104
105
106 def is_good(self):
107 pass
108
109 def name(self):
110 return self.test_name