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