blob: dfceaf1e3e3ef13cb11d17f22a104cde82e2bcea [file] [log] [blame]
Aviv Keshet6f455262013-03-01 16:02:29 -08001#pylint: disable-msg=C0111
Chris Masone8d6e6412012-06-28 11:20:56 -07002# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Fakes for dynamic_suite-related unit tests."""
7
Allen Lif20e17d2017-01-03 18:24:19 -08008import common
9from autotest_lib.client.common_lib import control_data
Chris Masone8d6e6412012-06-28 11:20:56 -070010
Allen Lif20e17d2017-01-03 18:24:19 -080011
12class FakeControlData(control_data.ControlData):
Chris Masone8d6e6412012-06-28 11:20:56 -070013 """A fake parsed control file data structure."""
Shuqian Zhaoab468812015-04-08 14:40:38 -070014 def __init__(self, suite, attributes, data, time='LONG', expr=False,
Fang Denge3bc24b2014-03-17 15:19:46 -070015 dependencies=None, job_retries=0):
Chris Masone8d6e6412012-06-28 11:20:56 -070016 self.string = 'text-' + data
17 self.name = 'name-' + data
Chris Masone8906ab12012-07-23 15:37:56 -070018 self.path = None # Will be set during 'parsing'.
Chris Masone8d6e6412012-06-28 11:20:56 -070019 self.data = data
20 self.suite = suite
Shuqian Zhaoab468812015-04-08 14:40:38 -070021 self.attributes = attributes
Chris Masone8d6e6412012-06-28 11:20:56 -070022 self.test_type = 'Client'
23 self.experimental = expr
Aviv Keshetd7959f32013-05-17 15:58:43 -070024 if not dependencies:
25 dependencies=[]
26 self.dependencies = dependencies
Dan Shief5b53f2013-01-22 10:22:01 -080027 self.time = time
Aviv Keshet6f455262013-03-01 16:02:29 -080028 self.retries = 0
Dan Shi6eedadb2013-12-04 15:38:01 -080029 self.sync_count = 1
Fang Denge3bc24b2014-03-17 15:19:46 -070030 self.job_retries = job_retries
Dan Shic566a182014-05-06 12:42:55 -070031 self.bug_template = {}
Dan Shiec1d47d2015-02-13 11:38:13 -080032 self.require_ssp = None
Chris Masone8d6e6412012-06-28 11:20:56 -070033
34
35class FakeJob(object):
36 """Faked out RPC-client-side Job object."""
Aviv Keshet133beb12013-08-20 14:37:13 -070037 def __init__(self, id=0, statuses=[], hostnames=[], parent_job_id=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070038 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070039 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070040 self.owner = 'tester'
41 self.name = 'Fake Job %d' % self.id
42 self.statuses = statuses
Aviv Keshet133beb12013-08-20 14:37:13 -070043 self.parent_job_id = parent_job_id
Chris Masone8d6e6412012-06-28 11:20:56 -070044
45
46class FakeHost(object):
47 """Faked out RPC-client-side Host object."""
Chris Masonee99bcf22012-08-17 15:09:49 -070048 def __init__(self, hostname='', status='Ready', locked=False, locked_by=''):
Chris Masone275ec902012-07-10 15:28:34 -070049 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070050 self.status = status
Chris Masonee99bcf22012-08-17 15:09:49 -070051 self.locked = locked
52 self.locked_by = locked_by
Chris Masone8d6e6412012-06-28 11:20:56 -070053
Chris Masone275ec902012-07-10 15:28:34 -070054
Chris Masone8906ab12012-07-23 15:37:56 -070055 def __str__(self):
56 return '%s: %s. %s%s' % (
57 self.hostname, self.status,
58 'Locked' if self.locked else 'Unlocked',
59 ' by %s' % self.locked_by if self.locked else '')
60
61
Chris Masone8d6e6412012-06-28 11:20:56 -070062class FakeLabel(object):
63 """Faked out RPC-client-side Label object."""
64 def __init__(self, id=0):
65 self.id = id
66
67
68class FakeStatus(object):
69 """Fake replacement for server-side job status objects.
70
71 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
72 @var test_name: name of the test this is status for
73 @var reason: reason for failure, if any
74 @var aborted: present and True if the job was aborted. Optional.
75 """
Fang Deng5c508332014-03-19 10:26:00 -070076 def __init__(self, code, name, reason, aborted=None,
77 hostname=None, subdir='fake_Test.tag.subdir_tag',
78 job_tag='id-owner/hostname'):
Chris Masone8d6e6412012-06-28 11:20:56 -070079 self.status = code
80 self.test_name = name
81 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070082 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070083 self.entry = {}
84 self.test_started_time = '2012-11-11 11:11:11'
85 self.test_finished_time = '2012-11-11 12:12:12'
Fang Deng5c508332014-03-19 10:26:00 -070086 self.job_tag=job_tag
87 self.subdir=subdir
Chris Masone8d6e6412012-06-28 11:20:56 -070088 if aborted:
89 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070090 if hostname:
91 self.entry['host'] = {'hostname': hostname}
92
Chris Masonee3dcadb2012-07-31 12:16:19 -070093
Chris Masone6ea0cad2012-07-02 09:43:36 -070094 def __repr__(self):
95 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
96 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070097
Chris Masonee3dcadb2012-07-31 12:16:19 -070098
Chris Masone8d6e6412012-06-28 11:20:56 -070099 def equals_record(self, status):
100 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -0700101 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -0700102 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -0700103 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -0700104 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -0700105 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -0700106
Chris Masonee3dcadb2012-07-31 12:16:19 -0700107
Chris Masone6ea0cad2012-07-02 09:43:36 -0700108 def equals_hostname_record(self, status):
109 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -0700110
Chris Masone6ea0cad2012-07-02 09:43:36 -0700111 Expects the test name field of |status| to contain |self.hostname|.
112 """
113 return (self.status == status._status and
114 self.hostname in status._test_name and
115 self.reason == status._reason)
Alex Miller176a29f2012-07-30 14:03:55 -0700116
117
118 def record_all(self, record):
119 pass
120
121
122 def is_good(self):
123 pass
124
125 def name(self):
126 return self.test_name