blob: 252c20a1ff134550befef3efb15d05247ae5d462 [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',
Matthew Sartori68186332015-04-27 17:19:53 -0700126 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000127 u'labels': [],
mbligh0887d402009-01-30 00:50:29 +0000128 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000129 u'synch_id': None,
130 u'platform': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800131 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000132 u'id': 1},
133 {u'status': u'Ready',
134 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000135 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000136 u'locked_by': 'user0',
137 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700138 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000139 u'labels': [u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000140 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000141 u'synch_id': None,
142 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800143 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000144 u'id': 2}])],
145 out_words_ok=['host0', 'host1', 'Ready',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800146 'plat1', 'False', 'True', 'None'])
mblighbe630eb2008-08-01 16:41:48 +0000147
148
149 def test_execute_list_all_with_labels(self):
150 self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
151 rpcs=[('get_hosts', {},
152 True,
153 [{u'status': u'Ready',
154 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000155 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000156 u'locked_by': 'user0',
157 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700158 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000159 u'labels': [u'label0', u'label1'],
mbligh0887d402009-01-30 00:50:29 +0000160 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000161 u'synch_id': None,
162 u'platform': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800163 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000164 u'id': 1},
165 {u'status': u'Ready',
166 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000167 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000168 u'locked_by': 'user0',
169 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700170 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000171 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000172 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000173 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800174 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000175 u'platform': u'plat1',
176 u'id': 2}])],
177 out_words_ok=['host0', 'host1', 'Ready', 'plat1',
178 'label0', 'label1', 'label2', 'label3',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800179 'False', 'True', 'None'])
mblighbe630eb2008-08-01 16:41:48 +0000180
181
182 def test_execute_list_filter_one_host(self):
183 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
184 '--ignore_site_file'],
185 rpcs=[('get_hosts', {'hostname__in': ['host1']},
186 True,
187 [{u'status': u'Ready',
188 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000189 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000190 u'locked_by': 'user0',
191 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700192 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000193 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000194 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000195 u'synch_id': None,
196 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800197 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000198 u'id': 2}])],
199 out_words_ok=['host1', 'Ready', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800200 'label2', 'label3', 'True', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000201 out_words_no=['host0', 'host2',
202 'label1', 'label4', 'False'])
203
204
205 def test_execute_list_filter_two_hosts(self):
206 mfile = cli_mock.create_file('host2')
207 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000208 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000209 # This is a bit fragile as the list order may change...
210 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
211 True,
212 [{u'status': u'Ready',
213 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000214 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000215 u'locked_by': 'user0',
216 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700217 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000218 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000219 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000220 u'synch_id': None,
221 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800222 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000223 u'id': 2},
224 {u'status': u'Ready',
225 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000226 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000227 u'locked_by': 'user0',
228 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700229 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000230 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000231 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000232 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800233 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000234 u'platform': u'plat1',
235 u'id': 3}])],
236 out_words_ok=['host1', 'Ready', 'plat1',
237 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800238 'host2', 'label4', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000239 out_words_no=['host0', 'label1', 'False'])
mbligh41515392009-07-11 00:13:11 +0000240 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000241
242
243 def test_execute_list_filter_two_hosts_one_not_found(self):
244 mfile = cli_mock.create_file('host2')
245 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh41515392009-07-11 00:13:11 +0000246 '--mlist', mfile.name, '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000247 # This is a bit fragile as the list order may change...
248 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
249 True,
250 [{u'status': u'Ready',
251 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000252 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000253 u'locked_by': 'user0',
254 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700255 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000256 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000257 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000258 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800259 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000260 u'platform': u'plat1',
261 u'id': 3}])],
262 out_words_ok=['Ready', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800263 'label3', 'label4', 'True', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000264 out_words_no=['host1', 'False'],
265 err_words_ok=['host1'])
mbligh41515392009-07-11 00:13:11 +0000266 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +0000267
268
269 def test_execute_list_filter_two_hosts_none_found(self):
270 self.run_cmd(argv=['atest', 'host', 'list',
271 'host1', 'host2', '--ignore_site_file'],
272 # This is a bit fragile as the list order may change...
273 rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
274 True,
275 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000276 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000277 out_words_no=['Hostname', 'Status'],
278 err_words_ok=['Unknown', 'host1', 'host2'])
279
280
281 def test_execute_list_filter_label(self):
282 self.run_cmd(argv=['atest', 'host', 'list',
283 '-b', 'label3', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000284 rpcs=[('get_hosts', {'labels__name__in': ['label3']},
mblighbe630eb2008-08-01 16:41:48 +0000285 True,
286 [{u'status': u'Ready',
287 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000288 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000289 u'locked_by': 'user0',
290 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700291 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000292 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000293 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000294 u'synch_id': None,
295 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800296 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000297 u'id': 2},
298 {u'status': u'Ready',
299 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000300 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000301 u'locked_by': 'user0',
302 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700303 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000304 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000305 u'invalid': False,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800306 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000307 u'synch_id': None,
308 u'platform': u'plat1',
309 u'id': 3}])],
310 out_words_ok=['host1', 'Ready', 'plat1',
311 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800312 'host2', 'label4', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000313 out_words_no=['host0', 'label1', 'False'])
314
315
mbligh6444c6b2008-10-27 20:55:13 +0000316 def test_execute_list_filter_multi_labels(self):
317 self.run_cmd(argv=['atest', 'host', 'list',
318 '-b', 'label3,label2', '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000319 rpcs=[('get_hosts', {'multiple_labels': ['label2',
320 'label3']},
mbligh6444c6b2008-10-27 20:55:13 +0000321 True,
322 [{u'status': u'Ready',
323 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000324 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000325 u'locked_by': 'user0',
326 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700327 u'lock_reason': u'',
mbligh6444c6b2008-10-27 20:55:13 +0000328 u'labels': [u'label2', u'label3', u'plat0'],
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'plat0',
333 u'id': 2},
334 {u'status': u'Ready',
335 u'hostname': u'host3',
mbligh0887d402009-01-30 00:50:29 +0000336 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000337 u'locked_by': 'user0',
338 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700339 u'lock_reason': u'',
mbligh6444c6b2008-10-27 20:55:13 +0000340 u'labels': [u'label3', u'label2', u'plat2'],
mbligh0887d402009-01-30 00:50:29 +0000341 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000342 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800343 u'shard': None,
mbligh6444c6b2008-10-27 20:55:13 +0000344 u'platform': u'plat2',
345 u'id': 4}])],
346 out_words_ok=['host1', 'host3', 'Ready', 'plat0',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800347 'label2', 'label3', 'plat2', 'None'],
mbligh6444c6b2008-10-27 20:55:13 +0000348 out_words_no=['host2', 'label4', 'False', 'plat1'])
349
350
351 def test_execute_list_filter_three_labels(self):
352 self.run_cmd(argv=['atest', 'host', 'list',
353 '-b', 'label3,label2, label4',
354 '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000355 rpcs=[('get_hosts', {'multiple_labels': ['label2',
356 'label3',
mbligh6444c6b2008-10-27 20:55:13 +0000357 'label4']},
358 True,
359 [{u'status': u'Ready',
360 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000361 u'locked': True,
mbligh6444c6b2008-10-27 20:55:13 +0000362 u'locked_by': 'user0',
363 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700364 u'lock_reason': u'',
mbligh6444c6b2008-10-27 20:55:13 +0000365 u'labels': [u'label3', u'label2', u'label4',
366 u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000367 u'invalid': False,
mbligh6444c6b2008-10-27 20:55:13 +0000368 u'synch_id': None,
369 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800370 u'shard': None,
mbligh6444c6b2008-10-27 20:55:13 +0000371 u'id': 3}])],
372 out_words_ok=['host2', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800373 'label2', 'label3', 'label4', 'None'],
mbligh6444c6b2008-10-27 20:55:13 +0000374 out_words_no=['host1', 'host3'])
375
376
mblighf703fb42009-01-30 00:35:05 +0000377 def test_execute_list_filter_wild_labels(self):
378 self.run_cmd(argv=['atest', 'host', 'list',
379 '-b', 'label*',
380 '--ignore_site_file'],
381 rpcs=[('get_hosts',
382 {'labels__name__startswith': 'label'},
383 True,
384 [{u'status': u'Ready',
385 u'hostname': u'host2',
386 u'locked': 1,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800387 u'shard': None,
mblighf703fb42009-01-30 00:35:05 +0000388 u'locked_by': 'user0',
389 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700390 u'lock_reason': u'',
mblighf703fb42009-01-30 00:35:05 +0000391 u'labels': [u'label3', u'label2', u'label4',
392 u'plat1'],
393 u'invalid': 0,
394 u'synch_id': None,
395 u'platform': u'plat1',
396 u'id': 3}])],
397 out_words_ok=['host2', 'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800398 'label2', 'label3', 'label4', 'None'],
mblighf703fb42009-01-30 00:35:05 +0000399 out_words_no=['host1', 'host3'])
400
401
mbligh6444c6b2008-10-27 20:55:13 +0000402 def test_execute_list_filter_multi_labels_no_results(self):
403 self.run_cmd(argv=['atest', 'host', 'list',
404 '-b', 'label3,label2, ', '--ignore_site_file'],
jamesrenc2863162010-07-12 21:20:51 +0000405 rpcs=[('get_hosts', {'multiple_labels': ['label2',
406 'label3']},
mbligh6444c6b2008-10-27 20:55:13 +0000407 True,
408 [])],
409 out_words_ok=[],
410 out_words_no=['host1', 'host2', 'host3',
411 'label2', 'label3', 'label4'])
412
mblighbe630eb2008-08-01 16:41:48 +0000413
414 def test_execute_list_filter_label_and_hosts(self):
415 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
416 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000417 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000418 'hostname__in': ['host2', 'host1']},
419 True,
420 [{u'status': u'Ready',
421 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000422 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000423 u'locked_by': 'user0',
424 u'lock_time': u'2008-07-23 12:54:15',
425 u'labels': [u'label2', u'label3', u'plat1'],
Matthew Sartori68186332015-04-27 17:19:53 -0700426 u'lock_reason': u'',
mbligh0887d402009-01-30 00:50:29 +0000427 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000428 u'synch_id': None,
429 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800430 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000431 u'id': 2},
432 {u'status': u'Ready',
433 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000434 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000435 u'locked_by': 'user0',
436 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700437 u'lock_reason': u'',
mblighbe630eb2008-08-01 16:41:48 +0000438 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000439 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000440 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800441 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000442 u'platform': u'plat1',
443 u'id': 3}])],
444 out_words_ok=['host1', 'Ready', 'plat1',
445 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800446 'host2', 'label4', 'None'],
mblighbe630eb2008-08-01 16:41:48 +0000447 out_words_no=['host0', 'label1', 'False'])
448
449
450 def test_execute_list_filter_label_and_hosts_none(self):
451 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
452 '-b', 'label3', 'host2', '--ignore_site_file'],
mblighf703fb42009-01-30 00:35:05 +0000453 rpcs=[('get_hosts', {'labels__name__in': ['label3'],
mblighbe630eb2008-08-01 16:41:48 +0000454 'hostname__in': ['host2', 'host1']},
455 True,
456 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000457 out_words_ok=[],
mblighbe630eb2008-08-01 16:41:48 +0000458 out_words_no=['Hostname', 'Status'],
459 err_words_ok=['Unknown', 'host1', 'host2'])
460
461
mblighcd8eb972008-08-25 19:20:39 +0000462 def test_execute_list_filter_status(self):
463 self.run_cmd(argv=['atest', 'host', 'list',
464 '-s', 'Ready', '--ignore_site_file'],
465 rpcs=[('get_hosts', {'status__in': ['Ready']},
466 True,
467 [{u'status': u'Ready',
468 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000469 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000470 u'locked_by': 'user0',
471 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700472 u'lock_reason': u'',
mblighcd8eb972008-08-25 19:20:39 +0000473 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000474 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000475 u'synch_id': None,
476 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800477 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000478 u'id': 2},
479 {u'status': u'Ready',
480 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000481 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000482 u'locked_by': 'user0',
483 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700484 u'lock_reason': u'',
mblighcd8eb972008-08-25 19:20:39 +0000485 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000486 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000487 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800488 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000489 u'platform': u'plat1',
490 u'id': 3}])],
491 out_words_ok=['host1', 'Ready', 'plat1',
492 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800493 'host2', 'label4', 'None'],
mblighcd8eb972008-08-25 19:20:39 +0000494 out_words_no=['host0', 'label1', 'False'])
495
496
497
498 def test_execute_list_filter_status_and_hosts(self):
499 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
500 '-s', 'Ready', 'host2', '--ignore_site_file'],
501 rpcs=[('get_hosts', {'status__in': ['Ready'],
502 'hostname__in': ['host2', 'host1']},
503 True,
504 [{u'status': u'Ready',
505 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000506 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000507 u'locked_by': 'user0',
508 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700509 u'lock_reason': u'',
mblighcd8eb972008-08-25 19:20:39 +0000510 u'labels': [u'label2', u'label3', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000511 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000512 u'synch_id': None,
513 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800514 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000515 u'id': 2},
516 {u'status': u'Ready',
517 u'hostname': u'host2',
mbligh0887d402009-01-30 00:50:29 +0000518 u'locked': True,
mblighcd8eb972008-08-25 19:20:39 +0000519 u'locked_by': 'user0',
520 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700521 u'lock_reason': u'',
mblighcd8eb972008-08-25 19:20:39 +0000522 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000523 u'invalid': False,
mblighcd8eb972008-08-25 19:20:39 +0000524 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800525 u'shard': None,
mblighcd8eb972008-08-25 19:20:39 +0000526 u'platform': u'plat1',
527 u'id': 3}])],
528 out_words_ok=['host1', 'Ready', 'plat1',
529 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800530 'host2', 'label4', 'None'],
mblighcd8eb972008-08-25 19:20:39 +0000531 out_words_no=['host0', 'label1', 'False'])
532
533
534 def test_execute_list_filter_status_and_hosts_none(self):
535 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
536 '--status', 'Repair',
537 'host2', '--ignore_site_file'],
538 rpcs=[('get_hosts', {'status__in': ['Repair'],
539 'hostname__in': ['host2', 'host1']},
540 True,
541 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000542 out_words_ok=[],
mblighcd8eb972008-08-25 19:20:39 +0000543 out_words_no=['Hostname', 'Status'],
544 err_words_ok=['Unknown', 'host2'])
545
546
mbligh6444c6b2008-10-27 20:55:13 +0000547 def test_execute_list_filter_statuses_and_hosts_none(self):
548 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
mbligh3df90c92009-03-09 21:09:29 +0000549 '--status', 'Repair',
mbligh6444c6b2008-10-27 20:55:13 +0000550 'host2', '--ignore_site_file'],
mbligh3df90c92009-03-09 21:09:29 +0000551 rpcs=[('get_hosts', {'status__in': ['Repair'],
mbligh6444c6b2008-10-27 20:55:13 +0000552 'hostname__in': ['host2', 'host1']},
553 True,
554 [])],
jadmanskic79a3982009-01-23 22:29:11 +0000555 out_words_ok=[],
mbligh6444c6b2008-10-27 20:55:13 +0000556 out_words_no=['Hostname', 'Status'],
557 err_words_ok=['Unknown', 'host2'])
558
559
mbligh91e0efd2009-02-26 01:02:16 +0000560 def test_execute_list_filter_locked(self):
561 self.run_cmd(argv=['atest', 'host', 'list', 'host1',
562 '--locked', 'host2', '--ignore_site_file'],
563 rpcs=[('get_hosts', {'locked': True,
564 'hostname__in': ['host2', 'host1']},
565 True,
566 [{u'status': u'Ready',
567 u'hostname': u'host1',
568 u'locked': True,
569 u'locked_by': 'user0',
Matthew Sartori68186332015-04-27 17:19:53 -0700570 u'lock_reason': u'',
mbligh91e0efd2009-02-26 01:02:16 +0000571 u'lock_time': u'2008-07-23 12:54:15',
572 u'labels': [u'label2', u'label3', u'plat1'],
573 u'invalid': False,
574 u'synch_id': None,
575 u'platform': u'plat1',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800576 u'shard': None,
mbligh91e0efd2009-02-26 01:02:16 +0000577 u'id': 2},
578 {u'status': u'Ready',
579 u'hostname': u'host2',
580 u'locked': True,
581 u'locked_by': 'user0',
Matthew Sartori68186332015-04-27 17:19:53 -0700582 u'lock_reason': u'',
mbligh91e0efd2009-02-26 01:02:16 +0000583 u'lock_time': u'2008-07-23 12:54:15',
584 u'labels': [u'label3', u'label4', 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': 3}])],
590 out_words_ok=['host1', 'Ready', 'plat1',
591 'label2', 'label3', 'True',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800592 'host2', 'label4', 'None'],
mbligh91e0efd2009-02-26 01:02:16 +0000593 out_words_no=['host0', 'label1', 'False'])
594
595
596 def test_execute_list_filter_unlocked(self):
597 self.run_cmd(argv=['atest', 'host', 'list',
598 '--unlocked', '--ignore_site_file'],
599 rpcs=[('get_hosts', {'locked': False},
600 True,
601 [{u'status': u'Ready',
602 u'hostname': u'host1',
603 u'locked': False,
604 u'locked_by': 'user0',
605 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700606 u'lock_reason': u'',
mbligh91e0efd2009-02-26 01:02:16 +0000607 u'labels': [u'label2', u'label3', u'plat1'],
608 u'invalid': False,
609 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800610 u'shard': None,
mbligh91e0efd2009-02-26 01:02:16 +0000611 u'platform': u'plat1',
612 u'id': 2},
613 {u'status': u'Ready',
614 u'hostname': u'host2',
615 u'locked': False,
616 u'locked_by': 'user0',
617 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700618 u'lock_reason': u'',
mbligh91e0efd2009-02-26 01:02:16 +0000619 u'labels': [u'label3', u'label4', u'plat1'],
620 u'invalid': False,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800621 u'shard': None,
mbligh91e0efd2009-02-26 01:02:16 +0000622 u'synch_id': None,
623 u'platform': u'plat1',
624 u'id': 3}])],
625 out_words_ok=['host1', 'Ready', 'plat1',
626 'label2', 'label3', 'False',
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800627 'host2', 'label4', 'None'],
mbligh91e0efd2009-02-26 01:02:16 +0000628 out_words_no=['host0', 'label1', 'True'])
629
630
mblighbe630eb2008-08-01 16:41:48 +0000631class host_stat_unittest(cli_mock.cli_unittest):
632 def test_execute_stat_two_hosts(self):
633 # The order of RPCs between host1 and host0 could change...
634 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
635 '--ignore_site_file'],
636 rpcs=[('get_hosts', {'hostname': 'host1'},
637 True,
638 [{u'status': u'Ready',
639 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000640 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000641 u'lock_time': u'2008-07-23 12:54:15',
642 u'locked_by': 'user0',
Matthew Sartori68186332015-04-27 17:19:53 -0700643 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000644 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000645 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000646 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000647 u'synch_id': None,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800648 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000649 u'platform': u'plat1',
Simran Basi0739d682015-02-25 16:22:56 -0800650 u'id': 3,
651 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000652 ('get_hosts', {'hostname': 'host0'},
653 True,
654 [{u'status': u'Ready',
655 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000656 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000657 u'locked_by': 'user0',
658 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700659 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000660 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000661 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000662 u'invalid': False,
Prashanth Balasubramaniana5048562014-12-12 10:14:11 -0800663 u'shard': None,
mblighbe630eb2008-08-01 16:41:48 +0000664 u'synch_id': None,
665 u'platform': u'plat0',
Simran Basi0739d682015-02-25 16:22:56 -0800666 u'id': 2,
667 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000668 ('get_acl_groups', {'hosts__hostname': 'host1'},
669 True,
670 [{u'description': u'',
671 u'hosts': [u'host0', u'host1'],
672 u'id': 1,
673 u'name': u'Everyone',
674 u'users': [u'user2', u'debug_user', u'user0']}]),
675 ('get_labels', {'host__hostname': 'host1'},
676 True,
677 [{u'id': 2,
678 u'platform': 1,
679 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000680 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000681 u'kernel_config': u''}]),
682 ('get_acl_groups', {'hosts__hostname': 'host0'},
683 True,
684 [{u'description': u'',
685 u'hosts': [u'host0', u'host1'],
686 u'id': 1,
687 u'name': u'Everyone',
688 u'users': [u'user0', u'debug_user']},
689 {u'description': u'myacl0',
690 u'hosts': [u'host0'],
691 u'id': 2,
692 u'name': u'acl0',
693 u'users': [u'user0']}]),
694 ('get_labels', {'host__hostname': 'host0'},
695 True,
696 [{u'id': 4,
697 u'platform': 0,
698 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000699 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000700 u'kernel_config': u''},
701 {u'id': 5,
702 u'platform': 1,
703 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000704 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000705 u'kernel_config': u''}])],
706 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
707 'Everyone', 'acl0', 'label0'])
708
709
710 def test_execute_stat_one_bad_host_verbose(self):
711 self.run_cmd(argv=['atest', 'host', 'stat', 'host0',
712 'host1', '-v', '--ignore_site_file'],
713 rpcs=[('get_hosts', {'hostname': 'host1'},
714 True,
715 []),
716 ('get_hosts', {'hostname': 'host0'},
717 True,
718 [{u'status': u'Ready',
719 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000720 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000721 u'locked_by': 'user0',
722 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700723 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000724 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000725 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000726 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000727 u'synch_id': None,
728 u'platform': u'plat0',
Simran Basi0739d682015-02-25 16:22:56 -0800729 u'id': 2,
730 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000731 ('get_acl_groups', {'hosts__hostname': 'host0'},
732 True,
733 [{u'description': u'',
734 u'hosts': [u'host0', u'host1'],
735 u'id': 1,
736 u'name': u'Everyone',
737 u'users': [u'user0', u'debug_user']},
738 {u'description': u'myacl0',
739 u'hosts': [u'host0'],
740 u'id': 2,
741 u'name': u'acl0',
742 u'users': [u'user0']}]),
743 ('get_labels', {'host__hostname': 'host0'},
744 True,
745 [{u'id': 4,
746 u'platform': 0,
747 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000748 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000749 u'kernel_config': u''},
750 {u'id': 5,
751 u'platform': 1,
752 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000753 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000754 u'kernel_config': u''}])],
755 out_words_ok=['host0', 'plat0',
756 'Everyone', 'acl0', 'label0'],
757 out_words_no=['host1'],
758 err_words_ok=['host1', 'Unknown host'],
759 err_words_no=['host0'])
760
761
762 def test_execute_stat_one_bad_host(self):
763 self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
764 '--ignore_site_file'],
765 rpcs=[('get_hosts', {'hostname': 'host1'},
766 True,
767 []),
768 ('get_hosts', {'hostname': 'host0'},
769 True,
770 [{u'status': u'Ready',
771 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000772 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000773 u'locked_by': 'user0',
774 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700775 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000776 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000777 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000778 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000779 u'synch_id': None,
780 u'platform': u'plat0',
Simran Basi0739d682015-02-25 16:22:56 -0800781 u'id': 2,
782 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000783 ('get_acl_groups', {'hosts__hostname': 'host0'},
784 True,
785 [{u'description': u'',
786 u'hosts': [u'host0', u'host1'],
787 u'id': 1,
788 u'name': u'Everyone',
789 u'users': [u'user0', u'debug_user']},
790 {u'description': u'myacl0',
791 u'hosts': [u'host0'],
792 u'id': 2,
793 u'name': u'acl0',
794 u'users': [u'user0']}]),
795 ('get_labels', {'host__hostname': 'host0'},
796 True,
797 [{u'id': 4,
798 u'platform': 0,
799 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000800 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000801 u'kernel_config': u''},
802 {u'id': 5,
803 u'platform': 1,
804 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000805 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000806 u'kernel_config': u''}])],
807 out_words_ok=['host0', 'plat0',
808 'Everyone', 'acl0', 'label0'],
809 out_words_no=['host1'],
810 err_words_ok=['host1', 'Unknown host'],
811 err_words_no=['host0'])
812
813
814 def test_execute_stat_wildcard(self):
815 # The order of RPCs between host1 and host0 could change...
816 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*',
817 '--ignore_site_file'],
818 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
819 True,
820 [{u'status': u'Ready',
821 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000822 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000823 u'lock_time': u'2008-07-23 12:54:15',
824 u'locked_by': 'user0',
Matthew Sartori68186332015-04-27 17:19:53 -0700825 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000826 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000827 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000828 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000829 u'synch_id': None,
830 u'platform': u'plat1',
Simran Basi0739d682015-02-25 16:22:56 -0800831 u'id': 3,
832 u'attributes': {}},
mblighbe630eb2008-08-01 16:41:48 +0000833 {u'status': u'Ready',
834 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000835 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000836 u'locked_by': 'user0',
837 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700838 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000839 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000840 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000841 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000842 u'synch_id': None,
843 u'platform': u'plat0',
Simran Basi0739d682015-02-25 16:22:56 -0800844 u'id': 2,
845 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000846 ('get_acl_groups', {'hosts__hostname': 'host1'},
847 True,
848 [{u'description': u'',
849 u'hosts': [u'host0', u'host1'],
850 u'id': 1,
851 u'name': u'Everyone',
852 u'users': [u'user2', u'debug_user', u'user0']}]),
853 ('get_labels', {'host__hostname': 'host1'},
854 True,
855 [{u'id': 2,
856 u'platform': 1,
857 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000858 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000859 u'kernel_config': u''}]),
860 ('get_acl_groups', {'hosts__hostname': 'host0'},
861 True,
862 [{u'description': u'',
863 u'hosts': [u'host0', u'host1'],
864 u'id': 1,
865 u'name': u'Everyone',
866 u'users': [u'user0', u'debug_user']},
867 {u'description': u'myacl0',
868 u'hosts': [u'host0'],
869 u'id': 2,
870 u'name': u'acl0',
871 u'users': [u'user0']}]),
872 ('get_labels', {'host__hostname': 'host0'},
873 True,
874 [{u'id': 4,
875 u'platform': 0,
876 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000877 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000878 u'kernel_config': u''},
879 {u'id': 5,
880 u'platform': 1,
881 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000882 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000883 u'kernel_config': u''}])],
884 out_words_ok=['host0', 'host1', 'plat0', 'plat1',
885 'Everyone', 'acl0', 'label0'])
886
887
888 def test_execute_stat_wildcard_and_host(self):
889 # The order of RPCs between host1 and host0 could change...
890 self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', 'newhost0',
891 '--ignore_site_file'],
892 rpcs=[('get_hosts', {'hostname': 'newhost0'},
893 True,
894 [{u'status': u'Ready',
895 u'hostname': u'newhost0',
mbligh0887d402009-01-30 00:50:29 +0000896 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000897 u'locked_by': 'user0',
898 u'lock_time': u'2008-07-23 12:54:15',
Matthew Sartori68186332015-04-27 17:19:53 -0700899 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000900 u'protection': u'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000901 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000902 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000903 u'synch_id': None,
904 u'platform': u'plat0',
Simran Basi0739d682015-02-25 16:22:56 -0800905 u'id': 5,
906 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000907 ('get_hosts', {'hostname__startswith': 'ho'},
908 True,
909 [{u'status': u'Ready',
910 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +0000911 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +0000912 u'lock_time': u'2008-07-23 12:54:15',
913 u'locked_by': 'user0',
Matthew Sartori68186332015-04-27 17:19:53 -0700914 u'lock_reason': u'',
mblighe163b032008-10-18 14:30:27 +0000915 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000916 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +0000917 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000918 u'synch_id': None,
919 u'platform': u'plat1',
Simran Basi0739d682015-02-25 16:22:56 -0800920 u'id': 3,
921 u'attributes': {}},
mblighbe630eb2008-08-01 16:41:48 +0000922 {u'status': u'Ready',
923 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000924 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000925 u'locked_by': 'user0',
Matthew Sartori68186332015-04-27 17:19:53 -0700926 u'lock_reason': u'',
mbligh536a5242008-10-18 14:35:54 +0000927 u'protection': 'No protection',
mblighbe630eb2008-08-01 16:41:48 +0000928 u'lock_time': u'2008-07-23 12:54:15',
929 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +0000930 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000931 u'synch_id': None,
932 u'platform': u'plat0',
Simran Basi0739d682015-02-25 16:22:56 -0800933 u'id': 2,
934 u'attributes': {}}]),
mblighbe630eb2008-08-01 16:41:48 +0000935 ('get_acl_groups', {'hosts__hostname': 'newhost0'},
936 True,
937 [{u'description': u'',
938 u'hosts': [u'newhost0', 'host1'],
939 u'id': 42,
940 u'name': u'my_acl',
941 u'users': [u'user0', u'debug_user']},
942 {u'description': u'my favorite acl',
943 u'hosts': [u'newhost0'],
944 u'id': 2,
945 u'name': u'acl10',
946 u'users': [u'user0']}]),
947 ('get_labels', {'host__hostname': 'newhost0'},
948 True,
949 [{u'id': 4,
950 u'platform': 0,
951 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000952 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000953 u'kernel_config': u''},
954 {u'id': 5,
955 u'platform': 1,
956 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000957 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000958 u'kernel_config': u''}]),
959 ('get_acl_groups', {'hosts__hostname': 'host1'},
960 True,
961 [{u'description': u'',
962 u'hosts': [u'host0', u'host1'],
963 u'id': 1,
964 u'name': u'Everyone',
965 u'users': [u'user2', u'debug_user', u'user0']}]),
966 ('get_labels', {'host__hostname': 'host1'},
967 True,
968 [{u'id': 2,
969 u'platform': 1,
970 u'name': u'jme',
mbligh0887d402009-01-30 00:50:29 +0000971 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000972 u'kernel_config': u''}]),
973 ('get_acl_groups', {'hosts__hostname': 'host0'},
974 True,
975 [{u'description': u'',
976 u'hosts': [u'host0', u'host1'],
977 u'id': 1,
978 u'name': u'Everyone',
979 u'users': [u'user0', u'debug_user']},
980 {u'description': u'myacl0',
981 u'hosts': [u'host0'],
982 u'id': 2,
983 u'name': u'acl0',
984 u'users': [u'user0']}]),
985 ('get_labels', {'host__hostname': 'host0'},
986 True,
987 [{u'id': 4,
988 u'platform': 0,
989 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +0000990 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000991 u'kernel_config': u''},
992 {u'id': 5,
993 u'platform': 1,
994 u'name': u'plat0',
mbligh0887d402009-01-30 00:50:29 +0000995 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000996 u'kernel_config': u''}])],
997 out_words_ok=['host0', 'host1', 'newhost0',
998 'plat0', 'plat1',
mblighe163b032008-10-18 14:30:27 +0000999 'Everyone', 'acl10', 'label0'])
mblighbe630eb2008-08-01 16:41:48 +00001000
1001
1002class host_jobs_unittest(cli_mock.cli_unittest):
1003 def test_execute_jobs_one_host(self):
1004 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
1005 '--ignore_site_file'],
1006 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001007 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001008 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001009 True,
1010 [{u'status': u'Failed',
1011 u'complete': 1,
1012 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001013 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001014 u'locked_by': 'user0',
1015 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001016 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001017 u'id': 3232,
1018 u'synch_id': None},
1019 u'priority': 0,
1020 u'meta_host': u'meta0',
1021 u'job': {u'control_file':
1022 (u"def step_init():\n"
1023 "\tjob.next_step([step_test])\n"
1024 "\ttestkernel = job.kernel("
1025 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1026 "\ttestkernel.install()\n"
1027 "\ttestkernel.boot()\n\n"
1028 "def step_test():\n"
1029 "\tjob.run_test('kernbench')\n\n"),
1030 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001031 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001032 u'synchronizing': None,
1033 u'priority': u'Low',
1034 u'owner': u'user0',
1035 u'created_on': u'2008-01-09 10:45:12',
1036 u'synch_count': None,
1037 u'synch_type': u'Asynchronous',
1038 u'id': 216},
1039 u'active': 0,
1040 u'id': 2981},
1041 {u'status': u'Aborted',
1042 u'complete': 1,
1043 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001044 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001045 u'locked_by': 'user0',
1046 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001047 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001048 u'id': 3232,
1049 u'synch_id': None},
1050 u'priority': 0,
1051 u'meta_host': None,
1052 u'job': {u'control_file':
1053 u"job.run_test('sleeptest')\n\n",
1054 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001055 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001056 u'synchronizing': 0,
1057 u'priority': u'Low',
1058 u'owner': u'user1',
1059 u'created_on': u'2008-01-17 15:04:53',
1060 u'synch_count': None,
1061 u'synch_type': u'Asynchronous',
1062 u'id': 289},
1063 u'active': 0,
1064 u'id': 3167}])],
1065 out_words_ok=['216', 'user0', 'Failed',
1066 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1067 '289', 'user1', 'Aborted',
1068 'testjob'])
1069
1070
1071 def test_execute_jobs_wildcard(self):
1072 self.run_cmd(argv=['atest', 'host', 'jobs', 'ho*',
1073 '--ignore_site_file'],
1074 rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
1075 True,
1076 [{u'status': u'Ready',
1077 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001078 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001079 u'lock_time': u'2008-07-23 12:54:15',
1080 u'locked_by': 'user0',
1081 u'labels': [u'label3', u'label4', u'plat1'],
mbligh0887d402009-01-30 00:50:29 +00001082 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001083 u'synch_id': None,
1084 u'platform': u'plat1',
1085 u'id': 3},
1086 {u'status': u'Ready',
1087 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001088 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +00001089 u'locked_by': 'user0',
1090 u'lock_time': u'2008-07-23 12:54:15',
1091 u'labels': [u'label0', u'plat0'],
mbligh0887d402009-01-30 00:50:29 +00001092 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001093 u'synch_id': None,
1094 u'platform': u'plat0',
1095 u'id': 2}]),
1096 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001097 {'host__hostname': 'host1', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001098 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001099 True,
1100 [{u'status': u'Failed',
1101 u'complete': 1,
1102 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001103 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001104 u'locked_by': 'user0',
1105 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001106 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001107 u'id': 3232,
1108 u'synch_id': None},
1109 u'priority': 0,
1110 u'meta_host': u'meta0',
1111 u'job': {u'control_file':
1112 (u"def step_init():\n"
1113 "\tjob.next_step([step_test])\n"
1114 "\ttestkernel = job.kernel("
1115 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1116 "\ttestkernel.install()\n"
1117 "\ttestkernel.boot()\n\n"
1118 "def step_test():\n"
1119 "\tjob.run_test('kernbench')\n\n"),
1120 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001121 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001122 u'synchronizing': None,
1123 u'priority': u'Low',
1124 u'owner': u'user0',
1125 u'created_on': u'2008-01-09 10:45:12',
1126 u'synch_count': None,
1127 u'synch_type': u'Asynchronous',
1128 u'id': 216},
1129 u'active': 0,
1130 u'id': 2981},
1131 {u'status': u'Aborted',
1132 u'complete': 1,
1133 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001134 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001135 u'locked_by': 'user0',
1136 u'hostname': u'host1',
mbligh0887d402009-01-30 00:50:29 +00001137 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001138 u'id': 3232,
1139 u'synch_id': None},
1140 u'priority': 0,
1141 u'meta_host': None,
1142 u'job': {u'control_file':
1143 u"job.run_test('sleeptest')\n\n",
1144 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001145 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001146 u'synchronizing': 0,
1147 u'priority': u'Low',
1148 u'owner': u'user1',
1149 u'created_on': u'2008-01-17 15:04:53',
1150 u'synch_count': None,
1151 u'synch_type': u'Asynchronous',
1152 u'id': 289},
1153 u'active': 0,
1154 u'id': 3167}]),
1155 ('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001156 {'host__hostname': 'host0', 'query_limit': 20,
showard6958c722009-09-23 20:03:16 +00001157 'sort_by': ['-job__id']},
mblighbe630eb2008-08-01 16:41:48 +00001158 True,
1159 [{u'status': u'Failed',
1160 u'complete': 1,
1161 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001162 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001163 u'locked_by': 'user0',
1164 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001165 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001166 u'id': 3232,
1167 u'synch_id': None},
1168 u'priority': 0,
1169 u'meta_host': u'meta0',
1170 u'job': {u'control_file':
1171 (u"def step_init():\n"
1172 "\tjob.next_step([step_test])\n"
1173 "\ttestkernel = job.kernel("
1174 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1175 "\ttestkernel.install()\n"
1176 "\ttestkernel.boot()\n\n"
1177 "def step_test():\n"
1178 "\tjob.run_test('kernbench')\n\n"),
1179 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001180 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001181 u'synchronizing': None,
1182 u'priority': u'Low',
1183 u'owner': u'user0',
1184 u'created_on': u'2008-01-09 10:45:12',
1185 u'synch_count': None,
1186 u'synch_type': u'Asynchronous',
1187 u'id': 216},
1188 u'active': 0,
1189 u'id': 2981},
1190 {u'status': u'Aborted',
1191 u'complete': 1,
1192 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001193 u'locked': True,
mblighbe630eb2008-08-01 16:41:48 +00001194 u'locked_by': 'user0',
1195 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001196 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001197 u'id': 3232,
1198 u'synch_id': None},
1199 u'priority': 0,
1200 u'meta_host': None,
1201 u'job': {u'control_file':
1202 u"job.run_test('sleeptest')\n\n",
1203 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001204 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +00001205 u'synchronizing': 0,
1206 u'priority': u'Low',
1207 u'owner': u'user1',
1208 u'created_on': u'2008-01-17 15:04:53',
1209 u'synch_count': None,
1210 u'synch_type': u'Asynchronous',
1211 u'id': 289},
1212 u'active': 0,
1213 u'id': 3167}])],
1214 out_words_ok=['216', 'user0', 'Failed',
1215 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1216 '289', 'user1', 'Aborted',
1217 'testjob'])
1218
mbligh6996fe82008-08-13 00:32:27 +00001219
1220 def test_execute_jobs_one_host_limit(self):
1221 self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
1222 '--ignore_site_file', '-q', '10'],
1223 rpcs=[('get_host_queue_entries',
mbligh1494eca2008-08-13 21:24:22 +00001224 {'host__hostname': 'host0', 'query_limit': 10,
showard6958c722009-09-23 20:03:16 +00001225 'sort_by': ['-job__id']},
mbligh6996fe82008-08-13 00:32:27 +00001226 True,
1227 [{u'status': u'Failed',
1228 u'complete': 1,
1229 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001230 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001231 u'locked_by': 'user0',
1232 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001233 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001234 u'id': 3232,
1235 u'synch_id': None},
1236 u'priority': 0,
1237 u'meta_host': u'meta0',
1238 u'job': {u'control_file':
1239 (u"def step_init():\n"
1240 "\tjob.next_step([step_test])\n"
1241 "\ttestkernel = job.kernel("
1242 "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
1243 "\ttestkernel.install()\n"
1244 "\ttestkernel.boot()\n\n"
1245 "def step_test():\n"
1246 "\tjob.run_test('kernbench')\n\n"),
1247 u'name': u'kernel-smp-2.6.xyz.x86_64',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001248 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001249 u'synchronizing': None,
1250 u'priority': u'Low',
1251 u'owner': u'user0',
1252 u'created_on': u'2008-01-09 10:45:12',
1253 u'synch_count': None,
1254 u'synch_type': u'Asynchronous',
1255 u'id': 216},
1256 u'active': 0,
1257 u'id': 2981},
1258 {u'status': u'Aborted',
1259 u'complete': 1,
1260 u'host': {u'status': u'Ready',
mbligh0887d402009-01-30 00:50:29 +00001261 u'locked': True,
mbligh6996fe82008-08-13 00:32:27 +00001262 u'locked_by': 'user0',
1263 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +00001264 u'invalid': False,
mbligh6996fe82008-08-13 00:32:27 +00001265 u'id': 3232,
1266 u'synch_id': None},
1267 u'priority': 0,
1268 u'meta_host': None,
1269 u'job': {u'control_file':
1270 u"job.run_test('sleeptest')\n\n",
1271 u'name': u'testjob',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001272 u'control_type': CLIENT,
mbligh6996fe82008-08-13 00:32:27 +00001273 u'synchronizing': 0,
1274 u'priority': u'Low',
1275 u'owner': u'user1',
1276 u'created_on': u'2008-01-17 15:04:53',
1277 u'synch_count': None,
1278 u'synch_type': u'Asynchronous',
1279 u'id': 289},
1280 u'active': 0,
1281 u'id': 3167}])],
1282 out_words_ok=['216', 'user0', 'Failed',
1283 'kernel-smp-2.6.xyz.x86_64', 'Aborted',
1284 '289', 'user1', 'Aborted',
1285 'testjob'])
1286
1287
mblighbe630eb2008-08-01 16:41:48 +00001288class host_mod_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +00001289 def test_execute_lock_one_host(self):
1290 self.run_cmd(argv=['atest', 'host', 'mod',
1291 '--lock', 'host0', '--ignore_site_file'],
1292 rpcs=[('modify_host', {'id': 'host0', 'locked': True},
1293 True, None)],
1294 out_words_ok=['Locked', 'host0'])
1295
1296
1297 def test_execute_unlock_two_hosts(self):
1298 self.run_cmd(argv=['atest', 'host', 'mod',
1299 '-u', 'host0,host1', '--ignore_site_file'],
Matthew Sartori68186332015-04-27 17:19:53 -07001300 rpcs=[('modify_host', {'id': 'host1', 'locked': False,
1301 'lock_reason': ''},
mblighbe630eb2008-08-01 16:41:48 +00001302 True, None),
Matthew Sartori68186332015-04-27 17:19:53 -07001303 ('modify_host', {'id': 'host0', 'locked': False,
1304 'lock_reason': ''},
mblighbe630eb2008-08-01 16:41:48 +00001305 True, None)],
1306 out_words_ok=['Unlocked', 'host0', 'host1'])
1307
1308
Shuqian Zhao4c0d2902016-01-12 17:03:15 -08001309 def test_execute_force_lock_one_host(self):
1310 self.run_cmd(argv=['atest', 'host', 'mod',
1311 '--lock', '--force_modify_locking', 'host0',
1312 '--ignore_site_file'],
1313 rpcs=[('modify_host',
1314 {'id': 'host0', 'locked': True,
1315 'force_modify_locking': True},
1316 True, None)],
1317 out_words_ok=['Locked', 'host0'])
1318
1319
1320 def test_execute_force_unlock_one_host(self):
1321 self.run_cmd(argv=['atest', 'host', 'mod',
1322 '--unlock', '--force_modify_locking', 'host0',
1323 '--ignore_site_file'],
1324 rpcs=[('modify_host',
1325 {'id': 'host0', 'locked': False,
1326 'force_modify_locking': True,
1327 'lock_reason': ''},
1328 True, None)],
1329 out_words_ok=['Unlocked', 'host0'])
1330
1331
mbligh6eca4602009-01-07 16:48:50 +00001332 def test_execute_lock_unknown_hosts(self):
1333 self.run_cmd(argv=['atest', 'host', 'mod',
1334 '-l', 'host0,host1', 'host2', '--ignore_site_file'],
1335 rpcs=[('modify_host', {'id': 'host2', 'locked': True},
1336 True, None),
1337 ('modify_host', {'id': 'host1', 'locked': True},
1338 False, 'DoesNotExist: Host matching '
1339 'query does not exist.'),
1340 ('modify_host', {'id': 'host0', 'locked': True},
1341 True, None)],
1342 out_words_ok=['Locked', 'host0', 'host2'],
1343 err_words_ok=['Host', 'matching', 'query', 'host1'])
1344
1345
showardbe0d8692009-08-20 23:42:44 +00001346 def test_execute_protection_hosts(self):
mblighbe630eb2008-08-01 16:41:48 +00001347 mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4')
showardbe0d8692009-08-20 23:42:44 +00001348 self.run_cmd(argv=['atest', 'host', 'mod', '--protection',
1349 'Do not repair',
mbligh41515392009-07-11 00:13:11 +00001350 'host5' ,'--mlist', mfile.name, 'host1', 'host6',
mblighbe630eb2008-08-01 16:41:48 +00001351 '--ignore_site_file'],
showardbe0d8692009-08-20 23:42:44 +00001352 rpcs=[('modify_host', {'id': 'host6',
1353 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001354 True, None),
showardbe0d8692009-08-20 23:42:44 +00001355 ('modify_host', {'id': 'host5',
1356 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001357 True, None),
showardbe0d8692009-08-20 23:42:44 +00001358 ('modify_host', {'id': 'host4',
1359 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001360 True, None),
showardbe0d8692009-08-20 23:42:44 +00001361 ('modify_host', {'id': 'host3',
1362 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001363 True, None),
showardbe0d8692009-08-20 23:42:44 +00001364 ('modify_host', {'id': 'host2',
1365 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001366 True, None),
showardbe0d8692009-08-20 23:42:44 +00001367 ('modify_host', {'id': 'host1',
1368 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001369 True, None),
showardbe0d8692009-08-20 23:42:44 +00001370 ('modify_host', {'id': 'host0',
1371 'protection': 'Do not repair'},
mblighbe630eb2008-08-01 16:41:48 +00001372 True, None)],
showardbe0d8692009-08-20 23:42:44 +00001373 out_words_ok=['Do not repair', 'host0', 'host1', 'host2',
mblighbe630eb2008-08-01 16:41:48 +00001374 'host3', 'host4', 'host5', 'host6'])
mbligh41515392009-07-11 00:13:11 +00001375 mfile.clean()
mblighbe630eb2008-08-01 16:41:48 +00001376
1377
1378
1379class host_create_unittest(cli_mock.cli_unittest):
1380 def test_execute_create_muliple_hosts_all_options(self):
1381 self.run_cmd(argv=['atest', 'host', 'create', '--lock',
1382 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1383 '--ignore_site_file'],
1384 rpcs=[('get_labels', {'name': 'label0'},
1385 True,
1386 [{u'id': 4,
1387 u'platform': 0,
1388 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001389 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +00001390 u'kernel_config': u''}]),
1391 ('get_acl_groups', {'name': 'acl0'},
1392 True, []),
1393 ('add_acl_group', {'name': 'acl0'},
1394 True, 5),
1395 ('add_host', {'hostname': 'host1',
1396 'status': 'Ready',
1397 'locked': True},
1398 True, 42),
1399 ('host_add_labels', {'id': 'host1',
1400 'labels': ['label0']},
1401 True, None),
1402 ('add_host', {'hostname': 'host0',
1403 'status': 'Ready',
1404 'locked': True},
1405 True, 42),
1406 ('host_add_labels', {'id': 'host0',
1407 'labels': ['label0']},
1408 True, None),
1409 ('acl_group_add_hosts',
1410 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1411 True, None)],
1412 out_words_ok=['host0', 'host1'])
1413
1414
mbligh719e14a2008-12-04 01:17:08 +00001415 def test_execute_create_muliple_hosts_unlocked(self):
1416 self.run_cmd(argv=['atest', 'host', 'create',
1417 '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
1418 '--ignore_site_file'],
1419 rpcs=[('get_labels', {'name': 'label0'},
1420 True,
1421 [{u'id': 4,
1422 u'platform': 0,
1423 u'name': u'label0',
mbligh0887d402009-01-30 00:50:29 +00001424 u'invalid': False,
mbligh719e14a2008-12-04 01:17:08 +00001425 u'kernel_config': u''}]),
1426 ('get_acl_groups', {'name': 'acl0'},
1427 True, []),
1428 ('add_acl_group', {'name': 'acl0'},
1429 True, 5),
1430 ('add_host', {'hostname': 'host1',
1431 'status': 'Ready',
Matthew Sartori68186332015-04-27 17:19:53 -07001432 'locked': True,
1433 'lock_reason': 'Forced lock on device creation'},
mbligh719e14a2008-12-04 01:17:08 +00001434 True, 42),
1435 ('host_add_labels', {'id': 'host1',
1436 'labels': ['label0']},
1437 True, None),
1438 ('add_host', {'hostname': 'host0',
1439 'status': 'Ready',
Matthew Sartori68186332015-04-27 17:19:53 -07001440 'locked': True,
1441 'lock_reason': 'Forced lock on device creation'},
mbligh719e14a2008-12-04 01:17:08 +00001442 True, 42),
1443 ('host_add_labels', {'id': 'host0',
1444 'labels': ['label0']},
1445 True, None),
1446 ('acl_group_add_hosts',
1447 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1448 True, None),
Matthew Sartori68186332015-04-27 17:19:53 -07001449 ('modify_host', {'id': 'host1', 'locked': False,
1450 'lock_reason': ''},
mbligh719e14a2008-12-04 01:17:08 +00001451 True, None),
Matthew Sartori68186332015-04-27 17:19:53 -07001452 ('modify_host', {'id': 'host0', 'locked': False,
1453 'lock_reason': ''},
mbligh719e14a2008-12-04 01:17:08 +00001454 True, None)],
1455 out_words_ok=['host0', 'host1'])
1456
1457
jamesrenc2863162010-07-12 21:20:51 +00001458 def test_execute_create_muliple_hosts_label_escaped_quotes(self):
1459 self.run_cmd(argv=['atest', 'host', 'create',
1460 '-b', 'label0,label\\,1,label\\,2',
1461 '--acls', 'acl0', 'host0', 'host1',
1462 '--ignore_site_file'],
1463 rpcs=[('get_labels', {'name': 'label0'},
1464 True,
1465 [{u'id': 4,
1466 u'platform': 0,
1467 u'name': u'label0',
1468 u'invalid': False,
1469 u'kernel_config': u''}]),
1470 ('get_labels', {'name': 'label,1'},
1471 True,
1472 [{u'id': 4,
1473 u'platform': 0,
1474 u'name': u'label,1',
1475 u'invalid': False,
1476 u'kernel_config': u''}]),
1477 ('get_labels', {'name': 'label,2'},
1478 True,
1479 [{u'id': 4,
1480 u'platform': 0,
1481 u'name': u'label,2',
1482 u'invalid': False,
1483 u'kernel_config': u''}]),
1484 ('get_acl_groups', {'name': 'acl0'},
1485 True, []),
1486 ('add_acl_group', {'name': 'acl0'},
1487 True, 5),
1488 ('add_host', {'hostname': 'host1',
1489 'status': 'Ready',
Matthew Sartori68186332015-04-27 17:19:53 -07001490 'locked': True,
1491 'lock_reason': 'Forced lock on device creation'},
jamesrenc2863162010-07-12 21:20:51 +00001492 True, 42),
1493 ('host_add_labels', {'id': 'host1',
1494 'labels': ['label0', 'label,1',
1495 'label,2']},
1496 True, None),
1497 ('add_host', {'hostname': 'host0',
1498 'status': 'Ready',
Matthew Sartori68186332015-04-27 17:19:53 -07001499 'locked': True,
1500 'lock_reason': 'Forced lock on device creation'},
jamesrenc2863162010-07-12 21:20:51 +00001501 True, 42),
1502 ('host_add_labels', {'id': 'host0',
1503 'labels': ['label0', 'label,1',
1504 'label,2']},
1505 True, None),
1506 ('acl_group_add_hosts',
1507 {'id': 'acl0', 'hosts': ['host1', 'host0']},
1508 True, None),
Matthew Sartori68186332015-04-27 17:19:53 -07001509 ('modify_host', {'id': 'host1', 'locked': False,
1510 'lock_reason': ''},
jamesrenc2863162010-07-12 21:20:51 +00001511 True, None),
Matthew Sartori68186332015-04-27 17:19:53 -07001512 ('modify_host', {'id': 'host0', 'locked': False,
1513 'lock_reason': ''},
jamesrenc2863162010-07-12 21:20:51 +00001514 True, None)],
1515 out_words_ok=['host0', 'host1'])
1516
1517
mblighbe630eb2008-08-01 16:41:48 +00001518if __name__ == '__main__':
1519 unittest.main()