mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2008 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Test for host.""" |
| 6 | |
| 7 | import unittest, os, sys |
| 8 | |
| 9 | import common |
| 10 | from autotest_lib.cli import cli_mock, host |
| 11 | |
| 12 | |
| 13 | class host_ut(cli_mock.cli_unittest): |
| 14 | def test_parse_lock_options_both_set(self): |
| 15 | hh = host.host() |
| 16 | class opt(object): |
| 17 | lock = True |
| 18 | unlock = True |
| 19 | options = opt() |
| 20 | self.usage = "unused" |
| 21 | sys.exit.expect_call(1).and_raises(cli_mock.ExitException) |
| 22 | self.god.mock_io() |
| 23 | self.assertRaises(cli_mock.ExitException, |
| 24 | hh._parse_lock_options, options) |
| 25 | self.god.unmock_io() |
| 26 | |
| 27 | |
| 28 | def test_cleanup_labels_with_platform(self): |
| 29 | labels = ['l0', 'l1', 'l2', 'p0', 'l3'] |
| 30 | hh = host.host() |
| 31 | self.assertEqual(['l0', 'l1', 'l2', 'l3'], |
| 32 | hh._cleanup_labels(labels, 'p0')) |
| 33 | |
| 34 | |
| 35 | def test_cleanup_labels_no_platform(self): |
| 36 | labels = ['l0', 'l1', 'l2', 'l3'] |
| 37 | hh = host.host() |
| 38 | self.assertEqual(['l0', 'l1', 'l2', 'l3'], |
| 39 | hh._cleanup_labels(labels)) |
| 40 | |
| 41 | |
| 42 | def test_cleanup_labels_with_non_avail_platform(self): |
| 43 | labels = ['l0', 'l1', 'l2', 'l3'] |
| 44 | hh = host.host() |
| 45 | self.assertEqual(['l0', 'l1', 'l2', 'l3'], |
| 46 | hh._cleanup_labels(labels, 'p0')) |
| 47 | |
| 48 | |
| 49 | class host_list_unittest(cli_mock.cli_unittest): |
| 50 | def test_parse_host_not_required(self): |
| 51 | hl = host.host_list() |
| 52 | sys.argv = ['atest'] |
| 53 | (options, leftover) = hl.parse() |
| 54 | self.assertEqual([], hl.hosts) |
| 55 | self.assertEqual([], leftover) |
| 56 | |
| 57 | |
| 58 | def test_parse_with_hosts(self): |
| 59 | hl = host.host_list() |
| 60 | mfile = cli_mock.create_file('host0\nhost3\nhost4\n') |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 61 | sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3'] |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 62 | (options, leftover) = hl.parse() |
| 63 | self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'], |
| 64 | hl.hosts) |
| 65 | self.assertEqual(leftover, []) |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 66 | mfile.clean() |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 67 | |
| 68 | |
| 69 | def test_parse_with_labels(self): |
| 70 | hl = host.host_list() |
| 71 | sys.argv = ['atest', '--label', 'label0'] |
| 72 | (options, leftover) = hl.parse() |
jamesren | c286316 | 2010-07-12 21:20:51 +0000 | [diff] [blame] | 73 | self.assertEqual(['label0'], hl.labels) |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 74 | self.assertEqual(leftover, []) |
| 75 | |
| 76 | |
| 77 | def test_parse_with_multi_labels(self): |
| 78 | hl = host.host_list() |
| 79 | sys.argv = ['atest', '--label', 'label0,label2'] |
| 80 | (options, leftover) = hl.parse() |
jamesren | c286316 | 2010-07-12 21:20:51 +0000 | [diff] [blame] | 81 | self.assertEqualNoOrder(['label0', 'label2'], hl.labels) |
| 82 | self.assertEqual(leftover, []) |
| 83 | |
| 84 | |
| 85 | def test_parse_with_escaped_commas_label(self): |
| 86 | hl = host.host_list() |
| 87 | sys.argv = ['atest', '--label', 'label\\,0'] |
| 88 | (options, leftover) = hl.parse() |
| 89 | self.assertEqual(['label,0'], hl.labels) |
| 90 | self.assertEqual(leftover, []) |
| 91 | |
| 92 | |
| 93 | def test_parse_with_escaped_commas_multi_labels(self): |
| 94 | hl = host.host_list() |
| 95 | sys.argv = ['atest', '--label', 'label\\,0,label\\,2'] |
| 96 | (options, leftover) = hl.parse() |
| 97 | self.assertEqualNoOrder(['label,0', 'label,2'], hl.labels) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 98 | self.assertEqual(leftover, []) |
| 99 | |
| 100 | |
| 101 | def test_parse_with_both(self): |
| 102 | hl = host.host_list() |
| 103 | mfile = cli_mock.create_file('host0\nhost3\nhost4\n') |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 104 | sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 105 | '--label', 'label0'] |
| 106 | (options, leftover) = hl.parse() |
| 107 | self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'], |
| 108 | hl.hosts) |
jamesren | c286316 | 2010-07-12 21:20:51 +0000 | [diff] [blame] | 109 | self.assertEqual(['label0'], hl.labels) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 110 | self.assertEqual(leftover, []) |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 111 | mfile.clean() |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 112 | |
| 113 | |
| 114 | def test_execute_list_all_no_labels(self): |
| 115 | self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'], |
| 116 | rpcs=[('get_hosts', {}, |
| 117 | True, |
| 118 | [{u'status': u'Ready', |
| 119 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 120 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 121 | u'locked_by': 'user0', |
| 122 | u'lock_time': u'2008-07-23 12:54:15', |
| 123 | u'labels': [], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 124 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 125 | u'synch_id': None, |
| 126 | u'platform': None, |
| 127 | u'id': 1}, |
| 128 | {u'status': u'Ready', |
| 129 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 130 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 131 | u'locked_by': 'user0', |
| 132 | u'lock_time': u'2008-07-23 12:54:15', |
| 133 | u'labels': [u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 134 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 135 | u'synch_id': None, |
| 136 | u'platform': u'plat1', |
| 137 | u'id': 2}])], |
| 138 | out_words_ok=['host0', 'host1', 'Ready', |
| 139 | 'plat1', 'False', 'True']) |
| 140 | |
| 141 | |
| 142 | def test_execute_list_all_with_labels(self): |
| 143 | self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'], |
| 144 | rpcs=[('get_hosts', {}, |
| 145 | True, |
| 146 | [{u'status': u'Ready', |
| 147 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 148 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 149 | u'locked_by': 'user0', |
| 150 | u'lock_time': u'2008-07-23 12:54:15', |
| 151 | u'labels': [u'label0', u'label1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 152 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 153 | u'synch_id': None, |
| 154 | u'platform': None, |
| 155 | u'id': 1}, |
| 156 | {u'status': u'Ready', |
| 157 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 158 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 159 | u'locked_by': 'user0', |
| 160 | u'lock_time': u'2008-07-23 12:54:15', |
| 161 | u'labels': [u'label2', u'label3', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 162 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 163 | u'synch_id': None, |
| 164 | u'platform': u'plat1', |
| 165 | u'id': 2}])], |
| 166 | out_words_ok=['host0', 'host1', 'Ready', 'plat1', |
| 167 | 'label0', 'label1', 'label2', 'label3', |
| 168 | 'False', 'True']) |
| 169 | |
| 170 | |
| 171 | def test_execute_list_filter_one_host(self): |
| 172 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
| 173 | '--ignore_site_file'], |
| 174 | rpcs=[('get_hosts', {'hostname__in': ['host1']}, |
| 175 | True, |
| 176 | [{u'status': u'Ready', |
| 177 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 178 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 179 | u'locked_by': 'user0', |
| 180 | u'lock_time': u'2008-07-23 12:54:15', |
| 181 | u'labels': [u'label2', u'label3', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 182 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 183 | u'synch_id': None, |
| 184 | u'platform': u'plat1', |
| 185 | u'id': 2}])], |
| 186 | out_words_ok=['host1', 'Ready', 'plat1', |
| 187 | 'label2', 'label3', 'True'], |
| 188 | out_words_no=['host0', 'host2', |
| 189 | 'label1', 'label4', 'False']) |
| 190 | |
| 191 | |
| 192 | def test_execute_list_filter_two_hosts(self): |
| 193 | mfile = cli_mock.create_file('host2') |
| 194 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 195 | '--mlist', mfile.name, '--ignore_site_file'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 196 | # This is a bit fragile as the list order may change... |
| 197 | rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']}, |
| 198 | True, |
| 199 | [{u'status': u'Ready', |
| 200 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 201 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 202 | u'locked_by': 'user0', |
| 203 | u'lock_time': u'2008-07-23 12:54:15', |
| 204 | u'labels': [u'label2', u'label3', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 205 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 206 | u'synch_id': None, |
| 207 | u'platform': u'plat1', |
| 208 | u'id': 2}, |
| 209 | {u'status': u'Ready', |
| 210 | u'hostname': u'host2', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 211 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 212 | u'locked_by': 'user0', |
| 213 | u'lock_time': u'2008-07-23 12:54:15', |
| 214 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 215 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 216 | u'synch_id': None, |
| 217 | u'platform': u'plat1', |
| 218 | u'id': 3}])], |
| 219 | out_words_ok=['host1', 'Ready', 'plat1', |
| 220 | 'label2', 'label3', 'True', |
| 221 | 'host2', 'label4'], |
| 222 | out_words_no=['host0', 'label1', 'False']) |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 223 | mfile.clean() |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 224 | |
| 225 | |
| 226 | def test_execute_list_filter_two_hosts_one_not_found(self): |
| 227 | mfile = cli_mock.create_file('host2') |
| 228 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 229 | '--mlist', mfile.name, '--ignore_site_file'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 230 | # This is a bit fragile as the list order may change... |
| 231 | rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']}, |
| 232 | True, |
| 233 | [{u'status': u'Ready', |
| 234 | u'hostname': u'host2', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 235 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 236 | u'locked_by': 'user0', |
| 237 | u'lock_time': u'2008-07-23 12:54:15', |
| 238 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 239 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 240 | u'synch_id': None, |
| 241 | u'platform': u'plat1', |
| 242 | u'id': 3}])], |
| 243 | out_words_ok=['Ready', 'plat1', |
| 244 | 'label3', 'label4', 'True'], |
| 245 | out_words_no=['host1', 'False'], |
| 246 | err_words_ok=['host1']) |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 247 | mfile.clean() |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 248 | |
| 249 | |
| 250 | def test_execute_list_filter_two_hosts_none_found(self): |
| 251 | self.run_cmd(argv=['atest', 'host', 'list', |
| 252 | 'host1', 'host2', '--ignore_site_file'], |
| 253 | # This is a bit fragile as the list order may change... |
| 254 | rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']}, |
| 255 | True, |
| 256 | [])], |
jadmanski | c79a398 | 2009-01-23 22:29:11 +0000 | [diff] [blame] | 257 | out_words_ok=[], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 258 | out_words_no=['Hostname', 'Status'], |
| 259 | err_words_ok=['Unknown', 'host1', 'host2']) |
| 260 | |
| 261 | |
| 262 | def test_execute_list_filter_label(self): |
| 263 | self.run_cmd(argv=['atest', 'host', 'list', |
| 264 | '-b', 'label3', '--ignore_site_file'], |
mbligh | f703fb4 | 2009-01-30 00:35:05 +0000 | [diff] [blame] | 265 | rpcs=[('get_hosts', {'labels__name__in': ['label3']}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 266 | True, |
| 267 | [{u'status': u'Ready', |
| 268 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 269 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 270 | u'locked_by': 'user0', |
| 271 | u'lock_time': u'2008-07-23 12:54:15', |
| 272 | u'labels': [u'label2', u'label3', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 273 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 274 | u'synch_id': None, |
| 275 | u'platform': u'plat1', |
| 276 | u'id': 2}, |
| 277 | {u'status': u'Ready', |
| 278 | u'hostname': u'host2', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 279 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 280 | u'locked_by': 'user0', |
| 281 | u'lock_time': u'2008-07-23 12:54:15', |
| 282 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 283 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 284 | u'synch_id': None, |
| 285 | u'platform': u'plat1', |
| 286 | u'id': 3}])], |
| 287 | out_words_ok=['host1', 'Ready', 'plat1', |
| 288 | 'label2', 'label3', 'True', |
| 289 | 'host2', 'label4'], |
| 290 | out_words_no=['host0', 'label1', 'False']) |
| 291 | |
| 292 | |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 293 | def test_execute_list_filter_multi_labels(self): |
| 294 | self.run_cmd(argv=['atest', 'host', 'list', |
| 295 | '-b', 'label3,label2', '--ignore_site_file'], |
jamesren | c286316 | 2010-07-12 21:20:51 +0000 | [diff] [blame] | 296 | rpcs=[('get_hosts', {'multiple_labels': ['label2', |
| 297 | 'label3']}, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 298 | True, |
| 299 | [{u'status': u'Ready', |
| 300 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 301 | u'locked': True, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 302 | u'locked_by': 'user0', |
| 303 | u'lock_time': u'2008-07-23 12:54:15', |
| 304 | u'labels': [u'label2', u'label3', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 305 | u'invalid': False, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 306 | u'synch_id': None, |
| 307 | u'platform': u'plat0', |
| 308 | u'id': 2}, |
| 309 | {u'status': u'Ready', |
| 310 | u'hostname': u'host3', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 311 | u'locked': True, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 312 | u'locked_by': 'user0', |
| 313 | u'lock_time': u'2008-07-23 12:54:15', |
| 314 | u'labels': [u'label3', u'label2', u'plat2'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 315 | u'invalid': False, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 316 | u'synch_id': None, |
| 317 | u'platform': u'plat2', |
| 318 | u'id': 4}])], |
| 319 | out_words_ok=['host1', 'host3', 'Ready', 'plat0', |
| 320 | 'label2', 'label3', 'plat2'], |
| 321 | out_words_no=['host2', 'label4', 'False', 'plat1']) |
| 322 | |
| 323 | |
| 324 | def test_execute_list_filter_three_labels(self): |
| 325 | self.run_cmd(argv=['atest', 'host', 'list', |
| 326 | '-b', 'label3,label2, label4', |
| 327 | '--ignore_site_file'], |
jamesren | c286316 | 2010-07-12 21:20:51 +0000 | [diff] [blame] | 328 | rpcs=[('get_hosts', {'multiple_labels': ['label2', |
| 329 | 'label3', |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 330 | 'label4']}, |
| 331 | True, |
| 332 | [{u'status': u'Ready', |
| 333 | u'hostname': u'host2', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 334 | u'locked': True, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 335 | u'locked_by': 'user0', |
| 336 | u'lock_time': u'2008-07-23 12:54:15', |
| 337 | u'labels': [u'label3', u'label2', u'label4', |
| 338 | u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 339 | u'invalid': False, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 340 | u'synch_id': None, |
| 341 | u'platform': u'plat1', |
| 342 | u'id': 3}])], |
| 343 | out_words_ok=['host2', 'plat1', |
| 344 | 'label2', 'label3', 'label4'], |
| 345 | out_words_no=['host1', 'host3']) |
| 346 | |
| 347 | |
mbligh | f703fb4 | 2009-01-30 00:35:05 +0000 | [diff] [blame] | 348 | def test_execute_list_filter_wild_labels(self): |
| 349 | self.run_cmd(argv=['atest', 'host', 'list', |
| 350 | '-b', 'label*', |
| 351 | '--ignore_site_file'], |
| 352 | rpcs=[('get_hosts', |
| 353 | {'labels__name__startswith': 'label'}, |
| 354 | True, |
| 355 | [{u'status': u'Ready', |
| 356 | u'hostname': u'host2', |
| 357 | u'locked': 1, |
| 358 | u'locked_by': 'user0', |
| 359 | u'lock_time': u'2008-07-23 12:54:15', |
| 360 | u'labels': [u'label3', u'label2', u'label4', |
| 361 | u'plat1'], |
| 362 | u'invalid': 0, |
| 363 | u'synch_id': None, |
| 364 | u'platform': u'plat1', |
| 365 | u'id': 3}])], |
| 366 | out_words_ok=['host2', 'plat1', |
| 367 | 'label2', 'label3', 'label4'], |
| 368 | out_words_no=['host1', 'host3']) |
| 369 | |
| 370 | |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 371 | def test_execute_list_filter_multi_labels_no_results(self): |
| 372 | self.run_cmd(argv=['atest', 'host', 'list', |
| 373 | '-b', 'label3,label2, ', '--ignore_site_file'], |
jamesren | c286316 | 2010-07-12 21:20:51 +0000 | [diff] [blame] | 374 | rpcs=[('get_hosts', {'multiple_labels': ['label2', |
| 375 | 'label3']}, |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 376 | True, |
| 377 | [])], |
| 378 | out_words_ok=[], |
| 379 | out_words_no=['host1', 'host2', 'host3', |
| 380 | 'label2', 'label3', 'label4']) |
| 381 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 382 | |
| 383 | def test_execute_list_filter_label_and_hosts(self): |
| 384 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
| 385 | '-b', 'label3', 'host2', '--ignore_site_file'], |
mbligh | f703fb4 | 2009-01-30 00:35:05 +0000 | [diff] [blame] | 386 | rpcs=[('get_hosts', {'labels__name__in': ['label3'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 387 | 'hostname__in': ['host2', 'host1']}, |
| 388 | True, |
| 389 | [{u'status': u'Ready', |
| 390 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 391 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 392 | u'locked_by': 'user0', |
| 393 | u'lock_time': u'2008-07-23 12:54:15', |
| 394 | u'labels': [u'label2', u'label3', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 395 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 396 | u'synch_id': None, |
| 397 | u'platform': u'plat1', |
| 398 | u'id': 2}, |
| 399 | {u'status': u'Ready', |
| 400 | u'hostname': u'host2', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 401 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 402 | u'locked_by': 'user0', |
| 403 | u'lock_time': u'2008-07-23 12:54:15', |
| 404 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 405 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 406 | u'synch_id': None, |
| 407 | u'platform': u'plat1', |
| 408 | u'id': 3}])], |
| 409 | out_words_ok=['host1', 'Ready', 'plat1', |
| 410 | 'label2', 'label3', 'True', |
| 411 | 'host2', 'label4'], |
| 412 | out_words_no=['host0', 'label1', 'False']) |
| 413 | |
| 414 | |
| 415 | def test_execute_list_filter_label_and_hosts_none(self): |
| 416 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
| 417 | '-b', 'label3', 'host2', '--ignore_site_file'], |
mbligh | f703fb4 | 2009-01-30 00:35:05 +0000 | [diff] [blame] | 418 | rpcs=[('get_hosts', {'labels__name__in': ['label3'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 419 | 'hostname__in': ['host2', 'host1']}, |
| 420 | True, |
| 421 | [])], |
jadmanski | c79a398 | 2009-01-23 22:29:11 +0000 | [diff] [blame] | 422 | out_words_ok=[], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 423 | out_words_no=['Hostname', 'Status'], |
| 424 | err_words_ok=['Unknown', 'host1', 'host2']) |
| 425 | |
| 426 | |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 427 | def test_execute_list_filter_status(self): |
| 428 | self.run_cmd(argv=['atest', 'host', 'list', |
| 429 | '-s', 'Ready', '--ignore_site_file'], |
| 430 | rpcs=[('get_hosts', {'status__in': ['Ready']}, |
| 431 | True, |
| 432 | [{u'status': u'Ready', |
| 433 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 434 | u'locked': True, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 435 | u'locked_by': 'user0', |
| 436 | u'lock_time': u'2008-07-23 12:54:15', |
| 437 | u'labels': [u'label2', u'label3', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 438 | u'invalid': False, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 439 | u'synch_id': None, |
| 440 | u'platform': u'plat1', |
| 441 | u'id': 2}, |
| 442 | {u'status': u'Ready', |
| 443 | u'hostname': u'host2', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 444 | u'locked': True, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 445 | u'locked_by': 'user0', |
| 446 | u'lock_time': u'2008-07-23 12:54:15', |
| 447 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 448 | u'invalid': False, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 449 | u'synch_id': None, |
| 450 | u'platform': u'plat1', |
| 451 | u'id': 3}])], |
| 452 | out_words_ok=['host1', 'Ready', 'plat1', |
| 453 | 'label2', 'label3', 'True', |
| 454 | 'host2', 'label4'], |
| 455 | out_words_no=['host0', 'label1', 'False']) |
| 456 | |
| 457 | |
| 458 | |
| 459 | def test_execute_list_filter_status_and_hosts(self): |
| 460 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
| 461 | '-s', 'Ready', 'host2', '--ignore_site_file'], |
| 462 | rpcs=[('get_hosts', {'status__in': ['Ready'], |
| 463 | 'hostname__in': ['host2', 'host1']}, |
| 464 | True, |
| 465 | [{u'status': u'Ready', |
| 466 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 467 | u'locked': True, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 468 | u'locked_by': 'user0', |
| 469 | u'lock_time': u'2008-07-23 12:54:15', |
| 470 | u'labels': [u'label2', u'label3', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 471 | u'invalid': False, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 472 | u'synch_id': None, |
| 473 | u'platform': u'plat1', |
| 474 | u'id': 2}, |
| 475 | {u'status': u'Ready', |
| 476 | u'hostname': u'host2', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 477 | u'locked': True, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 478 | u'locked_by': 'user0', |
| 479 | u'lock_time': u'2008-07-23 12:54:15', |
| 480 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 481 | u'invalid': False, |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 482 | u'synch_id': None, |
| 483 | u'platform': u'plat1', |
| 484 | u'id': 3}])], |
| 485 | out_words_ok=['host1', 'Ready', 'plat1', |
| 486 | 'label2', 'label3', 'True', |
| 487 | 'host2', 'label4'], |
| 488 | out_words_no=['host0', 'label1', 'False']) |
| 489 | |
| 490 | |
| 491 | def test_execute_list_filter_status_and_hosts_none(self): |
| 492 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
| 493 | '--status', 'Repair', |
| 494 | 'host2', '--ignore_site_file'], |
| 495 | rpcs=[('get_hosts', {'status__in': ['Repair'], |
| 496 | 'hostname__in': ['host2', 'host1']}, |
| 497 | True, |
| 498 | [])], |
jadmanski | c79a398 | 2009-01-23 22:29:11 +0000 | [diff] [blame] | 499 | out_words_ok=[], |
mbligh | cd8eb97 | 2008-08-25 19:20:39 +0000 | [diff] [blame] | 500 | out_words_no=['Hostname', 'Status'], |
| 501 | err_words_ok=['Unknown', 'host2']) |
| 502 | |
| 503 | |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 504 | def test_execute_list_filter_statuses_and_hosts_none(self): |
| 505 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
mbligh | 3df90c9 | 2009-03-09 21:09:29 +0000 | [diff] [blame] | 506 | '--status', 'Repair', |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 507 | 'host2', '--ignore_site_file'], |
mbligh | 3df90c9 | 2009-03-09 21:09:29 +0000 | [diff] [blame] | 508 | rpcs=[('get_hosts', {'status__in': ['Repair'], |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 509 | 'hostname__in': ['host2', 'host1']}, |
| 510 | True, |
| 511 | [])], |
jadmanski | c79a398 | 2009-01-23 22:29:11 +0000 | [diff] [blame] | 512 | out_words_ok=[], |
mbligh | 6444c6b | 2008-10-27 20:55:13 +0000 | [diff] [blame] | 513 | out_words_no=['Hostname', 'Status'], |
| 514 | err_words_ok=['Unknown', 'host2']) |
| 515 | |
| 516 | |
mbligh | 91e0efd | 2009-02-26 01:02:16 +0000 | [diff] [blame] | 517 | def test_execute_list_filter_locked(self): |
| 518 | self.run_cmd(argv=['atest', 'host', 'list', 'host1', |
| 519 | '--locked', 'host2', '--ignore_site_file'], |
| 520 | rpcs=[('get_hosts', {'locked': True, |
| 521 | 'hostname__in': ['host2', 'host1']}, |
| 522 | True, |
| 523 | [{u'status': u'Ready', |
| 524 | u'hostname': u'host1', |
| 525 | u'locked': True, |
| 526 | u'locked_by': 'user0', |
| 527 | u'lock_time': u'2008-07-23 12:54:15', |
| 528 | u'labels': [u'label2', u'label3', u'plat1'], |
| 529 | u'invalid': False, |
| 530 | u'synch_id': None, |
| 531 | u'platform': u'plat1', |
| 532 | u'id': 2}, |
| 533 | {u'status': u'Ready', |
| 534 | u'hostname': u'host2', |
| 535 | u'locked': True, |
| 536 | u'locked_by': 'user0', |
| 537 | u'lock_time': u'2008-07-23 12:54:15', |
| 538 | u'labels': [u'label3', u'label4', u'plat1'], |
| 539 | u'invalid': False, |
| 540 | u'synch_id': None, |
| 541 | u'platform': u'plat1', |
| 542 | u'id': 3}])], |
| 543 | out_words_ok=['host1', 'Ready', 'plat1', |
| 544 | 'label2', 'label3', 'True', |
| 545 | 'host2', 'label4'], |
| 546 | out_words_no=['host0', 'label1', 'False']) |
| 547 | |
| 548 | |
| 549 | def test_execute_list_filter_unlocked(self): |
| 550 | self.run_cmd(argv=['atest', 'host', 'list', |
| 551 | '--unlocked', '--ignore_site_file'], |
| 552 | rpcs=[('get_hosts', {'locked': False}, |
| 553 | True, |
| 554 | [{u'status': u'Ready', |
| 555 | u'hostname': u'host1', |
| 556 | u'locked': False, |
| 557 | u'locked_by': 'user0', |
| 558 | u'lock_time': u'2008-07-23 12:54:15', |
| 559 | u'labels': [u'label2', u'label3', u'plat1'], |
| 560 | u'invalid': False, |
| 561 | u'synch_id': None, |
| 562 | u'platform': u'plat1', |
| 563 | u'id': 2}, |
| 564 | {u'status': u'Ready', |
| 565 | u'hostname': u'host2', |
| 566 | u'locked': False, |
| 567 | u'locked_by': 'user0', |
| 568 | u'lock_time': u'2008-07-23 12:54:15', |
| 569 | u'labels': [u'label3', u'label4', u'plat1'], |
| 570 | u'invalid': False, |
| 571 | u'synch_id': None, |
| 572 | u'platform': u'plat1', |
| 573 | u'id': 3}])], |
| 574 | out_words_ok=['host1', 'Ready', 'plat1', |
| 575 | 'label2', 'label3', 'False', |
| 576 | 'host2', 'label4'], |
| 577 | out_words_no=['host0', 'label1', 'True']) |
| 578 | |
| 579 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 580 | class host_stat_unittest(cli_mock.cli_unittest): |
| 581 | def test_execute_stat_two_hosts(self): |
| 582 | # The order of RPCs between host1 and host0 could change... |
| 583 | self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1', |
| 584 | '--ignore_site_file'], |
| 585 | rpcs=[('get_hosts', {'hostname': 'host1'}, |
| 586 | True, |
| 587 | [{u'status': u'Ready', |
| 588 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 589 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 590 | u'lock_time': u'2008-07-23 12:54:15', |
| 591 | u'locked_by': 'user0', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 592 | u'protection': 'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 593 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 594 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 595 | u'synch_id': None, |
| 596 | u'platform': u'plat1', |
| 597 | u'id': 3}]), |
| 598 | ('get_hosts', {'hostname': 'host0'}, |
| 599 | True, |
| 600 | [{u'status': u'Ready', |
| 601 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 602 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 603 | u'locked_by': 'user0', |
| 604 | u'lock_time': u'2008-07-23 12:54:15', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 605 | u'protection': u'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 606 | u'labels': [u'label0', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 607 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 608 | u'synch_id': None, |
| 609 | u'platform': u'plat0', |
| 610 | u'id': 2}]), |
| 611 | ('get_acl_groups', {'hosts__hostname': 'host1'}, |
| 612 | True, |
| 613 | [{u'description': u'', |
| 614 | u'hosts': [u'host0', u'host1'], |
| 615 | u'id': 1, |
| 616 | u'name': u'Everyone', |
| 617 | u'users': [u'user2', u'debug_user', u'user0']}]), |
| 618 | ('get_labels', {'host__hostname': 'host1'}, |
| 619 | True, |
| 620 | [{u'id': 2, |
| 621 | u'platform': 1, |
| 622 | u'name': u'jme', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 623 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 624 | u'kernel_config': u''}]), |
| 625 | ('get_acl_groups', {'hosts__hostname': 'host0'}, |
| 626 | True, |
| 627 | [{u'description': u'', |
| 628 | u'hosts': [u'host0', u'host1'], |
| 629 | u'id': 1, |
| 630 | u'name': u'Everyone', |
| 631 | u'users': [u'user0', u'debug_user']}, |
| 632 | {u'description': u'myacl0', |
| 633 | u'hosts': [u'host0'], |
| 634 | u'id': 2, |
| 635 | u'name': u'acl0', |
| 636 | u'users': [u'user0']}]), |
| 637 | ('get_labels', {'host__hostname': 'host0'}, |
| 638 | True, |
| 639 | [{u'id': 4, |
| 640 | u'platform': 0, |
| 641 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 642 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 643 | u'kernel_config': u''}, |
| 644 | {u'id': 5, |
| 645 | u'platform': 1, |
| 646 | u'name': u'plat0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 647 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 648 | u'kernel_config': u''}])], |
| 649 | out_words_ok=['host0', 'host1', 'plat0', 'plat1', |
| 650 | 'Everyone', 'acl0', 'label0']) |
| 651 | |
| 652 | |
| 653 | def test_execute_stat_one_bad_host_verbose(self): |
| 654 | self.run_cmd(argv=['atest', 'host', 'stat', 'host0', |
| 655 | 'host1', '-v', '--ignore_site_file'], |
| 656 | rpcs=[('get_hosts', {'hostname': 'host1'}, |
| 657 | True, |
| 658 | []), |
| 659 | ('get_hosts', {'hostname': 'host0'}, |
| 660 | True, |
| 661 | [{u'status': u'Ready', |
| 662 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 663 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 664 | u'locked_by': 'user0', |
| 665 | u'lock_time': u'2008-07-23 12:54:15', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 666 | u'protection': u'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 667 | u'labels': [u'label0', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 668 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 669 | u'synch_id': None, |
| 670 | u'platform': u'plat0', |
| 671 | u'id': 2}]), |
| 672 | ('get_acl_groups', {'hosts__hostname': 'host0'}, |
| 673 | True, |
| 674 | [{u'description': u'', |
| 675 | u'hosts': [u'host0', u'host1'], |
| 676 | u'id': 1, |
| 677 | u'name': u'Everyone', |
| 678 | u'users': [u'user0', u'debug_user']}, |
| 679 | {u'description': u'myacl0', |
| 680 | u'hosts': [u'host0'], |
| 681 | u'id': 2, |
| 682 | u'name': u'acl0', |
| 683 | u'users': [u'user0']}]), |
| 684 | ('get_labels', {'host__hostname': 'host0'}, |
| 685 | True, |
| 686 | [{u'id': 4, |
| 687 | u'platform': 0, |
| 688 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 689 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 690 | u'kernel_config': u''}, |
| 691 | {u'id': 5, |
| 692 | u'platform': 1, |
| 693 | u'name': u'plat0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 694 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 695 | u'kernel_config': u''}])], |
| 696 | out_words_ok=['host0', 'plat0', |
| 697 | 'Everyone', 'acl0', 'label0'], |
| 698 | out_words_no=['host1'], |
| 699 | err_words_ok=['host1', 'Unknown host'], |
| 700 | err_words_no=['host0']) |
| 701 | |
| 702 | |
| 703 | def test_execute_stat_one_bad_host(self): |
| 704 | self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1', |
| 705 | '--ignore_site_file'], |
| 706 | rpcs=[('get_hosts', {'hostname': 'host1'}, |
| 707 | True, |
| 708 | []), |
| 709 | ('get_hosts', {'hostname': 'host0'}, |
| 710 | True, |
| 711 | [{u'status': u'Ready', |
| 712 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 713 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 714 | u'locked_by': 'user0', |
| 715 | u'lock_time': u'2008-07-23 12:54:15', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 716 | u'protection': u'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 717 | u'labels': [u'label0', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 718 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 719 | u'synch_id': None, |
| 720 | u'platform': u'plat0', |
| 721 | u'id': 2}]), |
| 722 | ('get_acl_groups', {'hosts__hostname': 'host0'}, |
| 723 | True, |
| 724 | [{u'description': u'', |
| 725 | u'hosts': [u'host0', u'host1'], |
| 726 | u'id': 1, |
| 727 | u'name': u'Everyone', |
| 728 | u'users': [u'user0', u'debug_user']}, |
| 729 | {u'description': u'myacl0', |
| 730 | u'hosts': [u'host0'], |
| 731 | u'id': 2, |
| 732 | u'name': u'acl0', |
| 733 | u'users': [u'user0']}]), |
| 734 | ('get_labels', {'host__hostname': 'host0'}, |
| 735 | True, |
| 736 | [{u'id': 4, |
| 737 | u'platform': 0, |
| 738 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 739 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 740 | u'kernel_config': u''}, |
| 741 | {u'id': 5, |
| 742 | u'platform': 1, |
| 743 | u'name': u'plat0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 744 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 745 | u'kernel_config': u''}])], |
| 746 | out_words_ok=['host0', 'plat0', |
| 747 | 'Everyone', 'acl0', 'label0'], |
| 748 | out_words_no=['host1'], |
| 749 | err_words_ok=['host1', 'Unknown host'], |
| 750 | err_words_no=['host0']) |
| 751 | |
| 752 | |
| 753 | def test_execute_stat_wildcard(self): |
| 754 | # The order of RPCs between host1 and host0 could change... |
| 755 | self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', |
| 756 | '--ignore_site_file'], |
| 757 | rpcs=[('get_hosts', {'hostname__startswith': 'ho'}, |
| 758 | True, |
| 759 | [{u'status': u'Ready', |
| 760 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 761 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 762 | u'lock_time': u'2008-07-23 12:54:15', |
| 763 | u'locked_by': 'user0', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 764 | u'protection': 'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 765 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 766 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 767 | u'synch_id': None, |
| 768 | u'platform': u'plat1', |
| 769 | u'id': 3}, |
| 770 | {u'status': u'Ready', |
| 771 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 772 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 773 | u'locked_by': 'user0', |
| 774 | u'lock_time': u'2008-07-23 12:54:15', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 775 | u'protection': u'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 776 | u'labels': [u'label0', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 777 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 778 | u'synch_id': None, |
| 779 | u'platform': u'plat0', |
| 780 | u'id': 2}]), |
| 781 | ('get_acl_groups', {'hosts__hostname': 'host1'}, |
| 782 | True, |
| 783 | [{u'description': u'', |
| 784 | u'hosts': [u'host0', u'host1'], |
| 785 | u'id': 1, |
| 786 | u'name': u'Everyone', |
| 787 | u'users': [u'user2', u'debug_user', u'user0']}]), |
| 788 | ('get_labels', {'host__hostname': 'host1'}, |
| 789 | True, |
| 790 | [{u'id': 2, |
| 791 | u'platform': 1, |
| 792 | u'name': u'jme', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 793 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 794 | u'kernel_config': u''}]), |
| 795 | ('get_acl_groups', {'hosts__hostname': 'host0'}, |
| 796 | True, |
| 797 | [{u'description': u'', |
| 798 | u'hosts': [u'host0', u'host1'], |
| 799 | u'id': 1, |
| 800 | u'name': u'Everyone', |
| 801 | u'users': [u'user0', u'debug_user']}, |
| 802 | {u'description': u'myacl0', |
| 803 | u'hosts': [u'host0'], |
| 804 | u'id': 2, |
| 805 | u'name': u'acl0', |
| 806 | u'users': [u'user0']}]), |
| 807 | ('get_labels', {'host__hostname': 'host0'}, |
| 808 | True, |
| 809 | [{u'id': 4, |
| 810 | u'platform': 0, |
| 811 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 812 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 813 | u'kernel_config': u''}, |
| 814 | {u'id': 5, |
| 815 | u'platform': 1, |
| 816 | u'name': u'plat0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 817 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 818 | u'kernel_config': u''}])], |
| 819 | out_words_ok=['host0', 'host1', 'plat0', 'plat1', |
| 820 | 'Everyone', 'acl0', 'label0']) |
| 821 | |
| 822 | |
| 823 | def test_execute_stat_wildcard_and_host(self): |
| 824 | # The order of RPCs between host1 and host0 could change... |
| 825 | self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', 'newhost0', |
| 826 | '--ignore_site_file'], |
| 827 | rpcs=[('get_hosts', {'hostname': 'newhost0'}, |
| 828 | True, |
| 829 | [{u'status': u'Ready', |
| 830 | u'hostname': u'newhost0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 831 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 832 | u'locked_by': 'user0', |
| 833 | u'lock_time': u'2008-07-23 12:54:15', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 834 | u'protection': u'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 835 | u'labels': [u'label0', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 836 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 837 | u'synch_id': None, |
| 838 | u'platform': u'plat0', |
| 839 | u'id': 5}]), |
| 840 | ('get_hosts', {'hostname__startswith': 'ho'}, |
| 841 | True, |
| 842 | [{u'status': u'Ready', |
| 843 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 844 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 845 | u'lock_time': u'2008-07-23 12:54:15', |
| 846 | u'locked_by': 'user0', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 847 | u'protection': 'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 848 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 849 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 850 | u'synch_id': None, |
| 851 | u'platform': u'plat1', |
| 852 | u'id': 3}, |
| 853 | {u'status': u'Ready', |
| 854 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 855 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 856 | u'locked_by': 'user0', |
mbligh | 536a524 | 2008-10-18 14:35:54 +0000 | [diff] [blame] | 857 | u'protection': 'No protection', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 858 | u'lock_time': u'2008-07-23 12:54:15', |
| 859 | u'labels': [u'label0', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 860 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 861 | u'synch_id': None, |
| 862 | u'platform': u'plat0', |
| 863 | u'id': 2}]), |
| 864 | ('get_acl_groups', {'hosts__hostname': 'newhost0'}, |
| 865 | True, |
| 866 | [{u'description': u'', |
| 867 | u'hosts': [u'newhost0', 'host1'], |
| 868 | u'id': 42, |
| 869 | u'name': u'my_acl', |
| 870 | u'users': [u'user0', u'debug_user']}, |
| 871 | {u'description': u'my favorite acl', |
| 872 | u'hosts': [u'newhost0'], |
| 873 | u'id': 2, |
| 874 | u'name': u'acl10', |
| 875 | u'users': [u'user0']}]), |
| 876 | ('get_labels', {'host__hostname': 'newhost0'}, |
| 877 | True, |
| 878 | [{u'id': 4, |
| 879 | u'platform': 0, |
| 880 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 881 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 882 | u'kernel_config': u''}, |
| 883 | {u'id': 5, |
| 884 | u'platform': 1, |
| 885 | u'name': u'plat0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 886 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 887 | u'kernel_config': u''}]), |
| 888 | ('get_acl_groups', {'hosts__hostname': 'host1'}, |
| 889 | True, |
| 890 | [{u'description': u'', |
| 891 | u'hosts': [u'host0', u'host1'], |
| 892 | u'id': 1, |
| 893 | u'name': u'Everyone', |
| 894 | u'users': [u'user2', u'debug_user', u'user0']}]), |
| 895 | ('get_labels', {'host__hostname': 'host1'}, |
| 896 | True, |
| 897 | [{u'id': 2, |
| 898 | u'platform': 1, |
| 899 | u'name': u'jme', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 900 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 901 | u'kernel_config': u''}]), |
| 902 | ('get_acl_groups', {'hosts__hostname': 'host0'}, |
| 903 | True, |
| 904 | [{u'description': u'', |
| 905 | u'hosts': [u'host0', u'host1'], |
| 906 | u'id': 1, |
| 907 | u'name': u'Everyone', |
| 908 | u'users': [u'user0', u'debug_user']}, |
| 909 | {u'description': u'myacl0', |
| 910 | u'hosts': [u'host0'], |
| 911 | u'id': 2, |
| 912 | u'name': u'acl0', |
| 913 | u'users': [u'user0']}]), |
| 914 | ('get_labels', {'host__hostname': 'host0'}, |
| 915 | True, |
| 916 | [{u'id': 4, |
| 917 | u'platform': 0, |
| 918 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 919 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 920 | u'kernel_config': u''}, |
| 921 | {u'id': 5, |
| 922 | u'platform': 1, |
| 923 | u'name': u'plat0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 924 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 925 | u'kernel_config': u''}])], |
| 926 | out_words_ok=['host0', 'host1', 'newhost0', |
| 927 | 'plat0', 'plat1', |
mbligh | e163b03 | 2008-10-18 14:30:27 +0000 | [diff] [blame] | 928 | 'Everyone', 'acl10', 'label0']) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 929 | |
| 930 | |
| 931 | class host_jobs_unittest(cli_mock.cli_unittest): |
| 932 | def test_execute_jobs_one_host(self): |
| 933 | self.run_cmd(argv=['atest', 'host', 'jobs', 'host0', |
| 934 | '--ignore_site_file'], |
| 935 | rpcs=[('get_host_queue_entries', |
mbligh | 1494eca | 2008-08-13 21:24:22 +0000 | [diff] [blame] | 936 | {'host__hostname': 'host0', 'query_limit': 20, |
showard | 6958c72 | 2009-09-23 20:03:16 +0000 | [diff] [blame] | 937 | 'sort_by': ['-job__id']}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 938 | True, |
| 939 | [{u'status': u'Failed', |
| 940 | u'complete': 1, |
| 941 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 942 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 943 | u'locked_by': 'user0', |
| 944 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 945 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 946 | u'id': 3232, |
| 947 | u'synch_id': None}, |
| 948 | u'priority': 0, |
| 949 | u'meta_host': u'meta0', |
| 950 | u'job': {u'control_file': |
| 951 | (u"def step_init():\n" |
| 952 | "\tjob.next_step([step_test])\n" |
| 953 | "\ttestkernel = job.kernel(" |
| 954 | "'kernel-smp-2.6.xyz.x86_64.rpm')\n" |
| 955 | "\ttestkernel.install()\n" |
| 956 | "\ttestkernel.boot()\n\n" |
| 957 | "def step_test():\n" |
| 958 | "\tjob.run_test('kernbench')\n\n"), |
| 959 | u'name': u'kernel-smp-2.6.xyz.x86_64', |
| 960 | u'control_type': u'Client', |
| 961 | u'synchronizing': None, |
| 962 | u'priority': u'Low', |
| 963 | u'owner': u'user0', |
| 964 | u'created_on': u'2008-01-09 10:45:12', |
| 965 | u'synch_count': None, |
| 966 | u'synch_type': u'Asynchronous', |
| 967 | u'id': 216}, |
| 968 | u'active': 0, |
| 969 | u'id': 2981}, |
| 970 | {u'status': u'Aborted', |
| 971 | u'complete': 1, |
| 972 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 973 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 974 | u'locked_by': 'user0', |
| 975 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 976 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 977 | u'id': 3232, |
| 978 | u'synch_id': None}, |
| 979 | u'priority': 0, |
| 980 | u'meta_host': None, |
| 981 | u'job': {u'control_file': |
| 982 | u"job.run_test('sleeptest')\n\n", |
| 983 | u'name': u'testjob', |
| 984 | u'control_type': u'Client', |
| 985 | u'synchronizing': 0, |
| 986 | u'priority': u'Low', |
| 987 | u'owner': u'user1', |
| 988 | u'created_on': u'2008-01-17 15:04:53', |
| 989 | u'synch_count': None, |
| 990 | u'synch_type': u'Asynchronous', |
| 991 | u'id': 289}, |
| 992 | u'active': 0, |
| 993 | u'id': 3167}])], |
| 994 | out_words_ok=['216', 'user0', 'Failed', |
| 995 | 'kernel-smp-2.6.xyz.x86_64', 'Aborted', |
| 996 | '289', 'user1', 'Aborted', |
| 997 | 'testjob']) |
| 998 | |
| 999 | |
| 1000 | def test_execute_jobs_wildcard(self): |
| 1001 | self.run_cmd(argv=['atest', 'host', 'jobs', 'ho*', |
| 1002 | '--ignore_site_file'], |
| 1003 | rpcs=[('get_hosts', {'hostname__startswith': 'ho'}, |
| 1004 | True, |
| 1005 | [{u'status': u'Ready', |
| 1006 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1007 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1008 | u'lock_time': u'2008-07-23 12:54:15', |
| 1009 | u'locked_by': 'user0', |
| 1010 | u'labels': [u'label3', u'label4', u'plat1'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1011 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1012 | u'synch_id': None, |
| 1013 | u'platform': u'plat1', |
| 1014 | u'id': 3}, |
| 1015 | {u'status': u'Ready', |
| 1016 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1017 | u'locked': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1018 | u'locked_by': 'user0', |
| 1019 | u'lock_time': u'2008-07-23 12:54:15', |
| 1020 | u'labels': [u'label0', u'plat0'], |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1021 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1022 | u'synch_id': None, |
| 1023 | u'platform': u'plat0', |
| 1024 | u'id': 2}]), |
| 1025 | ('get_host_queue_entries', |
mbligh | 1494eca | 2008-08-13 21:24:22 +0000 | [diff] [blame] | 1026 | {'host__hostname': 'host1', 'query_limit': 20, |
showard | 6958c72 | 2009-09-23 20:03:16 +0000 | [diff] [blame] | 1027 | 'sort_by': ['-job__id']}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1028 | True, |
| 1029 | [{u'status': u'Failed', |
| 1030 | u'complete': 1, |
| 1031 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1032 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1033 | u'locked_by': 'user0', |
| 1034 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1035 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1036 | u'id': 3232, |
| 1037 | u'synch_id': None}, |
| 1038 | u'priority': 0, |
| 1039 | u'meta_host': u'meta0', |
| 1040 | u'job': {u'control_file': |
| 1041 | (u"def step_init():\n" |
| 1042 | "\tjob.next_step([step_test])\n" |
| 1043 | "\ttestkernel = job.kernel(" |
| 1044 | "'kernel-smp-2.6.xyz.x86_64.rpm')\n" |
| 1045 | "\ttestkernel.install()\n" |
| 1046 | "\ttestkernel.boot()\n\n" |
| 1047 | "def step_test():\n" |
| 1048 | "\tjob.run_test('kernbench')\n\n"), |
| 1049 | u'name': u'kernel-smp-2.6.xyz.x86_64', |
| 1050 | u'control_type': u'Client', |
| 1051 | u'synchronizing': None, |
| 1052 | u'priority': u'Low', |
| 1053 | u'owner': u'user0', |
| 1054 | u'created_on': u'2008-01-09 10:45:12', |
| 1055 | u'synch_count': None, |
| 1056 | u'synch_type': u'Asynchronous', |
| 1057 | u'id': 216}, |
| 1058 | u'active': 0, |
| 1059 | u'id': 2981}, |
| 1060 | {u'status': u'Aborted', |
| 1061 | u'complete': 1, |
| 1062 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1063 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1064 | u'locked_by': 'user0', |
| 1065 | u'hostname': u'host1', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1066 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1067 | u'id': 3232, |
| 1068 | u'synch_id': None}, |
| 1069 | u'priority': 0, |
| 1070 | u'meta_host': None, |
| 1071 | u'job': {u'control_file': |
| 1072 | u"job.run_test('sleeptest')\n\n", |
| 1073 | u'name': u'testjob', |
| 1074 | u'control_type': u'Client', |
| 1075 | u'synchronizing': 0, |
| 1076 | u'priority': u'Low', |
| 1077 | u'owner': u'user1', |
| 1078 | u'created_on': u'2008-01-17 15:04:53', |
| 1079 | u'synch_count': None, |
| 1080 | u'synch_type': u'Asynchronous', |
| 1081 | u'id': 289}, |
| 1082 | u'active': 0, |
| 1083 | u'id': 3167}]), |
| 1084 | ('get_host_queue_entries', |
mbligh | 1494eca | 2008-08-13 21:24:22 +0000 | [diff] [blame] | 1085 | {'host__hostname': 'host0', 'query_limit': 20, |
showard | 6958c72 | 2009-09-23 20:03:16 +0000 | [diff] [blame] | 1086 | 'sort_by': ['-job__id']}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1087 | True, |
| 1088 | [{u'status': u'Failed', |
| 1089 | u'complete': 1, |
| 1090 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1091 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1092 | u'locked_by': 'user0', |
| 1093 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1094 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1095 | u'id': 3232, |
| 1096 | u'synch_id': None}, |
| 1097 | u'priority': 0, |
| 1098 | u'meta_host': u'meta0', |
| 1099 | u'job': {u'control_file': |
| 1100 | (u"def step_init():\n" |
| 1101 | "\tjob.next_step([step_test])\n" |
| 1102 | "\ttestkernel = job.kernel(" |
| 1103 | "'kernel-smp-2.6.xyz.x86_64.rpm')\n" |
| 1104 | "\ttestkernel.install()\n" |
| 1105 | "\ttestkernel.boot()\n\n" |
| 1106 | "def step_test():\n" |
| 1107 | "\tjob.run_test('kernbench')\n\n"), |
| 1108 | u'name': u'kernel-smp-2.6.xyz.x86_64', |
| 1109 | u'control_type': u'Client', |
| 1110 | u'synchronizing': None, |
| 1111 | u'priority': u'Low', |
| 1112 | u'owner': u'user0', |
| 1113 | u'created_on': u'2008-01-09 10:45:12', |
| 1114 | u'synch_count': None, |
| 1115 | u'synch_type': u'Asynchronous', |
| 1116 | u'id': 216}, |
| 1117 | u'active': 0, |
| 1118 | u'id': 2981}, |
| 1119 | {u'status': u'Aborted', |
| 1120 | u'complete': 1, |
| 1121 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1122 | u'locked': True, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1123 | u'locked_by': 'user0', |
| 1124 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1125 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1126 | u'id': 3232, |
| 1127 | u'synch_id': None}, |
| 1128 | u'priority': 0, |
| 1129 | u'meta_host': None, |
| 1130 | u'job': {u'control_file': |
| 1131 | u"job.run_test('sleeptest')\n\n", |
| 1132 | u'name': u'testjob', |
| 1133 | u'control_type': u'Client', |
| 1134 | u'synchronizing': 0, |
| 1135 | u'priority': u'Low', |
| 1136 | u'owner': u'user1', |
| 1137 | u'created_on': u'2008-01-17 15:04:53', |
| 1138 | u'synch_count': None, |
| 1139 | u'synch_type': u'Asynchronous', |
| 1140 | u'id': 289}, |
| 1141 | u'active': 0, |
| 1142 | u'id': 3167}])], |
| 1143 | out_words_ok=['216', 'user0', 'Failed', |
| 1144 | 'kernel-smp-2.6.xyz.x86_64', 'Aborted', |
| 1145 | '289', 'user1', 'Aborted', |
| 1146 | 'testjob']) |
| 1147 | |
mbligh | 6996fe8 | 2008-08-13 00:32:27 +0000 | [diff] [blame] | 1148 | |
| 1149 | def test_execute_jobs_one_host_limit(self): |
| 1150 | self.run_cmd(argv=['atest', 'host', 'jobs', 'host0', |
| 1151 | '--ignore_site_file', '-q', '10'], |
| 1152 | rpcs=[('get_host_queue_entries', |
mbligh | 1494eca | 2008-08-13 21:24:22 +0000 | [diff] [blame] | 1153 | {'host__hostname': 'host0', 'query_limit': 10, |
showard | 6958c72 | 2009-09-23 20:03:16 +0000 | [diff] [blame] | 1154 | 'sort_by': ['-job__id']}, |
mbligh | 6996fe8 | 2008-08-13 00:32:27 +0000 | [diff] [blame] | 1155 | True, |
| 1156 | [{u'status': u'Failed', |
| 1157 | u'complete': 1, |
| 1158 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1159 | u'locked': True, |
mbligh | 6996fe8 | 2008-08-13 00:32:27 +0000 | [diff] [blame] | 1160 | u'locked_by': 'user0', |
| 1161 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1162 | u'invalid': False, |
mbligh | 6996fe8 | 2008-08-13 00:32:27 +0000 | [diff] [blame] | 1163 | u'id': 3232, |
| 1164 | u'synch_id': None}, |
| 1165 | u'priority': 0, |
| 1166 | u'meta_host': u'meta0', |
| 1167 | u'job': {u'control_file': |
| 1168 | (u"def step_init():\n" |
| 1169 | "\tjob.next_step([step_test])\n" |
| 1170 | "\ttestkernel = job.kernel(" |
| 1171 | "'kernel-smp-2.6.xyz.x86_64.rpm')\n" |
| 1172 | "\ttestkernel.install()\n" |
| 1173 | "\ttestkernel.boot()\n\n" |
| 1174 | "def step_test():\n" |
| 1175 | "\tjob.run_test('kernbench')\n\n"), |
| 1176 | u'name': u'kernel-smp-2.6.xyz.x86_64', |
| 1177 | u'control_type': u'Client', |
| 1178 | u'synchronizing': None, |
| 1179 | u'priority': u'Low', |
| 1180 | u'owner': u'user0', |
| 1181 | u'created_on': u'2008-01-09 10:45:12', |
| 1182 | u'synch_count': None, |
| 1183 | u'synch_type': u'Asynchronous', |
| 1184 | u'id': 216}, |
| 1185 | u'active': 0, |
| 1186 | u'id': 2981}, |
| 1187 | {u'status': u'Aborted', |
| 1188 | u'complete': 1, |
| 1189 | u'host': {u'status': u'Ready', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1190 | u'locked': True, |
mbligh | 6996fe8 | 2008-08-13 00:32:27 +0000 | [diff] [blame] | 1191 | u'locked_by': 'user0', |
| 1192 | u'hostname': u'host0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1193 | u'invalid': False, |
mbligh | 6996fe8 | 2008-08-13 00:32:27 +0000 | [diff] [blame] | 1194 | u'id': 3232, |
| 1195 | u'synch_id': None}, |
| 1196 | u'priority': 0, |
| 1197 | u'meta_host': None, |
| 1198 | u'job': {u'control_file': |
| 1199 | u"job.run_test('sleeptest')\n\n", |
| 1200 | u'name': u'testjob', |
| 1201 | u'control_type': u'Client', |
| 1202 | u'synchronizing': 0, |
| 1203 | u'priority': u'Low', |
| 1204 | u'owner': u'user1', |
| 1205 | u'created_on': u'2008-01-17 15:04:53', |
| 1206 | u'synch_count': None, |
| 1207 | u'synch_type': u'Asynchronous', |
| 1208 | u'id': 289}, |
| 1209 | u'active': 0, |
| 1210 | u'id': 3167}])], |
| 1211 | out_words_ok=['216', 'user0', 'Failed', |
| 1212 | 'kernel-smp-2.6.xyz.x86_64', 'Aborted', |
| 1213 | '289', 'user1', 'Aborted', |
| 1214 | 'testjob']) |
| 1215 | |
| 1216 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1217 | class host_mod_unittest(cli_mock.cli_unittest): |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1218 | def test_execute_lock_one_host(self): |
| 1219 | self.run_cmd(argv=['atest', 'host', 'mod', |
| 1220 | '--lock', 'host0', '--ignore_site_file'], |
| 1221 | rpcs=[('modify_host', {'id': 'host0', 'locked': True}, |
| 1222 | True, None)], |
| 1223 | out_words_ok=['Locked', 'host0']) |
| 1224 | |
| 1225 | |
| 1226 | def test_execute_unlock_two_hosts(self): |
| 1227 | self.run_cmd(argv=['atest', 'host', 'mod', |
| 1228 | '-u', 'host0,host1', '--ignore_site_file'], |
| 1229 | rpcs=[('modify_host', {'id': 'host1', 'locked': False}, |
| 1230 | True, None), |
| 1231 | ('modify_host', {'id': 'host0', 'locked': False}, |
| 1232 | True, None)], |
| 1233 | out_words_ok=['Unlocked', 'host0', 'host1']) |
| 1234 | |
| 1235 | |
mbligh | 6eca460 | 2009-01-07 16:48:50 +0000 | [diff] [blame] | 1236 | def test_execute_lock_unknown_hosts(self): |
| 1237 | self.run_cmd(argv=['atest', 'host', 'mod', |
| 1238 | '-l', 'host0,host1', 'host2', '--ignore_site_file'], |
| 1239 | rpcs=[('modify_host', {'id': 'host2', 'locked': True}, |
| 1240 | True, None), |
| 1241 | ('modify_host', {'id': 'host1', 'locked': True}, |
| 1242 | False, 'DoesNotExist: Host matching ' |
| 1243 | 'query does not exist.'), |
| 1244 | ('modify_host', {'id': 'host0', 'locked': True}, |
| 1245 | True, None)], |
| 1246 | out_words_ok=['Locked', 'host0', 'host2'], |
| 1247 | err_words_ok=['Host', 'matching', 'query', 'host1']) |
| 1248 | |
| 1249 | |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1250 | def test_execute_protection_hosts(self): |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1251 | mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4') |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1252 | self.run_cmd(argv=['atest', 'host', 'mod', '--protection', |
| 1253 | 'Do not repair', |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 1254 | 'host5' ,'--mlist', mfile.name, 'host1', 'host6', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1255 | '--ignore_site_file'], |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1256 | rpcs=[('modify_host', {'id': 'host6', |
| 1257 | 'protection': 'Do not repair'}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1258 | True, None), |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1259 | ('modify_host', {'id': 'host5', |
| 1260 | 'protection': 'Do not repair'}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1261 | True, None), |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1262 | ('modify_host', {'id': 'host4', |
| 1263 | 'protection': 'Do not repair'}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1264 | True, None), |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1265 | ('modify_host', {'id': 'host3', |
| 1266 | 'protection': 'Do not repair'}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1267 | True, None), |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1268 | ('modify_host', {'id': 'host2', |
| 1269 | 'protection': 'Do not repair'}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1270 | True, None), |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1271 | ('modify_host', {'id': 'host1', |
| 1272 | 'protection': 'Do not repair'}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1273 | True, None), |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1274 | ('modify_host', {'id': 'host0', |
| 1275 | 'protection': 'Do not repair'}, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1276 | True, None)], |
showard | be0d869 | 2009-08-20 23:42:44 +0000 | [diff] [blame] | 1277 | out_words_ok=['Do not repair', 'host0', 'host1', 'host2', |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1278 | 'host3', 'host4', 'host5', 'host6']) |
mbligh | 4151539 | 2009-07-11 00:13:11 +0000 | [diff] [blame] | 1279 | mfile.clean() |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1280 | |
| 1281 | |
| 1282 | |
| 1283 | class host_create_unittest(cli_mock.cli_unittest): |
| 1284 | def test_execute_create_muliple_hosts_all_options(self): |
| 1285 | self.run_cmd(argv=['atest', 'host', 'create', '--lock', |
| 1286 | '-b', 'label0', '--acls', 'acl0', 'host0', 'host1', |
| 1287 | '--ignore_site_file'], |
| 1288 | rpcs=[('get_labels', {'name': 'label0'}, |
| 1289 | True, |
| 1290 | [{u'id': 4, |
| 1291 | u'platform': 0, |
| 1292 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1293 | u'invalid': False, |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1294 | u'kernel_config': u''}]), |
| 1295 | ('get_acl_groups', {'name': 'acl0'}, |
| 1296 | True, []), |
| 1297 | ('add_acl_group', {'name': 'acl0'}, |
| 1298 | True, 5), |
| 1299 | ('add_host', {'hostname': 'host1', |
| 1300 | 'status': 'Ready', |
| 1301 | 'locked': True}, |
| 1302 | True, 42), |
| 1303 | ('host_add_labels', {'id': 'host1', |
| 1304 | 'labels': ['label0']}, |
| 1305 | True, None), |
| 1306 | ('add_host', {'hostname': 'host0', |
| 1307 | 'status': 'Ready', |
| 1308 | 'locked': True}, |
| 1309 | True, 42), |
| 1310 | ('host_add_labels', {'id': 'host0', |
| 1311 | 'labels': ['label0']}, |
| 1312 | True, None), |
| 1313 | ('acl_group_add_hosts', |
| 1314 | {'id': 'acl0', 'hosts': ['host1', 'host0']}, |
| 1315 | True, None)], |
| 1316 | out_words_ok=['host0', 'host1']) |
| 1317 | |
| 1318 | |
mbligh | 719e14a | 2008-12-04 01:17:08 +0000 | [diff] [blame] | 1319 | def test_execute_create_muliple_hosts_unlocked(self): |
| 1320 | self.run_cmd(argv=['atest', 'host', 'create', |
| 1321 | '-b', 'label0', '--acls', 'acl0', 'host0', 'host1', |
| 1322 | '--ignore_site_file'], |
| 1323 | rpcs=[('get_labels', {'name': 'label0'}, |
| 1324 | True, |
| 1325 | [{u'id': 4, |
| 1326 | u'platform': 0, |
| 1327 | u'name': u'label0', |
mbligh | 0887d40 | 2009-01-30 00:50:29 +0000 | [diff] [blame] | 1328 | u'invalid': False, |
mbligh | 719e14a | 2008-12-04 01:17:08 +0000 | [diff] [blame] | 1329 | u'kernel_config': u''}]), |
| 1330 | ('get_acl_groups', {'name': 'acl0'}, |
| 1331 | True, []), |
| 1332 | ('add_acl_group', {'name': 'acl0'}, |
| 1333 | True, 5), |
| 1334 | ('add_host', {'hostname': 'host1', |
| 1335 | 'status': 'Ready', |
| 1336 | 'locked': True}, |
| 1337 | True, 42), |
| 1338 | ('host_add_labels', {'id': 'host1', |
| 1339 | 'labels': ['label0']}, |
| 1340 | True, None), |
| 1341 | ('add_host', {'hostname': 'host0', |
| 1342 | 'status': 'Ready', |
| 1343 | 'locked': True}, |
| 1344 | True, 42), |
| 1345 | ('host_add_labels', {'id': 'host0', |
| 1346 | 'labels': ['label0']}, |
| 1347 | True, None), |
| 1348 | ('acl_group_add_hosts', |
| 1349 | {'id': 'acl0', 'hosts': ['host1', 'host0']}, |
| 1350 | True, None), |
| 1351 | ('modify_host', {'id': 'host1', 'locked': False}, |
| 1352 | True, None), |
| 1353 | ('modify_host', {'id': 'host0', 'locked': False}, |
| 1354 | True, None)], |
| 1355 | out_words_ok=['host0', 'host1']) |
| 1356 | |
| 1357 | |
jamesren | c286316 | 2010-07-12 21:20:51 +0000 | [diff] [blame] | 1358 | def test_execute_create_muliple_hosts_label_escaped_quotes(self): |
| 1359 | self.run_cmd(argv=['atest', 'host', 'create', |
| 1360 | '-b', 'label0,label\\,1,label\\,2', |
| 1361 | '--acls', 'acl0', 'host0', 'host1', |
| 1362 | '--ignore_site_file'], |
| 1363 | rpcs=[('get_labels', {'name': 'label0'}, |
| 1364 | True, |
| 1365 | [{u'id': 4, |
| 1366 | u'platform': 0, |
| 1367 | u'name': u'label0', |
| 1368 | u'invalid': False, |
| 1369 | u'kernel_config': u''}]), |
| 1370 | ('get_labels', {'name': 'label,1'}, |
| 1371 | True, |
| 1372 | [{u'id': 4, |
| 1373 | u'platform': 0, |
| 1374 | u'name': u'label,1', |
| 1375 | u'invalid': False, |
| 1376 | u'kernel_config': u''}]), |
| 1377 | ('get_labels', {'name': 'label,2'}, |
| 1378 | True, |
| 1379 | [{u'id': 4, |
| 1380 | u'platform': 0, |
| 1381 | u'name': u'label,2', |
| 1382 | u'invalid': False, |
| 1383 | u'kernel_config': u''}]), |
| 1384 | ('get_acl_groups', {'name': 'acl0'}, |
| 1385 | True, []), |
| 1386 | ('add_acl_group', {'name': 'acl0'}, |
| 1387 | True, 5), |
| 1388 | ('add_host', {'hostname': 'host1', |
| 1389 | 'status': 'Ready', |
| 1390 | 'locked': True}, |
| 1391 | True, 42), |
| 1392 | ('host_add_labels', {'id': 'host1', |
| 1393 | 'labels': ['label0', 'label,1', |
| 1394 | 'label,2']}, |
| 1395 | True, None), |
| 1396 | ('add_host', {'hostname': 'host0', |
| 1397 | 'status': 'Ready', |
| 1398 | 'locked': True}, |
| 1399 | True, 42), |
| 1400 | ('host_add_labels', {'id': 'host0', |
| 1401 | 'labels': ['label0', 'label,1', |
| 1402 | 'label,2']}, |
| 1403 | True, None), |
| 1404 | ('acl_group_add_hosts', |
| 1405 | {'id': 'acl0', 'hosts': ['host1', 'host0']}, |
| 1406 | True, None), |
| 1407 | ('modify_host', {'id': 'host1', 'locked': False}, |
| 1408 | True, None), |
| 1409 | ('modify_host', {'id': 'host0', 'locked': False}, |
| 1410 | True, None)], |
| 1411 | out_words_ok=['host0', 'host1']) |
| 1412 | |
| 1413 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1414 | if __name__ == '__main__': |
| 1415 | unittest.main() |