3 # Copyright 2008 Google Inc. All Rights Reserved.
7 import unittest
, os
, sys
10 from autotest_lib
.cli
import cli_mock
, host
13 class host_ut(cli_mock
.cli_unittest
):
14 def test_parse_lock_options_both_set(self
):
21 sys
.exit
.expect_call(1).and_raises(cli_mock
.ExitException
)
23 self
.assertRaises(cli_mock
.ExitException
,
24 hh
._parse
_lock
_options
, options
)
28 def test_cleanup_labels_with_platform(self
):
29 labels
= ['l0', 'l1', 'l2', 'p0', 'l3']
31 self
.assertEqual(['l0', 'l1', 'l2', 'l3'],
32 hh
._cleanup
_labels
(labels
, 'p0'))
35 def test_cleanup_labels_no_platform(self
):
36 labels
= ['l0', 'l1', 'l2', 'l3']
38 self
.assertEqual(['l0', 'l1', 'l2', 'l3'],
39 hh
._cleanup
_labels
(labels
))
42 def test_cleanup_labels_with_non_avail_platform(self
):
43 labels
= ['l0', 'l1', 'l2', 'l3']
45 self
.assertEqual(['l0', 'l1', 'l2', 'l3'],
46 hh
._cleanup
_labels
(labels
, 'p0'))
49 class host_list_unittest(cli_mock
.cli_unittest
):
50 def test_parse_host_not_required(self
):
53 (options
, leftover
) = hl
.parse()
54 self
.assertEqual([], hl
.hosts
)
55 self
.assertEqual([], leftover
)
58 def test_parse_with_hosts(self
):
60 mfile
= cli_mock
.create_file('host0\nhost3\nhost4\n')
61 sys
.argv
= ['atest', 'host1', '--mlist', mfile
.name
, 'host3']
62 (options
, leftover
) = hl
.parse()
63 self
.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
65 self
.assertEqual(leftover
, [])
69 def test_parse_with_labels(self
):
71 sys
.argv
= ['atest', '--label', 'label0']
72 (options
, leftover
) = hl
.parse()
73 self
.assertEqual(['label0'], hl
.labels
)
74 self
.assertEqual(leftover
, [])
77 def test_parse_with_multi_labels(self
):
79 sys
.argv
= ['atest', '--label', 'label0,label2']
80 (options
, leftover
) = hl
.parse()
81 self
.assertEqualNoOrder(['label0', 'label2'], hl
.labels
)
82 self
.assertEqual(leftover
, [])
85 def test_parse_with_escaped_commas_label(self
):
87 sys
.argv
= ['atest', '--label', 'label\\,0']
88 (options
, leftover
) = hl
.parse()
89 self
.assertEqual(['label,0'], hl
.labels
)
90 self
.assertEqual(leftover
, [])
93 def test_parse_with_escaped_commas_multi_labels(self
):
95 sys
.argv
= ['atest', '--label', 'label\\,0,label\\,2']
96 (options
, leftover
) = hl
.parse()
97 self
.assertEqualNoOrder(['label,0', 'label,2'], hl
.labels
)
98 self
.assertEqual(leftover
, [])
101 def test_parse_with_both(self
):
102 hl
= host
.host_list()
103 mfile
= cli_mock
.create_file('host0\nhost3\nhost4\n')
104 sys
.argv
= ['atest', 'host1', '--mlist', mfile
.name
, 'host3',
106 (options
, leftover
) = hl
.parse()
107 self
.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
109 self
.assertEqual(['label0'], hl
.labels
)
110 self
.assertEqual(leftover
, [])
114 def test_execute_list_all_no_labels(self
):
115 self
.run_cmd(argv
=['atest', 'host', 'list', '--ignore_site_file'],
116 rpcs
=[('get_hosts', {},
118 [{u
'status': u
'Ready',
119 u
'hostname': u
'host0',
121 u
'locked_by': 'user0',
122 u
'lock_time': u
'2008-07-23 12:54:15',
128 {u
'status': u
'Ready',
129 u
'hostname': u
'host1',
131 u
'locked_by': 'user0',
132 u
'lock_time': u
'2008-07-23 12:54:15',
133 u
'labels': [u
'plat1'],
136 u
'platform': u
'plat1',
138 out_words_ok
=['host0', 'host1', 'Ready',
139 'plat1', 'False', 'True'])
142 def test_execute_list_all_with_labels(self
):
143 self
.run_cmd(argv
=['atest', 'host', 'list', '--ignore_site_file'],
144 rpcs
=[('get_hosts', {},
146 [{u
'status': u
'Ready',
147 u
'hostname': u
'host0',
149 u
'locked_by': 'user0',
150 u
'lock_time': u
'2008-07-23 12:54:15',
151 u
'labels': [u
'label0', u
'label1'],
156 {u
'status': u
'Ready',
157 u
'hostname': u
'host1',
159 u
'locked_by': 'user0',
160 u
'lock_time': u
'2008-07-23 12:54:15',
161 u
'labels': [u
'label2', u
'label3', u
'plat1'],
164 u
'platform': u
'plat1',
166 out_words_ok
=['host0', 'host1', 'Ready', 'plat1',
167 'label0', 'label1', 'label2', 'label3',
171 def test_execute_list_filter_one_host(self
):
172 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
173 '--ignore_site_file'],
174 rpcs
=[('get_hosts', {'hostname__in': ['host1']},
176 [{u
'status': u
'Ready',
177 u
'hostname': u
'host1',
179 u
'locked_by': 'user0',
180 u
'lock_time': u
'2008-07-23 12:54:15',
181 u
'labels': [u
'label2', u
'label3', u
'plat1'],
184 u
'platform': u
'plat1',
186 out_words_ok
=['host1', 'Ready', 'plat1',
187 'label2', 'label3', 'True'],
188 out_words_no
=['host0', 'host2',
189 'label1', 'label4', 'False'])
192 def test_execute_list_filter_two_hosts(self
):
193 mfile
= cli_mock
.create_file('host2')
194 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
195 '--mlist', mfile
.name
, '--ignore_site_file'],
196 # This is a bit fragile as the list order may change...
197 rpcs
=[('get_hosts', {'hostname__in': ['host2', 'host1']},
199 [{u
'status': u
'Ready',
200 u
'hostname': u
'host1',
202 u
'locked_by': 'user0',
203 u
'lock_time': u
'2008-07-23 12:54:15',
204 u
'labels': [u
'label2', u
'label3', u
'plat1'],
207 u
'platform': u
'plat1',
209 {u
'status': u
'Ready',
210 u
'hostname': u
'host2',
212 u
'locked_by': 'user0',
213 u
'lock_time': u
'2008-07-23 12:54:15',
214 u
'labels': [u
'label3', u
'label4', u
'plat1'],
217 u
'platform': u
'plat1',
219 out_words_ok
=['host1', 'Ready', 'plat1',
220 'label2', 'label3', 'True',
222 out_words_no
=['host0', 'label1', 'False'])
226 def test_execute_list_filter_two_hosts_one_not_found(self
):
227 mfile
= cli_mock
.create_file('host2')
228 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
229 '--mlist', mfile
.name
, '--ignore_site_file'],
230 # This is a bit fragile as the list order may change...
231 rpcs
=[('get_hosts', {'hostname__in': ['host2', 'host1']},
233 [{u
'status': u
'Ready',
234 u
'hostname': u
'host2',
236 u
'locked_by': 'user0',
237 u
'lock_time': u
'2008-07-23 12:54:15',
238 u
'labels': [u
'label3', u
'label4', u
'plat1'],
241 u
'platform': u
'plat1',
243 out_words_ok
=['Ready', 'plat1',
244 'label3', 'label4', 'True'],
245 out_words_no
=['host1', 'False'],
246 err_words_ok
=['host1'])
250 def test_execute_list_filter_two_hosts_none_found(self
):
251 self
.run_cmd(argv
=['atest', 'host', 'list',
252 'host1', 'host2', '--ignore_site_file'],
253 # This is a bit fragile as the list order may change...
254 rpcs
=[('get_hosts', {'hostname__in': ['host2', 'host1']},
258 out_words_no
=['Hostname', 'Status'],
259 err_words_ok
=['Unknown', 'host1', 'host2'])
262 def test_execute_list_filter_label(self
):
263 self
.run_cmd(argv
=['atest', 'host', 'list',
264 '-b', 'label3', '--ignore_site_file'],
265 rpcs
=[('get_hosts', {'labels__name__in': ['label3']},
267 [{u
'status': u
'Ready',
268 u
'hostname': u
'host1',
270 u
'locked_by': 'user0',
271 u
'lock_time': u
'2008-07-23 12:54:15',
272 u
'labels': [u
'label2', u
'label3', u
'plat1'],
275 u
'platform': u
'plat1',
277 {u
'status': u
'Ready',
278 u
'hostname': u
'host2',
280 u
'locked_by': 'user0',
281 u
'lock_time': u
'2008-07-23 12:54:15',
282 u
'labels': [u
'label3', u
'label4', u
'plat1'],
285 u
'platform': u
'plat1',
287 out_words_ok
=['host1', 'Ready', 'plat1',
288 'label2', 'label3', 'True',
290 out_words_no
=['host0', 'label1', 'False'])
293 def test_execute_list_filter_multi_labels(self
):
294 self
.run_cmd(argv
=['atest', 'host', 'list',
295 '-b', 'label3,label2', '--ignore_site_file'],
296 rpcs
=[('get_hosts', {'multiple_labels': ['label2',
299 [{u
'status': u
'Ready',
300 u
'hostname': u
'host1',
302 u
'locked_by': 'user0',
303 u
'lock_time': u
'2008-07-23 12:54:15',
304 u
'labels': [u
'label2', u
'label3', u
'plat0'],
307 u
'platform': u
'plat0',
309 {u
'status': u
'Ready',
310 u
'hostname': u
'host3',
312 u
'locked_by': 'user0',
313 u
'lock_time': u
'2008-07-23 12:54:15',
314 u
'labels': [u
'label3', u
'label2', u
'plat2'],
317 u
'platform': u
'plat2',
319 out_words_ok
=['host1', 'host3', 'Ready', 'plat0',
320 'label2', 'label3', 'plat2'],
321 out_words_no
=['host2', 'label4', 'False', 'plat1'])
324 def test_execute_list_filter_three_labels(self
):
325 self
.run_cmd(argv
=['atest', 'host', 'list',
326 '-b', 'label3,label2, label4',
327 '--ignore_site_file'],
328 rpcs
=[('get_hosts', {'multiple_labels': ['label2',
332 [{u
'status': u
'Ready',
333 u
'hostname': u
'host2',
335 u
'locked_by': 'user0',
336 u
'lock_time': u
'2008-07-23 12:54:15',
337 u
'labels': [u
'label3', u
'label2', u
'label4',
341 u
'platform': u
'plat1',
343 out_words_ok
=['host2', 'plat1',
344 'label2', 'label3', 'label4'],
345 out_words_no
=['host1', 'host3'])
348 def test_execute_list_filter_wild_labels(self
):
349 self
.run_cmd(argv
=['atest', 'host', 'list',
351 '--ignore_site_file'],
353 {'labels__name__startswith': 'label'},
355 [{u
'status': u
'Ready',
356 u
'hostname': u
'host2',
358 u
'locked_by': 'user0',
359 u
'lock_time': u
'2008-07-23 12:54:15',
360 u
'labels': [u
'label3', u
'label2', u
'label4',
364 u
'platform': u
'plat1',
366 out_words_ok
=['host2', 'plat1',
367 'label2', 'label3', 'label4'],
368 out_words_no
=['host1', 'host3'])
371 def test_execute_list_filter_multi_labels_no_results(self
):
372 self
.run_cmd(argv
=['atest', 'host', 'list',
373 '-b', 'label3,label2, ', '--ignore_site_file'],
374 rpcs
=[('get_hosts', {'multiple_labels': ['label2',
379 out_words_no
=['host1', 'host2', 'host3',
380 'label2', 'label3', 'label4'])
383 def test_execute_list_filter_label_and_hosts(self
):
384 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
385 '-b', 'label3', 'host2', '--ignore_site_file'],
386 rpcs
=[('get_hosts', {'labels__name__in': ['label3'],
387 'hostname__in': ['host2', 'host1']},
389 [{u
'status': u
'Ready',
390 u
'hostname': u
'host1',
392 u
'locked_by': 'user0',
393 u
'lock_time': u
'2008-07-23 12:54:15',
394 u
'labels': [u
'label2', u
'label3', u
'plat1'],
397 u
'platform': u
'plat1',
399 {u
'status': u
'Ready',
400 u
'hostname': u
'host2',
402 u
'locked_by': 'user0',
403 u
'lock_time': u
'2008-07-23 12:54:15',
404 u
'labels': [u
'label3', u
'label4', u
'plat1'],
407 u
'platform': u
'plat1',
409 out_words_ok
=['host1', 'Ready', 'plat1',
410 'label2', 'label3', 'True',
412 out_words_no
=['host0', 'label1', 'False'])
415 def test_execute_list_filter_label_and_hosts_none(self
):
416 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
417 '-b', 'label3', 'host2', '--ignore_site_file'],
418 rpcs
=[('get_hosts', {'labels__name__in': ['label3'],
419 'hostname__in': ['host2', 'host1']},
423 out_words_no
=['Hostname', 'Status'],
424 err_words_ok
=['Unknown', 'host1', 'host2'])
427 def test_execute_list_filter_status(self
):
428 self
.run_cmd(argv
=['atest', 'host', 'list',
429 '-s', 'Ready', '--ignore_site_file'],
430 rpcs
=[('get_hosts', {'status__in': ['Ready']},
432 [{u
'status': u
'Ready',
433 u
'hostname': u
'host1',
435 u
'locked_by': 'user0',
436 u
'lock_time': u
'2008-07-23 12:54:15',
437 u
'labels': [u
'label2', u
'label3', u
'plat1'],
440 u
'platform': u
'plat1',
442 {u
'status': u
'Ready',
443 u
'hostname': u
'host2',
445 u
'locked_by': 'user0',
446 u
'lock_time': u
'2008-07-23 12:54:15',
447 u
'labels': [u
'label3', u
'label4', u
'plat1'],
450 u
'platform': u
'plat1',
452 out_words_ok
=['host1', 'Ready', 'plat1',
453 'label2', 'label3', 'True',
455 out_words_no
=['host0', 'label1', 'False'])
459 def test_execute_list_filter_status_and_hosts(self
):
460 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
461 '-s', 'Ready', 'host2', '--ignore_site_file'],
462 rpcs
=[('get_hosts', {'status__in': ['Ready'],
463 'hostname__in': ['host2', 'host1']},
465 [{u
'status': u
'Ready',
466 u
'hostname': u
'host1',
468 u
'locked_by': 'user0',
469 u
'lock_time': u
'2008-07-23 12:54:15',
470 u
'labels': [u
'label2', u
'label3', u
'plat1'],
473 u
'platform': u
'plat1',
475 {u
'status': u
'Ready',
476 u
'hostname': u
'host2',
478 u
'locked_by': 'user0',
479 u
'lock_time': u
'2008-07-23 12:54:15',
480 u
'labels': [u
'label3', u
'label4', u
'plat1'],
483 u
'platform': u
'plat1',
485 out_words_ok
=['host1', 'Ready', 'plat1',
486 'label2', 'label3', 'True',
488 out_words_no
=['host0', 'label1', 'False'])
491 def test_execute_list_filter_status_and_hosts_none(self
):
492 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
493 '--status', 'Repair',
494 'host2', '--ignore_site_file'],
495 rpcs
=[('get_hosts', {'status__in': ['Repair'],
496 'hostname__in': ['host2', 'host1']},
500 out_words_no
=['Hostname', 'Status'],
501 err_words_ok
=['Unknown', 'host2'])
504 def test_execute_list_filter_statuses_and_hosts_none(self
):
505 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
506 '--status', 'Repair',
507 'host2', '--ignore_site_file'],
508 rpcs
=[('get_hosts', {'status__in': ['Repair'],
509 'hostname__in': ['host2', 'host1']},
513 out_words_no
=['Hostname', 'Status'],
514 err_words_ok
=['Unknown', 'host2'])
517 def test_execute_list_filter_locked(self
):
518 self
.run_cmd(argv
=['atest', 'host', 'list', 'host1',
519 '--locked', 'host2', '--ignore_site_file'],
520 rpcs
=[('get_hosts', {'locked': True,
521 'hostname__in': ['host2', 'host1']},
523 [{u
'status': u
'Ready',
524 u
'hostname': u
'host1',
526 u
'locked_by': 'user0',
527 u
'lock_time': u
'2008-07-23 12:54:15',
528 u
'labels': [u
'label2', u
'label3', u
'plat1'],
531 u
'platform': u
'plat1',
533 {u
'status': u
'Ready',
534 u
'hostname': u
'host2',
536 u
'locked_by': 'user0',
537 u
'lock_time': u
'2008-07-23 12:54:15',
538 u
'labels': [u
'label3', u
'label4', u
'plat1'],
541 u
'platform': u
'plat1',
543 out_words_ok
=['host1', 'Ready', 'plat1',
544 'label2', 'label3', 'True',
546 out_words_no
=['host0', 'label1', 'False'])
549 def test_execute_list_filter_unlocked(self
):
550 self
.run_cmd(argv
=['atest', 'host', 'list',
551 '--unlocked', '--ignore_site_file'],
552 rpcs
=[('get_hosts', {'locked': False},
554 [{u
'status': u
'Ready',
555 u
'hostname': u
'host1',
557 u
'locked_by': 'user0',
558 u
'lock_time': u
'2008-07-23 12:54:15',
559 u
'labels': [u
'label2', u
'label3', u
'plat1'],
562 u
'platform': u
'plat1',
564 {u
'status': u
'Ready',
565 u
'hostname': u
'host2',
567 u
'locked_by': 'user0',
568 u
'lock_time': u
'2008-07-23 12:54:15',
569 u
'labels': [u
'label3', u
'label4', u
'plat1'],
572 u
'platform': u
'plat1',
574 out_words_ok
=['host1', 'Ready', 'plat1',
575 'label2', 'label3', 'False',
577 out_words_no
=['host0', 'label1', 'True'])
580 class host_stat_unittest(cli_mock
.cli_unittest
):
581 def test_execute_stat_two_hosts(self
):
582 # The order of RPCs between host1 and host0 could change...
583 self
.run_cmd(argv
=['atest', 'host', 'stat', 'host0', 'host1',
584 '--ignore_site_file'],
585 rpcs
=[('get_hosts', {'hostname': 'host1'},
587 [{u
'status': u
'Ready',
588 u
'hostname': u
'host1',
590 u
'lock_time': u
'2008-07-23 12:54:15',
591 u
'locked_by': 'user0',
592 u
'protection': 'No protection',
593 u
'labels': [u
'label3', u
'label4', u
'plat1'],
596 u
'platform': u
'plat1',
598 ('get_hosts', {'hostname': 'host0'},
600 [{u
'status': u
'Ready',
601 u
'hostname': u
'host0',
603 u
'locked_by': 'user0',
604 u
'lock_time': u
'2008-07-23 12:54:15',
605 u
'protection': u
'No protection',
606 u
'labels': [u
'label0', u
'plat0'],
609 u
'platform': u
'plat0',
611 ('get_acl_groups', {'hosts__hostname': 'host1'},
613 [{u
'description': u
'',
614 u
'hosts': [u
'host0', u
'host1'],
616 u
'name': u
'Everyone',
617 u
'users': [u
'user2', u
'debug_user', u
'user0']}]),
618 ('get_labels', {'host__hostname': 'host1'},
624 u
'kernel_config': u
''}]),
625 ('get_acl_groups', {'hosts__hostname': 'host0'},
627 [{u
'description': u
'',
628 u
'hosts': [u
'host0', u
'host1'],
630 u
'name': u
'Everyone',
631 u
'users': [u
'user0', u
'debug_user']},
632 {u
'description': u
'myacl0',
633 u
'hosts': [u
'host0'],
636 u
'users': [u
'user0']}]),
637 ('get_labels', {'host__hostname': 'host0'},
643 u
'kernel_config': u
''},
648 u
'kernel_config': u
''}])],
649 out_words_ok
=['host0', 'host1', 'plat0', 'plat1',
650 'Everyone', 'acl0', 'label0'])
653 def test_execute_stat_one_bad_host_verbose(self
):
654 self
.run_cmd(argv
=['atest', 'host', 'stat', 'host0',
655 'host1', '-v', '--ignore_site_file'],
656 rpcs
=[('get_hosts', {'hostname': 'host1'},
659 ('get_hosts', {'hostname': 'host0'},
661 [{u
'status': u
'Ready',
662 u
'hostname': u
'host0',
664 u
'locked_by': 'user0',
665 u
'lock_time': u
'2008-07-23 12:54:15',
666 u
'protection': u
'No protection',
667 u
'labels': [u
'label0', u
'plat0'],
670 u
'platform': u
'plat0',
672 ('get_acl_groups', {'hosts__hostname': 'host0'},
674 [{u
'description': u
'',
675 u
'hosts': [u
'host0', u
'host1'],
677 u
'name': u
'Everyone',
678 u
'users': [u
'user0', u
'debug_user']},
679 {u
'description': u
'myacl0',
680 u
'hosts': [u
'host0'],
683 u
'users': [u
'user0']}]),
684 ('get_labels', {'host__hostname': 'host0'},
690 u
'kernel_config': u
''},
695 u
'kernel_config': u
''}])],
696 out_words_ok
=['host0', 'plat0',
697 'Everyone', 'acl0', 'label0'],
698 out_words_no
=['host1'],
699 err_words_ok
=['host1', 'Unknown host'],
700 err_words_no
=['host0'])
703 def test_execute_stat_one_bad_host(self
):
704 self
.run_cmd(argv
=['atest', 'host', 'stat', 'host0', 'host1',
705 '--ignore_site_file'],
706 rpcs
=[('get_hosts', {'hostname': 'host1'},
709 ('get_hosts', {'hostname': 'host0'},
711 [{u
'status': u
'Ready',
712 u
'hostname': u
'host0',
714 u
'locked_by': 'user0',
715 u
'lock_time': u
'2008-07-23 12:54:15',
716 u
'protection': u
'No protection',
717 u
'labels': [u
'label0', u
'plat0'],
720 u
'platform': u
'plat0',
722 ('get_acl_groups', {'hosts__hostname': 'host0'},
724 [{u
'description': u
'',
725 u
'hosts': [u
'host0', u
'host1'],
727 u
'name': u
'Everyone',
728 u
'users': [u
'user0', u
'debug_user']},
729 {u
'description': u
'myacl0',
730 u
'hosts': [u
'host0'],
733 u
'users': [u
'user0']}]),
734 ('get_labels', {'host__hostname': 'host0'},
740 u
'kernel_config': u
''},
745 u
'kernel_config': u
''}])],
746 out_words_ok
=['host0', 'plat0',
747 'Everyone', 'acl0', 'label0'],
748 out_words_no
=['host1'],
749 err_words_ok
=['host1', 'Unknown host'],
750 err_words_no
=['host0'])
753 def test_execute_stat_wildcard(self
):
754 # The order of RPCs between host1 and host0 could change...
755 self
.run_cmd(argv
=['atest', 'host', 'stat', 'ho*',
756 '--ignore_site_file'],
757 rpcs
=[('get_hosts', {'hostname__startswith': 'ho'},
759 [{u
'status': u
'Ready',
760 u
'hostname': u
'host1',
762 u
'lock_time': u
'2008-07-23 12:54:15',
763 u
'locked_by': 'user0',
764 u
'protection': 'No protection',
765 u
'labels': [u
'label3', u
'label4', u
'plat1'],
768 u
'platform': u
'plat1',
770 {u
'status': u
'Ready',
771 u
'hostname': u
'host0',
773 u
'locked_by': 'user0',
774 u
'lock_time': u
'2008-07-23 12:54:15',
775 u
'protection': u
'No protection',
776 u
'labels': [u
'label0', u
'plat0'],
779 u
'platform': u
'plat0',
781 ('get_acl_groups', {'hosts__hostname': 'host1'},
783 [{u
'description': u
'',
784 u
'hosts': [u
'host0', u
'host1'],
786 u
'name': u
'Everyone',
787 u
'users': [u
'user2', u
'debug_user', u
'user0']}]),
788 ('get_labels', {'host__hostname': 'host1'},
794 u
'kernel_config': u
''}]),
795 ('get_acl_groups', {'hosts__hostname': 'host0'},
797 [{u
'description': u
'',
798 u
'hosts': [u
'host0', u
'host1'],
800 u
'name': u
'Everyone',
801 u
'users': [u
'user0', u
'debug_user']},
802 {u
'description': u
'myacl0',
803 u
'hosts': [u
'host0'],
806 u
'users': [u
'user0']}]),
807 ('get_labels', {'host__hostname': 'host0'},
813 u
'kernel_config': u
''},
818 u
'kernel_config': u
''}])],
819 out_words_ok
=['host0', 'host1', 'plat0', 'plat1',
820 'Everyone', 'acl0', 'label0'])
823 def test_execute_stat_wildcard_and_host(self
):
824 # The order of RPCs between host1 and host0 could change...
825 self
.run_cmd(argv
=['atest', 'host', 'stat', 'ho*', 'newhost0',
826 '--ignore_site_file'],
827 rpcs
=[('get_hosts', {'hostname': 'newhost0'},
829 [{u
'status': u
'Ready',
830 u
'hostname': u
'newhost0',
832 u
'locked_by': 'user0',
833 u
'lock_time': u
'2008-07-23 12:54:15',
834 u
'protection': u
'No protection',
835 u
'labels': [u
'label0', u
'plat0'],
838 u
'platform': u
'plat0',
840 ('get_hosts', {'hostname__startswith': 'ho'},
842 [{u
'status': u
'Ready',
843 u
'hostname': u
'host1',
845 u
'lock_time': u
'2008-07-23 12:54:15',
846 u
'locked_by': 'user0',
847 u
'protection': 'No protection',
848 u
'labels': [u
'label3', u
'label4', u
'plat1'],
851 u
'platform': u
'plat1',
853 {u
'status': u
'Ready',
854 u
'hostname': u
'host0',
856 u
'locked_by': 'user0',
857 u
'protection': 'No protection',
858 u
'lock_time': u
'2008-07-23 12:54:15',
859 u
'labels': [u
'label0', u
'plat0'],
862 u
'platform': u
'plat0',
864 ('get_acl_groups', {'hosts__hostname': 'newhost0'},
866 [{u
'description': u
'',
867 u
'hosts': [u
'newhost0', 'host1'],
870 u
'users': [u
'user0', u
'debug_user']},
871 {u
'description': u
'my favorite acl',
872 u
'hosts': [u
'newhost0'],
875 u
'users': [u
'user0']}]),
876 ('get_labels', {'host__hostname': 'newhost0'},
882 u
'kernel_config': u
''},
887 u
'kernel_config': u
''}]),
888 ('get_acl_groups', {'hosts__hostname': 'host1'},
890 [{u
'description': u
'',
891 u
'hosts': [u
'host0', u
'host1'],
893 u
'name': u
'Everyone',
894 u
'users': [u
'user2', u
'debug_user', u
'user0']}]),
895 ('get_labels', {'host__hostname': 'host1'},
901 u
'kernel_config': u
''}]),
902 ('get_acl_groups', {'hosts__hostname': 'host0'},
904 [{u
'description': u
'',
905 u
'hosts': [u
'host0', u
'host1'],
907 u
'name': u
'Everyone',
908 u
'users': [u
'user0', u
'debug_user']},
909 {u
'description': u
'myacl0',
910 u
'hosts': [u
'host0'],
913 u
'users': [u
'user0']}]),
914 ('get_labels', {'host__hostname': 'host0'},
920 u
'kernel_config': u
''},
925 u
'kernel_config': u
''}])],
926 out_words_ok
=['host0', 'host1', 'newhost0',
928 'Everyone', 'acl10', 'label0'])
931 class host_jobs_unittest(cli_mock
.cli_unittest
):
932 def test_execute_jobs_one_host(self
):
933 self
.run_cmd(argv
=['atest', 'host', 'jobs', 'host0',
934 '--ignore_site_file'],
935 rpcs
=[('get_host_queue_entries',
936 {'host__hostname': 'host0', 'query_limit': 20,
937 'sort_by': ['-job__id']},
939 [{u
'status': u
'Failed',
941 u
'host': {u
'status': u
'Ready',
943 u
'locked_by': 'user0',
944 u
'hostname': u
'host0',
949 u
'meta_host': u
'meta0',
950 u
'job': {u
'control_file':
951 (u
"def step_init():\n"
952 "\tjob.next_step([step_test])\n"
953 "\ttestkernel = job.kernel("
954 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
955 "\ttestkernel.install()\n"
956 "\ttestkernel.boot()\n\n"
958 "\tjob.run_test('kernbench')\n\n"),
959 u
'name': u
'kernel-smp-2.6.xyz.x86_64',
960 u
'control_type': u
'Client',
961 u
'synchronizing': None,
964 u
'created_on': u
'2008-01-09 10:45:12',
965 u
'synch_count': None,
966 u
'synch_type': u
'Asynchronous',
970 {u
'status': u
'Aborted',
972 u
'host': {u
'status': u
'Ready',
974 u
'locked_by': 'user0',
975 u
'hostname': u
'host0',
981 u
'job': {u
'control_file':
982 u
"job.run_test('sleeptest')\n\n",
984 u
'control_type': u
'Client',
988 u
'created_on': u
'2008-01-17 15:04:53',
989 u
'synch_count': None,
990 u
'synch_type': u
'Asynchronous',
994 out_words_ok
=['216', 'user0', 'Failed',
995 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
996 '289', 'user1', 'Aborted',
1000 def test_execute_jobs_wildcard(self
):
1001 self
.run_cmd(argv
=['atest', 'host', 'jobs', 'ho*',
1002 '--ignore_site_file'],
1003 rpcs
=[('get_hosts', {'hostname__startswith': 'ho'},
1005 [{u
'status': u
'Ready',
1006 u
'hostname': u
'host1',
1008 u
'lock_time': u
'2008-07-23 12:54:15',
1009 u
'locked_by': 'user0',
1010 u
'labels': [u
'label3', u
'label4', u
'plat1'],
1013 u
'platform': u
'plat1',
1015 {u
'status': u
'Ready',
1016 u
'hostname': u
'host0',
1018 u
'locked_by': 'user0',
1019 u
'lock_time': u
'2008-07-23 12:54:15',
1020 u
'labels': [u
'label0', u
'plat0'],
1023 u
'platform': u
'plat0',
1025 ('get_host_queue_entries',
1026 {'host__hostname': 'host1', 'query_limit': 20,
1027 'sort_by': ['-job__id']},
1029 [{u
'status': u
'Failed',
1031 u
'host': {u
'status': u
'Ready',
1033 u
'locked_by': 'user0',
1034 u
'hostname': u
'host1',
1039 u
'meta_host': u
'meta0',
1040 u
'job': {u
'control_file':
1041 (u
"def step_init():\n"
1042 "\tjob.next_step([step_test])\n"
1043 "\ttestkernel = job.kernel("
1044 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1045 "\ttestkernel.install()\n"
1046 "\ttestkernel.boot()\n\n"
1047 "def step_test():\n"
1048 "\tjob.run_test('kernbench')\n\n"),
1049 u
'name': u
'kernel-smp-2.6.xyz.x86_64',
1050 u
'control_type': u
'Client',
1051 u
'synchronizing': None,
1052 u
'priority': u
'Low',
1054 u
'created_on': u
'2008-01-09 10:45:12',
1055 u
'synch_count': None,
1056 u
'synch_type': u
'Asynchronous',
1060 {u
'status': u
'Aborted',
1062 u
'host': {u
'status': u
'Ready',
1064 u
'locked_by': 'user0',
1065 u
'hostname': u
'host1',
1071 u
'job': {u
'control_file':
1072 u
"job.run_test('sleeptest')\n\n",
1073 u
'name': u
'testjob',
1074 u
'control_type': u
'Client',
1075 u
'synchronizing': 0,
1076 u
'priority': u
'Low',
1078 u
'created_on': u
'2008-01-17 15:04:53',
1079 u
'synch_count': None,
1080 u
'synch_type': u
'Asynchronous',
1084 ('get_host_queue_entries',
1085 {'host__hostname': 'host0', 'query_limit': 20,
1086 'sort_by': ['-job__id']},
1088 [{u
'status': u
'Failed',
1090 u
'host': {u
'status': u
'Ready',
1092 u
'locked_by': 'user0',
1093 u
'hostname': u
'host0',
1098 u
'meta_host': u
'meta0',
1099 u
'job': {u
'control_file':
1100 (u
"def step_init():\n"
1101 "\tjob.next_step([step_test])\n"
1102 "\ttestkernel = job.kernel("
1103 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1104 "\ttestkernel.install()\n"
1105 "\ttestkernel.boot()\n\n"
1106 "def step_test():\n"
1107 "\tjob.run_test('kernbench')\n\n"),
1108 u
'name': u
'kernel-smp-2.6.xyz.x86_64',
1109 u
'control_type': u
'Client',
1110 u
'synchronizing': None,
1111 u
'priority': u
'Low',
1113 u
'created_on': u
'2008-01-09 10:45:12',
1114 u
'synch_count': None,
1115 u
'synch_type': u
'Asynchronous',
1119 {u
'status': u
'Aborted',
1121 u
'host': {u
'status': u
'Ready',
1123 u
'locked_by': 'user0',
1124 u
'hostname': u
'host0',
1130 u
'job': {u
'control_file':
1131 u
"job.run_test('sleeptest')\n\n",
1132 u
'name': u
'testjob',
1133 u
'control_type': u
'Client',
1134 u
'synchronizing': 0,
1135 u
'priority': u
'Low',
1137 u
'created_on': u
'2008-01-17 15:04:53',
1138 u
'synch_count': None,
1139 u
'synch_type': u
'Asynchronous',
1143 out_words_ok
=['216', 'user0', 'Failed',
1144 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1145 '289', 'user1', 'Aborted',
1149 def test_execute_jobs_one_host_limit(self
):
1150 self
.run_cmd(argv
=['atest', 'host', 'jobs', 'host0',
1151 '--ignore_site_file', '-q', '10'],
1152 rpcs
=[('get_host_queue_entries',
1153 {'host__hostname': 'host0', 'query_limit': 10,
1154 'sort_by': ['-job__id']},
1156 [{u
'status': u
'Failed',
1158 u
'host': {u
'status': u
'Ready',
1160 u
'locked_by': 'user0',
1161 u
'hostname': u
'host0',
1166 u
'meta_host': u
'meta0',
1167 u
'job': {u
'control_file':
1168 (u
"def step_init():\n"
1169 "\tjob.next_step([step_test])\n"
1170 "\ttestkernel = job.kernel("
1171 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1172 "\ttestkernel.install()\n"
1173 "\ttestkernel.boot()\n\n"
1174 "def step_test():\n"
1175 "\tjob.run_test('kernbench')\n\n"),
1176 u
'name': u
'kernel-smp-2.6.xyz.x86_64',
1177 u
'control_type': u
'Client',
1178 u
'synchronizing': None,
1179 u
'priority': u
'Low',
1181 u
'created_on': u
'2008-01-09 10:45:12',
1182 u
'synch_count': None,
1183 u
'synch_type': u
'Asynchronous',
1187 {u
'status': u
'Aborted',
1189 u
'host': {u
'status': u
'Ready',
1191 u
'locked_by': 'user0',
1192 u
'hostname': u
'host0',
1198 u
'job': {u
'control_file':
1199 u
"job.run_test('sleeptest')\n\n",
1200 u
'name': u
'testjob',
1201 u
'control_type': u
'Client',
1202 u
'synchronizing': 0,
1203 u
'priority': u
'Low',
1205 u
'created_on': u
'2008-01-17 15:04:53',
1206 u
'synch_count': None,
1207 u
'synch_type': u
'Asynchronous',
1211 out_words_ok
=['216', 'user0', 'Failed',
1212 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1213 '289', 'user1', 'Aborted',
1217 class host_mod_unittest(cli_mock
.cli_unittest
):
1218 def test_execute_lock_one_host(self
):
1219 self
.run_cmd(argv
=['atest', 'host', 'mod',
1220 '--lock', 'host0', '--ignore_site_file'],
1221 rpcs
=[('modify_host', {'id': 'host0', 'locked': True},
1223 out_words_ok
=['Locked', 'host0'])
1226 def test_execute_unlock_two_hosts(self
):
1227 self
.run_cmd(argv
=['atest', 'host', 'mod',
1228 '-u', 'host0,host1', '--ignore_site_file'],
1229 rpcs
=[('modify_host', {'id': 'host1', 'locked': False},
1231 ('modify_host', {'id': 'host0', 'locked': False},
1233 out_words_ok
=['Unlocked', 'host0', 'host1'])
1236 def test_execute_lock_unknown_hosts(self
):
1237 self
.run_cmd(argv
=['atest', 'host', 'mod',
1238 '-l', 'host0,host1', 'host2', '--ignore_site_file'],
1239 rpcs
=[('modify_host', {'id': 'host2', 'locked': True},
1241 ('modify_host', {'id': 'host1', 'locked': True},
1242 False, 'DoesNotExist: Host matching '
1243 'query does not exist.'),
1244 ('modify_host', {'id': 'host0', 'locked': True},
1246 out_words_ok
=['Locked', 'host0', 'host2'],
1247 err_words_ok
=['Host', 'matching', 'query', 'host1'])
1250 def test_execute_protection_hosts(self
):
1251 mfile
= cli_mock
.create_file('host0\nhost1,host2\nhost3 host4')
1252 self
.run_cmd(argv
=['atest', 'host', 'mod', '--protection',
1254 'host5' ,'--mlist', mfile
.name
, 'host1', 'host6',
1255 '--ignore_site_file'],
1256 rpcs
=[('modify_host', {'id': 'host6',
1257 'protection': 'Do not repair'},
1259 ('modify_host', {'id': 'host5',
1260 'protection': 'Do not repair'},
1262 ('modify_host', {'id': 'host4',
1263 'protection': 'Do not repair'},
1265 ('modify_host', {'id': 'host3',
1266 'protection': 'Do not repair'},
1268 ('modify_host', {'id': 'host2',
1269 'protection': 'Do not repair'},
1271 ('modify_host', {'id': 'host1',
1272 'protection': 'Do not repair'},
1274 ('modify_host', {'id': 'host0',
1275 'protection': 'Do not repair'},
1277 out_words_ok
=['Do not repair', 'host0', 'host1', 'host2',
1278 'host3', 'host4', 'host5', 'host6'])
1283 class host_create_unittest(cli_mock
.cli_unittest
):
1284 def test_execute_create_muliple_hosts_all_options(self
):
1285 self
.run_cmd(argv
=['atest', 'host', 'create', '--lock',
1286 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1287 '--ignore_site_file'],
1288 rpcs
=[('get_labels', {'name': 'label0'},
1294 u
'kernel_config': u
''}]),
1295 ('get_acl_groups', {'name': 'acl0'},
1297 ('add_acl_group', {'name': 'acl0'},
1299 ('add_host', {'hostname': 'host1',
1303 ('host_add_labels', {'id': 'host1',
1304 'labels': ['label0']},
1306 ('add_host', {'hostname': 'host0',
1310 ('host_add_labels', {'id': 'host0',
1311 'labels': ['label0']},
1313 ('acl_group_add_hosts',
1314 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1316 out_words_ok
=['host0', 'host1'])
1319 def test_execute_create_muliple_hosts_unlocked(self
):
1320 self
.run_cmd(argv
=['atest', 'host', 'create',
1321 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1322 '--ignore_site_file'],
1323 rpcs
=[('get_labels', {'name': 'label0'},
1329 u
'kernel_config': u
''}]),
1330 ('get_acl_groups', {'name': 'acl0'},
1332 ('add_acl_group', {'name': 'acl0'},
1334 ('add_host', {'hostname': 'host1',
1338 ('host_add_labels', {'id': 'host1',
1339 'labels': ['label0']},
1341 ('add_host', {'hostname': 'host0',
1345 ('host_add_labels', {'id': 'host0',
1346 'labels': ['label0']},
1348 ('acl_group_add_hosts',
1349 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1351 ('modify_host', {'id': 'host1', 'locked': False},
1353 ('modify_host', {'id': 'host0', 'locked': False},
1355 out_words_ok
=['host0', 'host1'])
1358 def test_execute_create_muliple_hosts_label_escaped_quotes(self
):
1359 self
.run_cmd(argv
=['atest', 'host', 'create',
1360 '-b', 'label0,label\\,1,label\\,2',
1361 '--acls', 'acl0', 'host0', 'host1',
1362 '--ignore_site_file'],
1363 rpcs
=[('get_labels', {'name': 'label0'},
1369 u
'kernel_config': u
''}]),
1370 ('get_labels', {'name': 'label,1'},
1374 u
'name': u
'label,1',
1376 u
'kernel_config': u
''}]),
1377 ('get_labels', {'name': 'label,2'},
1381 u
'name': u
'label,2',
1383 u
'kernel_config': u
''}]),
1384 ('get_acl_groups', {'name': 'acl0'},
1386 ('add_acl_group', {'name': 'acl0'},
1388 ('add_host', {'hostname': 'host1',
1392 ('host_add_labels', {'id': 'host1',
1393 'labels': ['label0', 'label,1',
1396 ('add_host', {'hostname': 'host0',
1400 ('host_add_labels', {'id': 'host0',
1401 'labels': ['label0', 'label,1',
1404 ('acl_group_add_hosts',
1405 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1407 ('modify_host', {'id': 'host1', 'locked': False},
1409 ('modify_host', {'id': 'host0', 'locked': False},
1411 out_words_ok
=['host0', 'host1'])
1414 if __name__
== '__main__':