6 from autotest_lib
.client
.common_lib
.test_utils
import mock
7 from autotest_lib
.client
.common_lib
import boottool
10 class test_boottool(unittest
.TestCase
):
12 self
.god
= mock
.mock_god()
13 # creates a bootloader with _run_boottool mocked out
14 self
.bt_mock
= boottool
.boottool()
15 self
.god
.stub_function(self
.bt_mock
, '_run_boottool')
22 def expect_run_boottool(self
, args
, result
=''):
23 self
.bt_mock
._run
_boottool
.expect_call(*args
).and_return(result
)
26 def test_get_type(self
):
27 # set up the recording
28 self
.expect_run_boottool(('--bootloader-probe',), 'lilo\n')
30 self
.assertEquals(self
.bt_mock
.get_type(), 'lilo')
31 self
.god
.check_playback()
34 def test_get_arch(self
):
35 # set up the recording
36 self
.expect_run_boottool(('--arch-probe',), 'x86_64\n')
38 self
.assertEquals(self
.bt_mock
.get_architecture(), 'x86_64')
39 self
.god
.check_playback()
42 def test_get_default(self
):
43 # set up the recording
44 self
.expect_run_boottool(('--default',), '0\n')
46 self
.assertEquals(self
.bt_mock
.get_default(), 0)
47 self
.god
.check_playback()
50 def test_get_titles(self
):
51 # set up the recording
52 self
.expect_run_boottool(
53 ('--info=all',), '\nindex\t: 0\ntitle\t: title #1\n'
54 '\nindex\t: 1\ntitle\t: title #2\n')
56 self
.assertEquals(self
.bt_mock
.get_titles(),
57 ['title #1', 'title #2'])
58 self
.god
.check_playback()
61 def test_get_entry(self
):
66 'initrd\t: /boot/initrd.img-2.6.15-23-386\n'
67 'kernel\t: /boot/vmlinuz-2.6.15-23-386\n'
68 'root\t: UUID=07D7-0714\n'
70 'title\t: Distro, kernel 2.6.15-23-386\n'
72 # set up the recording
73 self
.expect_run_boottool(('--info=5',), RESULT
)
75 info
= self
.bt_mock
.get_entry(5)
76 self
.god
.check_playback()
77 expected_info
= {'index': 5, 'args': 'ro single',
79 'initrd': '/boot/initrd.img-2.6.15-23-386',
80 'kernel': '/boot/vmlinuz-2.6.15-23-386',
81 'root': 'UUID=07D7-0714', 'savedefault': '',
82 'title': 'Distro, kernel 2.6.15-23-386'}
83 self
.assertEquals(expected_info
, info
)
86 def test_get_entry_missing_result(self
):
87 # set up the recording
88 self
.expect_run_boottool(('--info=4',), '')
90 info
= self
.bt_mock
.get_entry(4)
91 self
.god
.check_playback()
92 self
.assertEquals({}, info
)
95 def test_get_entries(self
):
100 'initrd\t: /boot/initrd.img-2.6.15-23-386\n'
101 'kernel\t: /boot/vmlinuz-2.6.15-23-386\n'
102 'root\t: UUID=07D7-0714\n'
104 'title\t: Distro, kernel 2.6.15-23-386\n'
107 'args\t: ro single\n'
109 'initrd\t: /boot/initrd.img-2.6.15-23-686\n'
110 'kernel\t: /boot/vmlinuz-2.6.15-23-686\n'
111 'root\t: UUID=07D7-0714\n'
113 'title\t: Distro, kernel 2.6.15-23-686\n'
115 # set up the recording
116 self
.expect_run_boottool(('--info=all',), RESULT
)
118 info
= self
.bt_mock
.get_entries()
119 self
.god
.check_playback()
121 5: {'index': 5, 'args': 'ro single', 'boot': '(hd0,0)',
122 'initrd': '/boot/initrd.img-2.6.15-23-386',
123 'kernel': '/boot/vmlinuz-2.6.15-23-386',
124 'root': 'UUID=07D7-0714', 'savedefault': '',
125 'title': 'Distro, kernel 2.6.15-23-386'},
126 7: {'index': 7, 'args': 'ro single', 'boot': '(hd0,0)',
127 'initrd': '/boot/initrd.img-2.6.15-23-686',
128 'kernel': '/boot/vmlinuz-2.6.15-23-686',
129 'root': 'UUID=07D7-0714', 'savedefault': '',
130 'title': 'Distro, kernel 2.6.15-23-686'}}
131 self
.assertEquals(expected_info
, info
)
134 def test_set_default(self
):
135 # set up the recording
136 self
.expect_run_boottool(('--set-default=41',))
138 self
.bt_mock
.set_default(41)
139 self
.god
.check_playback()
142 def test_add_args(self
):
143 # set up the recording
144 self
.expect_run_boottool(
145 ('--update-kernel=10', '--args=some kernel args'))
147 self
.bt_mock
.add_args(10, 'some kernel args')
148 self
.god
.check_playback()
151 def test_remove_args(self
):
152 # set up the recording
153 self
.expect_run_boottool(
154 ('--update-kernel=12', '--remove-args=some kernel args'))
156 self
.bt_mock
.remove_args(12, 'some kernel args')
157 self
.god
.check_playback()
160 def setup_add_kernel(self
, oldtitle
, path
, title
, root
=None, args
=None,
161 initrd
=None, default
=False, position
='end',
162 xen_hypervisor
=None):
163 self
.bt_mock
.get_titles
= self
.god
.create_mock_function('get_titles')
164 # set up the recording
165 self
.bt_mock
.get_titles
.expect_call().and_return([oldtitle
])
166 if oldtitle
== title
:
167 self
.expect_run_boottool(('--remove-kernel=%s' % oldtitle
,))
169 parameters
= ['--add-kernel=%s' % path
, '--title=%s' % title
]
171 parameters
.append('--root=%s' % root
)
173 parameters
.append('--args=%s' % args
)
175 parameters
.append('--initrd=%s' % initrd
)
177 parameters
.append('--make-default')
179 parameters
.append('--position=%s' % position
)
180 if self
.bt_mock
.get_xen_mode():
181 parameters
.append('--xen')
183 parameters
.append('--xenhyper=%s' % xen_hypervisor
)
184 self
.expect_run_boottool(parameters
)
187 def test_add_kernel_basic(self
):
188 # set up the recording
189 self
.setup_add_kernel(
190 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel')
192 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
194 self
.god
.check_playback()
197 def test_add_kernel_removes_old(self
):
198 # set up the recording
199 self
.setup_add_kernel(
200 'mylabel', '/unittest/kernels/vmlinuz', 'mylabel')
202 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz', 'mylabel')
203 self
.god
.check_playback()
206 def test_add_kernel_adds_root(self
):
207 # set up the recording
208 self
.setup_add_kernel(
209 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel',
210 root
='/unittest/root')
212 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
213 'mylabel', root
='/unittest/root')
214 self
.god
.check_playback()
217 def test_add_kernel_adds_args(self
):
218 # set up the recording
219 self
.setup_add_kernel(
220 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel',
221 args
='my kernel args')
223 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
224 'mylabel', args
='my kernel args')
225 self
.god
.check_playback()
228 def test_add_kernel_args_remove_duplicates(self
):
229 # set up the recording
230 self
.setup_add_kernel(
231 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel',
232 args
='param2 param1')
234 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
235 'mylabel', args
='param1 param2 param1')
236 self
.god
.check_playback()
239 def test_add_kernel_adds_initrd(self
):
240 # set up the recording
241 self
.setup_add_kernel(
242 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel',
243 initrd
='/unittest/initrd')
245 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
246 'mylabel', initrd
='/unittest/initrd')
247 self
.god
.check_playback()
250 def test_add_kernel_enables_make_default(self
):
251 # set up the recording
252 self
.setup_add_kernel(
253 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel',
256 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
257 'mylabel', default
=True)
258 self
.god
.check_playback()
261 def test_add_kernel_position(self
):
262 # set up the recording
263 self
.setup_add_kernel(
264 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel',
267 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
268 'mylabel', position
=5)
269 self
.god
.check_playback()
272 def test_remove_kernel(self
):
273 # set up the recording
274 self
.expect_run_boottool(('--remove-kernel=14',))
276 self
.bt_mock
.remove_kernel(14)
277 self
.god
.check_playback()
280 def test_boot_once(self
):
281 # set up the recording
282 self
.expect_run_boottool(('--boot-once', '--title=autotest'))
284 self
.bt_mock
.boot_once('autotest')
285 self
.god
.check_playback()
288 def test_enable_xen(self
):
289 self
.bt_mock
.enable_xen_mode()
290 self
.assertTrue(self
.bt_mock
.get_xen_mode())
293 def test_disable_xen(self
):
294 self
.bt_mock
.disable_xen_mode()
295 self
.assertFalse(self
.bt_mock
.get_xen_mode())
298 def test_add_kernel_xen(self
):
299 # set up the recording
300 self
.bt_mock
.enable_xen_mode()
301 self
.setup_add_kernel(
302 'notmylabel', '/unittest/kernels/vmlinuz', 'mylabel',
303 xen_hypervisor
='xen_image')
305 self
.bt_mock
.add_kernel('/unittest/kernels/vmlinuz',
306 'mylabel', xen_hypervisor
='xen_image')
307 self
.god
.check_playback()
310 if __name__
== '__main__':