mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 2 | |
| 3 | __author__ = "raphtee@google.com (Travis Miller)" |
| 4 | |
mbligh | 060c471 | 2009-12-29 02:43:35 +0000 | [diff] [blame] | 5 | import unittest, os, tempfile, logging |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 6 | import common |
jadmanski | cb0e161 | 2009-02-27 18:03:10 +0000 | [diff] [blame] | 7 | from autotest_lib.server import autotest, utils, hosts, server_job, profilers |
jadmanski | c09fc15 | 2008-10-15 17:56:59 +0000 | [diff] [blame] | 8 | from autotest_lib.client.bin import sysinfo |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 9 | from autotest_lib.client.common_lib import utils as client_utils, packages |
showard | ad812bf | 2009-10-20 23:49:56 +0000 | [diff] [blame] | 10 | from autotest_lib.client.common_lib import error |
jadmanski | 3d161b0 | 2008-06-06 15:43:36 +0000 | [diff] [blame] | 11 | from autotest_lib.client.common_lib.test_utils import mock |
jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 12 | |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 13 | |
| 14 | class TestBaseAutotest(unittest.TestCase): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 15 | def setUp(self): |
| 16 | # create god |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 17 | self.god = mock.mock_god() |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 18 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 19 | # create mock host object |
jadmanski | 8d631c9 | 2008-08-18 21:12:40 +0000 | [diff] [blame] | 20 | self.host = self.god.create_mock_class(hosts.RemoteHost, "host") |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 21 | self.host.hostname = "hostname" |
jadmanski | b6eb2f1 | 2008-09-12 16:39:36 +0000 | [diff] [blame] | 22 | self.host.job = self.god.create_mock_class(server_job.server_job, |
| 23 | "job") |
jadmanski | 23afbec | 2008-09-17 18:12:07 +0000 | [diff] [blame] | 24 | self.host.job.run_test_cleanup = True |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 25 | self.host.job.last_boot_tag = 'Autotest' |
jadmanski | c09fc15 | 2008-10-15 17:56:59 +0000 | [diff] [blame] | 26 | self.host.job.sysinfo = self.god.create_mock_class( |
| 27 | sysinfo.sysinfo, "sysinfo") |
jadmanski | cb0e161 | 2009-02-27 18:03:10 +0000 | [diff] [blame] | 28 | self.host.job.profilers = self.god.create_mock_class( |
| 29 | profilers.profilers, "profilers") |
| 30 | self.host.job.profilers.add_log = {} |
jadmanski | c09fc15 | 2008-10-15 17:56:59 +0000 | [diff] [blame] | 31 | self.host.job.tmpdir = "/job/tmp" |
showard | a6082ef | 2009-10-12 20:25:44 +0000 | [diff] [blame] | 32 | self.host.job.default_profile_only = False |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 33 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 34 | # stubs |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 35 | self.god.stub_function(utils, "get_server_dir") |
| 36 | self.god.stub_function(utils, "run") |
| 37 | self.god.stub_function(utils, "get") |
| 38 | self.god.stub_function(utils, "read_keyval") |
| 39 | self.god.stub_function(utils, "write_keyval") |
showard | 4b97607 | 2009-10-20 23:50:08 +0000 | [diff] [blame] | 40 | self.god.stub_function(utils, "system") |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 41 | self.god.stub_function(tempfile, "mkstemp") |
| 42 | self.god.stub_function(tempfile, "mktemp") |
| 43 | self.god.stub_function(os, "getcwd") |
| 44 | self.god.stub_function(os, "system") |
| 45 | self.god.stub_function(os, "chdir") |
| 46 | self.god.stub_function(os, "makedirs") |
| 47 | self.god.stub_function(os, "remove") |
jadmanski | c09fc15 | 2008-10-15 17:56:59 +0000 | [diff] [blame] | 48 | self.god.stub_function(os, "fdopen") |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 49 | self.god.stub_function(os.path, "exists") |
mbligh | b8aa75b | 2009-09-18 16:50:37 +0000 | [diff] [blame] | 50 | self.god.stub_function(os.path, "isdir") |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 51 | self.god.stub_function(autotest, "open") |
| 52 | self.god.stub_function(autotest.global_config.global_config, |
| 53 | "get_config_value") |
mbligh | 060c471 | 2009-12-29 02:43:35 +0000 | [diff] [blame] | 54 | self.god.stub_function(logging, "exception") |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 55 | self.god.stub_class(autotest, "_Run") |
jadmanski | 043e113 | 2008-11-19 17:10:32 +0000 | [diff] [blame] | 56 | self.god.stub_class(autotest, "log_collector") |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 57 | |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 58 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 59 | def tearDown(self): |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 60 | self.god.unstub_all() |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 61 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 62 | |
| 63 | def construct(self): |
| 64 | # setup |
| 65 | self.serverdir = "serverdir" |
| 66 | |
| 67 | # record |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 68 | utils.get_server_dir.expect_call().and_return(self.serverdir) |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 69 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 70 | # create the autotest object |
| 71 | self.base_autotest = autotest.BaseAutotest(self.host) |
mbligh | b8aa75b | 2009-09-18 16:50:37 +0000 | [diff] [blame] | 72 | self.god.stub_function(self.base_autotest, "_install_using_send_file") |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 73 | |
jadmanski | a49e9c4 | 2008-10-09 22:30:49 +0000 | [diff] [blame] | 74 | # stub out abspath |
| 75 | self.god.stub_function(os.path, "abspath") |
| 76 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 77 | # check |
| 78 | self.god.check_playback() |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 79 | |
| 80 | |
mbligh | b8aa75b | 2009-09-18 16:50:37 +0000 | [diff] [blame] | 81 | def record_install_prologue(self): |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 82 | self.construct() |
| 83 | |
| 84 | # setup |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 85 | self.god.stub_class(packages, "PackageManager") |
| 86 | self.base_autotest.got = False |
| 87 | location = os.path.join(self.serverdir, '../client') |
| 88 | location = os.path.abspath.expect_call(location).and_return(location) |
jadmanski | 3d161b0 | 2008-06-06 15:43:36 +0000 | [diff] [blame] | 89 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 90 | # record |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 91 | os.getcwd.expect_call().and_return('cwd') |
| 92 | os.chdir.expect_call(os.path.join(self.serverdir, '../client')) |
showard | 4b97607 | 2009-10-20 23:50:08 +0000 | [diff] [blame] | 93 | utils.system.expect_call('tools/make_clean', ignore_status=True) |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 94 | os.chdir.expect_call('cwd') |
| 95 | utils.get.expect_call(os.path.join(self.serverdir, |
| 96 | '../client')).and_return('source_material') |
| 97 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 98 | self.host.wait_up.expect_call(timeout=30) |
| 99 | self.host.setup.expect_call() |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 100 | self.host.get_autodir.expect_call().and_return("autodir") |
mbligh | 0562e65 | 2008-08-20 20:11:45 +0000 | [diff] [blame] | 101 | self.host.set_autodir.expect_call("autodir") |
jadmanski | 3c23694 | 2009-03-04 17:51:26 +0000 | [diff] [blame] | 102 | self.host.run.expect_call('mkdir -p autodir') |
jadmanski | 3c23694 | 2009-03-04 17:51:26 +0000 | [diff] [blame] | 103 | self.host.run.expect_call('rm -rf autodir/results/*', |
jadmanski | 1c3c07b | 2009-03-03 23:29:36 +0000 | [diff] [blame] | 104 | ignore_status=True) |
mbligh | b8aa75b | 2009-09-18 16:50:37 +0000 | [diff] [blame] | 105 | |
| 106 | |
| 107 | def test_constructor(self): |
| 108 | self.construct() |
| 109 | |
| 110 | # we should check the calls |
| 111 | self.god.check_playback() |
| 112 | |
| 113 | |
| 114 | def test_full_client_install(self): |
| 115 | self.record_install_prologue() |
| 116 | |
| 117 | os.path.isdir.expect_call('source_material').and_return(True) |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 118 | c = autotest.global_config.global_config |
mbligh | b8aa75b | 2009-09-18 16:50:37 +0000 | [diff] [blame] | 119 | c.get_config_value.expect_call('PACKAGES', |
| 120 | 'serve_packages_from_autoserv', |
| 121 | type=bool).and_return(False) |
| 122 | self.host.send_file.expect_call('source_material', 'autodir', |
| 123 | delete_dest=True) |
| 124 | |
| 125 | # run and check |
| 126 | self.base_autotest.install_full_client() |
| 127 | self.god.check_playback() |
| 128 | |
| 129 | |
| 130 | def test_autoserv_install(self): |
| 131 | self.record_install_prologue() |
| 132 | |
| 133 | c = autotest.global_config.global_config |
| 134 | c.get_config_value.expect_call('PACKAGES', |
jadmanski | 2315a7e | 2009-09-18 18:39:37 +0000 | [diff] [blame] | 135 | 'fetch_location', type=list, default=[]).and_return([]) |
mbligh | b8aa75b | 2009-09-18 16:50:37 +0000 | [diff] [blame] | 136 | |
| 137 | os.path.isdir.expect_call('source_material').and_return(True) |
| 138 | c.get_config_value.expect_call('PACKAGES', |
| 139 | 'serve_packages_from_autoserv', |
| 140 | type=bool).and_return(True) |
| 141 | self.base_autotest._install_using_send_file.expect_call(self.host, |
| 142 | 'autodir') |
| 143 | |
| 144 | # run and check |
| 145 | self.base_autotest.install() |
| 146 | self.god.check_playback() |
| 147 | |
| 148 | |
| 149 | def test_packaging_install(self): |
| 150 | self.record_install_prologue() |
| 151 | |
| 152 | c = autotest.global_config.global_config |
| 153 | c.get_config_value.expect_call('PACKAGES', |
jadmanski | 2315a7e | 2009-09-18 18:39:37 +0000 | [diff] [blame] | 154 | 'fetch_location', type=list, default=[]).and_return(['repo']) |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 155 | pkgmgr = packages.PackageManager.expect_new('autodir', |
jadmanski | ede7e24 | 2009-08-10 15:43:33 +0000 | [diff] [blame] | 156 | repo_urls=['repo'], hostname='hostname', do_locking=False, |
mbligh | 76d19f7 | 2008-10-15 16:24:43 +0000 | [diff] [blame] | 157 | run_function=self.host.run, run_function_dargs=dict(timeout=600)) |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 158 | pkg_dir = os.path.join('autodir', 'packages') |
mbligh | c5ddfd1 | 2008-08-04 17:15:00 +0000 | [diff] [blame] | 159 | cmd = ('cd autodir && ls | grep -v "^packages$"' |
| 160 | ' | xargs rm -rf && rm -rf .[^.]*') |
| 161 | self.host.run.expect_call(cmd) |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 162 | pkgmgr.install_pkg.expect_call('autotest', 'client', pkg_dir, |
| 163 | 'autodir', preserve_install_dir=True) |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 164 | |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 165 | # run and check |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 166 | self.base_autotest.install() |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 167 | self.god.check_playback() |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 168 | |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 169 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 170 | def test_run(self): |
| 171 | self.construct() |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 172 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 173 | # setup |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 174 | control = "control" |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 175 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 176 | # stub out install |
| 177 | self.god.stub_function(self.base_autotest, "install") |
mbligh | 1e3b099 | 2008-10-14 16:29:54 +0000 | [diff] [blame] | 178 | self.god.stub_class(packages, "PackageManager") |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 179 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 180 | # record |
| 181 | self.base_autotest.install.expect_call(self.host) |
| 182 | self.host.wait_up.expect_call(timeout=30) |
| 183 | os.path.abspath.expect_call('.').and_return('.') |
mbligh | b3c0c91 | 2008-11-27 00:32:45 +0000 | [diff] [blame] | 184 | run_obj = autotest._Run.expect_new(self.host, '.', None, False, False) |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 185 | tag = None |
| 186 | run_obj.manual_control_file = os.path.join('autodir', |
| 187 | 'control.%s' % tag) |
| 188 | run_obj.remote_control_file = os.path.join('autodir', |
| 189 | 'control.%s.autoserv' % tag) |
| 190 | run_obj.tag = tag |
| 191 | run_obj.autodir = 'autodir' |
| 192 | run_obj.verify_machine.expect_call() |
| 193 | run_obj.verify_machine.expect_call() |
mbligh | b3c0c91 | 2008-11-27 00:32:45 +0000 | [diff] [blame] | 194 | run_obj.background = False |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 195 | debug = os.path.join('.', 'debug') |
| 196 | os.makedirs.expect_call(debug) |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 197 | delete_file_list = [run_obj.remote_control_file, |
| 198 | run_obj.remote_control_file + '.state', |
| 199 | run_obj.manual_control_file, |
| 200 | run_obj.manual_control_file + '.state'] |
| 201 | cmd = ';'.join('rm -f ' + control for control in delete_file_list) |
| 202 | self.host.run.expect_call(cmd, ignore_status=True) |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 203 | |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 204 | utils.get.expect_call(control).and_return("temp") |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 205 | |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 206 | c = autotest.global_config.global_config |
| 207 | c.get_config_value.expect_call("PACKAGES", |
jadmanski | ede7e24 | 2009-08-10 15:43:33 +0000 | [diff] [blame] | 208 | 'fetch_location', type=list).and_return(['repo']) |
mbligh | 76d19f7 | 2008-10-15 16:24:43 +0000 | [diff] [blame] | 209 | pkgmgr = packages.PackageManager.expect_new('autotest', |
jadmanski | ede7e24 | 2009-08-10 15:43:33 +0000 | [diff] [blame] | 210 | repo_urls=['repo'], |
mbligh | 76d19f7 | 2008-10-15 16:24:43 +0000 | [diff] [blame] | 211 | hostname='hostname') |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 212 | |
| 213 | cfile = self.god.create_mock_class(file, "file") |
| 214 | cfile_orig = "original control file" |
mbligh | fbf73ae | 2009-12-19 05:22:42 +0000 | [diff] [blame] | 215 | cfile_new = "job.add_repository(['repo'])\n" |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 216 | cfile_new += cfile_orig |
jadmanski | c09fc15 | 2008-10-15 17:56:59 +0000 | [diff] [blame] | 217 | |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 218 | autotest.open.expect_call("temp").and_return(cfile) |
| 219 | cfile.read.expect_call().and_return(cfile_orig) |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 220 | autotest.open.expect_call("temp", 'w').and_return(cfile) |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 221 | cfile.write.expect_call(cfile_new) |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 222 | |
mbligh | fc3da5b | 2010-01-06 18:37:22 +0000 | [diff] [blame] | 223 | self.host.job.preprocess_client_state.expect_call().and_return( |
| 224 | '/job/tmp/file1') |
mbligh | fbf73ae | 2009-12-19 05:22:42 +0000 | [diff] [blame] | 225 | self.host.send_file.expect_call( |
| 226 | "/job/tmp/file1", "autodir/control.None.autoserv.init.state") |
jadmanski | c09fc15 | 2008-10-15 17:56:59 +0000 | [diff] [blame] | 227 | os.remove.expect_call("/job/tmp/file1") |
| 228 | |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 229 | self.host.send_file.expect_call("temp", run_obj.remote_control_file) |
| 230 | os.path.abspath.expect_call('temp').and_return('control_file') |
mbligh | 0910844 | 2008-10-15 16:27:38 +0000 | [diff] [blame] | 231 | os.path.abspath.expect_call('control').and_return('control') |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 232 | os.remove.expect_call("temp") |
jadmanski | 6bb32d7 | 2009-03-19 20:25:24 +0000 | [diff] [blame] | 233 | |
jadmanski | 6dadd83 | 2009-02-05 23:39:27 +0000 | [diff] [blame] | 234 | run_obj.execute_control.expect_call(timeout=30, |
| 235 | client_disconnect_timeout=1800) |
jadmanski | 23afbec | 2008-09-17 18:12:07 +0000 | [diff] [blame] | 236 | |
mbligh | 24f8f5b | 2008-06-12 19:56:22 +0000 | [diff] [blame] | 237 | # run and check output |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 238 | self.base_autotest.run(control, timeout=30) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 239 | self.god.check_playback() |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 240 | |
mbligh | 3c7a150 | 2008-07-24 18:08:47 +0000 | [diff] [blame] | 241 | |
showard | ad812bf | 2009-10-20 23:49:56 +0000 | [diff] [blame] | 242 | def _stub_get_client_autodir_paths(self): |
| 243 | def mock_get_client_autodir_paths(cls, host): |
| 244 | return ['/some/path', '/another/path'] |
| 245 | self.god.stub_with(autotest.Autotest, 'get_client_autodir_paths', |
| 246 | classmethod(mock_get_client_autodir_paths)) |
| 247 | |
| 248 | |
| 249 | def _expect_failed_run(self, command): |
| 250 | (self.host.run.expect_call(command) |
| 251 | .and_raises(error.AutoservRunError('dummy', object()))) |
| 252 | |
| 253 | |
| 254 | def test_get_installed_autodir(self): |
| 255 | self._stub_get_client_autodir_paths() |
| 256 | self.host.get_autodir.expect_call().and_return(None) |
| 257 | self._expect_failed_run('test -x /some/path/bin/autotest') |
| 258 | self.host.run.expect_call('test -x /another/path/bin/autotest') |
| 259 | |
| 260 | autodir = autotest.Autotest.get_installed_autodir(self.host) |
| 261 | self.assertEquals(autodir, '/another/path') |
| 262 | |
| 263 | |
| 264 | def test_get_install_dir(self): |
| 265 | self._stub_get_client_autodir_paths() |
| 266 | self.host.get_autodir.expect_call().and_return(None) |
| 267 | self._expect_failed_run('test -x /some/path/bin/autotest') |
| 268 | self._expect_failed_run('test -x /another/path/bin/autotest') |
| 269 | self._expect_failed_run('mkdir -p /some/path') |
| 270 | self.host.run.expect_call('mkdir -p /another/path') |
| 271 | |
| 272 | install_dir = autotest.Autotest.get_install_dir(self.host) |
| 273 | self.assertEquals(install_dir, '/another/path') |
| 274 | |
| 275 | |
mbligh | 060c471 | 2009-12-29 02:43:35 +0000 | [diff] [blame] | 276 | def test_client_logger_process_line_log_copy_collection_failure(self): |
| 277 | collector = autotest.log_collector.expect_new(self.host, '', '') |
| 278 | logger = autotest.client_logger(self.host, '', '') |
| 279 | collector.collect_client_job_results.expect_call().and_raises( |
| 280 | Exception('log copy failure')) |
| 281 | logging.exception.expect_call(mock.is_string_comparator()) |
| 282 | logger._process_line('AUTOTEST_TEST_COMPLETE:/autotest/fifo1') |
| 283 | |
| 284 | |
| 285 | def test_client_logger_process_line_log_copy_fifo_failure(self): |
| 286 | collector = autotest.log_collector.expect_new(self.host, '', '') |
| 287 | logger = autotest.client_logger(self.host, '', '') |
| 288 | collector.collect_client_job_results.expect_call() |
| 289 | self.host.run.expect_call('echo A > /autotest/fifo2').and_raises( |
| 290 | Exception('fifo failure')) |
| 291 | logging.exception.expect_call(mock.is_string_comparator()) |
| 292 | logger._process_line('AUTOTEST_TEST_COMPLETE:/autotest/fifo2') |
| 293 | |
| 294 | |
| 295 | def test_client_logger_process_line_package_install_fifo_failure(self): |
| 296 | collector = autotest.log_collector.expect_new(self.host, '', '') |
| 297 | logger = autotest.client_logger(self.host, '', '') |
| 298 | self.god.stub_function(logger, '_send_tarball') |
| 299 | |
| 300 | c = autotest.global_config.global_config |
| 301 | c.get_config_value.expect_call('PACKAGES', |
| 302 | 'serve_packages_from_autoserv', |
| 303 | type=bool).and_return(True) |
| 304 | logger._send_tarball.expect_call('pkgname.tar.bz2', '/autotest/dest/') |
lmr | 12b4558 | 2010-01-11 21:22:02 +0000 | [diff] [blame] | 305 | |
mbligh | 060c471 | 2009-12-29 02:43:35 +0000 | [diff] [blame] | 306 | self.host.run.expect_call('echo B > /autotest/fifo3').and_raises( |
| 307 | Exception('fifo failure')) |
| 308 | logging.exception.expect_call(mock.is_string_comparator()) |
| 309 | logger._process_line('AUTOTEST_FETCH_PACKAGE:pkgname.tar.bz2:' |
| 310 | '/autotest/dest/:/autotest/fifo3') |
| 311 | |
| 312 | |
| 313 | def test_client_logger_write_handles_process_line_failures(self): |
| 314 | collector = autotest.log_collector.expect_new(self.host, '', '') |
| 315 | logger = autotest.client_logger(self.host, '', '') |
| 316 | logger.server_warnings = [(x, 'warn%d' % x) for x in xrange(5)] |
| 317 | self.god.stub_function(logger, '_process_warnings') |
| 318 | self.god.stub_function(logger, '_process_line') |
| 319 | def _update_timestamp(line): |
| 320 | logger.newest_timestamp += 2 |
| 321 | class ProcessingException(Exception): |
| 322 | pass |
| 323 | def _read_warnings(): |
| 324 | return [(5, 'warn5')] |
| 325 | logger._update_timestamp = _update_timestamp |
| 326 | logger.newest_timestamp = 0 |
| 327 | self.host.job._read_warnings = _read_warnings |
| 328 | # process line1, newest_timestamp -> 2 |
| 329 | logger._process_warnings.expect_call( |
| 330 | '', {}, [(0, 'warn0'), (1, 'warn1')]) |
| 331 | logger._process_line.expect_call('line1') |
| 332 | # process line2, newest_timestamp -> 4, failure occurs during process |
| 333 | logger._process_warnings.expect_call( |
| 334 | '', {}, [(2, 'warn2'), (3, 'warn3')]) |
| 335 | logger._process_line.expect_call('line2').and_raises( |
| 336 | ProcessingException('line processing failure')) |
| 337 | # when we call write with data we should get an exception |
| 338 | self.assertRaises(ProcessingException, logger.write, |
| 339 | 'line1\nline2\nline3\nline4') |
| 340 | # but, after the exception, the server_warnings and leftover buffers |
| 341 | # should contain the unprocessed data, and ONLY the unprocessed data |
| 342 | self.assertEqual(logger.server_warnings, [(4, 'warn4'), (5, 'warn5')]) |
| 343 | self.assertEqual(logger.leftover, 'line2\nline3\nline4') |
| 344 | |
| 345 | |
mbligh | 5fe5c95 | 2008-05-27 20:14:43 +0000 | [diff] [blame] | 346 | if __name__ == "__main__": |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 347 | unittest.main() |