blob: a9bdd9067655a1b05ddaf58eb47a19445463620a [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 Basi71f190b2015-02-25 16:22:56 -0800625 u'id': 3,
626 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000627 ('get_hosts', {'hostname': 'host0'},
628 True,
629 [{u'status': u'Ready',
630 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000631 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000632 u'locked_by': 'user0',
633 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000634 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000635 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000636 u'invalid': False,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800637 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000638 u'synch_id': None,
639 u'platform': u'plat0',
Simran Basi71f190b2015-02-25 16:22:56 -0800640 u'id': 2,
641 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000642 ('get_acl_groups', {'hosts__hostname': 'host1'},
643 True,
644 [{u'description': u'',
645 u'hosts': [u'host0', u'host1'],
646 u'id': 1,
647 u'name': u'Everyone',
648 u'users': [u'user2', u'debug_user', u'user0']}]),
649 ('get_labels', {'host__hostname': 'host1'},
650 True,
651 [{u'id': 2,
652 u'platform': 1,
653 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000654 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000655 u'kernel_config': u''}]),
656 ('get_acl_groups', {'hosts__hostname': 'host0'},
657 True,
658 [{u'description': u'',
659 u'hosts': [u'host0', u'host1'],
660 u'id': 1,
661 u'name': u'Everyone',
662 u'users': [u'user0', u'debug_user']},
663 {u'description': u'myacl0',
664 u'hosts': [u'host0'],
665 u'id': 2,
666 u'name': u'acl0',
667 u'users': [u'user0']}]),
668 ('get_labels', {'host__hostname': 'host0'},
669 True,
670 [{u'id': 4,
671 u'platform': 0,
672 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000673 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000674 u'kernel_config': u''},
675 {u'id': 5,
676 u'platform': 1,
677 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000678 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000679 u'kernel_config': u''}])],
680 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
681 'Everyone', 'acl0', 'label0'])
682
683
684 def test_execute_stat_one_bad_host_verbose(self):
685 self.run_cmd(argv=['atest', 'host', 'stat', 'host0',
686 'host1', '-v', '--ignore_site_file'],
687 rpcs=[('get_hosts', {'hostname': 'host1'},
688 True,
689 []),
690 ('get_hosts', {'hostname': 'host0'},
691 True,
692 [{u'status': u'Ready',
693 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000694 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000695 u'locked_by': 'user0',
696 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000697 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000698 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000699 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000700 u'synch_id': None,
701 u'platform': u'plat0',
Simran Basi71f190b2015-02-25 16:22:56 -0800702 u'id': 2,
703 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000704 ('get_acl_groups', {'hosts__hostname': 'host0'},
705 True,
706 [{u'description': u'',
707 u'hosts': [u'host0', u'host1'],
708 u'id': 1,
709 u'name': u'Everyone',
710 u'users': [u'user0', u'debug_user']},
711 {u'description': u'myacl0',
712 u'hosts': [u'host0'],
713 u'id': 2,
714 u'name': u'acl0',
715 u'users': [u'user0']}]),
716 ('get_labels', {'host__hostname': 'host0'},
717 True,
718 [{u'id': 4,
719 u'platform': 0,
720 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000721 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000722 u'kernel_config': u''},
723 {u'id': 5,
724 u'platform': 1,
725 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000726 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000727 u'kernel_config': u''}])],
728 out_words_ok=['host0', 'plat0',
729 'Everyone', 'acl0', 'label0'],
730 out_words_no=['host1'],
731 err_words_ok=['host1', 'Unknown host'],
732 err_words_no=['host0'])
733
734
735 def test_execute_stat_one_bad_host(self):
736 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
737 '--ignore_site_file'],
738 rpcs=[('get_hosts', {'hostname': 'host1'},
739 True,
740 []),
741 ('get_hosts', {'hostname': 'host0'},
742 True,
743 [{u'status': u'Ready',
744 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000745 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000746 u'locked_by': 'user0',
747 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000748 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000749 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000750 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000751 u'synch_id': None,
752 u'platform': u'plat0',
Simran Basi71f190b2015-02-25 16:22:56 -0800753 u'id': 2,
754 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000755 ('get_acl_groups', {'hosts__hostname': 'host0'},
756 True,
757 [{u'description': u'',
758 u'hosts': [u'host0', u'host1'],
759 u'id': 1,
760 u'name': u'Everyone',
761 u'users': [u'user0', u'debug_user']},
762 {u'description': u'myacl0',
763 u'hosts': [u'host0'],
764 u'id': 2,
765 u'name': u'acl0',
766 u'users': [u'user0']}]),
767 ('get_labels', {'host__hostname': 'host0'},
768 True,
769 [{u'id': 4,
770 u'platform': 0,
771 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000772 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000773 u'kernel_config': u''},
774 {u'id': 5,
775 u'platform': 1,
776 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000777 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000778 u'kernel_config': u''}])],
779 out_words_ok=['host0', 'plat0',
780 'Everyone', 'acl0', 'label0'],
781 out_words_no=['host1'],
782 err_words_ok=['host1', 'Unknown host'],
783 err_words_no=['host0'])
784
785
786 def test_execute_stat_wildcard(self):
787 # The order of RPCs between host1 and host0 could change...
788 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*',
789 '--ignore_site_file'],
790 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
791 True,
792 [{u'status': u'Ready',
793 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000794 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000795 u'lock_time': u'2008-07-23 12:54:15',
796 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000797 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000798 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000799 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000800 u'synch_id': None,
801 u'platform': u'plat1',
Simran Basi71f190b2015-02-25 16:22:56 -0800802 u'id': 3,
803 u'attributes': {}},
mblighbe630eb2008-08-01 16:41:48 +0000804 {u'status': u'Ready',
805 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000806 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000807 u'locked_by': 'user0',
808 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000809 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000810 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000811 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000812 u'synch_id': None,
813 u'platform': u'plat0',
Simran Basi71f190b2015-02-25 16:22:56 -0800814 u'id': 2,
815 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000816 ('get_acl_groups', {'hosts__hostname': 'host1'},
817 True,
818 [{u'description': u'',
819 u'hosts': [u'host0', u'host1'],
820 u'id': 1,
821 u'name': u'Everyone',
822 u'users': [u'user2', u'debug_user', u'user0']}]),
823 ('get_labels', {'host__hostname': 'host1'},
824 True,
825 [{u'id': 2,
826 u'platform': 1,
827 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000828 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000829 u'kernel_config': u''}]),
830 ('get_acl_groups', {'hosts__hostname': 'host0'},
831 True,
832 [{u'description': u'',
833 u'hosts': [u'host0', u'host1'],
834 u'id': 1,
835 u'name': u'Everyone',
836 u'users': [u'user0', u'debug_user']},
837 {u'description': u'myacl0',
838 u'hosts': [u'host0'],
839 u'id': 2,
840 u'name': u'acl0',
841 u'users': [u'user0']}]),
842 ('get_labels', {'host__hostname': 'host0'},
843 True,
844 [{u'id': 4,
845 u'platform': 0,
846 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000847 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000848 u'kernel_config': u''},
849 {u'id': 5,
850 u'platform': 1,
851 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000852 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000853 u'kernel_config': u''}])],
854 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
855 'Everyone', 'acl0', 'label0'])
856
857
858 def test_execute_stat_wildcard_and_host(self):
859 # The order of RPCs between host1 and host0 could change...
860 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', 'newhost0',
861 '--ignore_site_file'],
862 rpcs=[('get_hosts', {'hostname': 'newhost0'},
863 True,
864 [{u'status': u'Ready',
865 u'hostname': u'newhost0',
mbligh0887d402009-01-30 00:50:29 +0000866 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000867 u'locked_by': 'user0',
868 u'lock_time': u'2008-07-23 12:54:15',
mblighe163b032008-10-18 14:30:27 +0000869 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000870 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000871 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000872 u'synch_id': None,
873 u'platform': u'plat0',
Simran Basi71f190b2015-02-25 16:22:56 -0800874 u'id': 5,
875 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000876 ('get_hosts', {'hostname__startswith': 'ho'},
877 True,
878 [{u'status': u'Ready',
879 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000880 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000881 u'lock_time': u'2008-07-23 12:54:15',
882 u'locked_by': 'user0',
mblighe163b032008-10-18 14:30:27 +0000883 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000884 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000885 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000886 u'synch_id': None,
887 u'platform': u'plat1',
Simran Basi71f190b2015-02-25 16:22:56 -0800888 u'id': 3,
889 u'attributes': {}},
mblighbe630eb2008-08-01 16:41:48 +0000890 {u'status': u'Ready',
891 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000892 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000893 u'locked_by': 'user0',
mbligh536a5242008-10-18 14:35:54 +0000894 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000895 u'lock_time': u'2008-07-23 12:54:15',
896 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000897 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000898 u'synch_id': None,
899 u'platform': u'plat0',
Simran Basi71f190b2015-02-25 16:22:56 -0800900 u'id': 2,
901 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000902 ('get_acl_groups', {'hosts__hostname': 'newhost0'},
903 True,
904 [{u'description': u'',
905 u'hosts': [u'newhost0', 'host1'],
906 u'id': 42,
907 u'name': u'my_acl',
908 u'users': [u'user0', u'debug_user']},
909 {u'description': u'my favorite acl',
910 u'hosts': [u'newhost0'],
911 u'id': 2,
912 u'name': u'acl10',
913 u'users': [u'user0']}]),
914 ('get_labels', {'host__hostname': 'newhost0'},
915 True,
916 [{u'id': 4,
917 u'platform': 0,
918 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000919 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000920 u'kernel_config': u''},
921 {u'id': 5,
922 u'platform': 1,
923 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000924 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000925 u'kernel_config': u''}]),
926 ('get_acl_groups', {'hosts__hostname': 'host1'},
927 True,
928 [{u'description': u'',
929 u'hosts': [u'host0', u'host1'],
930 u'id': 1,
931 u'name': u'Everyone',
932 u'users': [u'user2', u'debug_user', u'user0']}]),
933 ('get_labels', {'host__hostname': 'host1'},
934 True,
935 [{u'id': 2,
936 u'platform': 1,
937 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000938 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000939 u'kernel_config': u''}]),
940 ('get_acl_groups', {'hosts__hostname': 'host0'},
941 True,
942 [{u'description': u'',
943 u'hosts': [u'host0', u'host1'],
944 u'id': 1,
945 u'name': u'Everyone',
946 u'users': [u'user0', u'debug_user']},
947 {u'description': u'myacl0',
948 u'hosts': [u'host0'],
949 u'id': 2,
950 u'name': u'acl0',
951 u'users': [u'user0']}]),
952 ('get_labels', {'host__hostname': 'host0'},
953 True,
954 [{u'id': 4,
955 u'platform': 0,
956 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000957 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000958 u'kernel_config': u''},
959 {u'id': 5,
960 u'platform': 1,
961 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000962 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000963 u'kernel_config': u''}])],
964 out_words_ok=['host0', 'host1', 'newhost0',
965 'plat0', 'plat1',
mblighe163b032008-10-18 14:30:27 +0000966 'Everyone', 'acl10', 'label0'])
mblighbe630eb2008-08-01 16:41:48 +0000967
968
969class host_jobs_unittest(cli_mock.cli_unittest):
970 def test_execute_jobs_one_host(self):
971 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
972 '--ignore_site_file'],
973 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +0000974 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +0000975 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +0000976 True,
977 [{u'status': u'Failed',
978 u'complete': 1,
979 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +0000980 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000981 u'locked_by': 'user0',
982 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000983 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000984 u'id': 3232,
985 u'synch_id': None},
986 u'priority': 0,
987 u'meta_host': u'meta0',
988 u'job': {u'control_file':
989 (u"def step_init():\n"
990 "\tjob.next_step([step_test])\n"
991 "\ttestkernel = job.kernel("
992 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
993 "\ttestkernel.install()\n"
994 "\ttestkernel.boot()\n\n"
995 "def step_test():\n"
996 "\tjob.run_test('kernbench')\n\n"),
997 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700998 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000999 u'synchronizing': None,
1000 u'priority': u'Low',
1001 u'owner': u'user0',
1002 u'created_on': u'2008-01-09 10:45:12',
1003 u'synch_count': None,
1004 u'synch_type': u'Asynchronous',
1005 u'id': 216},
1006 u'active': 0,
1007 u'id': 2981},
1008 {u'status': u'Aborted',
1009 u'complete': 1,
1010 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001011 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001012 u'locked_by': 'user0',
1013 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001014 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001015 u'id': 3232,
1016 u'synch_id': None},
1017 u'priority': 0,
1018 u'meta_host': None,
1019 u'job': {u'control_file':
1020 u"job.run_test('sleeptest')\n\n",
1021 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001022 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001023 u'synchronizing': 0,
1024 u'priority': u'Low',
1025 u'owner': u'user1',
1026 u'created_on': u'2008-01-17 15:04:53',
1027 u'synch_count': None,
1028 u'synch_type': u'Asynchronous',
1029 u'id': 289},
1030 u'active': 0,
1031 u'id': 3167}])],
1032 out_words_ok=['216', 'user0', 'Failed',
1033 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1034 '289', 'user1', 'Aborted',
1035 'testjob'])
1036
1037
1038 def test_execute_jobs_wildcard(self):
1039 self.run_cmd(argv=['atest', 'host', 'jobs', 'ho*',
1040 '--ignore_site_file'],
1041 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
1042 True,
1043 [{u'status': u'Ready',
1044 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001045 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001046 u'lock_time': u'2008-07-23 12:54:15',
1047 u'locked_by': 'user0',
1048 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +00001049 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001050 u'synch_id': None,
1051 u'platform': u'plat1',
1052 u'id': 3},
1053 {u'status': u'Ready',
1054 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001055 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +00001056 u'locked_by': 'user0',
1057 u'lock_time': u'2008-07-23 12:54:15',
1058 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +00001059 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001060 u'synch_id': None,
1061 u'platform': u'plat0',
1062 u'id': 2}]),
1063 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001064 {'host__hostname': 'host1', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001065 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001066 True,
1067 [{u'status': u'Failed',
1068 u'complete': 1,
1069 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001070 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001071 u'locked_by': 'user0',
1072 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001073 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001074 u'id': 3232,
1075 u'synch_id': None},
1076 u'priority': 0,
1077 u'meta_host': u'meta0',
1078 u'job': {u'control_file':
1079 (u"def step_init():\n"
1080 "\tjob.next_step([step_test])\n"
1081 "\ttestkernel = job.kernel("
1082 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1083 "\ttestkernel.install()\n"
1084 "\ttestkernel.boot()\n\n"
1085 "def step_test():\n"
1086 "\tjob.run_test('kernbench')\n\n"),
1087 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001088 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001089 u'synchronizing': None,
1090 u'priority': u'Low',
1091 u'owner': u'user0',
1092 u'created_on': u'2008-01-09 10:45:12',
1093 u'synch_count': None,
1094 u'synch_type': u'Asynchronous',
1095 u'id': 216},
1096 u'active': 0,
1097 u'id': 2981},
1098 {u'status': u'Aborted',
1099 u'complete': 1,
1100 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001101 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001102 u'locked_by': 'user0',
1103 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001104 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001105 u'id': 3232,
1106 u'synch_id': None},
1107 u'priority': 0,
1108 u'meta_host': None,
1109 u'job': {u'control_file':
1110 u"job.run_test('sleeptest')\n\n",
1111 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001112 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001113 u'synchronizing': 0,
1114 u'priority': u'Low',
1115 u'owner': u'user1',
1116 u'created_on': u'2008-01-17 15:04:53',
1117 u'synch_count': None,
1118 u'synch_type': u'Asynchronous',
1119 u'id': 289},
1120 u'active': 0,
1121 u'id': 3167}]),
1122 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001123 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001124 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001125 True,
1126 [{u'status': u'Failed',
1127 u'complete': 1,
1128 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001129 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001130 u'locked_by': 'user0',
1131 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001132 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001133 u'id': 3232,
1134 u'synch_id': None},
1135 u'priority': 0,
1136 u'meta_host': u'meta0',
1137 u'job': {u'control_file':
1138 (u"def step_init():\n"
1139 "\tjob.next_step([step_test])\n"
1140 "\ttestkernel = job.kernel("
1141 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1142 "\ttestkernel.install()\n"
1143 "\ttestkernel.boot()\n\n"
1144 "def step_test():\n"
1145 "\tjob.run_test('kernbench')\n\n"),
1146 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001147 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001148 u'synchronizing': None,
1149 u'priority': u'Low',
1150 u'owner': u'user0',
1151 u'created_on': u'2008-01-09 10:45:12',
1152 u'synch_count': None,
1153 u'synch_type': u'Asynchronous',
1154 u'id': 216},
1155 u'active': 0,
1156 u'id': 2981},
1157 {u'status': u'Aborted',
1158 u'complete': 1,
1159 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001160 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001161 u'locked_by': 'user0',
1162 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001163 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001164 u'id': 3232,
1165 u'synch_id': None},
1166 u'priority': 0,
1167 u'meta_host': None,
1168 u'job': {u'control_file':
1169 u"job.run_test('sleeptest')\n\n",
1170 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001171 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001172 u'synchronizing': 0,
1173 u'priority': u'Low',
1174 u'owner': u'user1',
1175 u'created_on': u'2008-01-17 15:04:53',
1176 u'synch_count': None,
1177 u'synch_type': u'Asynchronous',
1178 u'id': 289},
1179 u'active': 0,
1180 u'id': 3167}])],
1181 out_words_ok=['216', 'user0', 'Failed',
1182 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1183 '289', 'user1', 'Aborted',
1184 'testjob'])
1185
mbligh6996fe82008-08-13 00:32:27 +00001186
1187 def test_execute_jobs_one_host_limit(self):
1188 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
1189 '--ignore_site_file', '-q', '10'],
1190 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001191 {'host__hostname': 'host0', 'query_limit': 10,
showard6958c722009-09-23 20:03:16 +00001192 'sort_by': ['-job__id']},
mbligh6996fe82008-08-13 00:32:27 +00001193 True,
1194 [{u'status': u'Failed',
1195 u'complete': 1,
1196 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001197 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001198 u'locked_by': 'user0',
1199 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001200 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001201 u'id': 3232,
1202 u'synch_id': None},
1203 u'priority': 0,
1204 u'meta_host': u'meta0',
1205 u'job': {u'control_file':
1206 (u"def step_init():\n"
1207 "\tjob.next_step([step_test])\n"
1208 "\ttestkernel = job.kernel("
1209 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1210 "\ttestkernel.install()\n"
1211 "\ttestkernel.boot()\n\n"
1212 "def step_test():\n"
1213 "\tjob.run_test('kernbench')\n\n"),
1214 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001215 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001216 u'synchronizing': None,
1217 u'priority': u'Low',
1218 u'owner': u'user0',
1219 u'created_on': u'2008-01-09 10:45:12',
1220 u'synch_count': None,
1221 u'synch_type': u'Asynchronous',
1222 u'id': 216},
1223 u'active': 0,
1224 u'id': 2981},
1225 {u'status': u'Aborted',
1226 u'complete': 1,
1227 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001228 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001229 u'locked_by': 'user0',
1230 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001231 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001232 u'id': 3232,
1233 u'synch_id': None},
1234 u'priority': 0,
1235 u'meta_host': None,
1236 u'job': {u'control_file':
1237 u"job.run_test('sleeptest')\n\n",
1238 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001239 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001240 u'synchronizing': 0,
1241 u'priority': u'Low',
1242 u'owner': u'user1',
1243 u'created_on': u'2008-01-17 15:04:53',
1244 u'synch_count': None,
1245 u'synch_type': u'Asynchronous',
1246 u'id': 289},
1247 u'active': 0,
1248 u'id': 3167}])],
1249 out_words_ok=['216', 'user0', 'Failed',
1250 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1251 '289', 'user1', 'Aborted',
1252 'testjob'])
1253
1254
mblighbe630eb2008-08-01 16:41:48 +00001255class host_mod_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +00001256 def test_execute_lock_one_host(self):
1257 self.run_cmd(argv=['atest', 'host', 'mod',
1258 '--lock', 'host0', '--ignore_site_file'],
1259 rpcs=[('modify_host', {'id': 'host0', 'locked': True},
1260 True, None)],
1261 out_words_ok=['Locked', 'host0'])
1262
1263
1264 def test_execute_unlock_two_hosts(self):
1265 self.run_cmd(argv=['atest', 'host', 'mod',
1266 '-u', 'host0,host1', '--ignore_site_file'],
1267 rpcs=[('modify_host', {'id': 'host1', 'locked': False},
1268 True, None),
1269 ('modify_host', {'id': 'host0', 'locked': False},
1270 True, None)],
1271 out_words_ok=['Unlocked', 'host0', 'host1'])
1272
1273
mbligh6eca4602009-01-07 16:48:50 +00001274 def test_execute_lock_unknown_hosts(self):
1275 self.run_cmd(argv=['atest', 'host', 'mod',
1276 '-l', 'host0,host1', 'host2', '--ignore_site_file'],
1277 rpcs=[('modify_host', {'id': 'host2', 'locked': True},
1278 True, None),
1279 ('modify_host', {'id': 'host1', 'locked': True},
1280 False, 'DoesNotExist: Host matching '
1281 'query does not exist.'),
1282 ('modify_host', {'id': 'host0', 'locked': True},
1283 True, None)],
1284 out_words_ok=['Locked', 'host0', 'host2'],
1285 err_words_ok=['Host', 'matching', 'query', 'host1'])
1286
1287
showardbe0d8692009-08-20 23:42:44 +00001288 def test_execute_protection_hosts(self):
mblighbe630eb2008-08-01 16:41:48 +00001289 mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4')
showardbe0d8692009-08-20 23:42:44 +00001290 self.run_cmd(argv=['atest', 'host', 'mod', '--protection',
1291 'Do not repair',
mbligh41515392009-07-11 00:13:11 +00001292 'host5' ,'--mlist', mfile.name, 'host1', 'host6',
mblighbe630eb2008-08-01 16:41:48 +00001293 '--ignore_site_file'],
showardbe0d8692009-08-20 23:42:44 +00001294 rpcs=[('modify_host', {'id': 'host6',
1295 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001296 True, None),
showardbe0d8692009-08-20 23:42:44 +00001297 ('modify_host', {'id': 'host5',
1298 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001299 True, None),
showardbe0d8692009-08-20 23:42:44 +00001300 ('modify_host', {'id': 'host4',
1301 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001302 True, None),
showardbe0d8692009-08-20 23:42:44 +00001303 ('modify_host', {'id': 'host3',
1304 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001305 True, None),
showardbe0d8692009-08-20 23:42:44 +00001306 ('modify_host', {'id': 'host2',
1307 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001308 True, None),
showardbe0d8692009-08-20 23:42:44 +00001309 ('modify_host', {'id': 'host1',
1310 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001311 True, None),
showardbe0d8692009-08-20 23:42:44 +00001312 ('modify_host', {'id': 'host0',
1313 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001314 True, None)],
showardbe0d8692009-08-20 23:42:44 +00001315 out_words_ok=['Do not repair', 'host0', 'host1', 'host2',
mblighbe630eb2008-08-01 16:41:48 +00001316 'host3', 'host4', 'host5', 'host6'])
mbligh41515392009-07-11 00:13:11 +00001317 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +00001318
1319
1320
1321class host_create_unittest(cli_mock.cli_unittest):
1322 def test_execute_create_muliple_hosts_all_options(self):
1323 self.run_cmd(argv=['atest', 'host', 'create', '--lock',
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,
mblighbe630eb2008-08-01 16:41:48 +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 out_words_ok=['host0', 'host1'])
1355
1356
mbligh719e14a2008-12-04 01:17:08 +00001357 def test_execute_create_muliple_hosts_unlocked(self):
1358 self.run_cmd(argv=['atest', 'host', 'create',
1359 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1360 '--ignore_site_file'],
1361 rpcs=[('get_labels', {'name': 'label0'},
1362 True,
1363 [{u'id': 4,
1364 u'platform': 0,
1365 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001366 u'invalid': False,
mbligh719e14a2008-12-04 01:17:08 +00001367 u'kernel_config': u''}]),
1368 ('get_acl_groups', {'name': 'acl0'},
1369 True, []),
1370 ('add_acl_group', {'name': 'acl0'},
1371 True, 5),
1372 ('add_host', {'hostname': 'host1',
1373 'status': 'Ready',
1374 'locked': True},
1375 True, 42),
1376 ('host_add_labels', {'id': 'host1',
1377 'labels': ['label0']},
1378 True, None),
1379 ('add_host', {'hostname': 'host0',
1380 'status': 'Ready',
1381 'locked': True},
1382 True, 42),
1383 ('host_add_labels', {'id': 'host0',
1384 'labels': ['label0']},
1385 True, None),
1386 ('acl_group_add_hosts',
1387 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1388 True, None),
1389 ('modify_host', {'id': 'host1', 'locked': False},
1390 True, None),
1391 ('modify_host', {'id': 'host0', 'locked': False},
1392 True, None)],
1393 out_words_ok=['host0', 'host1'])
1394
1395
jamesrenc2863162010-07-12 21:20:51 +00001396 def test_execute_create_muliple_hosts_label_escaped_quotes(self):
1397 self.run_cmd(argv=['atest', 'host', 'create',
1398 '-b', 'label0,label\\,1,label\\,2',
1399 '--acls', 'acl0', 'host0', 'host1',
1400 '--ignore_site_file'],
1401 rpcs=[('get_labels', {'name': 'label0'},
1402 True,
1403 [{u'id': 4,
1404 u'platform': 0,
1405 u'name': u'label0',
1406 u'invalid': False,
1407 u'kernel_config': u''}]),
1408 ('get_labels', {'name': 'label,1'},
1409 True,
1410 [{u'id': 4,
1411 u'platform': 0,
1412 u'name': u'label,1',
1413 u'invalid': False,
1414 u'kernel_config': u''}]),
1415 ('get_labels', {'name': 'label,2'},
1416 True,
1417 [{u'id': 4,
1418 u'platform': 0,
1419 u'name': u'label,2',
1420 u'invalid': False,
1421 u'kernel_config': u''}]),
1422 ('get_acl_groups', {'name': 'acl0'},
1423 True, []),
1424 ('add_acl_group', {'name': 'acl0'},
1425 True, 5),
1426 ('add_host', {'hostname': 'host1',
1427 'status': 'Ready',
1428 'locked': True},
1429 True, 42),
1430 ('host_add_labels', {'id': 'host1',
1431 'labels': ['label0', 'label,1',
1432 'label,2']},
1433 True, None),
1434 ('add_host', {'hostname': 'host0',
1435 'status': 'Ready',
1436 'locked': True},
1437 True, 42),
1438 ('host_add_labels', {'id': 'host0',
1439 'labels': ['label0', 'label,1',
1440 'label,2']},
1441 True, None),
1442 ('acl_group_add_hosts',
1443 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1444 True, None),
1445 ('modify_host', {'id': 'host1', 'locked': False},
1446 True, None),
1447 ('modify_host', {'id': 'host0', 'locked': False},
1448 True, None)],
1449 out_words_ok=['host0', 'host1'])
1450
1451
mblighbe630eb2008-08-01 16:41:48 +00001452if __name__ == '__main__':
1453 unittest.main()