blob: 166f3fd0c0949951eb47b0110d417806e6378f42 [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
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070011from autotest_lib.client.common_lib import control_data
mblighbe630eb2008-08-01 16:41:48 +000012
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070013CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT
14SERVER = control_data.CONTROL_TYPE_NAMES.SERVER
mblighbe630eb2008-08-01 16:41:48 +000015
16class host_ut(cli_mock.cli_unittest):
17 def test_parse_lock_options_both_set(self):
18 hh = host.host()
19 class opt(object):
20 lock = True
21 unlock = True
22 options = opt()
23 self.usage = "unused"
24 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
25 self.god.mock_io()
26 self.assertRaises(cli_mock.ExitException,
27 hh._parse_lock_options, options)
28 self.god.unmock_io()
29
30
31 def test_cleanup_labels_with_platform(self):
32 labels = ['l0', 'l1', 'l2', 'p0', 'l3']
33 hh = host.host()
34 self.assertEqual(['l0', 'l1', 'l2', 'l3'],
35 hh._cleanup_labels(labels, 'p0'))
36
37
38 def test_cleanup_labels_no_platform(self):
39 labels = ['l0', 'l1', 'l2', 'l3']
40 hh = host.host()
41 self.assertEqual(['l0', 'l1', 'l2', 'l3'],
42 hh._cleanup_labels(labels))
43
44
45 def test_cleanup_labels_with_non_avail_platform(self):
46 labels = ['l0', 'l1', 'l2', 'l3']
47 hh = host.host()
48 self.assertEqual(['l0', 'l1', 'l2', 'l3'],
49 hh._cleanup_labels(labels, 'p0'))
50
51
52class host_list_unittest(cli_mock.cli_unittest):
53 def test_parse_host_not_required(self):
54 hl = host.host_list()
55 sys.argv = ['atest']
56 (options, leftover) = hl.parse()
57 self.assertEqual([], hl.hosts)
58 self.assertEqual([], leftover)
59
60
61 def test_parse_with_hosts(self):
62 hl = host.host_list()
63 mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
mbligh41515392009-07-11 00:13:11 +000064 sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3']
mblighbe630eb2008-08-01 16:41:48 +000065 (options, leftover) = hl.parse()
66 self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
67 hl.hosts)
68 self.assertEqual(leftover, [])
mbligh41515392009-07-11 00:13:11 +000069 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +000070
71
72 def test_parse_with_labels(self):
73 hl = host.host_list()
74 sys.argv = ['atest', '--label', 'label0']
75 (options, leftover) = hl.parse()
jamesrenc2863162010-07-12 21:20:51 +000076 self.assertEqual(['label0'], hl.labels)
mbligh6444c6b2008-10-27 20:55:13 +000077 self.assertEqual(leftover, [])
78
79
80 def test_parse_with_multi_labels(self):
81 hl = host.host_list()
82 sys.argv = ['atest', '--label', 'label0,label2']
83 (options, leftover) = hl.parse()
jamesrenc2863162010-07-12 21:20:51 +000084 self.assertEqualNoOrder(['label0', 'label2'], hl.labels)
85 self.assertEqual(leftover, [])
86
87
88 def test_parse_with_escaped_commas_label(self):
89 hl = host.host_list()
90 sys.argv = ['atest', '--label', 'label\\,0']
91 (options, leftover) = hl.parse()
92 self.assertEqual(['label,0'], hl.labels)
93 self.assertEqual(leftover, [])
94
95
96 def test_parse_with_escaped_commas_multi_labels(self):
97 hl = host.host_list()
98 sys.argv = ['atest', '--label', 'label\\,0,label\\,2']
99 (options, leftover) = hl.parse()
100 self.assertEqualNoOrder(['label,0', 'label,2'], hl.labels)
mblighbe630eb2008-08-01 16:41:48 +0000101 self.assertEqual(leftover, [])
102
103
104 def test_parse_with_both(self):
105 hl = host.host_list()
106 mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
mbligh41515392009-07-11 00:13:11 +0000107 sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3',
mblighbe630eb2008-08-01 16:41:48 +0000108 '--label', 'label0']
109 (options, leftover) = hl.parse()
110 self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
111 hl.hosts)
jamesrenc2863162010-07-12 21:20:51 +0000112 self.assertEqual(['label0'], hl.labels)
mblighbe630eb2008-08-01 16:41:48 +0000113 self.assertEqual(leftover, [])
mbligh41515392009-07-11 00:13:11 +0000114 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000115
116
117 def test_execute_list_all_no_labels(self):
118 self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
119 rpcs=[('get_hosts', {},
120 True,
121 [{u'status': u'Ready',
122 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000123 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000124 u'locked_by': 'user0',
125 u'lock_time': u'2008-07-23 12:54:15',
126 u'labels': [],
mbligh0887d402009-01-30 00:50:29 +0000127 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000128 u'synch_id': None,
129 u'platform': None,
130 u'id': 1},
131 {u'status': u'Ready',
132 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000133 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000134 u'locked_by': 'user0',
135 u'lock_time': u'2008-07-23 12:54:15',
136 u'labels': [u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000137 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000138 u'synch_id': None,
139 u'platform': u'plat1',
140 u'id': 2}])],
141 out_words_ok=['host0', 'host1', 'Ready',
142 'plat1', 'False', 'True'])
143
144
145 def test_execute_list_all_with_labels(self):
146 self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
147 rpcs=[('get_hosts', {},
148 True,
149 [{u'status': u'Ready',
150 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000151 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000152 u'locked_by': 'user0',
153 u'lock_time': u'2008-07-23 12:54:15',
154 u'labels': [u'label0', u'label1'],
mbligh0887d402009-01-30 00:50:29 +0000155 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000156 u'synch_id': None,
157 u'platform': None,
158 u'id': 1},
159 {u'status': u'Ready',
160 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000161 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000162 u'locked_by': 'user0',
163 u'lock_time': u'2008-07-23 12:54:15',
164 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000165 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000166 u'synch_id': None,
167 u'platform': u'plat1',
168 u'id': 2}])],
169 out_words_ok=['host0', 'host1', 'Ready', 'plat1',
170 'label0', 'label1', 'label2', 'label3',
171 'False', 'True'])
172
173
174 def test_execute_list_filter_one_host(self):
175 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
176 '--ignore_site_file'],
177 rpcs=[('get_hosts', {'hostname__in': ['host1']},
178 True,
179 [{u'status': u'Ready',
180 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000181 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000182 u'locked_by': 'user0',
183 u'lock_time': u'2008-07-23 12:54:15',
184 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000185 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000186 u'synch_id': None,
187 u'platform': u'plat1',
188 u'id': 2}])],
189 out_words_ok=['host1', 'Ready', 'plat1',
190 'label2', 'label3', 'True'],
191 out_words_no=['host0', 'host2',
192 'label1', 'label4', 'False'])
193
194
195 def test_execute_list_filter_two_hosts(self):
196 mfile = cli_mock.create_file('host2')
197 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000198 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000199 # This is a bit fragile as the list order may change...
200 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
201 True,
202 [{u'status': u'Ready',
203 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000204 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000205 u'locked_by': 'user0',
206 u'lock_time': u'2008-07-23 12:54:15',
207 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000208 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000209 u'synch_id': None,
210 u'platform': u'plat1',
211 u'id': 2},
212 {u'status': u'Ready',
213 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000214 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000215 u'locked_by': 'user0',
216 u'lock_time': u'2008-07-23 12:54:15',
217 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000218 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000219 u'synch_id': None,
220 u'platform': u'plat1',
221 u'id': 3}])],
222 out_words_ok=['host1', 'Ready', 'plat1',
223 'label2', 'label3', 'True',
224 'host2', 'label4'],
225 out_words_no=['host0', 'label1', 'False'])
mbligh41515392009-07-11 00:13:11 +0000226 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000227
228
229 def test_execute_list_filter_two_hosts_one_not_found(self):
230 mfile = cli_mock.create_file('host2')
231 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000232 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000233 # This is a bit fragile as the list order may change...
234 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
235 True,
236 [{u'status': u'Ready',
237 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000238 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000239 u'locked_by': 'user0',
240 u'lock_time': u'2008-07-23 12:54:15',
241 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000242 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000243 u'synch_id': None,
244 u'platform': u'plat1',
245 u'id': 3}])],
246 out_words_ok=['Ready', 'plat1',
247 'label3', 'label4', 'True'],
248 out_words_no=['host1', 'False'],
249 err_words_ok=['host1'])
mbligh41515392009-07-11 00:13:11 +0000250 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000251
252
253 def test_execute_list_filter_two_hosts_none_found(self):
254 self.run_cmd(argv=['atest', 'host', 'list',
255 'host1', 'host2', '--ignore_site_file'],
256 # This is a bit fragile as the list order may change...
257 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
258 True,
259 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000260 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000261 out_words_no=['Hostname', 'Status'],
262 err_words_ok=['Unknown', 'host1', 'host2'])
263
264
265 def test_execute_list_filter_label(self):
266 self.run_cmd(argv=['atest', 'host', 'list',
267 '-b', 'label3', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000268 rpcs=[('get_hosts', {'labels__name__in': ['label3']},
mblighbe630eb2008-08-01 16:41:48 +0000269 True,
270 [{u'status': u'Ready',
271 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000272 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000273 u'locked_by': 'user0',
274 u'lock_time': u'2008-07-23 12:54:15',
275 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000276 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000277 u'synch_id': None,
278 u'platform': u'plat1',
279 u'id': 2},
280 {u'status': u'Ready',
281 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000282 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000283 u'locked_by': 'user0',
284 u'lock_time': u'2008-07-23 12:54:15',
285 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000286 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000287 u'synch_id': None,
288 u'platform': u'plat1',
289 u'id': 3}])],
290 out_words_ok=['host1', 'Ready', 'plat1',
291 'label2', 'label3', 'True',
292 'host2', 'label4'],
293 out_words_no=['host0', 'label1', 'False'])
294
295
mbligh6444c6b2008-10-27 20:55:13 +0000296 def test_execute_list_filter_multi_labels(self):
297 self.run_cmd(argv=['atest', 'host', 'list',
298 '-b', 'label3,label2', '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000299 rpcs=[('get_hosts', {'multiple_labels': ['label2',
300 'label3']},
mbligh6444c6b2008-10-27 20:55:13 +0000301 True,
302 [{u'status': u'Ready',
303 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000304 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000305 u'locked_by': 'user0',
306 u'lock_time': u'2008-07-23 12:54:15',
307 u'labels': [u'label2', u'label3', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000308 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000309 u'synch_id': None,
310 u'platform': u'plat0',
311 u'id': 2},
312 {u'status': u'Ready',
313 u'hostname': u'host3',
mbligh0887d402009-01-30 00:50:29 +0000314 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000315 u'locked_by': 'user0',
316 u'lock_time': u'2008-07-23 12:54:15',
317 u'labels': [u'label3', u'label2', u'plat2'],
mbligh0887d402009-01-30 00:50:29 +0000318 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000319 u'synch_id': None,
320 u'platform': u'plat2',
321 u'id': 4}])],
322 out_words_ok=['host1', 'host3', 'Ready', 'plat0',
323 'label2', 'label3', 'plat2'],
324 out_words_no=['host2', 'label4', 'False', 'plat1'])
325
326
327 def test_execute_list_filter_three_labels(self):
328 self.run_cmd(argv=['atest', 'host', 'list',
329 '-b', 'label3,label2, label4',
330 '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000331 rpcs=[('get_hosts', {'multiple_labels': ['label2',
332 'label3',
mbligh6444c6b2008-10-27 20:55:13 +0000333 'label4']},
334 True,
335 [{u'status': u'Ready',
336 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000337 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000338 u'locked_by': 'user0',
339 u'lock_time': u'2008-07-23 12:54:15',
340 u'labels': [u'label3', u'label2', u'label4',
341 u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000342 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000343 u'synch_id': None,
344 u'platform': u'plat1',
345 u'id': 3}])],
346 out_words_ok=['host2', 'plat1',
347 'label2', 'label3', 'label4'],
348 out_words_no=['host1', 'host3'])
349
350
mblighf703fb42009-01-30 00:35:05 +0000351 def test_execute_list_filter_wild_labels(self):
352 self.run_cmd(argv=['atest', 'host', 'list',
353 '-b', 'label*',
354 '--ignore_site_file'],
355 rpcs=[('get_hosts',
356 {'labels__name__startswith': 'label'},
357 True,
358 [{u'status': u'Ready',
359 u'hostname': u'host2',
360 u'locked': 1,
361 u'locked_by': 'user0',
362 u'lock_time': u'2008-07-23 12:54:15',
363 u'labels': [u'label3', u'label2', u'label4',
364 u'plat1'],
365 u'invalid': 0,
366 u'synch_id': None,
367 u'platform': u'plat1',
368 u'id': 3}])],
369 out_words_ok=['host2', 'plat1',
370 'label2', 'label3', 'label4'],
371 out_words_no=['host1', 'host3'])
372
373
mbligh6444c6b2008-10-27 20:55:13 +0000374 def test_execute_list_filter_multi_labels_no_results(self):
375 self.run_cmd(argv=['atest', 'host', 'list',
376 '-b', 'label3,label2, ', '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000377 rpcs=[('get_hosts', {'multiple_labels': ['label2',
378 'label3']},
mbligh6444c6b2008-10-27 20:55:13 +0000379 True,
380 [])],
381 out_words_ok=[],
382 out_words_no=['host1', 'host2', 'host3',
383 'label2', 'label3', 'label4'])
384
mblighbe630eb2008-08-01 16:41:48 +0000385
386 def test_execute_list_filter_label_and_hosts(self):
387 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
388 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000389 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000390 'hostname__in': ['host2', 'host1']},
391 True,
392 [{u'status': u'Ready',
393 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000394 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000395 u'locked_by': 'user0',
396 u'lock_time': u'2008-07-23 12:54:15',
397 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000398 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000399 u'synch_id': None,
400 u'platform': u'plat1',
401 u'id': 2},
402 {u'status': u'Ready',
403 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000404 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000405 u'locked_by': 'user0',
406 u'lock_time': u'2008-07-23 12:54:15',
407 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000408 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000409 u'synch_id': None,
410 u'platform': u'plat1',
411 u'id': 3}])],
412 out_words_ok=['host1', 'Ready', 'plat1',
413 'label2', 'label3', 'True',
414 'host2', 'label4'],
415 out_words_no=['host0', 'label1', 'False'])
416
417
418 def test_execute_list_filter_label_and_hosts_none(self):
419 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
420 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000421 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000422 'hostname__in': ['host2', 'host1']},
423 True,
424 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000425 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000426 out_words_no=['Hostname', 'Status'],
427 err_words_ok=['Unknown', 'host1', 'host2'])
428
429
mblighcd8eb972008-08-25 19:20:39 +0000430 def test_execute_list_filter_status(self):
431 self.run_cmd(argv=['atest', 'host', 'list',
432 '-s', 'Ready', '--ignore_site_file'],
433 rpcs=[('get_hosts', {'status__in': ['Ready']},
434 True,
435 [{u'status': u'Ready',
436 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000437 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000438 u'locked_by': 'user0',
439 u'lock_time': u'2008-07-23 12:54:15',
440 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000441 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000442 u'synch_id': None,
443 u'platform': u'plat1',
444 u'id': 2},
445 {u'status': u'Ready',
446 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000447 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000448 u'locked_by': 'user0',
449 u'lock_time': u'2008-07-23 12:54:15',
450 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000451 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000452 u'synch_id': None,
453 u'platform': u'plat1',
454 u'id': 3}])],
455 out_words_ok=['host1', 'Ready', 'plat1',
456 'label2', 'label3', 'True',
457 'host2', 'label4'],
458 out_words_no=['host0', 'label1', 'False'])
459
460
461
462 def test_execute_list_filter_status_and_hosts(self):
463 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
464 '-s', 'Ready', 'host2', '--ignore_site_file'],
465 rpcs=[('get_hosts', {'status__in': ['Ready'],
466 'hostname__in': ['host2', 'host1']},
467 True,
468 [{u'status': u'Ready',
469 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000470 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000471 u'locked_by': 'user0',
472 u'lock_time': u'2008-07-23 12:54:15',
473 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000474 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000475 u'synch_id': None,
476 u'platform': u'plat1',
477 u'id': 2},
478 {u'status': u'Ready',
479 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000480 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000481 u'locked_by': 'user0',
482 u'lock_time': u'2008-07-23 12:54:15',
483 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000484 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000485 u'synch_id': None,
486 u'platform': u'plat1',
487 u'id': 3}])],
488 out_words_ok=['host1', 'Ready', 'plat1',
489 'label2', 'label3', 'True',
490 'host2', 'label4'],
491 out_words_no=['host0', 'label1', 'False'])
492
493
494 def test_execute_list_filter_status_and_hosts_none(self):
495 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
496 '--status', 'Repair',
497 'host2', '--ignore_site_file'],
498 rpcs=[('get_hosts', {'status__in': ['Repair'],
499 'hostname__in': ['host2', 'host1']},
500 True,
501 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000502 out_words_ok=[],
mblighcd8eb972008-08-25 19:20:39 +0000503 out_words_no=['Hostname', 'Status'],
504 err_words_ok=['Unknown', 'host2'])
505
506
mbligh6444c6b2008-10-27 20:55:13 +0000507 def test_execute_list_filter_statuses_and_hosts_none(self):
508 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh3df90c92009-03-09 21:09:29 +0000509 '--status', 'Repair',
mbligh6444c6b2008-10-27 20:55:13 +0000510 'host2', '--ignore_site_file'],
mbligh3df90c92009-03-09 21:09:29 +0000511 rpcs=[('get_hosts', {'status__in': ['Repair'],
mbligh6444c6b2008-10-27 20:55:13 +0000512 'hostname__in': ['host2', 'host1']},
513 True,
514 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000515 out_words_ok=[],
mbligh6444c6b2008-10-27 20:55:13 +0000516 out_words_no=['Hostname', 'Status'],
517 err_words_ok=['Unknown', 'host2'])
518
519
mbligh91e0efd2009-02-26 01:02:16 +0000520 def test_execute_list_filter_locked(self):
521 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
522 '--locked', 'host2', '--ignore_site_file'],
523 rpcs=[('get_hosts', {'locked': True,
524 'hostname__in': ['host2', 'host1']},
525 True,
526 [{u'status': u'Ready',
527 u'hostname': u'host1',
528 u'locked': True,
529 u'locked_by': 'user0',
530 u'lock_time': u'2008-07-23 12:54:15',
531 u'labels': [u'label2', u'label3', u'plat1'],
532 u'invalid': False,
533 u'synch_id': None,
534 u'platform': u'plat1',
535 u'id': 2},
536 {u'status': u'Ready',
537 u'hostname': u'host2',
538 u'locked': True,
539 u'locked_by': 'user0',
540 u'lock_time': u'2008-07-23 12:54:15',
541 u'labels': [u'label3', u'label4', u'plat1'],
542 u'invalid': False,
543 u'synch_id': None,
544 u'platform': u'plat1',
545 u'id': 3}])],
546 out_words_ok=['host1', 'Ready', 'plat1',
547 'label2', 'label3', 'True',
548 'host2', 'label4'],
549 out_words_no=['host0', 'label1', 'False'])
550
551
552 def test_execute_list_filter_unlocked(self):
553 self.run_cmd(argv=['atest', 'host', 'list',
554 '--unlocked', '--ignore_site_file'],
555 rpcs=[('get_hosts', {'locked': False},
556 True,
557 [{u'status': u'Ready',
558 u'hostname': u'host1',
559 u'locked': False,
560 u'locked_by': 'user0',
561 u'lock_time': u'2008-07-23 12:54:15',
562 u'labels': [u'label2', u'label3', u'plat1'],
563 u'invalid': False,
564 u'synch_id': None,
565 u'platform': u'plat1',
566 u'id': 2},
567 {u'status': u'Ready',
568 u'hostname': u'host2',
569 u'locked': False,
570 u'locked_by': 'user0',
571 u'lock_time': u'2008-07-23 12:54:15',
572 u'labels': [u'label3', u'label4', u'plat1'],
573 u'invalid': False,
574 u'synch_id': None,
575 u'platform': u'plat1',
576 u'id': 3}])],
577 out_words_ok=['host1', 'Ready', 'plat1',
578 'label2', 'label3', 'False',
579 'host2', 'label4'],
580 out_words_no=['host0', 'label1', 'True'])
581
582
mblighbe630eb2008-08-01 16:41:48 +0000583class host_stat_unittest(cli_mock.cli_unittest):
584 def test_execute_stat_two_hosts(self):
585 # The order of RPCs between host1 and host0 could change...
586 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
587 '--ignore_site_file'],
588 rpcs=[('get_hosts', {'hostname': 'host1'},
589 True,
590 [{u'status': u'Ready',
591 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000592 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000593 u'lock_time': u'2008-07-23 12:54:15',
594 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000595 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000596 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000597 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000598 u'synch_id': None,
599 u'platform': u'plat1',
600 u'id': 3}]),
601 ('get_hosts', {'hostname': 'host0'},
602 True,
603 [{u'status': u'Ready',
604 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000605 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000606 u'locked_by': 'user0',
607 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000608 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000609 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000610 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000611 u'synch_id': None,
612 u'platform': u'plat0',
613 u'id': 2}]),
614 ('get_acl_groups', {'hosts__hostname': 'host1'},
615 True,
616 [{u'description': u'',
617 u'hosts': [u'host0', u'host1'],
618 u'id': 1,
619 u'name': u'Everyone',
620 u'users': [u'user2', u'debug_user', u'user0']}]),
621 ('get_labels', {'host__hostname': 'host1'},
622 True,
623 [{u'id': 2,
624 u'platform': 1,
625 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000626 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000627 u'kernel_config': u''}]),
628 ('get_acl_groups', {'hosts__hostname': 'host0'},
629 True,
630 [{u'description': u'',
631 u'hosts': [u'host0', u'host1'],
632 u'id': 1,
633 u'name': u'Everyone',
634 u'users': [u'user0', u'debug_user']},
635 {u'description': u'myacl0',
636 u'hosts': [u'host0'],
637 u'id': 2,
638 u'name': u'acl0',
639 u'users': [u'user0']}]),
640 ('get_labels', {'host__hostname': 'host0'},
641 True,
642 [{u'id': 4,
643 u'platform': 0,
644 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000645 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000646 u'kernel_config': u''},
647 {u'id': 5,
648 u'platform': 1,
649 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000650 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000651 u'kernel_config': u''}])],
652 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
653 'Everyone', 'acl0', 'label0'])
654
655
656 def test_execute_stat_one_bad_host_verbose(self):
657 self.run_cmd(argv=['atest', 'host', 'stat', 'host0',
658 'host1', '-v', '--ignore_site_file'],
659 rpcs=[('get_hosts', {'hostname': 'host1'},
660 True,
661 []),
662 ('get_hosts', {'hostname': 'host0'},
663 True,
664 [{u'status': u'Ready',
665 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000666 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000667 u'locked_by': 'user0',
668 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000669 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000670 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000671 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000672 u'synch_id': None,
673 u'platform': u'plat0',
674 u'id': 2}]),
675 ('get_acl_groups', {'hosts__hostname': 'host0'},
676 True,
677 [{u'description': u'',
678 u'hosts': [u'host0', u'host1'],
679 u'id': 1,
680 u'name': u'Everyone',
681 u'users': [u'user0', u'debug_user']},
682 {u'description': u'myacl0',
683 u'hosts': [u'host0'],
684 u'id': 2,
685 u'name': u'acl0',
686 u'users': [u'user0']}]),
687 ('get_labels', {'host__hostname': 'host0'},
688 True,
689 [{u'id': 4,
690 u'platform': 0,
691 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000692 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000693 u'kernel_config': u''},
694 {u'id': 5,
695 u'platform': 1,
696 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000697 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000698 u'kernel_config': u''}])],
699 out_words_ok=['host0', 'plat0',
700 'Everyone', 'acl0', 'label0'],
701 out_words_no=['host1'],
702 err_words_ok=['host1', 'Unknown host'],
703 err_words_no=['host0'])
704
705
706 def test_execute_stat_one_bad_host(self):
707 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
708 '--ignore_site_file'],
709 rpcs=[('get_hosts', {'hostname': 'host1'},
710 True,
711 []),
712 ('get_hosts', {'hostname': 'host0'},
713 True,
714 [{u'status': u'Ready',
715 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000716 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000717 u'locked_by': 'user0',
718 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000719 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000720 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000721 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000722 u'synch_id': None,
723 u'platform': u'plat0',
724 u'id': 2}]),
725 ('get_acl_groups', {'hosts__hostname': 'host0'},
726 True,
727 [{u'description': u'',
728 u'hosts': [u'host0', u'host1'],
729 u'id': 1,
730 u'name': u'Everyone',
731 u'users': [u'user0', u'debug_user']},
732 {u'description': u'myacl0',
733 u'hosts': [u'host0'],
734 u'id': 2,
735 u'name': u'acl0',
736 u'users': [u'user0']}]),
737 ('get_labels', {'host__hostname': 'host0'},
738 True,
739 [{u'id': 4,
740 u'platform': 0,
741 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000742 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000743 u'kernel_config': u''},
744 {u'id': 5,
745 u'platform': 1,
746 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000747 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000748 u'kernel_config': u''}])],
749 out_words_ok=['host0', 'plat0',
750 'Everyone', 'acl0', 'label0'],
751 out_words_no=['host1'],
752 err_words_ok=['host1', 'Unknown host'],
753 err_words_no=['host0'])
754
755
756 def test_execute_stat_wildcard(self):
757 # The order of RPCs between host1 and host0 could change...
758 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*',
759 '--ignore_site_file'],
760 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
761 True,
762 [{u'status': u'Ready',
763 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000764 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000765 u'lock_time': u'2008-07-23 12:54:15',
766 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000767 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000768 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000769 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000770 u'synch_id': None,
771 u'platform': u'plat1',
772 u'id': 3},
773 {u'status': u'Ready',
774 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000775 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000776 u'locked_by': 'user0',
777 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000778 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000779 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000780 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000781 u'synch_id': None,
782 u'platform': u'plat0',
783 u'id': 2}]),
784 ('get_acl_groups', {'hosts__hostname': 'host1'},
785 True,
786 [{u'description': u'',
787 u'hosts': [u'host0', u'host1'],
788 u'id': 1,
789 u'name': u'Everyone',
790 u'users': [u'user2', u'debug_user', u'user0']}]),
791 ('get_labels', {'host__hostname': 'host1'},
792 True,
793 [{u'id': 2,
794 u'platform': 1,
795 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000796 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000797 u'kernel_config': u''}]),
798 ('get_acl_groups', {'hosts__hostname': 'host0'},
799 True,
800 [{u'description': u'',
801 u'hosts': [u'host0', u'host1'],
802 u'id': 1,
803 u'name': u'Everyone',
804 u'users': [u'user0', u'debug_user']},
805 {u'description': u'myacl0',
806 u'hosts': [u'host0'],
807 u'id': 2,
808 u'name': u'acl0',
809 u'users': [u'user0']}]),
810 ('get_labels', {'host__hostname': 'host0'},
811 True,
812 [{u'id': 4,
813 u'platform': 0,
814 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000815 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000816 u'kernel_config': u''},
817 {u'id': 5,
818 u'platform': 1,
819 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000820 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000821 u'kernel_config': u''}])],
822 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
823 'Everyone', 'acl0', 'label0'])
824
825
826 def test_execute_stat_wildcard_and_host(self):
827 # The order of RPCs between host1 and host0 could change...
828 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', 'newhost0',
829 '--ignore_site_file'],
830 rpcs=[('get_hosts', {'hostname': 'newhost0'},
831 True,
832 [{u'status': u'Ready',
833 u'hostname': u'newhost0',
mbligh0887d402009-01-30 00:50:29 +0000834 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000835 u'locked_by': 'user0',
836 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000837 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000838 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000839 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000840 u'synch_id': None,
841 u'platform': u'plat0',
842 u'id': 5}]),
843 ('get_hosts', {'hostname__startswith': 'ho'},
844 True,
845 [{u'status': u'Ready',
846 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000847 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000848 u'lock_time': u'2008-07-23 12:54:15',
849 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000850 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000851 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000852 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000853 u'synch_id': None,
854 u'platform': u'plat1',
855 u'id': 3},
856 {u'status': u'Ready',
857 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000858 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000859 u'locked_by': 'user0',
mbligh536a5242008-10-18 14:35:54 +0000860 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000861 u'lock_time': u'2008-07-23 12:54:15',
862 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000863 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000864 u'synch_id': None,
865 u'platform': u'plat0',
866 u'id': 2}]),
867 ('get_acl_groups', {'hosts__hostname': 'newhost0'},
868 True,
869 [{u'description': u'',
870 u'hosts': [u'newhost0', 'host1'],
871 u'id': 42,
872 u'name': u'my_acl',
873 u'users': [u'user0', u'debug_user']},
874 {u'description': u'my favorite acl',
875 u'hosts': [u'newhost0'],
876 u'id': 2,
877 u'name': u'acl10',
878 u'users': [u'user0']}]),
879 ('get_labels', {'host__hostname': 'newhost0'},
880 True,
881 [{u'id': 4,
882 u'platform': 0,
883 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000884 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000885 u'kernel_config': u''},
886 {u'id': 5,
887 u'platform': 1,
888 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000889 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000890 u'kernel_config': u''}]),
891 ('get_acl_groups', {'hosts__hostname': 'host1'},
892 True,
893 [{u'description': u'',
894 u'hosts': [u'host0', u'host1'],
895 u'id': 1,
896 u'name': u'Everyone',
897 u'users': [u'user2', u'debug_user', u'user0']}]),
898 ('get_labels', {'host__hostname': 'host1'},
899 True,
900 [{u'id': 2,
901 u'platform': 1,
902 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000903 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000904 u'kernel_config': u''}]),
905 ('get_acl_groups', {'hosts__hostname': 'host0'},
906 True,
907 [{u'description': u'',
908 u'hosts': [u'host0', u'host1'],
909 u'id': 1,
910 u'name': u'Everyone',
911 u'users': [u'user0', u'debug_user']},
912 {u'description': u'myacl0',
913 u'hosts': [u'host0'],
914 u'id': 2,
915 u'name': u'acl0',
916 u'users': [u'user0']}]),
917 ('get_labels', {'host__hostname': 'host0'},
918 True,
919 [{u'id': 4,
920 u'platform': 0,
921 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000922 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000923 u'kernel_config': u''},
924 {u'id': 5,
925 u'platform': 1,
926 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000927 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000928 u'kernel_config': u''}])],
929 out_words_ok=['host0', 'host1', 'newhost0',
930 'plat0', 'plat1',
mblighe163b032008-10-18 14:30:27 +0000931 'Everyone', 'acl10', 'label0'])
mblighbe630eb2008-08-01 16:41:48 +0000932
933
934class host_jobs_unittest(cli_mock.cli_unittest):
935 def test_execute_jobs_one_host(self):
936 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
937 '--ignore_site_file'],
938 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +0000939 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +0000940 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +0000941 True,
942 [{u'status': u'Failed',
943 u'complete': 1,
944 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +0000945 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000946 u'locked_by': 'user0',
947 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000948 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000949 u'id': 3232,
950 u'synch_id': None},
951 u'priority': 0,
952 u'meta_host': u'meta0',
953 u'job': {u'control_file':
954 (u"def step_init():\n"
955 "\tjob.next_step([step_test])\n"
956 "\ttestkernel = job.kernel("
957 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
958 "\ttestkernel.install()\n"
959 "\ttestkernel.boot()\n\n"
960 "def step_test():\n"
961 "\tjob.run_test('kernbench')\n\n"),
962 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700963 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000964 u'synchronizing': None,
965 u'priority': u'Low',
966 u'owner': u'user0',
967 u'created_on': u'2008-01-09 10:45:12',
968 u'synch_count': None,
969 u'synch_type': u'Asynchronous',
970 u'id': 216},
971 u'active': 0,
972 u'id': 2981},
973 {u'status': u'Aborted',
974 u'complete': 1,
975 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +0000976 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000977 u'locked_by': 'user0',
978 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000979 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000980 u'id': 3232,
981 u'synch_id': None},
982 u'priority': 0,
983 u'meta_host': None,
984 u'job': {u'control_file':
985 u"job.run_test('sleeptest')\n\n",
986 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700987 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000988 u'synchronizing': 0,
989 u'priority': u'Low',
990 u'owner': u'user1',
991 u'created_on': u'2008-01-17 15:04:53',
992 u'synch_count': None,
993 u'synch_type': u'Asynchronous',
994 u'id': 289},
995 u'active': 0,
996 u'id': 3167}])],
997 out_words_ok=['216', 'user0', 'Failed',
998 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
999 '289', 'user1', 'Aborted',
1000 'testjob'])
1001
1002
1003 def test_execute_jobs_wildcard(self):
1004 self.run_cmd(argv=['atest', 'host', 'jobs', 'ho*',
1005 '--ignore_site_file'],
1006 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
1007 True,
1008 [{u'status': u'Ready',
1009 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001010 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001011 u'lock_time': u'2008-07-23 12:54:15',
1012 u'locked_by': 'user0',
1013 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +00001014 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001015 u'synch_id': None,
1016 u'platform': u'plat1',
1017 u'id': 3},
1018 {u'status': u'Ready',
1019 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001020 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +00001021 u'locked_by': 'user0',
1022 u'lock_time': u'2008-07-23 12:54:15',
1023 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +00001024 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001025 u'synch_id': None,
1026 u'platform': u'plat0',
1027 u'id': 2}]),
1028 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001029 {'host__hostname': 'host1', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001030 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001031 True,
1032 [{u'status': u'Failed',
1033 u'complete': 1,
1034 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001035 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001036 u'locked_by': 'user0',
1037 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001038 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001039 u'id': 3232,
1040 u'synch_id': None},
1041 u'priority': 0,
1042 u'meta_host': u'meta0',
1043 u'job': {u'control_file':
1044 (u"def step_init():\n"
1045 "\tjob.next_step([step_test])\n"
1046 "\ttestkernel = job.kernel("
1047 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1048 "\ttestkernel.install()\n"
1049 "\ttestkernel.boot()\n\n"
1050 "def step_test():\n"
1051 "\tjob.run_test('kernbench')\n\n"),
1052 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001053 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001054 u'synchronizing': None,
1055 u'priority': u'Low',
1056 u'owner': u'user0',
1057 u'created_on': u'2008-01-09 10:45:12',
1058 u'synch_count': None,
1059 u'synch_type': u'Asynchronous',
1060 u'id': 216},
1061 u'active': 0,
1062 u'id': 2981},
1063 {u'status': u'Aborted',
1064 u'complete': 1,
1065 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001066 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001067 u'locked_by': 'user0',
1068 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001069 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001070 u'id': 3232,
1071 u'synch_id': None},
1072 u'priority': 0,
1073 u'meta_host': None,
1074 u'job': {u'control_file':
1075 u"job.run_test('sleeptest')\n\n",
1076 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001077 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001078 u'synchronizing': 0,
1079 u'priority': u'Low',
1080 u'owner': u'user1',
1081 u'created_on': u'2008-01-17 15:04:53',
1082 u'synch_count': None,
1083 u'synch_type': u'Asynchronous',
1084 u'id': 289},
1085 u'active': 0,
1086 u'id': 3167}]),
1087 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001088 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001089 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001090 True,
1091 [{u'status': u'Failed',
1092 u'complete': 1,
1093 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001094 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001095 u'locked_by': 'user0',
1096 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001097 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001098 u'id': 3232,
1099 u'synch_id': None},
1100 u'priority': 0,
1101 u'meta_host': u'meta0',
1102 u'job': {u'control_file':
1103 (u"def step_init():\n"
1104 "\tjob.next_step([step_test])\n"
1105 "\ttestkernel = job.kernel("
1106 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1107 "\ttestkernel.install()\n"
1108 "\ttestkernel.boot()\n\n"
1109 "def step_test():\n"
1110 "\tjob.run_test('kernbench')\n\n"),
1111 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001112 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001113 u'synchronizing': None,
1114 u'priority': u'Low',
1115 u'owner': u'user0',
1116 u'created_on': u'2008-01-09 10:45:12',
1117 u'synch_count': None,
1118 u'synch_type': u'Asynchronous',
1119 u'id': 216},
1120 u'active': 0,
1121 u'id': 2981},
1122 {u'status': u'Aborted',
1123 u'complete': 1,
1124 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001125 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001126 u'locked_by': 'user0',
1127 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001128 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001129 u'id': 3232,
1130 u'synch_id': None},
1131 u'priority': 0,
1132 u'meta_host': None,
1133 u'job': {u'control_file':
1134 u"job.run_test('sleeptest')\n\n",
1135 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001136 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001137 u'synchronizing': 0,
1138 u'priority': u'Low',
1139 u'owner': u'user1',
1140 u'created_on': u'2008-01-17 15:04:53',
1141 u'synch_count': None,
1142 u'synch_type': u'Asynchronous',
1143 u'id': 289},
1144 u'active': 0,
1145 u'id': 3167}])],
1146 out_words_ok=['216', 'user0', 'Failed',
1147 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1148 '289', 'user1', 'Aborted',
1149 'testjob'])
1150
mbligh6996fe82008-08-13 00:32:27 +00001151
1152 def test_execute_jobs_one_host_limit(self):
1153 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
1154 '--ignore_site_file', '-q', '10'],
1155 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001156 {'host__hostname': 'host0', 'query_limit': 10,
showard6958c722009-09-23 20:03:16 +00001157 'sort_by': ['-job__id']},
mbligh6996fe82008-08-13 00:32:27 +00001158 True,
1159 [{u'status': u'Failed',
1160 u'complete': 1,
1161 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001162 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001163 u'locked_by': 'user0',
1164 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001165 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001166 u'id': 3232,
1167 u'synch_id': None},
1168 u'priority': 0,
1169 u'meta_host': u'meta0',
1170 u'job': {u'control_file':
1171 (u"def step_init():\n"
1172 "\tjob.next_step([step_test])\n"
1173 "\ttestkernel = job.kernel("
1174 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1175 "\ttestkernel.install()\n"
1176 "\ttestkernel.boot()\n\n"
1177 "def step_test():\n"
1178 "\tjob.run_test('kernbench')\n\n"),
1179 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001180 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001181 u'synchronizing': None,
1182 u'priority': u'Low',
1183 u'owner': u'user0',
1184 u'created_on': u'2008-01-09 10:45:12',
1185 u'synch_count': None,
1186 u'synch_type': u'Asynchronous',
1187 u'id': 216},
1188 u'active': 0,
1189 u'id': 2981},
1190 {u'status': u'Aborted',
1191 u'complete': 1,
1192 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001193 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001194 u'locked_by': 'user0',
1195 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001196 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001197 u'id': 3232,
1198 u'synch_id': None},
1199 u'priority': 0,
1200 u'meta_host': None,
1201 u'job': {u'control_file':
1202 u"job.run_test('sleeptest')\n\n",
1203 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001204 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001205 u'synchronizing': 0,
1206 u'priority': u'Low',
1207 u'owner': u'user1',
1208 u'created_on': u'2008-01-17 15:04:53',
1209 u'synch_count': None,
1210 u'synch_type': u'Asynchronous',
1211 u'id': 289},
1212 u'active': 0,
1213 u'id': 3167}])],
1214 out_words_ok=['216', 'user0', 'Failed',
1215 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1216 '289', 'user1', 'Aborted',
1217 'testjob'])
1218
1219
mblighbe630eb2008-08-01 16:41:48 +00001220class host_mod_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +00001221 def test_execute_lock_one_host(self):
1222 self.run_cmd(argv=['atest', 'host', 'mod',
1223 '--lock', 'host0', '--ignore_site_file'],
1224 rpcs=[('modify_host', {'id': 'host0', 'locked': True},
1225 True, None)],
1226 out_words_ok=['Locked', 'host0'])
1227
1228
1229 def test_execute_unlock_two_hosts(self):
1230 self.run_cmd(argv=['atest', 'host', 'mod',
1231 '-u', 'host0,host1', '--ignore_site_file'],
1232 rpcs=[('modify_host', {'id': 'host1', 'locked': False},
1233 True, None),
1234 ('modify_host', {'id': 'host0', 'locked': False},
1235 True, None)],
1236 out_words_ok=['Unlocked', 'host0', 'host1'])
1237
1238
mbligh6eca4602009-01-07 16:48:50 +00001239 def test_execute_lock_unknown_hosts(self):
1240 self.run_cmd(argv=['atest', 'host', 'mod',
1241 '-l', 'host0,host1', 'host2', '--ignore_site_file'],
1242 rpcs=[('modify_host', {'id': 'host2', 'locked': True},
1243 True, None),
1244 ('modify_host', {'id': 'host1', 'locked': True},
1245 False, 'DoesNotExist: Host matching '
1246 'query does not exist.'),
1247 ('modify_host', {'id': 'host0', 'locked': True},
1248 True, None)],
1249 out_words_ok=['Locked', 'host0', 'host2'],
1250 err_words_ok=['Host', 'matching', 'query', 'host1'])
1251
1252
showardbe0d8692009-08-20 23:42:44 +00001253 def test_execute_protection_hosts(self):
mblighbe630eb2008-08-01 16:41:48 +00001254 mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4')
showardbe0d8692009-08-20 23:42:44 +00001255 self.run_cmd(argv=['atest', 'host', 'mod', '--protection',
1256 'Do not repair',
mbligh41515392009-07-11 00:13:11 +00001257 'host5' ,'--mlist', mfile.name, 'host1', 'host6',
mblighbe630eb2008-08-01 16:41:48 +00001258 '--ignore_site_file'],
showardbe0d8692009-08-20 23:42:44 +00001259 rpcs=[('modify_host', {'id': 'host6',
1260 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001261 True, None),
showardbe0d8692009-08-20 23:42:44 +00001262 ('modify_host', {'id': 'host5',
1263 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001264 True, None),
showardbe0d8692009-08-20 23:42:44 +00001265 ('modify_host', {'id': 'host4',
1266 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001267 True, None),
showardbe0d8692009-08-20 23:42:44 +00001268 ('modify_host', {'id': 'host3',
1269 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001270 True, None),
showardbe0d8692009-08-20 23:42:44 +00001271 ('modify_host', {'id': 'host2',
1272 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001273 True, None),
showardbe0d8692009-08-20 23:42:44 +00001274 ('modify_host', {'id': 'host1',
1275 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001276 True, None),
showardbe0d8692009-08-20 23:42:44 +00001277 ('modify_host', {'id': 'host0',
1278 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001279 True, None)],
showardbe0d8692009-08-20 23:42:44 +00001280 out_words_ok=['Do not repair', 'host0', 'host1', 'host2',
mblighbe630eb2008-08-01 16:41:48 +00001281 'host3', 'host4', 'host5', 'host6'])
mbligh41515392009-07-11 00:13:11 +00001282 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +00001283
1284
1285
1286class host_create_unittest(cli_mock.cli_unittest):
1287 def test_execute_create_muliple_hosts_all_options(self):
1288 self.run_cmd(argv=['atest', 'host', 'create', '--lock',
1289 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1290 '--ignore_site_file'],
1291 rpcs=[('get_labels', {'name': 'label0'},
1292 True,
1293 [{u'id': 4,
1294 u'platform': 0,
1295 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001296 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001297 u'kernel_config': u''}]),
1298 ('get_acl_groups', {'name': 'acl0'},
1299 True, []),
1300 ('add_acl_group', {'name': 'acl0'},
1301 True, 5),
1302 ('add_host', {'hostname': 'host1',
1303 'status': 'Ready',
1304 'locked': True},
1305 True, 42),
1306 ('host_add_labels', {'id': 'host1',
1307 'labels': ['label0']},
1308 True, None),
1309 ('add_host', {'hostname': 'host0',
1310 'status': 'Ready',
1311 'locked': True},
1312 True, 42),
1313 ('host_add_labels', {'id': 'host0',
1314 'labels': ['label0']},
1315 True, None),
1316 ('acl_group_add_hosts',
1317 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1318 True, None)],
1319 out_words_ok=['host0', 'host1'])
1320
1321
mbligh719e14a2008-12-04 01:17:08 +00001322 def test_execute_create_muliple_hosts_unlocked(self):
1323 self.run_cmd(argv=['atest', 'host', 'create',
1324 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1325 '--ignore_site_file'],
1326 rpcs=[('get_labels', {'name': 'label0'},
1327 True,
1328 [{u'id': 4,
1329 u'platform': 0,
1330 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001331 u'invalid': False,
mbligh719e14a2008-12-04 01:17:08 +00001332 u'kernel_config': u''}]),
1333 ('get_acl_groups', {'name': 'acl0'},
1334 True, []),
1335 ('add_acl_group', {'name': 'acl0'},
1336 True, 5),
1337 ('add_host', {'hostname': 'host1',
1338 'status': 'Ready',
1339 'locked': True},
1340 True, 42),
1341 ('host_add_labels', {'id': 'host1',
1342 'labels': ['label0']},
1343 True, None),
1344 ('add_host', {'hostname': 'host0',
1345 'status': 'Ready',
1346 'locked': True},
1347 True, 42),
1348 ('host_add_labels', {'id': 'host0',
1349 'labels': ['label0']},
1350 True, None),
1351 ('acl_group_add_hosts',
1352 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1353 True, None),
1354 ('modify_host', {'id': 'host1', 'locked': False},
1355 True, None),
1356 ('modify_host', {'id': 'host0', 'locked': False},
1357 True, None)],
1358 out_words_ok=['host0', 'host1'])
1359
1360
jamesrenc2863162010-07-12 21:20:51 +00001361 def test_execute_create_muliple_hosts_label_escaped_quotes(self):
1362 self.run_cmd(argv=['atest', 'host', 'create',
1363 '-b', 'label0,label\\,1,label\\,2',
1364 '--acls', 'acl0', 'host0', 'host1',
1365 '--ignore_site_file'],
1366 rpcs=[('get_labels', {'name': 'label0'},
1367 True,
1368 [{u'id': 4,
1369 u'platform': 0,
1370 u'name': u'label0',
1371 u'invalid': False,
1372 u'kernel_config': u''}]),
1373 ('get_labels', {'name': 'label,1'},
1374 True,
1375 [{u'id': 4,
1376 u'platform': 0,
1377 u'name': u'label,1',
1378 u'invalid': False,
1379 u'kernel_config': u''}]),
1380 ('get_labels', {'name': 'label,2'},
1381 True,
1382 [{u'id': 4,
1383 u'platform': 0,
1384 u'name': u'label,2',
1385 u'invalid': False,
1386 u'kernel_config': u''}]),
1387 ('get_acl_groups', {'name': 'acl0'},
1388 True, []),
1389 ('add_acl_group', {'name': 'acl0'},
1390 True, 5),
1391 ('add_host', {'hostname': 'host1',
1392 'status': 'Ready',
1393 'locked': True},
1394 True, 42),
1395 ('host_add_labels', {'id': 'host1',
1396 'labels': ['label0', 'label,1',
1397 'label,2']},
1398 True, None),
1399 ('add_host', {'hostname': 'host0',
1400 'status': 'Ready',
1401 'locked': True},
1402 True, 42),
1403 ('host_add_labels', {'id': 'host0',
1404 'labels': ['label0', 'label,1',
1405 'label,2']},
1406 True, None),
1407 ('acl_group_add_hosts',
1408 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1409 True, None),
1410 ('modify_host', {'id': 'host1', 'locked': False},
1411 True, None),
1412 ('modify_host', {'id': 'host0', 'locked': False},
1413 True, None)],
1414 out_words_ok=['host0', 'host1'])
1415
1416
mblighbe630eb2008-08-01 16:41:48 +00001417if __name__ == '__main__':
1418 unittest.main()