| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 import logging, os, shutil, sys, time, StringIO | 3 import logging, os, shutil, sys, time, StringIO |
| 4 import common | 4 import common |
| 5 | 5 |
| 6 from autotest_lib.client.bin import job, boottool, config, sysinfo, harness | 6 from autotest_lib.client.bin import job, boottool, config, sysinfo, harness |
| 7 from autotest_lib.client.bin import test, xen, kernel, utils | 7 from autotest_lib.client.bin import test, xen, kernel, utils |
| 8 from autotest_lib.client.common_lib import packages, error, log | 8 from autotest_lib.client.common_lib import packages, error, log |
| 9 from autotest_lib.client.common_lib import logging_manager, logging_config | 9 from autotest_lib.client.common_lib import logging_manager, logging_config |
| 10 from autotest_lib.client.common_lib import base_job_unittest | 10 from autotest_lib.client.common_lib import base_job_unittest |
| 11 from autotest_lib.client.common_lib.test_utils import mock, unittest | 11 from autotest_lib.client.common_lib.test_utils import mock, unittest |
| 12 | 12 |
| 13 | 13 |
| 14 class job_test_case(unittest.TestCase): | 14 class job_test_case(unittest.TestCase): |
| 15 """Generic job TestCase class that defines a standard job setUp and | 15 """Generic job TestCase class that defines a standard job setUp and |
| 16 tearDown, with some standard stubs.""" | 16 tearDown, with some standard stubs.""" |
| 17 | 17 |
| 18 job_class = job.base_client_job | 18 job_class = job.base_client_job |
| 19 | 19 |
| 20 def setUp(self): | 20 def setUp(self): |
| 21 self.god = mock.mock_god() | 21 self.god = mock.mock_god(ut=self) |
| 22 self.god.stub_with(job.base_client_job, '_get_environ_autodir', | 22 self.god.stub_with(job.base_client_job, '_get_environ_autodir', |
| 23 classmethod(lambda cls: '/adir')) | 23 classmethod(lambda cls: '/adir')) |
| 24 self.job = self.job_class.__new__(self.job_class) | 24 self.job = self.job_class.__new__(self.job_class) |
| 25 self.job._job_directory = base_job_unittest.stub_job_directory | 25 self.job._job_directory = base_job_unittest.stub_job_directory |
| 26 | 26 |
| 27 | 27 |
| 28 def tearDown(self): | 28 def tearDown(self): |
| 29 self.god.unstub_all() | 29 self.god.unstub_all() |
| 30 | 30 |
| 31 | 31 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 self.god.stub_function_to_return(job.boottool, 'boottool', object()) | 79 self.god.stub_function_to_return(job.boottool, 'boottool', object()) |
| 80 class options: | 80 class options: |
| 81 tag = '' | 81 tag = '' |
| 82 verbose = False | 82 verbose = False |
| 83 cont = False | 83 cont = False |
| 84 harness = 'stub' | 84 harness = 'stub' |
| 85 hostname = None | 85 hostname = None |
| 86 user = None | 86 user = None |
| 87 log = False | 87 log = False |
| 88 args = '' | 88 args = '' |
| 89 tap_report = None |
| 89 self.god.stub_function_to_return(job.utils, 'drop_caches', None) | 90 self.god.stub_function_to_return(job.utils, 'drop_caches', None) |
| 90 | 91 |
| 91 self.job._job_state = base_job_unittest.stub_job_state | 92 self.job._job_state = base_job_unittest.stub_job_state |
| 92 self.job.__init__('/control', options) | 93 self.job.__init__('/control', options) |
| 93 | 94 |
| 94 | 95 |
| 95 class dummy(object): | 96 class dummy(object): |
| 96 """A simple placeholder for attributes""" | 97 """A simple placeholder for attributes""" |
| 97 pass | 98 pass |
| 98 | 99 |
| 99 | 100 |
| 100 class first_line_comparator(mock.argument_comparator): | 101 class first_line_comparator(mock.argument_comparator): |
| 101 def __init__(self, first_line): | 102 def __init__(self, first_line): |
| 102 self.first_line = first_line | 103 self.first_line = first_line |
| 103 | 104 |
| 104 | 105 |
| 105 def is_satisfied_by(self, parameter): | 106 def is_satisfied_by(self, parameter): |
| 106 return self.first_line == parameter.splitlines()[0] | 107 return self.first_line == parameter.splitlines()[0] |
| 107 | 108 |
| 108 | 109 |
| 109 class test_base_job(unittest.TestCase): | 110 class test_base_job(unittest.TestCase): |
| 110 def setUp(self): | 111 def setUp(self): |
| 111 # make god | 112 # make god |
| 112 self.god = mock.mock_god() | 113 self.god = mock.mock_god(ut=self) |
| 113 | 114 |
| 114 # need to set some environ variables | 115 # need to set some environ variables |
| 115 self.autodir = "autodir" | 116 self.autodir = "autodir" |
| 116 os.environ['AUTODIR'] = self.autodir | 117 os.environ['AUTODIR'] = self.autodir |
| 117 | 118 |
| 118 # set up some variables | 119 # set up some variables |
| 119 self.control = "control" | 120 self.control = "control" |
| 120 self.jobtag = "jobtag" | 121 self.jobtag = "jobtag" |
| 121 | 122 |
| 122 # get rid of stdout and logging | 123 # get rid of stdout and logging |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 # finish constructor | 235 # finish constructor |
| 235 options = dummy() | 236 options = dummy() |
| 236 options.tag = self.jobtag | 237 options.tag = self.jobtag |
| 237 options.cont = cont | 238 options.cont = cont |
| 238 options.harness = None | 239 options.harness = None |
| 239 options.log = False | 240 options.log = False |
| 240 options.verbose = False | 241 options.verbose = False |
| 241 options.hostname = 'localhost' | 242 options.hostname = 'localhost' |
| 242 options.user = 'my_user' | 243 options.user = 'my_user' |
| 243 options.args = '' | 244 options.args = '' |
| 245 options.tap_report = None |
| 244 self.job.__init__(self.control, options, | 246 self.job.__init__(self.control, options, |
| 245 extra_copy_cmdline=['more-blah']) | 247 extra_copy_cmdline=['more-blah']) |
| 246 | 248 |
| 247 # check | 249 # check |
| 248 self.god.check_playback() | 250 self.god.check_playback() |
| 249 | 251 |
| 250 | 252 |
| 251 def get_partition_mock(self, devname): | 253 def get_partition_mock(self, devname): |
| 252 """ | 254 """ |
| 253 Create a mock of a partition object and return it. | 255 Create a mock of a partition object and return it. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 273 self.job = job.base_client_job.__new__(job.base_client_job) | 275 self.job = job.base_client_job.__new__(job.base_client_job) |
| 274 options = dummy() | 276 options = dummy() |
| 275 options.tag = self.jobtag | 277 options.tag = self.jobtag |
| 276 options.cont = False | 278 options.cont = False |
| 277 options.harness = None | 279 options.harness = None |
| 278 options.log = False | 280 options.log = False |
| 279 options.verbose = False | 281 options.verbose = False |
| 280 options.hostname = 'localhost' | 282 options.hostname = 'localhost' |
| 281 options.user = 'my_user' | 283 options.user = 'my_user' |
| 282 options.args = '' | 284 options.args = '' |
| 285 options.tap_report = None |
| 283 error = Exception('fail') | 286 error = Exception('fail') |
| 284 | 287 |
| 285 self.god.stub_function(self.job, '_post_record_init') | 288 self.god.stub_function(self.job, '_post_record_init') |
| 286 self.god.stub_function(self.job, 'record') | 289 self.god.stub_function(self.job, 'record') |
| 287 | 290 |
| 288 self._setup_pre_record_init(False) | 291 self._setup_pre_record_init(False) |
| 289 self.job._post_record_init.expect_call( | 292 self.job._post_record_init.expect_call( |
| 290 self.control, options, True, ['more-blah']).and_raises(error) | 293 self.control, options, True, ['more-blah']).and_raises(error) |
| 291 self.job.record.expect_call( | 294 self.job.record.expect_call( |
| 292 'ABORT', None, None,'client.bin.job.__init__ failed: %s' % | 295 'ABORT', None, None,'client.bin.job.__init__ failed: %s' % |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 687 |
| 685 self.job._record_reboot_failure.expect_call("sub", "reboot.verify", | 688 self.job._record_reboot_failure.expect_call("sub", "reboot.verify", |
| 686 "boot failure", running_id="2.6.15-smp") | 689 "boot failure", running_id="2.6.15-smp") |
| 687 | 690 |
| 688 # run test | 691 # run test |
| 689 self.assertRaises(error.JobError, self.job.end_reboot_and_verify, | 692 self.assertRaises(error.JobError, self.job.end_reboot_and_verify, |
| 690 91234567, "2.6.16-smp", "sub") | 693 91234567, "2.6.16-smp", "sub") |
| 691 self.god.check_playback() | 694 self.god.check_playback() |
| 692 | 695 |
| 693 | 696 |
| 697 def test_parse_args(self): |
| 698 test_set = {"a='foo bar baz' b='moo apt'": |
| 699 ["a='foo bar baz'", "b='moo apt'"], |
| 700 "a='foo bar baz' only=gah": |
| 701 ["a='foo bar baz'", "only=gah"], |
| 702 "a='b c d' no=argh": |
| 703 ["a='b c d'", "no=argh"]} |
| 704 for t in test_set: |
| 705 parsed_args = job.base_client_job._parse_args(t) |
| 706 expected_args = test_set[t] |
| 707 self.assertEqual(parsed_args, expected_args) |
| 708 |
| 709 |
| 694 if __name__ == "__main__": | 710 if __name__ == "__main__": |
| 695 unittest.main() | 711 unittest.main() |
| OLD | NEW |