blob: 33a210310608a3c67e478af29539bda8c4bafd7d [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,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800130 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000131 u'id': 1},
132 {u'status': u'Ready',
133 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000134 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000135 u'locked_by': 'user0',
136 u'lock_time': u'2008-07-23 12:54:15',
137 u'labels': [u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000138 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000139 u'synch_id': None,
140 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800141 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000142 u'id': 2}])],
143 out_words_ok=['host0', 'host1', 'Ready',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800144 'plat1', 'False', 'True', 'None'])
mblighbe630eb2008-08-01 16:41:48 +0000145
146
147 def test_execute_list_all_with_labels(self):
148 self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
149 rpcs=[('get_hosts', {},
150 True,
151 [{u'status': u'Ready',
152 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000153 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000154 u'locked_by': 'user0',
155 u'lock_time': u'2008-07-23 12:54:15',
156 u'labels': [u'label0', u'label1'],
mbligh0887d402009-01-30 00:50:29 +0000157 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000158 u'synch_id': None,
159 u'platform': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800160 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000161 u'id': 1},
162 {u'status': u'Ready',
163 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000164 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000165 u'locked_by': 'user0',
166 u'lock_time': u'2008-07-23 12:54:15',
167 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000168 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000169 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800170 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000171 u'platform': u'plat1',
172 u'id': 2}])],
173 out_words_ok=['host0', 'host1', 'Ready', 'plat1',
174 'label0', 'label1', 'label2', 'label3',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800175 'False', 'True', 'None'])
mblighbe630eb2008-08-01 16:41:48 +0000176
177
178 def test_execute_list_filter_one_host(self):
179 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
180 '--ignore_site_file'],
181 rpcs=[('get_hosts', {'hostname__in': ['host1']},
182 True,
183 [{u'status': u'Ready',
184 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000185 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000186 u'locked_by': 'user0',
187 u'lock_time': u'2008-07-23 12:54:15',
188 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000189 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000190 u'synch_id': None,
191 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800192 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000193 u'id': 2}])],
194 out_words_ok=['host1', 'Ready', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800195 'label2', 'label3', 'True', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000196 out_words_no=['host0', 'host2',
197 'label1', 'label4', 'False'])
198
199
200 def test_execute_list_filter_two_hosts(self):
201 mfile = cli_mock.create_file('host2')
202 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000203 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000204 # This is a bit fragile as the list order may change...
205 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
206 True,
207 [{u'status': u'Ready',
208 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000209 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000210 u'locked_by': 'user0',
211 u'lock_time': u'2008-07-23 12:54:15',
212 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000213 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000214 u'synch_id': None,
215 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800216 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000217 u'id': 2},
218 {u'status': u'Ready',
219 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000220 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000221 u'locked_by': 'user0',
222 u'lock_time': u'2008-07-23 12:54:15',
223 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000224 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000225 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800226 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000227 u'platform': u'plat1',
228 u'id': 3}])],
229 out_words_ok=['host1', 'Ready', 'plat1',
230 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800231 'host2', 'label4', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000232 out_words_no=['host0', 'label1', 'False'])
mbligh41515392009-07-11 00:13:11 +0000233 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000234
235
236 def test_execute_list_filter_two_hosts_one_not_found(self):
237 mfile = cli_mock.create_file('host2')
238 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000239 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000240 # This is a bit fragile as the list order may change...
241 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
242 True,
243 [{u'status': u'Ready',
244 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000245 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000246 u'locked_by': 'user0',
247 u'lock_time': u'2008-07-23 12:54:15',
248 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000249 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000250 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800251 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000252 u'platform': u'plat1',
253 u'id': 3}])],
254 out_words_ok=['Ready', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800255 'label3', 'label4', 'True', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000256 out_words_no=['host1', 'False'],
257 err_words_ok=['host1'])
mbligh41515392009-07-11 00:13:11 +0000258 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000259
260
261 def test_execute_list_filter_two_hosts_none_found(self):
262 self.run_cmd(argv=['atest', 'host', 'list',
263 'host1', 'host2', '--ignore_site_file'],
264 # This is a bit fragile as the list order may change...
265 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
266 True,
267 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000268 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000269 out_words_no=['Hostname', 'Status'],
270 err_words_ok=['Unknown', 'host1', 'host2'])
271
272
273 def test_execute_list_filter_label(self):
274 self.run_cmd(argv=['atest', 'host', 'list',
275 '-b', 'label3', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000276 rpcs=[('get_hosts', {'labels__name__in': ['label3']},
mblighbe630eb2008-08-01 16:41:48 +0000277 True,
278 [{u'status': u'Ready',
279 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000280 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000281 u'locked_by': 'user0',
282 u'lock_time': u'2008-07-23 12:54:15',
283 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000284 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000285 u'synch_id': None,
286 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800287 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000288 u'id': 2},
289 {u'status': u'Ready',
290 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000291 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000292 u'locked_by': 'user0',
293 u'lock_time': u'2008-07-23 12:54:15',
294 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000295 u'invalid': False,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800296 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000297 u'synch_id': None,
298 u'platform': u'plat1',
299 u'id': 3}])],
300 out_words_ok=['host1', 'Ready', 'plat1',
301 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800302 'host2', 'label4', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000303 out_words_no=['host0', 'label1', 'False'])
304
305
mbligh6444c6b2008-10-27 20:55:13 +0000306 def test_execute_list_filter_multi_labels(self):
307 self.run_cmd(argv=['atest', 'host', 'list',
308 '-b', 'label3,label2', '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000309 rpcs=[('get_hosts', {'multiple_labels': ['label2',
310 'label3']},
mbligh6444c6b2008-10-27 20:55:13 +0000311 True,
312 [{u'status': u'Ready',
313 u'hostname': u'host1',
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'label2', u'label3', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000318 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000319 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800320 u'shard': None,
mbligh6444c6b2008-10-27 20:55:13 +0000321 u'platform': u'plat0',
322 u'id': 2},
323 {u'status': u'Ready',
324 u'hostname': u'host3',
mbligh0887d402009-01-30 00:50:29 +0000325 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000326 u'locked_by': 'user0',
327 u'lock_time': u'2008-07-23 12:54:15',
328 u'labels': [u'label3', u'label2', u'plat2'],
mbligh0887d402009-01-30 00:50:29 +0000329 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000330 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800331 u'shard': None,
mbligh6444c6b2008-10-27 20:55:13 +0000332 u'platform': u'plat2',
333 u'id': 4}])],
334 out_words_ok=['host1', 'host3', 'Ready', 'plat0',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800335 'label2', 'label3', 'plat2', 'None'],
mbligh6444c6b2008-10-27 20:55:13 +0000336 out_words_no=['host2', 'label4', 'False', 'plat1'])
337
338
339 def test_execute_list_filter_three_labels(self):
340 self.run_cmd(argv=['atest', 'host', 'list',
341 '-b', 'label3,label2, label4',
342 '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000343 rpcs=[('get_hosts', {'multiple_labels': ['label2',
344 'label3',
mbligh6444c6b2008-10-27 20:55:13 +0000345 'label4']},
346 True,
347 [{u'status': u'Ready',
348 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000349 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000350 u'locked_by': 'user0',
351 u'lock_time': u'2008-07-23 12:54:15',
352 u'labels': [u'label3', u'label2', u'label4',
353 u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000354 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000355 u'synch_id': None,
356 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800357 u'shard': None,
mbligh6444c6b2008-10-27 20:55:13 +0000358 u'id': 3}])],
359 out_words_ok=['host2', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800360 'label2', 'label3', 'label4', 'None'],
mbligh6444c6b2008-10-27 20:55:13 +0000361 out_words_no=['host1', 'host3'])
362
363
mblighf703fb42009-01-30 00:35:05 +0000364 def test_execute_list_filter_wild_labels(self):
365 self.run_cmd(argv=['atest', 'host', 'list',
366 '-b', 'label*',
367 '--ignore_site_file'],
368 rpcs=[('get_hosts',
369 {'labels__name__startswith': 'label'},
370 True,
371 [{u'status': u'Ready',
372 u'hostname': u'host2',
373 u'locked': 1,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800374 u'shard': None,
mblighf703fb42009-01-30 00:35:05 +0000375 u'locked_by': 'user0',
376 u'lock_time': u'2008-07-23 12:54:15',
377 u'labels': [u'label3', u'label2', u'label4',
378 u'plat1'],
379 u'invalid': 0,
380 u'synch_id': None,
381 u'platform': u'plat1',
382 u'id': 3}])],
383 out_words_ok=['host2', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800384 'label2', 'label3', 'label4', 'None'],
mblighf703fb42009-01-30 00:35:05 +0000385 out_words_no=['host1', 'host3'])
386
387
mbligh6444c6b2008-10-27 20:55:13 +0000388 def test_execute_list_filter_multi_labels_no_results(self):
389 self.run_cmd(argv=['atest', 'host', 'list',
390 '-b', 'label3,label2, ', '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000391 rpcs=[('get_hosts', {'multiple_labels': ['label2',
392 'label3']},
mbligh6444c6b2008-10-27 20:55:13 +0000393 True,
394 [])],
395 out_words_ok=[],
396 out_words_no=['host1', 'host2', 'host3',
397 'label2', 'label3', 'label4'])
398
mblighbe630eb2008-08-01 16:41:48 +0000399
400 def test_execute_list_filter_label_and_hosts(self):
401 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
402 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000403 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000404 'hostname__in': ['host2', 'host1']},
405 True,
406 [{u'status': u'Ready',
407 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000408 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000409 u'locked_by': 'user0',
410 u'lock_time': u'2008-07-23 12:54:15',
411 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000412 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000413 u'synch_id': None,
414 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800415 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000416 u'id': 2},
417 {u'status': u'Ready',
418 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000419 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000420 u'locked_by': 'user0',
421 u'lock_time': u'2008-07-23 12:54:15',
422 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000423 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000424 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800425 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000426 u'platform': u'plat1',
427 u'id': 3}])],
428 out_words_ok=['host1', 'Ready', 'plat1',
429 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800430 'host2', 'label4', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000431 out_words_no=['host0', 'label1', 'False'])
432
433
434 def test_execute_list_filter_label_and_hosts_none(self):
435 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
436 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000437 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000438 'hostname__in': ['host2', 'host1']},
439 True,
440 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000441 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000442 out_words_no=['Hostname', 'Status'],
443 err_words_ok=['Unknown', 'host1', 'host2'])
444
445
mblighcd8eb972008-08-25 19:20:39 +0000446 def test_execute_list_filter_status(self):
447 self.run_cmd(argv=['atest', 'host', 'list',
448 '-s', 'Ready', '--ignore_site_file'],
449 rpcs=[('get_hosts', {'status__in': ['Ready']},
450 True,
451 [{u'status': u'Ready',
452 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000453 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000454 u'locked_by': 'user0',
455 u'lock_time': u'2008-07-23 12:54:15',
456 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000457 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000458 u'synch_id': None,
459 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800460 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000461 u'id': 2},
462 {u'status': u'Ready',
463 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000464 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000465 u'locked_by': 'user0',
466 u'lock_time': u'2008-07-23 12:54:15',
467 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000468 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000469 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800470 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000471 u'platform': u'plat1',
472 u'id': 3}])],
473 out_words_ok=['host1', 'Ready', 'plat1',
474 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800475 'host2', 'label4', 'None'],
mblighcd8eb972008-08-25 19:20:39 +0000476 out_words_no=['host0', 'label1', 'False'])
477
478
479
480 def test_execute_list_filter_status_and_hosts(self):
481 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
482 '-s', 'Ready', 'host2', '--ignore_site_file'],
483 rpcs=[('get_hosts', {'status__in': ['Ready'],
484 'hostname__in': ['host2', 'host1']},
485 True,
486 [{u'status': u'Ready',
487 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000488 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000489 u'locked_by': 'user0',
490 u'lock_time': u'2008-07-23 12:54:15',
491 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000492 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000493 u'synch_id': None,
494 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800495 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000496 u'id': 2},
497 {u'status': u'Ready',
498 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000499 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000500 u'locked_by': 'user0',
501 u'lock_time': u'2008-07-23 12:54:15',
502 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000503 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000504 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800505 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000506 u'platform': u'plat1',
507 u'id': 3}])],
508 out_words_ok=['host1', 'Ready', 'plat1',
509 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800510 'host2', 'label4', 'None'],
mblighcd8eb972008-08-25 19:20:39 +0000511 out_words_no=['host0', 'label1', 'False'])
512
513
514 def test_execute_list_filter_status_and_hosts_none(self):
515 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
516 '--status', 'Repair',
517 'host2', '--ignore_site_file'],
518 rpcs=[('get_hosts', {'status__in': ['Repair'],
519 'hostname__in': ['host2', 'host1']},
520 True,
521 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000522 out_words_ok=[],
mblighcd8eb972008-08-25 19:20:39 +0000523 out_words_no=['Hostname', 'Status'],
524 err_words_ok=['Unknown', 'host2'])
525
526
mbligh6444c6b2008-10-27 20:55:13 +0000527 def test_execute_list_filter_statuses_and_hosts_none(self):
528 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh3df90c92009-03-09 21:09:29 +0000529 '--status', 'Repair',
mbligh6444c6b2008-10-27 20:55:13 +0000530 'host2', '--ignore_site_file'],
mbligh3df90c92009-03-09 21:09:29 +0000531 rpcs=[('get_hosts', {'status__in': ['Repair'],
mbligh6444c6b2008-10-27 20:55:13 +0000532 'hostname__in': ['host2', 'host1']},
533 True,
534 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000535 out_words_ok=[],
mbligh6444c6b2008-10-27 20:55:13 +0000536 out_words_no=['Hostname', 'Status'],
537 err_words_ok=['Unknown', 'host2'])
538
539
mbligh91e0efd2009-02-26 01:02:16 +0000540 def test_execute_list_filter_locked(self):
541 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
542 '--locked', 'host2', '--ignore_site_file'],
543 rpcs=[('get_hosts', {'locked': True,
544 'hostname__in': ['host2', 'host1']},
545 True,
546 [{u'status': u'Ready',
547 u'hostname': u'host1',
548 u'locked': True,
549 u'locked_by': 'user0',
550 u'lock_time': u'2008-07-23 12:54:15',
551 u'labels': [u'label2', u'label3', u'plat1'],
552 u'invalid': False,
553 u'synch_id': None,
554 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800555 u'shard': None,
mbligh91e0efd2009-02-26 01:02:16 +0000556 u'id': 2},
557 {u'status': u'Ready',
558 u'hostname': u'host2',
559 u'locked': True,
560 u'locked_by': 'user0',
561 u'lock_time': u'2008-07-23 12:54:15',
562 u'labels': [u'label3', u'label4', u'plat1'],
563 u'invalid': False,
564 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800565 u'shard': None,
mbligh91e0efd2009-02-26 01:02:16 +0000566 u'platform': u'plat1',
567 u'id': 3}])],
568 out_words_ok=['host1', 'Ready', 'plat1',
569 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800570 'host2', 'label4', 'None'],
mbligh91e0efd2009-02-26 01:02:16 +0000571 out_words_no=['host0', 'label1', 'False'])
572
573
574 def test_execute_list_filter_unlocked(self):
575 self.run_cmd(argv=['atest', 'host', 'list',
576 '--unlocked', '--ignore_site_file'],
577 rpcs=[('get_hosts', {'locked': False},
578 True,
579 [{u'status': u'Ready',
580 u'hostname': u'host1',
581 u'locked': False,
582 u'locked_by': 'user0',
583 u'lock_time': u'2008-07-23 12:54:15',
584 u'labels': [u'label2', u'label3', u'plat1'],
585 u'invalid': False,
586 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800587 u'shard': None,
mbligh91e0efd2009-02-26 01:02:16 +0000588 u'platform': u'plat1',
589 u'id': 2},
590 {u'status': u'Ready',
591 u'hostname': u'host2',
592 u'locked': False,
593 u'locked_by': 'user0',
594 u'lock_time': u'2008-07-23 12:54:15',
595 u'labels': [u'label3', u'label4', u'plat1'],
596 u'invalid': False,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800597 u'shard': None,
mbligh91e0efd2009-02-26 01:02:16 +0000598 u'synch_id': None,
599 u'platform': u'plat1',
600 u'id': 3}])],
601 out_words_ok=['host1', 'Ready', 'plat1',
602 'label2', 'label3', 'False',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800603 'host2', 'label4', 'None'],
mbligh91e0efd2009-02-26 01:02:16 +0000604 out_words_no=['host0', 'label1', 'True'])
605
606
mblighbe630eb2008-08-01 16:41:48 +0000607class host_stat_unittest(cli_mock.cli_unittest):
608 def test_execute_stat_two_hosts(self):
609 # The order of RPCs between host1 and host0 could change...
610 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
611 '--ignore_site_file'],
612 rpcs=[('get_hosts', {'hostname': 'host1'},
613 True,
614 [{u'status': u'Ready',
615 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000616 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000617 u'lock_time': u'2008-07-23 12:54:15',
618 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000619 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000620 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000621 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000622 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800623 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000624 u'platform': u'plat1',
Simran Basi211c5ac2015-03-03 02:42:34 +0000625 u'id': 3}]),
mblighbe630eb2008-08-01 16:41:48 +0000626 ('get_hosts', {'hostname': 'host0'},
627 True,
628 [{u'status': u'Ready',
629 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000630 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000631 u'locked_by': 'user0',
632 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000633 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000634 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000635 u'invalid': False,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800636 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000637 u'synch_id': None,
638 u'platform': u'plat0',
Simran Basi211c5ac2015-03-03 02:42:34 +0000639 u'id': 2}]),
mblighbe630eb2008-08-01 16:41:48 +0000640 ('get_acl_groups', {'hosts__hostname': 'host1'},
641 True,
642 [{u'description': u'',
643 u'hosts': [u'host0', u'host1'],
644 u'id': 1,
645 u'name': u'Everyone',
646 u'users': [u'user2', u'debug_user', u'user0']}]),
647 ('get_labels', {'host__hostname': 'host1'},
648 True,
649 [{u'id': 2,
650 u'platform': 1,
651 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000652 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000653 u'kernel_config': u''}]),
654 ('get_acl_groups', {'hosts__hostname': 'host0'},
655 True,
656 [{u'description': u'',
657 u'hosts': [u'host0', u'host1'],
658 u'id': 1,
659 u'name': u'Everyone',
660 u'users': [u'user0', u'debug_user']},
661 {u'description': u'myacl0',
662 u'hosts': [u'host0'],
663 u'id': 2,
664 u'name': u'acl0',
665 u'users': [u'user0']}]),
666 ('get_labels', {'host__hostname': 'host0'},
667 True,
668 [{u'id': 4,
669 u'platform': 0,
670 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000671 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000672 u'kernel_config': u''},
673 {u'id': 5,
674 u'platform': 1,
675 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000676 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000677 u'kernel_config': u''}])],
678 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
679 'Everyone', 'acl0', 'label0'])
680
681
682 def test_execute_stat_one_bad_host_verbose(self):
683 self.run_cmd(argv=['atest', 'host', 'stat', 'host0',
684 'host1', '-v', '--ignore_site_file'],
685 rpcs=[('get_hosts', {'hostname': 'host1'},
686 True,
687 []),
688 ('get_hosts', {'hostname': 'host0'},
689 True,
690 [{u'status': u'Ready',
691 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000692 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000693 u'locked_by': 'user0',
694 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000695 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000696 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000697 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000698 u'synch_id': None,
699 u'platform': u'plat0',
Simran Basi211c5ac2015-03-03 02:42:34 +0000700 u'id': 2}]),
mblighbe630eb2008-08-01 16:41:48 +0000701 ('get_acl_groups', {'hosts__hostname': 'host0'},
702 True,
703 [{u'description': u'',
704 u'hosts': [u'host0', u'host1'],
705 u'id': 1,
706 u'name': u'Everyone',
707 u'users': [u'user0', u'debug_user']},
708 {u'description': u'myacl0',
709 u'hosts': [u'host0'],
710 u'id': 2,
711 u'name': u'acl0',
712 u'users': [u'user0']}]),
713 ('get_labels', {'host__hostname': 'host0'},
714 True,
715 [{u'id': 4,
716 u'platform': 0,
717 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000718 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000719 u'kernel_config': u''},
720 {u'id': 5,
721 u'platform': 1,
722 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000723 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000724 u'kernel_config': u''}])],
725 out_words_ok=['host0', 'plat0',
726 'Everyone', 'acl0', 'label0'],
727 out_words_no=['host1'],
728 err_words_ok=['host1', 'Unknown host'],
729 err_words_no=['host0'])
730
731
732 def test_execute_stat_one_bad_host(self):
733 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
734 '--ignore_site_file'],
735 rpcs=[('get_hosts', {'hostname': 'host1'},
736 True,
737 []),
738 ('get_hosts', {'hostname': 'host0'},
739 True,
740 [{u'status': u'Ready',
741 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000742 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000743 u'locked_by': 'user0',
744 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000745 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000746 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000747 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000748 u'synch_id': None,
749 u'platform': u'plat0',
Simran Basi211c5ac2015-03-03 02:42:34 +0000750 u'id': 2}]),
mblighbe630eb2008-08-01 16:41:48 +0000751 ('get_acl_groups', {'hosts__hostname': 'host0'},
752 True,
753 [{u'description': u'',
754 u'hosts': [u'host0', u'host1'],
755 u'id': 1,
756 u'name': u'Everyone',
757 u'users': [u'user0', u'debug_user']},
758 {u'description': u'myacl0',
759 u'hosts': [u'host0'],
760 u'id': 2,
761 u'name': u'acl0',
762 u'users': [u'user0']}]),
763 ('get_labels', {'host__hostname': 'host0'},
764 True,
765 [{u'id': 4,
766 u'platform': 0,
767 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000768 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000769 u'kernel_config': u''},
770 {u'id': 5,
771 u'platform': 1,
772 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000773 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000774 u'kernel_config': u''}])],
775 out_words_ok=['host0', 'plat0',
776 'Everyone', 'acl0', 'label0'],
777 out_words_no=['host1'],
778 err_words_ok=['host1', 'Unknown host'],
779 err_words_no=['host0'])
780
781
782 def test_execute_stat_wildcard(self):
783 # The order of RPCs between host1 and host0 could change...
784 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*',
785 '--ignore_site_file'],
786 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
787 True,
788 [{u'status': u'Ready',
789 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000790 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000791 u'lock_time': u'2008-07-23 12:54:15',
792 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000793 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000794 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000795 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000796 u'synch_id': None,
797 u'platform': u'plat1',
Simran Basi211c5ac2015-03-03 02:42:34 +0000798 u'id': 3},
mblighbe630eb2008-08-01 16:41:48 +0000799 {u'status': u'Ready',
800 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000801 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000802 u'locked_by': 'user0',
803 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000804 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000805 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000806 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000807 u'synch_id': None,
808 u'platform': u'plat0',
Simran Basi211c5ac2015-03-03 02:42:34 +0000809 u'id': 2}]),
mblighbe630eb2008-08-01 16:41:48 +0000810 ('get_acl_groups', {'hosts__hostname': 'host1'},
811 True,
812 [{u'description': u'',
813 u'hosts': [u'host0', u'host1'],
814 u'id': 1,
815 u'name': u'Everyone',
816 u'users': [u'user2', u'debug_user', u'user0']}]),
817 ('get_labels', {'host__hostname': 'host1'},
818 True,
819 [{u'id': 2,
820 u'platform': 1,
821 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000822 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000823 u'kernel_config': u''}]),
824 ('get_acl_groups', {'hosts__hostname': 'host0'},
825 True,
826 [{u'description': u'',
827 u'hosts': [u'host0', u'host1'],
828 u'id': 1,
829 u'name': u'Everyone',
830 u'users': [u'user0', u'debug_user']},
831 {u'description': u'myacl0',
832 u'hosts': [u'host0'],
833 u'id': 2,
834 u'name': u'acl0',
835 u'users': [u'user0']}]),
836 ('get_labels', {'host__hostname': 'host0'},
837 True,
838 [{u'id': 4,
839 u'platform': 0,
840 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000841 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000842 u'kernel_config': u''},
843 {u'id': 5,
844 u'platform': 1,
845 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000846 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000847 u'kernel_config': u''}])],
848 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
849 'Everyone', 'acl0', 'label0'])
850
851
852 def test_execute_stat_wildcard_and_host(self):
853 # The order of RPCs between host1 and host0 could change...
854 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', 'newhost0',
855 '--ignore_site_file'],
856 rpcs=[('get_hosts', {'hostname': 'newhost0'},
857 True,
858 [{u'status': u'Ready',
859 u'hostname': u'newhost0',
mbligh0887d402009-01-30 00:50:29 +0000860 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000861 u'locked_by': 'user0',
862 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000863 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000864 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000865 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000866 u'synch_id': None,
867 u'platform': u'plat0',
Simran Basi211c5ac2015-03-03 02:42:34 +0000868 u'id': 5}]),
mblighbe630eb2008-08-01 16:41:48 +0000869 ('get_hosts', {'hostname__startswith': 'ho'},
870 True,
871 [{u'status': u'Ready',
872 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000873 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000874 u'lock_time': u'2008-07-23 12:54:15',
875 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000876 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000877 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000878 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000879 u'synch_id': None,
880 u'platform': u'plat1',
Simran Basi211c5ac2015-03-03 02:42:34 +0000881 u'id': 3},
mblighbe630eb2008-08-01 16:41:48 +0000882 {u'status': u'Ready',
883 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000884 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000885 u'locked_by': 'user0',
mbligh536a5242008-10-18 14:35:54 +0000886 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000887 u'lock_time': u'2008-07-23 12:54:15',
888 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000889 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000890 u'synch_id': None,
891 u'platform': u'plat0',
Simran Basi211c5ac2015-03-03 02:42:34 +0000892 u'id': 2}]),
mblighbe630eb2008-08-01 16:41:48 +0000893 ('get_acl_groups', {'hosts__hostname': 'newhost0'},
894 True,
895 [{u'description': u'',
896 u'hosts': [u'newhost0', 'host1'],
897 u'id': 42,
898 u'name': u'my_acl',
899 u'users': [u'user0', u'debug_user']},
900 {u'description': u'my favorite acl',
901 u'hosts': [u'newhost0'],
902 u'id': 2,
903 u'name': u'acl10',
904 u'users': [u'user0']}]),
905 ('get_labels', {'host__hostname': 'newhost0'},
906 True,
907 [{u'id': 4,
908 u'platform': 0,
909 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000910 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000911 u'kernel_config': u''},
912 {u'id': 5,
913 u'platform': 1,
914 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000915 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000916 u'kernel_config': u''}]),
917 ('get_acl_groups', {'hosts__hostname': 'host1'},
918 True,
919 [{u'description': u'',
920 u'hosts': [u'host0', u'host1'],
921 u'id': 1,
922 u'name': u'Everyone',
923 u'users': [u'user2', u'debug_user', u'user0']}]),
924 ('get_labels', {'host__hostname': 'host1'},
925 True,
926 [{u'id': 2,
927 u'platform': 1,
928 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000929 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000930 u'kernel_config': u''}]),
931 ('get_acl_groups', {'hosts__hostname': 'host0'},
932 True,
933 [{u'description': u'',
934 u'hosts': [u'host0', u'host1'],
935 u'id': 1,
936 u'name': u'Everyone',
937 u'users': [u'user0', u'debug_user']},
938 {u'description': u'myacl0',
939 u'hosts': [u'host0'],
940 u'id': 2,
941 u'name': u'acl0',
942 u'users': [u'user0']}]),
943 ('get_labels', {'host__hostname': 'host0'},
944 True,
945 [{u'id': 4,
946 u'platform': 0,
947 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000948 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000949 u'kernel_config': u''},
950 {u'id': 5,
951 u'platform': 1,
952 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000953 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000954 u'kernel_config': u''}])],
955 out_words_ok=['host0', 'host1', 'newhost0',
956 'plat0', 'plat1',
mblighe163b032008-10-18 14:30:27 +0000957 'Everyone', 'acl10', 'label0'])
mblighbe630eb2008-08-01 16:41:48 +0000958
959
960class host_jobs_unittest(cli_mock.cli_unittest):
961 def test_execute_jobs_one_host(self):
962 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
963 '--ignore_site_file'],
964 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +0000965 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +0000966 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +0000967 True,
968 [{u'status': u'Failed',
969 u'complete': 1,
970 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +0000971 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000972 u'locked_by': 'user0',
973 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000974 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000975 u'id': 3232,
976 u'synch_id': None},
977 u'priority': 0,
978 u'meta_host': u'meta0',
979 u'job': {u'control_file':
980 (u"def step_init():\n"
981 "\tjob.next_step([step_test])\n"
982 "\ttestkernel = job.kernel("
983 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
984 "\ttestkernel.install()\n"
985 "\ttestkernel.boot()\n\n"
986 "def step_test():\n"
987 "\tjob.run_test('kernbench')\n\n"),
988 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700989 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000990 u'synchronizing': None,
991 u'priority': u'Low',
992 u'owner': u'user0',
993 u'created_on': u'2008-01-09 10:45:12',
994 u'synch_count': None,
995 u'synch_type': u'Asynchronous',
996 u'id': 216},
997 u'active': 0,
998 u'id': 2981},
999 {u'status': u'Aborted',
1000 u'complete': 1,
1001 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001002 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001003 u'locked_by': 'user0',
1004 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001005 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001006 u'id': 3232,
1007 u'synch_id': None},
1008 u'priority': 0,
1009 u'meta_host': None,
1010 u'job': {u'control_file':
1011 u"job.run_test('sleeptest')\n\n",
1012 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001013 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001014 u'synchronizing': 0,
1015 u'priority': u'Low',
1016 u'owner': u'user1',
1017 u'created_on': u'2008-01-17 15:04:53',
1018 u'synch_count': None,
1019 u'synch_type': u'Asynchronous',
1020 u'id': 289},
1021 u'active': 0,
1022 u'id': 3167}])],
1023 out_words_ok=['216', 'user0', 'Failed',
1024 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1025 '289', 'user1', 'Aborted',
1026 'testjob'])
1027
1028
1029 def test_execute_jobs_wildcard(self):
1030 self.run_cmd(argv=['atest', 'host', 'jobs', 'ho*',
1031 '--ignore_site_file'],
1032 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
1033 True,
1034 [{u'status': u'Ready',
1035 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001036 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001037 u'lock_time': u'2008-07-23 12:54:15',
1038 u'locked_by': 'user0',
1039 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +00001040 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001041 u'synch_id': None,
1042 u'platform': u'plat1',
1043 u'id': 3},
1044 {u'status': u'Ready',
1045 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001046 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +00001047 u'locked_by': 'user0',
1048 u'lock_time': u'2008-07-23 12:54:15',
1049 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +00001050 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001051 u'synch_id': None,
1052 u'platform': u'plat0',
1053 u'id': 2}]),
1054 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001055 {'host__hostname': 'host1', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001056 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001057 True,
1058 [{u'status': u'Failed',
1059 u'complete': 1,
1060 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001061 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001062 u'locked_by': 'user0',
1063 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001064 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001065 u'id': 3232,
1066 u'synch_id': None},
1067 u'priority': 0,
1068 u'meta_host': u'meta0',
1069 u'job': {u'control_file':
1070 (u"def step_init():\n"
1071 "\tjob.next_step([step_test])\n"
1072 "\ttestkernel = job.kernel("
1073 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1074 "\ttestkernel.install()\n"
1075 "\ttestkernel.boot()\n\n"
1076 "def step_test():\n"
1077 "\tjob.run_test('kernbench')\n\n"),
1078 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001079 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001080 u'synchronizing': None,
1081 u'priority': u'Low',
1082 u'owner': u'user0',
1083 u'created_on': u'2008-01-09 10:45:12',
1084 u'synch_count': None,
1085 u'synch_type': u'Asynchronous',
1086 u'id': 216},
1087 u'active': 0,
1088 u'id': 2981},
1089 {u'status': u'Aborted',
1090 u'complete': 1,
1091 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001092 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001093 u'locked_by': 'user0',
1094 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001095 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001096 u'id': 3232,
1097 u'synch_id': None},
1098 u'priority': 0,
1099 u'meta_host': None,
1100 u'job': {u'control_file':
1101 u"job.run_test('sleeptest')\n\n",
1102 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001103 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001104 u'synchronizing': 0,
1105 u'priority': u'Low',
1106 u'owner': u'user1',
1107 u'created_on': u'2008-01-17 15:04:53',
1108 u'synch_count': None,
1109 u'synch_type': u'Asynchronous',
1110 u'id': 289},
1111 u'active': 0,
1112 u'id': 3167}]),
1113 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001114 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001115 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001116 True,
1117 [{u'status': u'Failed',
1118 u'complete': 1,
1119 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001120 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001121 u'locked_by': 'user0',
1122 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001123 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001124 u'id': 3232,
1125 u'synch_id': None},
1126 u'priority': 0,
1127 u'meta_host': u'meta0',
1128 u'job': {u'control_file':
1129 (u"def step_init():\n"
1130 "\tjob.next_step([step_test])\n"
1131 "\ttestkernel = job.kernel("
1132 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1133 "\ttestkernel.install()\n"
1134 "\ttestkernel.boot()\n\n"
1135 "def step_test():\n"
1136 "\tjob.run_test('kernbench')\n\n"),
1137 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001138 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001139 u'synchronizing': None,
1140 u'priority': u'Low',
1141 u'owner': u'user0',
1142 u'created_on': u'2008-01-09 10:45:12',
1143 u'synch_count': None,
1144 u'synch_type': u'Asynchronous',
1145 u'id': 216},
1146 u'active': 0,
1147 u'id': 2981},
1148 {u'status': u'Aborted',
1149 u'complete': 1,
1150 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001151 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001152 u'locked_by': 'user0',
1153 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001154 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001155 u'id': 3232,
1156 u'synch_id': None},
1157 u'priority': 0,
1158 u'meta_host': None,
1159 u'job': {u'control_file':
1160 u"job.run_test('sleeptest')\n\n",
1161 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001162 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001163 u'synchronizing': 0,
1164 u'priority': u'Low',
1165 u'owner': u'user1',
1166 u'created_on': u'2008-01-17 15:04:53',
1167 u'synch_count': None,
1168 u'synch_type': u'Asynchronous',
1169 u'id': 289},
1170 u'active': 0,
1171 u'id': 3167}])],
1172 out_words_ok=['216', 'user0', 'Failed',
1173 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1174 '289', 'user1', 'Aborted',
1175 'testjob'])
1176
mbligh6996fe82008-08-13 00:32:27 +00001177
1178 def test_execute_jobs_one_host_limit(self):
1179 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
1180 '--ignore_site_file', '-q', '10'],
1181 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001182 {'host__hostname': 'host0', 'query_limit': 10,
showard6958c722009-09-23 20:03:16 +00001183 'sort_by': ['-job__id']},
mbligh6996fe82008-08-13 00:32:27 +00001184 True,
1185 [{u'status': u'Failed',
1186 u'complete': 1,
1187 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001188 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001189 u'locked_by': 'user0',
1190 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001191 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001192 u'id': 3232,
1193 u'synch_id': None},
1194 u'priority': 0,
1195 u'meta_host': u'meta0',
1196 u'job': {u'control_file':
1197 (u"def step_init():\n"
1198 "\tjob.next_step([step_test])\n"
1199 "\ttestkernel = job.kernel("
1200 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1201 "\ttestkernel.install()\n"
1202 "\ttestkernel.boot()\n\n"
1203 "def step_test():\n"
1204 "\tjob.run_test('kernbench')\n\n"),
1205 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001206 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001207 u'synchronizing': None,
1208 u'priority': u'Low',
1209 u'owner': u'user0',
1210 u'created_on': u'2008-01-09 10:45:12',
1211 u'synch_count': None,
1212 u'synch_type': u'Asynchronous',
1213 u'id': 216},
1214 u'active': 0,
1215 u'id': 2981},
1216 {u'status': u'Aborted',
1217 u'complete': 1,
1218 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001219 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001220 u'locked_by': 'user0',
1221 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001222 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001223 u'id': 3232,
1224 u'synch_id': None},
1225 u'priority': 0,
1226 u'meta_host': None,
1227 u'job': {u'control_file':
1228 u"job.run_test('sleeptest')\n\n",
1229 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001230 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001231 u'synchronizing': 0,
1232 u'priority': u'Low',
1233 u'owner': u'user1',
1234 u'created_on': u'2008-01-17 15:04:53',
1235 u'synch_count': None,
1236 u'synch_type': u'Asynchronous',
1237 u'id': 289},
1238 u'active': 0,
1239 u'id': 3167}])],
1240 out_words_ok=['216', 'user0', 'Failed',
1241 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1242 '289', 'user1', 'Aborted',
1243 'testjob'])
1244
1245
mblighbe630eb2008-08-01 16:41:48 +00001246class host_mod_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +00001247 def test_execute_lock_one_host(self):
1248 self.run_cmd(argv=['atest', 'host', 'mod',
1249 '--lock', 'host0', '--ignore_site_file'],
1250 rpcs=[('modify_host', {'id': 'host0', 'locked': True},
1251 True, None)],
1252 out_words_ok=['Locked', 'host0'])
1253
1254
1255 def test_execute_unlock_two_hosts(self):
1256 self.run_cmd(argv=['atest', 'host', 'mod',
1257 '-u', 'host0,host1', '--ignore_site_file'],
1258 rpcs=[('modify_host', {'id': 'host1', 'locked': False},
1259 True, None),
1260 ('modify_host', {'id': 'host0', 'locked': False},
1261 True, None)],
1262 out_words_ok=['Unlocked', 'host0', 'host1'])
1263
1264
mbligh6eca4602009-01-07 16:48:50 +00001265 def test_execute_lock_unknown_hosts(self):
1266 self.run_cmd(argv=['atest', 'host', 'mod',
1267 '-l', 'host0,host1', 'host2', '--ignore_site_file'],
1268 rpcs=[('modify_host', {'id': 'host2', 'locked': True},
1269 True, None),
1270 ('modify_host', {'id': 'host1', 'locked': True},
1271 False, 'DoesNotExist: Host matching '
1272 'query does not exist.'),
1273 ('modify_host', {'id': 'host0', 'locked': True},
1274 True, None)],
1275 out_words_ok=['Locked', 'host0', 'host2'],
1276 err_words_ok=['Host', 'matching', 'query', 'host1'])
1277
1278
showardbe0d8692009-08-20 23:42:44 +00001279 def test_execute_protection_hosts(self):
mblighbe630eb2008-08-01 16:41:48 +00001280 mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4')
showardbe0d8692009-08-20 23:42:44 +00001281 self.run_cmd(argv=['atest', 'host', 'mod', '--protection',
1282 'Do not repair',
mbligh41515392009-07-11 00:13:11 +00001283 'host5' ,'--mlist', mfile.name, 'host1', 'host6',
mblighbe630eb2008-08-01 16:41:48 +00001284 '--ignore_site_file'],
showardbe0d8692009-08-20 23:42:44 +00001285 rpcs=[('modify_host', {'id': 'host6',
1286 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001287 True, None),
showardbe0d8692009-08-20 23:42:44 +00001288 ('modify_host', {'id': 'host5',
1289 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001290 True, None),
showardbe0d8692009-08-20 23:42:44 +00001291 ('modify_host', {'id': 'host4',
1292 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001293 True, None),
showardbe0d8692009-08-20 23:42:44 +00001294 ('modify_host', {'id': 'host3',
1295 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001296 True, None),
showardbe0d8692009-08-20 23:42:44 +00001297 ('modify_host', {'id': 'host2',
1298 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001299 True, None),
showardbe0d8692009-08-20 23:42:44 +00001300 ('modify_host', {'id': 'host1',
1301 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001302 True, None),
showardbe0d8692009-08-20 23:42:44 +00001303 ('modify_host', {'id': 'host0',
1304 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001305 True, None)],
showardbe0d8692009-08-20 23:42:44 +00001306 out_words_ok=['Do not repair', 'host0', 'host1', 'host2',
mblighbe630eb2008-08-01 16:41:48 +00001307 'host3', 'host4', 'host5', 'host6'])
mbligh41515392009-07-11 00:13:11 +00001308 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +00001309
1310
1311
1312class host_create_unittest(cli_mock.cli_unittest):
1313 def test_execute_create_muliple_hosts_all_options(self):
1314 self.run_cmd(argv=['atest', 'host', 'create', '--lock',
1315 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1316 '--ignore_site_file'],
1317 rpcs=[('get_labels', {'name': 'label0'},
1318 True,
1319 [{u'id': 4,
1320 u'platform': 0,
1321 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001322 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001323 u'kernel_config': u''}]),
1324 ('get_acl_groups', {'name': 'acl0'},
1325 True, []),
1326 ('add_acl_group', {'name': 'acl0'},
1327 True, 5),
1328 ('add_host', {'hostname': 'host1',
1329 'status': 'Ready',
1330 'locked': True},
1331 True, 42),
1332 ('host_add_labels', {'id': 'host1',
1333 'labels': ['label0']},
1334 True, None),
1335 ('add_host', {'hostname': 'host0',
1336 'status': 'Ready',
1337 'locked': True},
1338 True, 42),
1339 ('host_add_labels', {'id': 'host0',
1340 'labels': ['label0']},
1341 True, None),
1342 ('acl_group_add_hosts',
1343 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1344 True, None)],
1345 out_words_ok=['host0', 'host1'])
1346
1347
mbligh719e14a2008-12-04 01:17:08 +00001348 def test_execute_create_muliple_hosts_unlocked(self):
1349 self.run_cmd(argv=['atest', 'host', 'create',
1350 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1351 '--ignore_site_file'],
1352 rpcs=[('get_labels', {'name': 'label0'},
1353 True,
1354 [{u'id': 4,
1355 u'platform': 0,
1356 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001357 u'invalid': False,
mbligh719e14a2008-12-04 01:17:08 +00001358 u'kernel_config': u''}]),
1359 ('get_acl_groups', {'name': 'acl0'},
1360 True, []),
1361 ('add_acl_group', {'name': 'acl0'},
1362 True, 5),
1363 ('add_host', {'hostname': 'host1',
1364 'status': 'Ready',
1365 'locked': True},
1366 True, 42),
1367 ('host_add_labels', {'id': 'host1',
1368 'labels': ['label0']},
1369 True, None),
1370 ('add_host', {'hostname': 'host0',
1371 'status': 'Ready',
1372 'locked': True},
1373 True, 42),
1374 ('host_add_labels', {'id': 'host0',
1375 'labels': ['label0']},
1376 True, None),
1377 ('acl_group_add_hosts',
1378 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1379 True, None),
1380 ('modify_host', {'id': 'host1', 'locked': False},
1381 True, None),
1382 ('modify_host', {'id': 'host0', 'locked': False},
1383 True, None)],
1384 out_words_ok=['host0', 'host1'])
1385
1386
jamesrenc2863162010-07-12 21:20:51 +00001387 def test_execute_create_muliple_hosts_label_escaped_quotes(self):
1388 self.run_cmd(argv=['atest', 'host', 'create',
1389 '-b', 'label0,label\\,1,label\\,2',
1390 '--acls', 'acl0', 'host0', 'host1',
1391 '--ignore_site_file'],
1392 rpcs=[('get_labels', {'name': 'label0'},
1393 True,
1394 [{u'id': 4,
1395 u'platform': 0,
1396 u'name': u'label0',
1397 u'invalid': False,
1398 u'kernel_config': u''}]),
1399 ('get_labels', {'name': 'label,1'},
1400 True,
1401 [{u'id': 4,
1402 u'platform': 0,
1403 u'name': u'label,1',
1404 u'invalid': False,
1405 u'kernel_config': u''}]),
1406 ('get_labels', {'name': 'label,2'},
1407 True,
1408 [{u'id': 4,
1409 u'platform': 0,
1410 u'name': u'label,2',
1411 u'invalid': False,
1412 u'kernel_config': u''}]),
1413 ('get_acl_groups', {'name': 'acl0'},
1414 True, []),
1415 ('add_acl_group', {'name': 'acl0'},
1416 True, 5),
1417 ('add_host', {'hostname': 'host1',
1418 'status': 'Ready',
1419 'locked': True},
1420 True, 42),
1421 ('host_add_labels', {'id': 'host1',
1422 'labels': ['label0', 'label,1',
1423 'label,2']},
1424 True, None),
1425 ('add_host', {'hostname': 'host0',
1426 'status': 'Ready',
1427 'locked': True},
1428 True, 42),
1429 ('host_add_labels', {'id': 'host0',
1430 'labels': ['label0', 'label,1',
1431 'label,2']},
1432 True, None),
1433 ('acl_group_add_hosts',
1434 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1435 True, None),
1436 ('modify_host', {'id': 'host1', 'locked': False},
1437 True, None),
1438 ('modify_host', {'id': 'host0', 'locked': False},
1439 True, None)],
1440 out_words_ok=['host0', 'host1'])
1441
1442
mblighbe630eb2008-08-01 16:41:48 +00001443if __name__ == '__main__':
1444 unittest.main()