blob: 2ea53d4d93b67e5d2778fc755e13ca6d1e32a7f7 [file] [log] [blame]
mblighb62f7242009-07-29 14:34:30 +00001#!/usr/bin/python
2# Copyright 2009 Google Inc. Released under the GPL v2
3
4import unittest
5
6import common
7from autotest_lib.mirror import trigger
8from autotest_lib.client.common_lib.test_utils import mock
9
10
11class map_action_unittest(unittest.TestCase):
12 def setUp(self):
13 self.god = mock.mock_god()
14
15
16 def tearDown(self):
17 pass
18
19
20 def test_machine_info_api(self):
mblighb8f5b702009-11-06 03:09:03 +000021 tests = object()
mblighb62f7242009-07-29 14:34:30 +000022 configs = object()
23
mblighb8f5b702009-11-06 03:09:03 +000024 info = trigger.map_action.machine_info(tests, configs)
25 self.assertEquals(tests, info.tests)
mblighb62f7242009-07-29 14:34:30 +000026 self.assertEquals(configs, info.kernel_configs)
27
28
mblighb8f5b702009-11-06 03:09:03 +000029 @staticmethod
30 def _make_control_dict(contents, is_server=False, synch_count=1,
31 dependencies=()):
mblighf0c5bbf2009-11-21 01:44:59 +000032 class ControlFile(object):
33 def __init__(self, contents, is_server, synch_count, dependencies):
34 self.control_file = contents
35 self.is_server = is_server
36 self.synch_count = synch_count
37 self.dependencies = dependencies
38
39 return ControlFile(contents, is_server, synch_count, dependencies)
mblighb8f5b702009-11-06 03:09:03 +000040
41
mblighb62f7242009-07-29 14:34:30 +000042 def test_job_grouping(self):
mblighb8f5b702009-11-06 03:09:03 +000043 tests_map = {
mblighb62f7242009-07-29 14:34:30 +000044 'mach1': trigger.map_action.machine_info(
mblighb8f5b702009-11-06 03:09:03 +000045 ('test1', 'test2'), {'2.6.20': 'config1'}),
mblighb62f7242009-07-29 14:34:30 +000046 'mach2': trigger.map_action.machine_info(
mblighb8f5b702009-11-06 03:09:03 +000047 ('test3',), {'2.6.10': 'config2', '2.6.20': 'config1'}),
mblighb62f7242009-07-29 14:34:30 +000048 'mach3': trigger.map_action.machine_info(
mblighb8f5b702009-11-06 03:09:03 +000049 ('test2', 'test3'), {'2.6.20': 'config1'}),
mblighb62f7242009-07-29 14:34:30 +000050 }
mblighb8f5b702009-11-06 03:09:03 +000051 action = trigger.map_action(tests_map, 'jobname %s')
mblighfdec32c2009-11-21 01:44:17 +000052 self.assertTrue(isinstance(action._afe, trigger.frontend.AFE))
53 action._afe = self.god.create_mock_class(trigger.frontend.AFE, 'AFE')
mblighb62f7242009-07-29 14:34:30 +000054
mblighb8f5b702009-11-06 03:09:03 +000055 control2 = self._make_control_dict('control contents2')
mblighfdec32c2009-11-21 01:44:17 +000056 (action._afe.generate_control_file.expect_call(
57 tests=['test2'],
58 kernel=[dict(version='2.6.21', config_file='config1')],
59 upload_kernel_config=False)
mblighb8f5b702009-11-06 03:09:03 +000060 .and_return(control2))
mblighfdec32c2009-11-21 01:44:17 +000061 action._afe.create_job.expect_call(
mblighf0c5bbf2009-11-21 01:44:59 +000062 control2.control_file, 'jobname 2.6.21',
mblighfdec32c2009-11-21 01:44:17 +000063 control_type='Client', hosts=['mach1', 'mach3'])
mblighb62f7242009-07-29 14:34:30 +000064
mblighfdec32c2009-11-21 01:44:17 +000065 control3 = self._make_control_dict('control contents3', is_server=True)
66 (action._afe.generate_control_file.expect_call(
67 tests=['test3'],
68 kernel=[dict(version='2.6.21', config_file='config1')],
69 upload_kernel_config=False)
mblighb8f5b702009-11-06 03:09:03 +000070 .and_return(control3))
mblighfdec32c2009-11-21 01:44:17 +000071 action._afe.create_job.expect_call(
mblighf0c5bbf2009-11-21 01:44:59 +000072 control3.control_file, 'jobname 2.6.21',
mblighfdec32c2009-11-21 01:44:17 +000073 control_type='Server', hosts=['mach2', 'mach3'])
mblighb62f7242009-07-29 14:34:30 +000074
mblighb8f5b702009-11-06 03:09:03 +000075 control1 = self._make_control_dict('control contents1')
mblighfdec32c2009-11-21 01:44:17 +000076 (action._afe.generate_control_file.expect_call(
77 tests=['test1'],
78 kernel=[dict(version='2.6.21', config_file='config1')],
79 upload_kernel_config=False)
mblighb8f5b702009-11-06 03:09:03 +000080 .and_return(control1))
mblighfdec32c2009-11-21 01:44:17 +000081 action._afe.create_job.expect_call(
mblighf0c5bbf2009-11-21 01:44:59 +000082 control1.control_file, 'jobname 2.6.21',
mblighfdec32c2009-11-21 01:44:17 +000083 control_type='Client', hosts=['mach1'])
mblighb62f7242009-07-29 14:34:30 +000084
85 action(['2.6.21'])
86 self.god.check_playback()
87
88
89 def test_kver_cmp(self):
90 def check_cmp(ver1, ver2):
91 # function to make sure "cmp" invariants are followed
92 cmp_func = trigger.map_action._kver_cmp
93 if ver1 != ver2:
94 self.assertEquals(cmp_func(ver1, ver2), -1)
95 self.assertEquals(cmp_func(ver2, ver1), 1)
96 else:
97 self.assertEquals(cmp_func(ver1, ver2), 0)
98 self.assertEquals(cmp_func(ver2, ver1), 0)
99
100 check_cmp('2.6.20', '2.6.20')
101 check_cmp('2.6.20', '2.6.21')
102 check_cmp('2.6.20', '2.6.21-rc2')
103 check_cmp('2.6.20-rc2-git2', '2.6.20-rc2')
104
105
mblighfdec32c2009-11-21 01:44:17 +0000106 def test_upload_kernel_config(self):
107 tests_map = {
108 'mach1': trigger.map_action.machine_info(
mblighad575162010-03-24 22:14:18 +0000109 ('test1',), {'2.6.20': 'config1'}),
110 'mach3': trigger.map_action.machine_info(
mblighfdec32c2009-11-21 01:44:17 +0000111 ('test1',), {'2.6.20': 'config1'})
112 }
113
114 action = trigger.map_action(tests_map, 'jobname %s',
115 upload_kernel_config=True)
116 self.assertTrue(isinstance(action._afe, trigger.frontend.AFE))
117 action._afe = self.god.create_mock_class(trigger.frontend.AFE, 'AFE')
118
119 control = self._make_control_dict('control contents', is_server=True)
120 (action._afe.generate_control_file.expect_call(
121 tests=['test1'],
122 kernel=[dict(version='2.6.21', config_file='config1')],
123 upload_kernel_config=True)
124 .and_return(control))
125 action._afe.create_job.expect_call(
mblighf0c5bbf2009-11-21 01:44:59 +0000126 control.control_file, 'jobname 2.6.21',
mblighfdec32c2009-11-21 01:44:17 +0000127 control_type='Server', hosts=['mach1', 'mach3'])
128
129 action(['2.6.21'])
130 self.god.check_playback()
131
132
mblighb62f7242009-07-29 14:34:30 +0000133if __name__ == "__main__":
134 unittest.main()