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