blob: 197e9f3cee426f6fd80575d8c8ad04c1d5642e77 [file] [log] [blame]
mblighbe630eb2008-08-01 16:41:48 +00001#!/usr/bin/python
2#
3# Copyright 2008 Google Inc. All Rights Reserved.
4
5"""Test for host."""
6
7import unittest, os, sys
8
9import common
10from autotest_lib.cli import cli_mock, host
11
12
13class host_ut(cli_mock.cli_unittest):
14 def test_parse_lock_options_both_set(self):
15 hh = host.host()
16 class opt(object):
17 lock = True
18 unlock = True
19 options = opt()
20 self.usage = "unused"
21 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
22 self.god.mock_io()
23 self.assertRaises(cli_mock.ExitException,
24 hh._parse_lock_options, options)
25 self.god.unmock_io()
26
27
28 def test_cleanup_labels_with_platform(self):
29 labels = ['l0', 'l1', 'l2', 'p0', 'l3']
30 hh = host.host()
31 self.assertEqual(['l0', 'l1', 'l2', 'l3'],
32 hh._cleanup_labels(labels, 'p0'))
33
34
35 def test_cleanup_labels_no_platform(self):
36 labels = ['l0', 'l1', 'l2', 'l3']
37 hh = host.host()
38 self.assertEqual(['l0', 'l1', 'l2', 'l3'],
39 hh._cleanup_labels(labels))
40
41
42 def test_cleanup_labels_with_non_avail_platform(self):
43 labels = ['l0', 'l1', 'l2', 'l3']
44 hh = host.host()
45 self.assertEqual(['l0', 'l1', 'l2', 'l3'],
46 hh._cleanup_labels(labels, 'p0'))
47
48
49class host_list_unittest(cli_mock.cli_unittest):
50 def test_parse_host_not_required(self):
51 hl = host.host_list()
52 sys.argv = ['atest']
53 (options, leftover) = hl.parse()
54 self.assertEqual([], hl.hosts)
55 self.assertEqual([], leftover)
56
57
58 def test_parse_with_hosts(self):
59 hl = host.host_list()
60 mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
mbligh41515392009-07-11 00:13:11 +000061 sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3']
mblighbe630eb2008-08-01 16:41:48 +000062 (options, leftover) = hl.parse()
63 self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
64 hl.hosts)
65 self.assertEqual(leftover, [])
mbligh41515392009-07-11 00:13:11 +000066 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +000067
68
69 def test_parse_with_labels(self):
70 hl = host.host_list()
71 sys.argv = ['atest', '--label', 'label0']
72 (options, leftover) = hl.parse()
mbligh6444c6b2008-10-27 20:55:13 +000073 self.assertEqual('label0', hl.labels)
74 self.assertEqual(leftover, [])
75
76
77 def test_parse_with_multi_labels(self):
78 hl = host.host_list()
79 sys.argv = ['atest', '--label', 'label0,label2']
80 (options, leftover) = hl.parse()
81 self.assertEqual('label0,label2', hl.labels)
mblighbe630eb2008-08-01 16:41:48 +000082 self.assertEqual(leftover, [])
83
84
85 def test_parse_with_both(self):
86 hl = host.host_list()
87 mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
mbligh41515392009-07-11 00:13:11 +000088 sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3',
mblighbe630eb2008-08-01 16:41:48 +000089 '--label', 'label0']
90 (options, leftover) = hl.parse()
91 self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
92 hl.hosts)
mbligh6444c6b2008-10-27 20:55:13 +000093 self.assertEqual('label0', hl.labels)
mblighbe630eb2008-08-01 16:41:48 +000094 self.assertEqual(leftover, [])
mbligh41515392009-07-11 00:13:11 +000095 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +000096
97
98 def test_execute_list_all_no_labels(self):
99 self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
100 rpcs=[('get_hosts', {},
101 True,
102 [{u'status': u'Ready',
103 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000104 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000105 u'locked_by': 'user0',
106 u'lock_time': u'2008-07-23 12:54:15',
107 u'labels': [],
mbligh0887d402009-01-30 00:50:29 +0000108 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000109 u'synch_id': None,
110 u'platform': None,
111 u'id': 1},
112 {u'status': u'Ready',
113 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000114 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000115 u'locked_by': 'user0',
116 u'lock_time': u'2008-07-23 12:54:15',
117 u'labels': [u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000118 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000119 u'synch_id': None,
120 u'platform': u'plat1',
121 u'id': 2}])],
122 out_words_ok=['host0', 'host1', 'Ready',
123 'plat1', 'False', 'True'])
124
125
126 def test_execute_list_all_with_labels(self):
127 self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
128 rpcs=[('get_hosts', {},
129 True,
130 [{u'status': u'Ready',
131 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000132 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000133 u'locked_by': 'user0',
134 u'lock_time': u'2008-07-23 12:54:15',
135 u'labels': [u'label0', u'label1'],
mbligh0887d402009-01-30 00:50:29 +0000136 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000137 u'synch_id': None,
138 u'platform': None,
139 u'id': 1},
140 {u'status': u'Ready',
141 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000142 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000143 u'locked_by': 'user0',
144 u'lock_time': u'2008-07-23 12:54:15',
145 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000146 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000147 u'synch_id': None,
148 u'platform': u'plat1',
149 u'id': 2}])],
150 out_words_ok=['host0', 'host1', 'Ready', 'plat1',
151 'label0', 'label1', 'label2', 'label3',
152 'False', 'True'])
153
154
155 def test_execute_list_filter_one_host(self):
156 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
157 '--ignore_site_file'],
158 rpcs=[('get_hosts', {'hostname__in': ['host1']},
159 True,
160 [{u'status': u'Ready',
161 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000162 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000163 u'locked_by': 'user0',
164 u'lock_time': u'2008-07-23 12:54:15',
165 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000166 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000167 u'synch_id': None,
168 u'platform': u'plat1',
169 u'id': 2}])],
170 out_words_ok=['host1', 'Ready', 'plat1',
171 'label2', 'label3', 'True'],
172 out_words_no=['host0', 'host2',
173 'label1', 'label4', 'False'])
174
175
176 def test_execute_list_filter_two_hosts(self):
177 mfile = cli_mock.create_file('host2')
178 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000179 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000180 # This is a bit fragile as the list order may change...
181 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
182 True,
183 [{u'status': u'Ready',
184 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000185 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000186 u'locked_by': 'user0',
187 u'lock_time': u'2008-07-23 12:54:15',
188 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000189 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000190 u'synch_id': None,
191 u'platform': u'plat1',
192 u'id': 2},
193 {u'status': u'Ready',
194 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000195 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000196 u'locked_by': 'user0',
197 u'lock_time': u'2008-07-23 12:54:15',
198 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000199 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000200 u'synch_id': None,
201 u'platform': u'plat1',
202 u'id': 3}])],
203 out_words_ok=['host1', 'Ready', 'plat1',
204 'label2', 'label3', 'True',
205 'host2', 'label4'],
206 out_words_no=['host0', 'label1', 'False'])
mbligh41515392009-07-11 00:13:11 +0000207 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000208
209
210 def test_execute_list_filter_two_hosts_one_not_found(self):
211 mfile = cli_mock.create_file('host2')
212 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000213 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000214 # This is a bit fragile as the list order may change...
215 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
216 True,
217 [{u'status': u'Ready',
218 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000219 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000220 u'locked_by': 'user0',
221 u'lock_time': u'2008-07-23 12:54:15',
222 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000223 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000224 u'synch_id': None,
225 u'platform': u'plat1',
226 u'id': 3}])],
227 out_words_ok=['Ready', 'plat1',
228 'label3', 'label4', 'True'],
229 out_words_no=['host1', 'False'],
230 err_words_ok=['host1'])
mbligh41515392009-07-11 00:13:11 +0000231 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000232
233
234 def test_execute_list_filter_two_hosts_none_found(self):
235 self.run_cmd(argv=['atest', 'host', 'list',
236 'host1', 'host2', '--ignore_site_file'],
237 # This is a bit fragile as the list order may change...
238 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
239 True,
240 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000241 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000242 out_words_no=['Hostname', 'Status'],
243 err_words_ok=['Unknown', 'host1', 'host2'])
244
245
246 def test_execute_list_filter_label(self):
247 self.run_cmd(argv=['atest', 'host', 'list',
248 '-b', 'label3', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000249 rpcs=[('get_hosts', {'labels__name__in': ['label3']},
mblighbe630eb2008-08-01 16:41:48 +0000250 True,
251 [{u'status': u'Ready',
252 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000253 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000254 u'locked_by': 'user0',
255 u'lock_time': u'2008-07-23 12:54:15',
256 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000257 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000258 u'synch_id': None,
259 u'platform': u'plat1',
260 u'id': 2},
261 {u'status': u'Ready',
262 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000263 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000264 u'locked_by': 'user0',
265 u'lock_time': u'2008-07-23 12:54:15',
266 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000267 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000268 u'synch_id': None,
269 u'platform': u'plat1',
270 u'id': 3}])],
271 out_words_ok=['host1', 'Ready', 'plat1',
272 'label2', 'label3', 'True',
273 'host2', 'label4'],
274 out_words_no=['host0', 'label1', 'False'])
275
276
mbligh6444c6b2008-10-27 20:55:13 +0000277 def test_execute_list_filter_multi_labels(self):
278 self.run_cmd(argv=['atest', 'host', 'list',
279 '-b', 'label3,label2', '--ignore_site_file'],
280 rpcs=[('get_hosts', {'multiple_labels': ['label3',
281 'label2']},
282 True,
283 [{u'status': u'Ready',
284 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000285 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000286 u'locked_by': 'user0',
287 u'lock_time': u'2008-07-23 12:54:15',
288 u'labels': [u'label2', u'label3', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000289 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000290 u'synch_id': None,
291 u'platform': u'plat0',
292 u'id': 2},
293 {u'status': u'Ready',
294 u'hostname': u'host3',
mbligh0887d402009-01-30 00:50:29 +0000295 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000296 u'locked_by': 'user0',
297 u'lock_time': u'2008-07-23 12:54:15',
298 u'labels': [u'label3', u'label2', u'plat2'],
mbligh0887d402009-01-30 00:50:29 +0000299 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000300 u'synch_id': None,
301 u'platform': u'plat2',
302 u'id': 4}])],
303 out_words_ok=['host1', 'host3', 'Ready', 'plat0',
304 'label2', 'label3', 'plat2'],
305 out_words_no=['host2', 'label4', 'False', 'plat1'])
306
307
308 def test_execute_list_filter_three_labels(self):
309 self.run_cmd(argv=['atest', 'host', 'list',
310 '-b', 'label3,label2, label4',
311 '--ignore_site_file'],
312 rpcs=[('get_hosts', {'multiple_labels': ['label3',
313 'label2',
314 'label4']},
315 True,
316 [{u'status': u'Ready',
317 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000318 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000319 u'locked_by': 'user0',
320 u'lock_time': u'2008-07-23 12:54:15',
321 u'labels': [u'label3', u'label2', u'label4',
322 u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000323 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000324 u'synch_id': None,
325 u'platform': u'plat1',
326 u'id': 3}])],
327 out_words_ok=['host2', 'plat1',
328 'label2', 'label3', 'label4'],
329 out_words_no=['host1', 'host3'])
330
331
mblighf703fb42009-01-30 00:35:05 +0000332 def test_execute_list_filter_wild_labels(self):
333 self.run_cmd(argv=['atest', 'host', 'list',
334 '-b', 'label*',
335 '--ignore_site_file'],
336 rpcs=[('get_hosts',
337 {'labels__name__startswith': 'label'},
338 True,
339 [{u'status': u'Ready',
340 u'hostname': u'host2',
341 u'locked': 1,
342 u'locked_by': 'user0',
343 u'lock_time': u'2008-07-23 12:54:15',
344 u'labels': [u'label3', u'label2', u'label4',
345 u'plat1'],
346 u'invalid': 0,
347 u'synch_id': None,
348 u'platform': u'plat1',
349 u'id': 3}])],
350 out_words_ok=['host2', 'plat1',
351 'label2', 'label3', 'label4'],
352 out_words_no=['host1', 'host3'])
353
354
mbligh6444c6b2008-10-27 20:55:13 +0000355 def test_execute_list_filter_multi_labels_no_results(self):
356 self.run_cmd(argv=['atest', 'host', 'list',
357 '-b', 'label3,label2, ', '--ignore_site_file'],
358 rpcs=[('get_hosts', {'multiple_labels': ['label3',
359 'label2']},
360 True,
361 [])],
362 out_words_ok=[],
363 out_words_no=['host1', 'host2', 'host3',
364 'label2', 'label3', 'label4'])
365
mblighbe630eb2008-08-01 16:41:48 +0000366
367 def test_execute_list_filter_label_and_hosts(self):
368 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
369 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000370 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000371 'hostname__in': ['host2', 'host1']},
372 True,
373 [{u'status': u'Ready',
374 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000375 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000376 u'locked_by': 'user0',
377 u'lock_time': u'2008-07-23 12:54:15',
378 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000379 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000380 u'synch_id': None,
381 u'platform': u'plat1',
382 u'id': 2},
383 {u'status': u'Ready',
384 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000385 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000386 u'locked_by': 'user0',
387 u'lock_time': u'2008-07-23 12:54:15',
388 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000389 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000390 u'synch_id': None,
391 u'platform': u'plat1',
392 u'id': 3}])],
393 out_words_ok=['host1', 'Ready', 'plat1',
394 'label2', 'label3', 'True',
395 'host2', 'label4'],
396 out_words_no=['host0', 'label1', 'False'])
397
398
399 def test_execute_list_filter_label_and_hosts_none(self):
400 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
401 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000402 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000403 'hostname__in': ['host2', 'host1']},
404 True,
405 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000406 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000407 out_words_no=['Hostname', 'Status'],
408 err_words_ok=['Unknown', 'host1', 'host2'])
409
410
mblighcd8eb972008-08-25 19:20:39 +0000411 def test_execute_list_filter_status(self):
412 self.run_cmd(argv=['atest', 'host', 'list',
413 '-s', 'Ready', '--ignore_site_file'],
414 rpcs=[('get_hosts', {'status__in': ['Ready']},
415 True,
416 [{u'status': u'Ready',
417 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000418 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000419 u'locked_by': 'user0',
420 u'lock_time': u'2008-07-23 12:54:15',
421 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000422 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000423 u'synch_id': None,
424 u'platform': u'plat1',
425 u'id': 2},
426 {u'status': u'Ready',
427 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000428 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000429 u'locked_by': 'user0',
430 u'lock_time': u'2008-07-23 12:54:15',
431 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000432 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000433 u'synch_id': None,
434 u'platform': u'plat1',
435 u'id': 3}])],
436 out_words_ok=['host1', 'Ready', 'plat1',
437 'label2', 'label3', 'True',
438 'host2', 'label4'],
439 out_words_no=['host0', 'label1', 'False'])
440
441
442
443 def test_execute_list_filter_status_and_hosts(self):
444 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
445 '-s', 'Ready', 'host2', '--ignore_site_file'],
446 rpcs=[('get_hosts', {'status__in': ['Ready'],
447 'hostname__in': ['host2', 'host1']},
448 True,
449 [{u'status': u'Ready',
450 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000451 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000452 u'locked_by': 'user0',
453 u'lock_time': u'2008-07-23 12:54:15',
454 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000455 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000456 u'synch_id': None,
457 u'platform': u'plat1',
458 u'id': 2},
459 {u'status': u'Ready',
460 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000461 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000462 u'locked_by': 'user0',
463 u'lock_time': u'2008-07-23 12:54:15',
464 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000465 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000466 u'synch_id': None,
467 u'platform': u'plat1',
468 u'id': 3}])],
469 out_words_ok=['host1', 'Ready', 'plat1',
470 'label2', 'label3', 'True',
471 'host2', 'label4'],
472 out_words_no=['host0', 'label1', 'False'])
473
474
475 def test_execute_list_filter_status_and_hosts_none(self):
476 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
477 '--status', 'Repair',
478 'host2', '--ignore_site_file'],
479 rpcs=[('get_hosts', {'status__in': ['Repair'],
480 'hostname__in': ['host2', 'host1']},
481 True,
482 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000483 out_words_ok=[],
mblighcd8eb972008-08-25 19:20:39 +0000484 out_words_no=['Hostname', 'Status'],
485 err_words_ok=['Unknown', 'host2'])
486
487
mbligh6444c6b2008-10-27 20:55:13 +0000488 def test_execute_list_filter_statuses_and_hosts_none(self):
489 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh3df90c92009-03-09 21:09:29 +0000490 '--status', 'Repair',
mbligh6444c6b2008-10-27 20:55:13 +0000491 'host2', '--ignore_site_file'],
mbligh3df90c92009-03-09 21:09:29 +0000492 rpcs=[('get_hosts', {'status__in': ['Repair'],
mbligh6444c6b2008-10-27 20:55:13 +0000493 'hostname__in': ['host2', 'host1']},
494 True,
495 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000496 out_words_ok=[],
mbligh6444c6b2008-10-27 20:55:13 +0000497 out_words_no=['Hostname', 'Status'],
498 err_words_ok=['Unknown', 'host2'])
499
500
mbligh91e0efd2009-02-26 01:02:16 +0000501 def test_execute_list_filter_locked(self):
502 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
503 '--locked', 'host2', '--ignore_site_file'],
504 rpcs=[('get_hosts', {'locked': True,
505 'hostname__in': ['host2', 'host1']},
506 True,
507 [{u'status': u'Ready',
508 u'hostname': u'host1',
509 u'locked': True,
510 u'locked_by': 'user0',
511 u'lock_time': u'2008-07-23 12:54:15',
512 u'labels': [u'label2', u'label3', u'plat1'],
513 u'invalid': False,
514 u'synch_id': None,
515 u'platform': u'plat1',
516 u'id': 2},
517 {u'status': u'Ready',
518 u'hostname': u'host2',
519 u'locked': True,
520 u'locked_by': 'user0',
521 u'lock_time': u'2008-07-23 12:54:15',
522 u'labels': [u'label3', u'label4', u'plat1'],
523 u'invalid': False,
524 u'synch_id': None,
525 u'platform': u'plat1',
526 u'id': 3}])],
527 out_words_ok=['host1', 'Ready', 'plat1',
528 'label2', 'label3', 'True',
529 'host2', 'label4'],
530 out_words_no=['host0', 'label1', 'False'])
531
532
533 def test_execute_list_filter_unlocked(self):
534 self.run_cmd(argv=['atest', 'host', 'list',
535 '--unlocked', '--ignore_site_file'],
536 rpcs=[('get_hosts', {'locked': False},
537 True,
538 [{u'status': u'Ready',
539 u'hostname': u'host1',
540 u'locked': False,
541 u'locked_by': 'user0',
542 u'lock_time': u'2008-07-23 12:54:15',
543 u'labels': [u'label2', u'label3', u'plat1'],
544 u'invalid': False,
545 u'synch_id': None,
546 u'platform': u'plat1',
547 u'id': 2},
548 {u'status': u'Ready',
549 u'hostname': u'host2',
550 u'locked': False,
551 u'locked_by': 'user0',
552 u'lock_time': u'2008-07-23 12:54:15',
553 u'labels': [u'label3', u'label4', u'plat1'],
554 u'invalid': False,
555 u'synch_id': None,
556 u'platform': u'plat1',
557 u'id': 3}])],
558 out_words_ok=['host1', 'Ready', 'plat1',
559 'label2', 'label3', 'False',
560 'host2', 'label4'],
561 out_words_no=['host0', 'label1', 'True'])
562
563
mblighbe630eb2008-08-01 16:41:48 +0000564class host_stat_unittest(cli_mock.cli_unittest):
565 def test_execute_stat_two_hosts(self):
566 # The order of RPCs between host1 and host0 could change...
567 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
568 '--ignore_site_file'],
569 rpcs=[('get_hosts', {'hostname': 'host1'},
570 True,
571 [{u'status': u'Ready',
572 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000573 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000574 u'lock_time': u'2008-07-23 12:54:15',
575 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000576 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000577 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000578 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000579 u'synch_id': None,
580 u'platform': u'plat1',
581 u'id': 3}]),
582 ('get_hosts', {'hostname': 'host0'},
583 True,
584 [{u'status': u'Ready',
585 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000586 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000587 u'locked_by': 'user0',
588 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000589 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000590 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000591 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000592 u'synch_id': None,
593 u'platform': u'plat0',
594 u'id': 2}]),
595 ('get_acl_groups', {'hosts__hostname': 'host1'},
596 True,
597 [{u'description': u'',
598 u'hosts': [u'host0', u'host1'],
599 u'id': 1,
600 u'name': u'Everyone',
601 u'users': [u'user2', u'debug_user', u'user0']}]),
602 ('get_labels', {'host__hostname': 'host1'},
603 True,
604 [{u'id': 2,
605 u'platform': 1,
606 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000607 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000608 u'kernel_config': u''}]),
609 ('get_acl_groups', {'hosts__hostname': 'host0'},
610 True,
611 [{u'description': u'',
612 u'hosts': [u'host0', u'host1'],
613 u'id': 1,
614 u'name': u'Everyone',
615 u'users': [u'user0', u'debug_user']},
616 {u'description': u'myacl0',
617 u'hosts': [u'host0'],
618 u'id': 2,
619 u'name': u'acl0',
620 u'users': [u'user0']}]),
621 ('get_labels', {'host__hostname': 'host0'},
622 True,
623 [{u'id': 4,
624 u'platform': 0,
625 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000626 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000627 u'kernel_config': u''},
628 {u'id': 5,
629 u'platform': 1,
630 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000631 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000632 u'kernel_config': u''}])],
633 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
634 'Everyone', 'acl0', 'label0'])
635
636
637 def test_execute_stat_one_bad_host_verbose(self):
638 self.run_cmd(argv=['atest', 'host', 'stat', 'host0',
639 'host1', '-v', '--ignore_site_file'],
640 rpcs=[('get_hosts', {'hostname': 'host1'},
641 True,
642 []),
643 ('get_hosts', {'hostname': 'host0'},
644 True,
645 [{u'status': u'Ready',
646 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000647 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000648 u'locked_by': 'user0',
649 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000650 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000651 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000652 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000653 u'synch_id': None,
654 u'platform': u'plat0',
655 u'id': 2}]),
656 ('get_acl_groups', {'hosts__hostname': 'host0'},
657 True,
658 [{u'description': u'',
659 u'hosts': [u'host0', u'host1'],
660 u'id': 1,
661 u'name': u'Everyone',
662 u'users': [u'user0', u'debug_user']},
663 {u'description': u'myacl0',
664 u'hosts': [u'host0'],
665 u'id': 2,
666 u'name': u'acl0',
667 u'users': [u'user0']}]),
668 ('get_labels', {'host__hostname': 'host0'},
669 True,
670 [{u'id': 4,
671 u'platform': 0,
672 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000673 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000674 u'kernel_config': u''},
675 {u'id': 5,
676 u'platform': 1,
677 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000678 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000679 u'kernel_config': u''}])],
680 out_words_ok=['host0', 'plat0',
681 'Everyone', 'acl0', 'label0'],
682 out_words_no=['host1'],
683 err_words_ok=['host1', 'Unknown host'],
684 err_words_no=['host0'])
685
686
687 def test_execute_stat_one_bad_host(self):
688 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
689 '--ignore_site_file'],
690 rpcs=[('get_hosts', {'hostname': 'host1'},
691 True,
692 []),
693 ('get_hosts', {'hostname': 'host0'},
694 True,
695 [{u'status': u'Ready',
696 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000697 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000698 u'locked_by': 'user0',
699 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000700 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000701 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000702 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000703 u'synch_id': None,
704 u'platform': u'plat0',
705 u'id': 2}]),
706 ('get_acl_groups', {'hosts__hostname': 'host0'},
707 True,
708 [{u'description': u'',
709 u'hosts': [u'host0', u'host1'],
710 u'id': 1,
711 u'name': u'Everyone',
712 u'users': [u'user0', u'debug_user']},
713 {u'description': u'myacl0',
714 u'hosts': [u'host0'],
715 u'id': 2,
716 u'name': u'acl0',
717 u'users': [u'user0']}]),
718 ('get_labels', {'host__hostname': 'host0'},
719 True,
720 [{u'id': 4,
721 u'platform': 0,
722 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000723 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000724 u'kernel_config': u''},
725 {u'id': 5,
726 u'platform': 1,
727 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000728 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000729 u'kernel_config': u''}])],
730 out_words_ok=['host0', 'plat0',
731 'Everyone', 'acl0', 'label0'],
732 out_words_no=['host1'],
733 err_words_ok=['host1', 'Unknown host'],
734 err_words_no=['host0'])
735
736
737 def test_execute_stat_wildcard(self):
738 # The order of RPCs between host1 and host0 could change...
739 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*',
740 '--ignore_site_file'],
741 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
742 True,
743 [{u'status': u'Ready',
744 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000745 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000746 u'lock_time': u'2008-07-23 12:54:15',
747 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000748 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000749 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000750 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000751 u'synch_id': None,
752 u'platform': u'plat1',
753 u'id': 3},
754 {u'status': u'Ready',
755 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000756 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000757 u'locked_by': 'user0',
758 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000759 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000760 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000761 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000762 u'synch_id': None,
763 u'platform': u'plat0',
764 u'id': 2}]),
765 ('get_acl_groups', {'hosts__hostname': 'host1'},
766 True,
767 [{u'description': u'',
768 u'hosts': [u'host0', u'host1'],
769 u'id': 1,
770 u'name': u'Everyone',
771 u'users': [u'user2', u'debug_user', u'user0']}]),
772 ('get_labels', {'host__hostname': 'host1'},
773 True,
774 [{u'id': 2,
775 u'platform': 1,
776 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000777 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000778 u'kernel_config': u''}]),
779 ('get_acl_groups', {'hosts__hostname': 'host0'},
780 True,
781 [{u'description': u'',
782 u'hosts': [u'host0', u'host1'],
783 u'id': 1,
784 u'name': u'Everyone',
785 u'users': [u'user0', u'debug_user']},
786 {u'description': u'myacl0',
787 u'hosts': [u'host0'],
788 u'id': 2,
789 u'name': u'acl0',
790 u'users': [u'user0']}]),
791 ('get_labels', {'host__hostname': 'host0'},
792 True,
793 [{u'id': 4,
794 u'platform': 0,
795 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000796 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000797 u'kernel_config': u''},
798 {u'id': 5,
799 u'platform': 1,
800 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000801 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000802 u'kernel_config': u''}])],
803 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
804 'Everyone', 'acl0', 'label0'])
805
806
807 def test_execute_stat_wildcard_and_host(self):
808 # The order of RPCs between host1 and host0 could change...
809 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', 'newhost0',
810 '--ignore_site_file'],
811 rpcs=[('get_hosts', {'hostname': 'newhost0'},
812 True,
813 [{u'status': u'Ready',
814 u'hostname': u'newhost0',
mbligh0887d402009-01-30 00:50:29 +0000815 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000816 u'locked_by': 'user0',
817 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000818 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000819 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000820 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000821 u'synch_id': None,
822 u'platform': u'plat0',
823 u'id': 5}]),
824 ('get_hosts', {'hostname__startswith': 'ho'},
825 True,
826 [{u'status': u'Ready',
827 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000828 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000829 u'lock_time': u'2008-07-23 12:54:15',
830 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000831 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000832 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000833 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000834 u'synch_id': None,
835 u'platform': u'plat1',
836 u'id': 3},
837 {u'status': u'Ready',
838 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000839 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000840 u'locked_by': 'user0',
mbligh536a5242008-10-18 14:35:54 +0000841 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000842 u'lock_time': u'2008-07-23 12:54:15',
843 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000844 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000845 u'synch_id': None,
846 u'platform': u'plat0',
847 u'id': 2}]),
848 ('get_acl_groups', {'hosts__hostname': 'newhost0'},
849 True,
850 [{u'description': u'',
851 u'hosts': [u'newhost0', 'host1'],
852 u'id': 42,
853 u'name': u'my_acl',
854 u'users': [u'user0', u'debug_user']},
855 {u'description': u'my favorite acl',
856 u'hosts': [u'newhost0'],
857 u'id': 2,
858 u'name': u'acl10',
859 u'users': [u'user0']}]),
860 ('get_labels', {'host__hostname': 'newhost0'},
861 True,
862 [{u'id': 4,
863 u'platform': 0,
864 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000865 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000866 u'kernel_config': u''},
867 {u'id': 5,
868 u'platform': 1,
869 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000870 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000871 u'kernel_config': u''}]),
872 ('get_acl_groups', {'hosts__hostname': 'host1'},
873 True,
874 [{u'description': u'',
875 u'hosts': [u'host0', u'host1'],
876 u'id': 1,
877 u'name': u'Everyone',
878 u'users': [u'user2', u'debug_user', u'user0']}]),
879 ('get_labels', {'host__hostname': 'host1'},
880 True,
881 [{u'id': 2,
882 u'platform': 1,
883 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000884 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000885 u'kernel_config': u''}]),
886 ('get_acl_groups', {'hosts__hostname': 'host0'},
887 True,
888 [{u'description': u'',
889 u'hosts': [u'host0', u'host1'],
890 u'id': 1,
891 u'name': u'Everyone',
892 u'users': [u'user0', u'debug_user']},
893 {u'description': u'myacl0',
894 u'hosts': [u'host0'],
895 u'id': 2,
896 u'name': u'acl0',
897 u'users': [u'user0']}]),
898 ('get_labels', {'host__hostname': 'host0'},
899 True,
900 [{u'id': 4,
901 u'platform': 0,
902 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000903 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000904 u'kernel_config': u''},
905 {u'id': 5,
906 u'platform': 1,
907 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000908 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000909 u'kernel_config': u''}])],
910 out_words_ok=['host0', 'host1', 'newhost0',
911 'plat0', 'plat1',
mblighe163b032008-10-18 14:30:27 +0000912 'Everyone', 'acl10', 'label0'])
mblighbe630eb2008-08-01 16:41:48 +0000913
914
915class host_jobs_unittest(cli_mock.cli_unittest):
916 def test_execute_jobs_one_host(self):
917 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
918 '--ignore_site_file'],
919 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +0000920 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +0000921 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +0000922 True,
923 [{u'status': u'Failed',
924 u'complete': 1,
925 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +0000926 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000927 u'locked_by': 'user0',
928 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000929 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000930 u'id': 3232,
931 u'synch_id': None},
932 u'priority': 0,
933 u'meta_host': u'meta0',
934 u'job': {u'control_file':
935 (u"def step_init():\n"
936 "\tjob.next_step([step_test])\n"
937 "\ttestkernel = job.kernel("
938 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
939 "\ttestkernel.install()\n"
940 "\ttestkernel.boot()\n\n"
941 "def step_test():\n"
942 "\tjob.run_test('kernbench')\n\n"),
943 u'name': u'kernel-smp-2.6.xyz.x86_64',
944 u'control_type': u'Client',
945 u'synchronizing': None,
946 u'priority': u'Low',
947 u'owner': u'user0',
948 u'created_on': u'2008-01-09 10:45:12',
949 u'synch_count': None,
950 u'synch_type': u'Asynchronous',
951 u'id': 216},
952 u'active': 0,
953 u'id': 2981},
954 {u'status': u'Aborted',
955 u'complete': 1,
956 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +0000957 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000958 u'locked_by': 'user0',
959 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000960 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000961 u'id': 3232,
962 u'synch_id': None},
963 u'priority': 0,
964 u'meta_host': None,
965 u'job': {u'control_file':
966 u"job.run_test('sleeptest')\n\n",
967 u'name': u'testjob',
968 u'control_type': u'Client',
969 u'synchronizing': 0,
970 u'priority': u'Low',
971 u'owner': u'user1',
972 u'created_on': u'2008-01-17 15:04:53',
973 u'synch_count': None,
974 u'synch_type': u'Asynchronous',
975 u'id': 289},
976 u'active': 0,
977 u'id': 3167}])],
978 out_words_ok=['216', 'user0', 'Failed',
979 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
980 '289', 'user1', 'Aborted',
981 'testjob'])
982
983
984 def test_execute_jobs_wildcard(self):
985 self.run_cmd(argv=['atest', 'host', 'jobs', 'ho*',
986 '--ignore_site_file'],
987 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
988 True,
989 [{u'status': u'Ready',
990 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000991 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000992 u'lock_time': u'2008-07-23 12:54:15',
993 u'locked_by': 'user0',
994 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000995 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000996 u'synch_id': None,
997 u'platform': u'plat1',
998 u'id': 3},
999 {u'status': u'Ready',
1000 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001001 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +00001002 u'locked_by': 'user0',
1003 u'lock_time': u'2008-07-23 12:54:15',
1004 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +00001005 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001006 u'synch_id': None,
1007 u'platform': u'plat0',
1008 u'id': 2}]),
1009 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001010 {'host__hostname': 'host1', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001011 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001012 True,
1013 [{u'status': u'Failed',
1014 u'complete': 1,
1015 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001016 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001017 u'locked_by': 'user0',
1018 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001019 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001020 u'id': 3232,
1021 u'synch_id': None},
1022 u'priority': 0,
1023 u'meta_host': u'meta0',
1024 u'job': {u'control_file':
1025 (u"def step_init():\n"
1026 "\tjob.next_step([step_test])\n"
1027 "\ttestkernel = job.kernel("
1028 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1029 "\ttestkernel.install()\n"
1030 "\ttestkernel.boot()\n\n"
1031 "def step_test():\n"
1032 "\tjob.run_test('kernbench')\n\n"),
1033 u'name': u'kernel-smp-2.6.xyz.x86_64',
1034 u'control_type': u'Client',
1035 u'synchronizing': None,
1036 u'priority': u'Low',
1037 u'owner': u'user0',
1038 u'created_on': u'2008-01-09 10:45:12',
1039 u'synch_count': None,
1040 u'synch_type': u'Asynchronous',
1041 u'id': 216},
1042 u'active': 0,
1043 u'id': 2981},
1044 {u'status': u'Aborted',
1045 u'complete': 1,
1046 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001047 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001048 u'locked_by': 'user0',
1049 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001050 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001051 u'id': 3232,
1052 u'synch_id': None},
1053 u'priority': 0,
1054 u'meta_host': None,
1055 u'job': {u'control_file':
1056 u"job.run_test('sleeptest')\n\n",
1057 u'name': u'testjob',
1058 u'control_type': u'Client',
1059 u'synchronizing': 0,
1060 u'priority': u'Low',
1061 u'owner': u'user1',
1062 u'created_on': u'2008-01-17 15:04:53',
1063 u'synch_count': None,
1064 u'synch_type': u'Asynchronous',
1065 u'id': 289},
1066 u'active': 0,
1067 u'id': 3167}]),
1068 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001069 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001070 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001071 True,
1072 [{u'status': u'Failed',
1073 u'complete': 1,
1074 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001075 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001076 u'locked_by': 'user0',
1077 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001078 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001079 u'id': 3232,
1080 u'synch_id': None},
1081 u'priority': 0,
1082 u'meta_host': u'meta0',
1083 u'job': {u'control_file':
1084 (u"def step_init():\n"
1085 "\tjob.next_step([step_test])\n"
1086 "\ttestkernel = job.kernel("
1087 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1088 "\ttestkernel.install()\n"
1089 "\ttestkernel.boot()\n\n"
1090 "def step_test():\n"
1091 "\tjob.run_test('kernbench')\n\n"),
1092 u'name': u'kernel-smp-2.6.xyz.x86_64',
1093 u'control_type': u'Client',
1094 u'synchronizing': None,
1095 u'priority': u'Low',
1096 u'owner': u'user0',
1097 u'created_on': u'2008-01-09 10:45:12',
1098 u'synch_count': None,
1099 u'synch_type': u'Asynchronous',
1100 u'id': 216},
1101 u'active': 0,
1102 u'id': 2981},
1103 {u'status': u'Aborted',
1104 u'complete': 1,
1105 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001106 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001107 u'locked_by': 'user0',
1108 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001109 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001110 u'id': 3232,
1111 u'synch_id': None},
1112 u'priority': 0,
1113 u'meta_host': None,
1114 u'job': {u'control_file':
1115 u"job.run_test('sleeptest')\n\n",
1116 u'name': u'testjob',
1117 u'control_type': u'Client',
1118 u'synchronizing': 0,
1119 u'priority': u'Low',
1120 u'owner': u'user1',
1121 u'created_on': u'2008-01-17 15:04:53',
1122 u'synch_count': None,
1123 u'synch_type': u'Asynchronous',
1124 u'id': 289},
1125 u'active': 0,
1126 u'id': 3167}])],
1127 out_words_ok=['216', 'user0', 'Failed',
1128 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1129 '289', 'user1', 'Aborted',
1130 'testjob'])
1131
mbligh6996fe82008-08-13 00:32:27 +00001132
1133 def test_execute_jobs_one_host_limit(self):
1134 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
1135 '--ignore_site_file', '-q', '10'],
1136 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001137 {'host__hostname': 'host0', 'query_limit': 10,
showard6958c722009-09-23 20:03:16 +00001138 'sort_by': ['-job__id']},
mbligh6996fe82008-08-13 00:32:27 +00001139 True,
1140 [{u'status': u'Failed',
1141 u'complete': 1,
1142 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001143 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001144 u'locked_by': 'user0',
1145 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001146 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001147 u'id': 3232,
1148 u'synch_id': None},
1149 u'priority': 0,
1150 u'meta_host': u'meta0',
1151 u'job': {u'control_file':
1152 (u"def step_init():\n"
1153 "\tjob.next_step([step_test])\n"
1154 "\ttestkernel = job.kernel("
1155 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1156 "\ttestkernel.install()\n"
1157 "\ttestkernel.boot()\n\n"
1158 "def step_test():\n"
1159 "\tjob.run_test('kernbench')\n\n"),
1160 u'name': u'kernel-smp-2.6.xyz.x86_64',
1161 u'control_type': u'Client',
1162 u'synchronizing': None,
1163 u'priority': u'Low',
1164 u'owner': u'user0',
1165 u'created_on': u'2008-01-09 10:45:12',
1166 u'synch_count': None,
1167 u'synch_type': u'Asynchronous',
1168 u'id': 216},
1169 u'active': 0,
1170 u'id': 2981},
1171 {u'status': u'Aborted',
1172 u'complete': 1,
1173 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001174 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001175 u'locked_by': 'user0',
1176 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001177 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001178 u'id': 3232,
1179 u'synch_id': None},
1180 u'priority': 0,
1181 u'meta_host': None,
1182 u'job': {u'control_file':
1183 u"job.run_test('sleeptest')\n\n",
1184 u'name': u'testjob',
1185 u'control_type': u'Client',
1186 u'synchronizing': 0,
1187 u'priority': u'Low',
1188 u'owner': u'user1',
1189 u'created_on': u'2008-01-17 15:04:53',
1190 u'synch_count': None,
1191 u'synch_type': u'Asynchronous',
1192 u'id': 289},
1193 u'active': 0,
1194 u'id': 3167}])],
1195 out_words_ok=['216', 'user0', 'Failed',
1196 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1197 '289', 'user1', 'Aborted',
1198 'testjob'])
1199
1200
mblighbe630eb2008-08-01 16:41:48 +00001201class host_mod_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +00001202 def test_execute_lock_one_host(self):
1203 self.run_cmd(argv=['atest', 'host', 'mod',
1204 '--lock', 'host0', '--ignore_site_file'],
1205 rpcs=[('modify_host', {'id': 'host0', 'locked': True},
1206 True, None)],
1207 out_words_ok=['Locked', 'host0'])
1208
1209
1210 def test_execute_unlock_two_hosts(self):
1211 self.run_cmd(argv=['atest', 'host', 'mod',
1212 '-u', 'host0,host1', '--ignore_site_file'],
1213 rpcs=[('modify_host', {'id': 'host1', 'locked': False},
1214 True, None),
1215 ('modify_host', {'id': 'host0', 'locked': False},
1216 True, None)],
1217 out_words_ok=['Unlocked', 'host0', 'host1'])
1218
1219
mbligh6eca4602009-01-07 16:48:50 +00001220 def test_execute_lock_unknown_hosts(self):
1221 self.run_cmd(argv=['atest', 'host', 'mod',
1222 '-l', 'host0,host1', 'host2', '--ignore_site_file'],
1223 rpcs=[('modify_host', {'id': 'host2', 'locked': True},
1224 True, None),
1225 ('modify_host', {'id': 'host1', 'locked': True},
1226 False, 'DoesNotExist: Host matching '
1227 'query does not exist.'),
1228 ('modify_host', {'id': 'host0', 'locked': True},
1229 True, None)],
1230 out_words_ok=['Locked', 'host0', 'host2'],
1231 err_words_ok=['Host', 'matching', 'query', 'host1'])
1232
1233
showardbe0d8692009-08-20 23:42:44 +00001234 def test_execute_protection_hosts(self):
mblighbe630eb2008-08-01 16:41:48 +00001235 mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4')
showardbe0d8692009-08-20 23:42:44 +00001236 self.run_cmd(argv=['atest', 'host', 'mod', '--protection',
1237 'Do not repair',
mbligh41515392009-07-11 00:13:11 +00001238 'host5' ,'--mlist', mfile.name, 'host1', 'host6',
mblighbe630eb2008-08-01 16:41:48 +00001239 '--ignore_site_file'],
showardbe0d8692009-08-20 23:42:44 +00001240 rpcs=[('modify_host', {'id': 'host6',
1241 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001242 True, None),
showardbe0d8692009-08-20 23:42:44 +00001243 ('modify_host', {'id': 'host5',
1244 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001245 True, None),
showardbe0d8692009-08-20 23:42:44 +00001246 ('modify_host', {'id': 'host4',
1247 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001248 True, None),
showardbe0d8692009-08-20 23:42:44 +00001249 ('modify_host', {'id': 'host3',
1250 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001251 True, None),
showardbe0d8692009-08-20 23:42:44 +00001252 ('modify_host', {'id': 'host2',
1253 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001254 True, None),
showardbe0d8692009-08-20 23:42:44 +00001255 ('modify_host', {'id': 'host1',
1256 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001257 True, None),
showardbe0d8692009-08-20 23:42:44 +00001258 ('modify_host', {'id': 'host0',
1259 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001260 True, None)],
showardbe0d8692009-08-20 23:42:44 +00001261 out_words_ok=['Do not repair', 'host0', 'host1', 'host2',
mblighbe630eb2008-08-01 16:41:48 +00001262 'host3', 'host4', 'host5', 'host6'])
mbligh41515392009-07-11 00:13:11 +00001263 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +00001264
1265
1266
1267class host_create_unittest(cli_mock.cli_unittest):
1268 def test_execute_create_muliple_hosts_all_options(self):
1269 self.run_cmd(argv=['atest', 'host', 'create', '--lock',
1270 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1271 '--ignore_site_file'],
1272 rpcs=[('get_labels', {'name': 'label0'},
1273 True,
1274 [{u'id': 4,
1275 u'platform': 0,
1276 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001277 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001278 u'kernel_config': u''}]),
1279 ('get_acl_groups', {'name': 'acl0'},
1280 True, []),
1281 ('add_acl_group', {'name': 'acl0'},
1282 True, 5),
1283 ('add_host', {'hostname': 'host1',
1284 'status': 'Ready',
1285 'locked': True},
1286 True, 42),
1287 ('host_add_labels', {'id': 'host1',
1288 'labels': ['label0']},
1289 True, None),
1290 ('add_host', {'hostname': 'host0',
1291 'status': 'Ready',
1292 'locked': True},
1293 True, 42),
1294 ('host_add_labels', {'id': 'host0',
1295 'labels': ['label0']},
1296 True, None),
1297 ('acl_group_add_hosts',
1298 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1299 True, None)],
1300 out_words_ok=['host0', 'host1'])
1301
1302
mbligh719e14a2008-12-04 01:17:08 +00001303 def test_execute_create_muliple_hosts_unlocked(self):
1304 self.run_cmd(argv=['atest', 'host', 'create',
1305 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1306 '--ignore_site_file'],
1307 rpcs=[('get_labels', {'name': 'label0'},
1308 True,
1309 [{u'id': 4,
1310 u'platform': 0,
1311 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001312 u'invalid': False,
mbligh719e14a2008-12-04 01:17:08 +00001313 u'kernel_config': u''}]),
1314 ('get_acl_groups', {'name': 'acl0'},
1315 True, []),
1316 ('add_acl_group', {'name': 'acl0'},
1317 True, 5),
1318 ('add_host', {'hostname': 'host1',
1319 'status': 'Ready',
1320 'locked': True},
1321 True, 42),
1322 ('host_add_labels', {'id': 'host1',
1323 'labels': ['label0']},
1324 True, None),
1325 ('add_host', {'hostname': 'host0',
1326 'status': 'Ready',
1327 'locked': True},
1328 True, 42),
1329 ('host_add_labels', {'id': 'host0',
1330 'labels': ['label0']},
1331 True, None),
1332 ('acl_group_add_hosts',
1333 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1334 True, None),
1335 ('modify_host', {'id': 'host1', 'locked': False},
1336 True, None),
1337 ('modify_host', {'id': 'host0', 'locked': False},
1338 True, None)],
1339 out_words_ok=['host0', 'host1'])
1340
1341
mblighbe630eb2008-08-01 16:41:48 +00001342if __name__ == '__main__':
1343 unittest.main()