KVM test: Add helpers to control the TAP/bridge
[autotest-zwu.git] / cli / host_unittest.py
blob911de1a44af33d9cf93589a5a6f26db0132ee453
1 #!/usr/bin/python
3 # Copyright 2008 Google Inc. All Rights Reserved.
5 """Test for host."""
7 import unittest, os, sys
9 import common
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):
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()
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'))
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))
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'))
49 class 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)
58 def test_parse_with_hosts(self):
59 hl = host.host_list()
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'],
64 hl.hosts)
65 self.assertEqual(leftover, [])
66 mfile.clean()
69 def test_parse_with_labels(self):
70 hl = host.host_list()
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):
78 hl = host.host_list()
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):
86 hl = host.host_list()
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):
94 hl = host.host_list()
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',
105 '--label', 'label0']
106 (options, leftover) = hl.parse()
107 self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
108 hl.hosts)
109 self.assertEqual(['label0'], hl.labels)
110 self.assertEqual(leftover, [])
111 mfile.clean()
114 def test_execute_list_all_no_labels(self):
115 self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
116 rpcs=[('get_hosts', {},
117 True,
118 [{u'status': u'Ready',
119 u'hostname': u'host0',
120 u'locked': False,
121 u'locked_by': 'user0',
122 u'lock_time': u'2008-07-23 12:54:15',
123 u'labels': [],
124 u'invalid': False,
125 u'synch_id': None,
126 u'platform': None,
127 u'id': 1},
128 {u'status': u'Ready',
129 u'hostname': u'host1',
130 u'locked': True,
131 u'locked_by': 'user0',
132 u'lock_time': u'2008-07-23 12:54:15',
133 u'labels': [u'plat1'],
134 u'invalid': False,
135 u'synch_id': None,
136 u'platform': u'plat1',
137 u'id': 2}])],
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', {},
145 True,
146 [{u'status': u'Ready',
147 u'hostname': u'host0',
148 u'locked': False,
149 u'locked_by': 'user0',
150 u'lock_time': u'2008-07-23 12:54:15',
151 u'labels': [u'label0', u'label1'],
152 u'invalid': False,
153 u'synch_id': None,
154 u'platform': None,
155 u'id': 1},
156 {u'status': u'Ready',
157 u'hostname': u'host1',
158 u'locked': True,
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'],
162 u'invalid': False,
163 u'synch_id': None,
164 u'platform': u'plat1',
165 u'id': 2}])],
166 out_words_ok=['host0', 'host1', 'Ready', 'plat1',
167 'label0', 'label1', 'label2', 'label3',
168 'False', 'True'])
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']},
175 True,
176 [{u'status': u'Ready',
177 u'hostname': u'host1',
178 u'locked': True,
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'],
182 u'invalid': False,
183 u'synch_id': None,
184 u'platform': u'plat1',
185 u'id': 2}])],
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']},
198 True,
199 [{u'status': u'Ready',
200 u'hostname': u'host1',
201 u'locked': True,
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'],
205 u'invalid': False,
206 u'synch_id': None,
207 u'platform': u'plat1',
208 u'id': 2},
209 {u'status': u'Ready',
210 u'hostname': u'host2',
211 u'locked': True,
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'],
215 u'invalid': False,
216 u'synch_id': None,
217 u'platform': u'plat1',
218 u'id': 3}])],
219 out_words_ok=['host1', 'Ready', 'plat1',
220 'label2', 'label3', 'True',
221 'host2', 'label4'],
222 out_words_no=['host0', 'label1', 'False'])
223 mfile.clean()
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']},
232 True,
233 [{u'status': u'Ready',
234 u'hostname': u'host2',
235 u'locked': True,
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'],
239 u'invalid': False,
240 u'synch_id': None,
241 u'platform': u'plat1',
242 u'id': 3}])],
243 out_words_ok=['Ready', 'plat1',
244 'label3', 'label4', 'True'],
245 out_words_no=['host1', 'False'],
246 err_words_ok=['host1'])
247 mfile.clean()
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']},
255 True,
256 [])],
257 out_words_ok=[],
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']},
266 True,
267 [{u'status': u'Ready',
268 u'hostname': u'host1',
269 u'locked': True,
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'],
273 u'invalid': False,
274 u'synch_id': None,
275 u'platform': u'plat1',
276 u'id': 2},
277 {u'status': u'Ready',
278 u'hostname': u'host2',
279 u'locked': True,
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'],
283 u'invalid': False,
284 u'synch_id': None,
285 u'platform': u'plat1',
286 u'id': 3}])],
287 out_words_ok=['host1', 'Ready', 'plat1',
288 'label2', 'label3', 'True',
289 'host2', 'label4'],
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',
297 'label3']},
298 True,
299 [{u'status': u'Ready',
300 u'hostname': u'host1',
301 u'locked': True,
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'],
305 u'invalid': False,
306 u'synch_id': None,
307 u'platform': u'plat0',
308 u'id': 2},
309 {u'status': u'Ready',
310 u'hostname': u'host3',
311 u'locked': True,
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'],
315 u'invalid': False,
316 u'synch_id': None,
317 u'platform': u'plat2',
318 u'id': 4}])],
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',
329 'label3',
330 'label4']},
331 True,
332 [{u'status': u'Ready',
333 u'hostname': u'host2',
334 u'locked': True,
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',
338 u'plat1'],
339 u'invalid': False,
340 u'synch_id': None,
341 u'platform': u'plat1',
342 u'id': 3}])],
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',
350 '-b', 'label*',
351 '--ignore_site_file'],
352 rpcs=[('get_hosts',
353 {'labels__name__startswith': 'label'},
354 True,
355 [{u'status': u'Ready',
356 u'hostname': u'host2',
357 u'locked': 1,
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',
361 u'plat1'],
362 u'invalid': 0,
363 u'synch_id': None,
364 u'platform': u'plat1',
365 u'id': 3}])],
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',
375 'label3']},
376 True,
377 [])],
378 out_words_ok=[],
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']},
388 True,
389 [{u'status': u'Ready',
390 u'hostname': u'host1',
391 u'locked': True,
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'],
395 u'invalid': False,
396 u'synch_id': None,
397 u'platform': u'plat1',
398 u'id': 2},
399 {u'status': u'Ready',
400 u'hostname': u'host2',
401 u'locked': True,
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'],
405 u'invalid': False,
406 u'synch_id': None,
407 u'platform': u'plat1',
408 u'id': 3}])],
409 out_words_ok=['host1', 'Ready', 'plat1',
410 'label2', 'label3', 'True',
411 'host2', 'label4'],
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']},
420 True,
421 [])],
422 out_words_ok=[],
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']},
431 True,
432 [{u'status': u'Ready',
433 u'hostname': u'host1',
434 u'locked': True,
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'],
438 u'invalid': False,
439 u'synch_id': None,
440 u'platform': u'plat1',
441 u'id': 2},
442 {u'status': u'Ready',
443 u'hostname': u'host2',
444 u'locked': True,
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'],
448 u'invalid': False,
449 u'synch_id': None,
450 u'platform': u'plat1',
451 u'id': 3}])],
452 out_words_ok=['host1', 'Ready', 'plat1',
453 'label2', 'label3', 'True',
454 'host2', 'label4'],
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']},
464 True,
465 [{u'status': u'Ready',
466 u'hostname': u'host1',
467 u'locked': True,
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'],
471 u'invalid': False,
472 u'synch_id': None,
473 u'platform': u'plat1',
474 u'id': 2},
475 {u'status': u'Ready',
476 u'hostname': u'host2',
477 u'locked': True,
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'],
481 u'invalid': False,
482 u'synch_id': None,
483 u'platform': u'plat1',
484 u'id': 3}])],
485 out_words_ok=['host1', 'Ready', 'plat1',
486 'label2', 'label3', 'True',
487 'host2', 'label4'],
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']},
497 True,
498 [])],
499 out_words_ok=[],
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']},
510 True,
511 [])],
512 out_words_ok=[],
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']},
522 True,
523 [{u'status': u'Ready',
524 u'hostname': u'host1',
525 u'locked': True,
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'],
529 u'invalid': False,
530 u'synch_id': None,
531 u'platform': u'plat1',
532 u'id': 2},
533 {u'status': u'Ready',
534 u'hostname': u'host2',
535 u'locked': True,
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'],
539 u'invalid': False,
540 u'synch_id': None,
541 u'platform': u'plat1',
542 u'id': 3}])],
543 out_words_ok=['host1', 'Ready', 'plat1',
544 'label2', 'label3', 'True',
545 'host2', 'label4'],
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},
553 True,
554 [{u'status': u'Ready',
555 u'hostname': u'host1',
556 u'locked': False,
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'],
560 u'invalid': False,
561 u'synch_id': None,
562 u'platform': u'plat1',
563 u'id': 2},
564 {u'status': u'Ready',
565 u'hostname': u'host2',
566 u'locked': False,
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'],
570 u'invalid': False,
571 u'synch_id': None,
572 u'platform': u'plat1',
573 u'id': 3}])],
574 out_words_ok=['host1', 'Ready', 'plat1',
575 'label2', 'label3', 'False',
576 'host2', 'label4'],
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'},
586 True,
587 [{u'status': u'Ready',
588 u'hostname': u'host1',
589 u'locked': True,
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'],
594 u'invalid': False,
595 u'synch_id': None,
596 u'platform': u'plat1',
597 u'id': 3}]),
598 ('get_hosts', {'hostname': 'host0'},
599 True,
600 [{u'status': u'Ready',
601 u'hostname': u'host0',
602 u'locked': False,
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'],
607 u'invalid': False,
608 u'synch_id': None,
609 u'platform': u'plat0',
610 u'id': 2}]),
611 ('get_acl_groups', {'hosts__hostname': 'host1'},
612 True,
613 [{u'description': u'',
614 u'hosts': [u'host0', u'host1'],
615 u'id': 1,
616 u'name': u'Everyone',
617 u'users': [u'user2', u'debug_user', u'user0']}]),
618 ('get_labels', {'host__hostname': 'host1'},
619 True,
620 [{u'id': 2,
621 u'platform': 1,
622 u'name': u'jme',
623 u'invalid': False,
624 u'kernel_config': u''}]),
625 ('get_acl_groups', {'hosts__hostname': 'host0'},
626 True,
627 [{u'description': u'',
628 u'hosts': [u'host0', u'host1'],
629 u'id': 1,
630 u'name': u'Everyone',
631 u'users': [u'user0', u'debug_user']},
632 {u'description': u'myacl0',
633 u'hosts': [u'host0'],
634 u'id': 2,
635 u'name': u'acl0',
636 u'users': [u'user0']}]),
637 ('get_labels', {'host__hostname': 'host0'},
638 True,
639 [{u'id': 4,
640 u'platform': 0,
641 u'name': u'label0',
642 u'invalid': False,
643 u'kernel_config': u''},
644 {u'id': 5,
645 u'platform': 1,
646 u'name': u'plat0',
647 u'invalid': False,
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'},
657 True,
658 []),
659 ('get_hosts', {'hostname': 'host0'},
660 True,
661 [{u'status': u'Ready',
662 u'hostname': u'host0',
663 u'locked': False,
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'],
668 u'invalid': False,
669 u'synch_id': None,
670 u'platform': u'plat0',
671 u'id': 2}]),
672 ('get_acl_groups', {'hosts__hostname': 'host0'},
673 True,
674 [{u'description': u'',
675 u'hosts': [u'host0', u'host1'],
676 u'id': 1,
677 u'name': u'Everyone',
678 u'users': [u'user0', u'debug_user']},
679 {u'description': u'myacl0',
680 u'hosts': [u'host0'],
681 u'id': 2,
682 u'name': u'acl0',
683 u'users': [u'user0']}]),
684 ('get_labels', {'host__hostname': 'host0'},
685 True,
686 [{u'id': 4,
687 u'platform': 0,
688 u'name': u'label0',
689 u'invalid': False,
690 u'kernel_config': u''},
691 {u'id': 5,
692 u'platform': 1,
693 u'name': u'plat0',
694 u'invalid': False,
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'},
707 True,
708 []),
709 ('get_hosts', {'hostname': 'host0'},
710 True,
711 [{u'status': u'Ready',
712 u'hostname': u'host0',
713 u'locked': False,
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'],
718 u'invalid': False,
719 u'synch_id': None,
720 u'platform': u'plat0',
721 u'id': 2}]),
722 ('get_acl_groups', {'hosts__hostname': 'host0'},
723 True,
724 [{u'description': u'',
725 u'hosts': [u'host0', u'host1'],
726 u'id': 1,
727 u'name': u'Everyone',
728 u'users': [u'user0', u'debug_user']},
729 {u'description': u'myacl0',
730 u'hosts': [u'host0'],
731 u'id': 2,
732 u'name': u'acl0',
733 u'users': [u'user0']}]),
734 ('get_labels', {'host__hostname': 'host0'},
735 True,
736 [{u'id': 4,
737 u'platform': 0,
738 u'name': u'label0',
739 u'invalid': False,
740 u'kernel_config': u''},
741 {u'id': 5,
742 u'platform': 1,
743 u'name': u'plat0',
744 u'invalid': False,
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'},
758 True,
759 [{u'status': u'Ready',
760 u'hostname': u'host1',
761 u'locked': True,
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'],
766 u'invalid': False,
767 u'synch_id': None,
768 u'platform': u'plat1',
769 u'id': 3},
770 {u'status': u'Ready',
771 u'hostname': u'host0',
772 u'locked': False,
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'],
777 u'invalid': False,
778 u'synch_id': None,
779 u'platform': u'plat0',
780 u'id': 2}]),
781 ('get_acl_groups', {'hosts__hostname': 'host1'},
782 True,
783 [{u'description': u'',
784 u'hosts': [u'host0', u'host1'],
785 u'id': 1,
786 u'name': u'Everyone',
787 u'users': [u'user2', u'debug_user', u'user0']}]),
788 ('get_labels', {'host__hostname': 'host1'},
789 True,
790 [{u'id': 2,
791 u'platform': 1,
792 u'name': u'jme',
793 u'invalid': False,
794 u'kernel_config': u''}]),
795 ('get_acl_groups', {'hosts__hostname': 'host0'},
796 True,
797 [{u'description': u'',
798 u'hosts': [u'host0', u'host1'],
799 u'id': 1,
800 u'name': u'Everyone',
801 u'users': [u'user0', u'debug_user']},
802 {u'description': u'myacl0',
803 u'hosts': [u'host0'],
804 u'id': 2,
805 u'name': u'acl0',
806 u'users': [u'user0']}]),
807 ('get_labels', {'host__hostname': 'host0'},
808 True,
809 [{u'id': 4,
810 u'platform': 0,
811 u'name': u'label0',
812 u'invalid': False,
813 u'kernel_config': u''},
814 {u'id': 5,
815 u'platform': 1,
816 u'name': u'plat0',
817 u'invalid': False,
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'},
828 True,
829 [{u'status': u'Ready',
830 u'hostname': u'newhost0',
831 u'locked': False,
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'],
836 u'invalid': False,
837 u'synch_id': None,
838 u'platform': u'plat0',
839 u'id': 5}]),
840 ('get_hosts', {'hostname__startswith': 'ho'},
841 True,
842 [{u'status': u'Ready',
843 u'hostname': u'host1',
844 u'locked': True,
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'],
849 u'invalid': False,
850 u'synch_id': None,
851 u'platform': u'plat1',
852 u'id': 3},
853 {u'status': u'Ready',
854 u'hostname': u'host0',
855 u'locked': False,
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'],
860 u'invalid': False,
861 u'synch_id': None,
862 u'platform': u'plat0',
863 u'id': 2}]),
864 ('get_acl_groups', {'hosts__hostname': 'newhost0'},
865 True,
866 [{u'description': u'',
867 u'hosts': [u'newhost0', 'host1'],
868 u'id': 42,
869 u'name': u'my_acl',
870 u'users': [u'user0', u'debug_user']},
871 {u'description': u'my favorite acl',
872 u'hosts': [u'newhost0'],
873 u'id': 2,
874 u'name': u'acl10',
875 u'users': [u'user0']}]),
876 ('get_labels', {'host__hostname': 'newhost0'},
877 True,
878 [{u'id': 4,
879 u'platform': 0,
880 u'name': u'label0',
881 u'invalid': False,
882 u'kernel_config': u''},
883 {u'id': 5,
884 u'platform': 1,
885 u'name': u'plat0',
886 u'invalid': False,
887 u'kernel_config': u''}]),
888 ('get_acl_groups', {'hosts__hostname': 'host1'},
889 True,
890 [{u'description': u'',
891 u'hosts': [u'host0', u'host1'],
892 u'id': 1,
893 u'name': u'Everyone',
894 u'users': [u'user2', u'debug_user', u'user0']}]),
895 ('get_labels', {'host__hostname': 'host1'},
896 True,
897 [{u'id': 2,
898 u'platform': 1,
899 u'name': u'jme',
900 u'invalid': False,
901 u'kernel_config': u''}]),
902 ('get_acl_groups', {'hosts__hostname': 'host0'},
903 True,
904 [{u'description': u'',
905 u'hosts': [u'host0', u'host1'],
906 u'id': 1,
907 u'name': u'Everyone',
908 u'users': [u'user0', u'debug_user']},
909 {u'description': u'myacl0',
910 u'hosts': [u'host0'],
911 u'id': 2,
912 u'name': u'acl0',
913 u'users': [u'user0']}]),
914 ('get_labels', {'host__hostname': 'host0'},
915 True,
916 [{u'id': 4,
917 u'platform': 0,
918 u'name': u'label0',
919 u'invalid': False,
920 u'kernel_config': u''},
921 {u'id': 5,
922 u'platform': 1,
923 u'name': u'plat0',
924 u'invalid': False,
925 u'kernel_config': u''}])],
926 out_words_ok=['host0', 'host1', 'newhost0',
927 'plat0', 'plat1',
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']},
938 True,
939 [{u'status': u'Failed',
940 u'complete': 1,
941 u'host': {u'status': u'Ready',
942 u'locked': True,
943 u'locked_by': 'user0',
944 u'hostname': u'host0',
945 u'invalid': False,
946 u'id': 3232,
947 u'synch_id': None},
948 u'priority': 0,
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"
957 "def step_test():\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,
962 u'priority': u'Low',
963 u'owner': u'user0',
964 u'created_on': u'2008-01-09 10:45:12',
965 u'synch_count': None,
966 u'synch_type': u'Asynchronous',
967 u'id': 216},
968 u'active': 0,
969 u'id': 2981},
970 {u'status': u'Aborted',
971 u'complete': 1,
972 u'host': {u'status': u'Ready',
973 u'locked': True,
974 u'locked_by': 'user0',
975 u'hostname': u'host0',
976 u'invalid': False,
977 u'id': 3232,
978 u'synch_id': None},
979 u'priority': 0,
980 u'meta_host': None,
981 u'job': {u'control_file':
982 u"job.run_test('sleeptest')\n\n",
983 u'name': u'testjob',
984 u'control_type': u'Client',
985 u'synchronizing': 0,
986 u'priority': u'Low',
987 u'owner': u'user1',
988 u'created_on': u'2008-01-17 15:04:53',
989 u'synch_count': None,
990 u'synch_type': u'Asynchronous',
991 u'id': 289},
992 u'active': 0,
993 u'id': 3167}])],
994 out_words_ok=['216', 'user0', 'Failed',
995 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
996 '289', 'user1', 'Aborted',
997 'testjob'])
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'},
1004 True,
1005 [{u'status': u'Ready',
1006 u'hostname': u'host1',
1007 u'locked': True,
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'],
1011 u'invalid': False,
1012 u'synch_id': None,
1013 u'platform': u'plat1',
1014 u'id': 3},
1015 {u'status': u'Ready',
1016 u'hostname': u'host0',
1017 u'locked': False,
1018 u'locked_by': 'user0',
1019 u'lock_time': u'2008-07-23 12:54:15',
1020 u'labels': [u'label0', u'plat0'],
1021 u'invalid': False,
1022 u'synch_id': None,
1023 u'platform': u'plat0',
1024 u'id': 2}]),
1025 ('get_host_queue_entries',
1026 {'host__hostname': 'host1', 'query_limit': 20,
1027 'sort_by': ['-job__id']},
1028 True,
1029 [{u'status': u'Failed',
1030 u'complete': 1,
1031 u'host': {u'status': u'Ready',
1032 u'locked': True,
1033 u'locked_by': 'user0',
1034 u'hostname': u'host1',
1035 u'invalid': False,
1036 u'id': 3232,
1037 u'synch_id': None},
1038 u'priority': 0,
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',
1053 u'owner': u'user0',
1054 u'created_on': u'2008-01-09 10:45:12',
1055 u'synch_count': None,
1056 u'synch_type': u'Asynchronous',
1057 u'id': 216},
1058 u'active': 0,
1059 u'id': 2981},
1060 {u'status': u'Aborted',
1061 u'complete': 1,
1062 u'host': {u'status': u'Ready',
1063 u'locked': True,
1064 u'locked_by': 'user0',
1065 u'hostname': u'host1',
1066 u'invalid': False,
1067 u'id': 3232,
1068 u'synch_id': None},
1069 u'priority': 0,
1070 u'meta_host': None,
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',
1077 u'owner': u'user1',
1078 u'created_on': u'2008-01-17 15:04:53',
1079 u'synch_count': None,
1080 u'synch_type': u'Asynchronous',
1081 u'id': 289},
1082 u'active': 0,
1083 u'id': 3167}]),
1084 ('get_host_queue_entries',
1085 {'host__hostname': 'host0', 'query_limit': 20,
1086 'sort_by': ['-job__id']},
1087 True,
1088 [{u'status': u'Failed',
1089 u'complete': 1,
1090 u'host': {u'status': u'Ready',
1091 u'locked': True,
1092 u'locked_by': 'user0',
1093 u'hostname': u'host0',
1094 u'invalid': False,
1095 u'id': 3232,
1096 u'synch_id': None},
1097 u'priority': 0,
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',
1112 u'owner': u'user0',
1113 u'created_on': u'2008-01-09 10:45:12',
1114 u'synch_count': None,
1115 u'synch_type': u'Asynchronous',
1116 u'id': 216},
1117 u'active': 0,
1118 u'id': 2981},
1119 {u'status': u'Aborted',
1120 u'complete': 1,
1121 u'host': {u'status': u'Ready',
1122 u'locked': True,
1123 u'locked_by': 'user0',
1124 u'hostname': u'host0',
1125 u'invalid': False,
1126 u'id': 3232,
1127 u'synch_id': None},
1128 u'priority': 0,
1129 u'meta_host': None,
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',
1136 u'owner': u'user1',
1137 u'created_on': u'2008-01-17 15:04:53',
1138 u'synch_count': None,
1139 u'synch_type': u'Asynchronous',
1140 u'id': 289},
1141 u'active': 0,
1142 u'id': 3167}])],
1143 out_words_ok=['216', 'user0', 'Failed',
1144 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1145 '289', 'user1', 'Aborted',
1146 'testjob'])
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']},
1155 True,
1156 [{u'status': u'Failed',
1157 u'complete': 1,
1158 u'host': {u'status': u'Ready',
1159 u'locked': True,
1160 u'locked_by': 'user0',
1161 u'hostname': u'host0',
1162 u'invalid': False,
1163 u'id': 3232,
1164 u'synch_id': None},
1165 u'priority': 0,
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',
1180 u'owner': u'user0',
1181 u'created_on': u'2008-01-09 10:45:12',
1182 u'synch_count': None,
1183 u'synch_type': u'Asynchronous',
1184 u'id': 216},
1185 u'active': 0,
1186 u'id': 2981},
1187 {u'status': u'Aborted',
1188 u'complete': 1,
1189 u'host': {u'status': u'Ready',
1190 u'locked': True,
1191 u'locked_by': 'user0',
1192 u'hostname': u'host0',
1193 u'invalid': False,
1194 u'id': 3232,
1195 u'synch_id': None},
1196 u'priority': 0,
1197 u'meta_host': None,
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',
1204 u'owner': u'user1',
1205 u'created_on': u'2008-01-17 15:04:53',
1206 u'synch_count': None,
1207 u'synch_type': u'Asynchronous',
1208 u'id': 289},
1209 u'active': 0,
1210 u'id': 3167}])],
1211 out_words_ok=['216', 'user0', 'Failed',
1212 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1213 '289', 'user1', 'Aborted',
1214 'testjob'])
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},
1222 True, None)],
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},
1230 True, None),
1231 ('modify_host', {'id': 'host0', 'locked': False},
1232 True, None)],
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},
1240 True, None),
1241 ('modify_host', {'id': 'host1', 'locked': True},
1242 False, 'DoesNotExist: Host matching '
1243 'query does not exist.'),
1244 ('modify_host', {'id': 'host0', 'locked': True},
1245 True, None)],
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',
1253 'Do not repair',
1254 'host5' ,'--mlist', mfile.name, 'host1', 'host6',
1255 '--ignore_site_file'],
1256 rpcs=[('modify_host', {'id': 'host6',
1257 'protection': 'Do not repair'},
1258 True, None),
1259 ('modify_host', {'id': 'host5',
1260 'protection': 'Do not repair'},
1261 True, None),
1262 ('modify_host', {'id': 'host4',
1263 'protection': 'Do not repair'},
1264 True, None),
1265 ('modify_host', {'id': 'host3',
1266 'protection': 'Do not repair'},
1267 True, None),
1268 ('modify_host', {'id': 'host2',
1269 'protection': 'Do not repair'},
1270 True, None),
1271 ('modify_host', {'id': 'host1',
1272 'protection': 'Do not repair'},
1273 True, None),
1274 ('modify_host', {'id': 'host0',
1275 'protection': 'Do not repair'},
1276 True, None)],
1277 out_words_ok=['Do not repair', 'host0', 'host1', 'host2',
1278 'host3', 'host4', 'host5', 'host6'])
1279 mfile.clean()
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'},
1289 True,
1290 [{u'id': 4,
1291 u'platform': 0,
1292 u'name': u'label0',
1293 u'invalid': False,
1294 u'kernel_config': u''}]),
1295 ('get_acl_groups', {'name': 'acl0'},
1296 True, []),
1297 ('add_acl_group', {'name': 'acl0'},
1298 True, 5),
1299 ('add_host', {'hostname': 'host1',
1300 'status': 'Ready',
1301 'locked': True},
1302 True, 42),
1303 ('host_add_labels', {'id': 'host1',
1304 'labels': ['label0']},
1305 True, None),
1306 ('add_host', {'hostname': 'host0',
1307 'status': 'Ready',
1308 'locked': True},
1309 True, 42),
1310 ('host_add_labels', {'id': 'host0',
1311 'labels': ['label0']},
1312 True, None),
1313 ('acl_group_add_hosts',
1314 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1315 True, None)],
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'},
1324 True,
1325 [{u'id': 4,
1326 u'platform': 0,
1327 u'name': u'label0',
1328 u'invalid': False,
1329 u'kernel_config': u''}]),
1330 ('get_acl_groups', {'name': 'acl0'},
1331 True, []),
1332 ('add_acl_group', {'name': 'acl0'},
1333 True, 5),
1334 ('add_host', {'hostname': 'host1',
1335 'status': 'Ready',
1336 'locked': True},
1337 True, 42),
1338 ('host_add_labels', {'id': 'host1',
1339 'labels': ['label0']},
1340 True, None),
1341 ('add_host', {'hostname': 'host0',
1342 'status': 'Ready',
1343 'locked': True},
1344 True, 42),
1345 ('host_add_labels', {'id': 'host0',
1346 'labels': ['label0']},
1347 True, None),
1348 ('acl_group_add_hosts',
1349 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1350 True, None),
1351 ('modify_host', {'id': 'host1', 'locked': False},
1352 True, None),
1353 ('modify_host', {'id': 'host0', 'locked': False},
1354 True, None)],
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'},
1364 True,
1365 [{u'id': 4,
1366 u'platform': 0,
1367 u'name': u'label0',
1368 u'invalid': False,
1369 u'kernel_config': u''}]),
1370 ('get_labels', {'name': 'label,1'},
1371 True,
1372 [{u'id': 4,
1373 u'platform': 0,
1374 u'name': u'label,1',
1375 u'invalid': False,
1376 u'kernel_config': u''}]),
1377 ('get_labels', {'name': 'label,2'},
1378 True,
1379 [{u'id': 4,
1380 u'platform': 0,
1381 u'name': u'label,2',
1382 u'invalid': False,
1383 u'kernel_config': u''}]),
1384 ('get_acl_groups', {'name': 'acl0'},
1385 True, []),
1386 ('add_acl_group', {'name': 'acl0'},
1387 True, 5),
1388 ('add_host', {'hostname': 'host1',
1389 'status': 'Ready',
1390 'locked': True},
1391 True, 42),
1392 ('host_add_labels', {'id': 'host1',
1393 'labels': ['label0', 'label,1',
1394 'label,2']},
1395 True, None),
1396 ('add_host', {'hostname': 'host0',
1397 'status': 'Ready',
1398 'locked': True},
1399 True, 42),
1400 ('host_add_labels', {'id': 'host0',
1401 'labels': ['label0', 'label,1',
1402 'label,2']},
1403 True, None),
1404 ('acl_group_add_hosts',
1405 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1406 True, None),
1407 ('modify_host', {'id': 'host1', 'locked': False},
1408 True, None),
1409 ('modify_host', {'id': 'host0', 'locked': False},
1410 True, None)],
1411 out_words_ok=['host0', 'host1'])
1414 if __name__ == '__main__':
1415 unittest.main()