J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 6 | import collections |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 7 | import itertools |
J. Richard Barnette | f60a1ee | 2015-06-02 10:52:37 -0700 | [diff] [blame] | 8 | import logging |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 9 | import os |
| 10 | import unittest |
| 11 | |
| 12 | import common |
Aviv Keshet | 7ee9586 | 2016-08-30 15:18:27 -0700 | [diff] [blame] | 13 | from autotest_lib.server.lib import status_history |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 14 | from autotest_lib.site_utils import lab_inventory |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 15 | |
| 16 | |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 17 | class _FakeHost(object): |
| 18 | """Class to mock `Host` in _FakeHostHistory for testing.""" |
| 19 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 20 | def __init__(self, hostname): |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 21 | self.hostname = hostname |
| 22 | |
| 23 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 24 | class _FakeHostHistory(object): |
| 25 | """Class to mock `HostJobHistory` for testing.""" |
| 26 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 27 | def __init__(self, model, pool, status, hostname=''): |
| 28 | self.host_model = model |
| 29 | self.host_board = model + '_board' |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 30 | self.host_pool = pool |
| 31 | self.status = status |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 32 | self.host = _FakeHost(hostname) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 33 | |
| 34 | |
| 35 | def last_diagnosis(self): |
| 36 | """Return the recorded diagnosis.""" |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 37 | return self.status, None |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 38 | |
| 39 | |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 40 | class _FakeHostLocation(object): |
| 41 | """Class to mock `HostJobHistory` for location sorting.""" |
| 42 | |
| 43 | _HOSTNAME_FORMAT = 'chromeos%d-row%d-rack%d-host%d' |
| 44 | |
| 45 | |
| 46 | def __init__(self, location): |
| 47 | self.hostname = self._HOSTNAME_FORMAT % location |
| 48 | |
| 49 | |
| 50 | @property |
| 51 | def host(self): |
| 52 | """Return a fake host object with a hostname.""" |
| 53 | return self |
| 54 | |
| 55 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 56 | # Status values that may be returned by `HostJobHistory`. |
| 57 | # |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 58 | # These merely rename the corresponding values in `status_history` |
| 59 | # for convenience. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 60 | |
| 61 | _WORKING = status_history.WORKING |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 62 | _UNUSED = status_history.UNUSED |
| 63 | _BROKEN = status_history.BROKEN |
| 64 | _UNKNOWN = status_history.UNKNOWN |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 65 | |
| 66 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 67 | class HostSetInventoryTestCase(unittest.TestCase): |
| 68 | """Unit tests for class `_HostSetInventory`. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 69 | |
| 70 | Coverage is quite basic: mostly just enough to make sure every |
| 71 | function gets called, and to make sure that the counting knows |
| 72 | the difference between 0 and 1. |
| 73 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 74 | The testing also ensures that all known status values that can be |
| 75 | returned by `HostJobHistory` are counted as expected. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 76 | """ |
| 77 | |
| 78 | def setUp(self): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 79 | super(HostSetInventoryTestCase, self).setUp() |
| 80 | self.histories = lab_inventory._HostSetInventory() |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 81 | |
| 82 | |
| 83 | def _add_host(self, status): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 84 | fake = _FakeHostHistory('zebra', lab_inventory.SPARE_POOL, status) |
Prathmesh Prabhu | 0ecbf32 | 2017-11-08 17:04:24 -0800 | [diff] [blame] | 85 | self.histories.record_host(fake) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 86 | |
| 87 | |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 88 | def _check_counts(self, working, broken, idle): |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 89 | """Check that pool counts match expectations. |
| 90 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 91 | Asserts that `get_working()`, `get_broken()`, and `get_idle()` |
| 92 | return the given expected values. Also assert that |
| 93 | `get_total()` is the sum of all counts. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 94 | |
| 95 | @param working The expected total of working devices. |
| 96 | @param broken The expected total of broken devices. |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 97 | @param idle The expected total of idle devices. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 98 | """ |
Prathmesh Prabhu | 0ecbf32 | 2017-11-08 17:04:24 -0800 | [diff] [blame] | 99 | self.assertEqual(self.histories.get_working(), working) |
| 100 | self.assertEqual(self.histories.get_broken(), broken) |
| 101 | self.assertEqual(self.histories.get_idle(), idle) |
| 102 | self.assertEqual(self.histories.get_total(), |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 103 | working + broken + idle) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 104 | |
| 105 | |
| 106 | def test_empty(self): |
| 107 | """Test counts when there are no DUTs recorded.""" |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 108 | self._check_counts(0, 0, 0) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 109 | |
| 110 | |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 111 | def test_broken(self): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 112 | """Test counting for broken DUTs.""" |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 113 | self._add_host(_BROKEN) |
| 114 | self._check_counts(0, 1, 0) |
| 115 | |
| 116 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 117 | def test_working(self): |
| 118 | """Test counting for working DUTs.""" |
| 119 | self._add_host(_WORKING) |
| 120 | self._check_counts(1, 0, 0) |
| 121 | |
| 122 | |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 123 | def test_idle(self): |
| 124 | """Testing counting for idle status values.""" |
| 125 | self._add_host(_UNUSED) |
| 126 | self._check_counts(0, 0, 1) |
| 127 | self._add_host(_UNKNOWN) |
| 128 | self._check_counts(0, 0, 2) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 129 | |
| 130 | |
| 131 | def test_working_then_broken(self): |
| 132 | """Test counts after adding a working and then a broken DUT.""" |
| 133 | self._add_host(_WORKING) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 134 | self._add_host(_BROKEN) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 135 | self._check_counts(1, 1, 0) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 136 | |
| 137 | |
| 138 | def test_broken_then_working(self): |
| 139 | """Test counts after adding a broken and then a working DUT.""" |
| 140 | self._add_host(_BROKEN) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 141 | self._add_host(_WORKING) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 142 | self._check_counts(1, 1, 0) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 143 | |
| 144 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 145 | class PoolSetInventoryTestCase(unittest.TestCase): |
| 146 | """Unit tests for class `_PoolSetInventory`. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 147 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 148 | Coverage is quite basic: just enough to make sure every function |
| 149 | gets called, and to make sure that the counting knows the difference |
| 150 | between 0 and 1. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 151 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 152 | The tests make sure that both individual pool counts and totals are |
| 153 | counted correctly. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 154 | """ |
| 155 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 156 | _POOL_SET = ['humpty', 'dumpty'] |
| 157 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 158 | def setUp(self): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 159 | super(PoolSetInventoryTestCase, self).setUp() |
| 160 | self._pool_histories = lab_inventory._PoolSetInventory(self._POOL_SET) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 161 | |
| 162 | |
| 163 | def _add_host(self, pool, status): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 164 | fake = _FakeHostHistory('zebra', pool, status) |
| 165 | self._pool_histories.record_host(fake) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 166 | |
| 167 | |
| 168 | def _check_all_counts(self, working, broken): |
| 169 | """Check that total counts for all pools match expectations. |
| 170 | |
| 171 | Checks that `get_working()` and `get_broken()` return the |
| 172 | given expected values when called without a pool specified. |
| 173 | Also check that `get_total()` is the sum of working and |
| 174 | broken devices. |
| 175 | |
| 176 | Additionally, call the various functions for all the pools |
| 177 | individually, and confirm that the totals across pools match |
| 178 | the given expectations. |
| 179 | |
| 180 | @param working The expected total of working devices. |
| 181 | @param broken The expected total of broken devices. |
| 182 | |
| 183 | """ |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 184 | self.assertEqual(self._pool_histories.get_working(), working) |
| 185 | self.assertEqual(self._pool_histories.get_broken(), broken) |
| 186 | self.assertEqual(self._pool_histories.get_total(), |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 187 | working + broken) |
| 188 | count_working = 0 |
| 189 | count_broken = 0 |
| 190 | count_total = 0 |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 191 | for pool in self._POOL_SET: |
| 192 | count_working += self._pool_histories.get_working(pool) |
| 193 | count_broken += self._pool_histories.get_broken(pool) |
| 194 | count_total += self._pool_histories.get_total(pool) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 195 | self.assertEqual(count_working, working) |
| 196 | self.assertEqual(count_broken, broken) |
| 197 | self.assertEqual(count_total, working + broken) |
| 198 | |
| 199 | |
| 200 | def _check_pool_counts(self, pool, working, broken): |
| 201 | """Check that counts for a given pool match expectations. |
| 202 | |
| 203 | Checks that `get_working()` and `get_broken()` return the |
| 204 | given expected values for the given pool. Also check that |
| 205 | `get_total()` is the sum of working and broken devices. |
| 206 | |
| 207 | @param pool The pool to be checked. |
| 208 | @param working The expected total of working devices. |
| 209 | @param broken The expected total of broken devices. |
| 210 | |
| 211 | """ |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 212 | self.assertEqual(self._pool_histories.get_working(pool), |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 213 | working) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 214 | self.assertEqual(self._pool_histories.get_broken(pool), |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 215 | broken) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 216 | self.assertEqual(self._pool_histories.get_total(pool), |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 217 | working + broken) |
| 218 | |
| 219 | |
| 220 | def test_empty(self): |
| 221 | """Test counts when there are no DUTs recorded.""" |
| 222 | self._check_all_counts(0, 0) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 223 | for pool in self._POOL_SET: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 224 | self._check_pool_counts(pool, 0, 0) |
| 225 | |
| 226 | |
| 227 | def test_all_working_then_broken(self): |
| 228 | """Test counts after adding a working and then a broken DUT. |
| 229 | |
| 230 | For each pool, add first a working, then a broken DUT. After |
| 231 | each DUT is added, check counts to confirm the correct values. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 232 | """ |
| 233 | working = 0 |
| 234 | broken = 0 |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 235 | for pool in self._POOL_SET: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 236 | self._add_host(pool, _WORKING) |
| 237 | working += 1 |
| 238 | self._check_pool_counts(pool, 1, 0) |
| 239 | self._check_all_counts(working, broken) |
| 240 | self._add_host(pool, _BROKEN) |
| 241 | broken += 1 |
| 242 | self._check_pool_counts(pool, 1, 1) |
| 243 | self._check_all_counts(working, broken) |
| 244 | |
| 245 | |
| 246 | def test_all_broken_then_working(self): |
| 247 | """Test counts after adding a broken and then a working DUT. |
| 248 | |
| 249 | For each pool, add first a broken, then a working DUT. After |
| 250 | each DUT is added, check counts to confirm the correct values. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 251 | """ |
| 252 | working = 0 |
| 253 | broken = 0 |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 254 | for pool in self._POOL_SET: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 255 | self._add_host(pool, _BROKEN) |
| 256 | broken += 1 |
| 257 | self._check_pool_counts(pool, 0, 1) |
| 258 | self._check_all_counts(working, broken) |
| 259 | self._add_host(pool, _WORKING) |
| 260 | working += 1 |
| 261 | self._check_pool_counts(pool, 1, 1) |
| 262 | self._check_all_counts(working, broken) |
| 263 | |
| 264 | |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 265 | class LocationSortTests(unittest.TestCase): |
| 266 | """Unit tests for `_sort_by_location()`.""" |
| 267 | |
| 268 | def setUp(self): |
| 269 | super(LocationSortTests, self).setUp() |
| 270 | |
| 271 | |
| 272 | def _check_sorting(self, *locations): |
| 273 | """Test sorting a given list of locations. |
| 274 | |
| 275 | The input is an already ordered list of lists of tuples with |
| 276 | row, rack, and host numbers. The test converts the tuples |
| 277 | to hostnames, preserving the original ordering. Then it |
| 278 | flattens and scrambles the input, runs it through |
| 279 | `_sort_by_location()`, and asserts that the result matches |
| 280 | the original. |
| 281 | |
| 282 | """ |
| 283 | lab = 0 |
| 284 | expected = [] |
| 285 | for tuples in locations: |
| 286 | lab += 1 |
| 287 | expected.append( |
| 288 | [_FakeHostLocation((lab,) + t) for t in tuples]) |
| 289 | scrambled = [e for e in itertools.chain(*expected)] |
| 290 | scrambled = [e for e in reversed(scrambled)] |
| 291 | actual = lab_inventory._sort_by_location(scrambled) |
| 292 | # The ordering of the labs in the output isn't guaranteed, |
| 293 | # so we can't compare `expected` and `actual` directly. |
| 294 | # Instead, we create a dictionary keyed on the first host in |
| 295 | # each lab, and compare the dictionaries. |
| 296 | self.assertEqual({l[0]: l for l in expected}, |
| 297 | {l[0]: l for l in actual}) |
| 298 | |
| 299 | |
| 300 | def test_separate_labs(self): |
| 301 | """Test that sorting distinguishes labs.""" |
| 302 | self._check_sorting([(1, 1, 1)], [(1, 1, 1)], [(1, 1, 1)]) |
| 303 | |
| 304 | |
| 305 | def test_separate_rows(self): |
| 306 | """Test for proper sorting when only rows are different.""" |
| 307 | self._check_sorting([(1, 1, 1), (9, 1, 1), (10, 1, 1)]) |
| 308 | |
| 309 | |
| 310 | def test_separate_racks(self): |
| 311 | """Test for proper sorting when only racks are different.""" |
| 312 | self._check_sorting([(1, 1, 1), (1, 9, 1), (1, 10, 1)]) |
| 313 | |
| 314 | |
| 315 | def test_separate_hosts(self): |
| 316 | """Test for proper sorting when only hosts are different.""" |
| 317 | self._check_sorting([(1, 1, 1), (1, 1, 9), (1, 1, 10)]) |
| 318 | |
| 319 | |
| 320 | def test_diagonal(self): |
| 321 | """Test for proper sorting when all parts are different.""" |
| 322 | self._check_sorting([(1, 1, 2), (1, 2, 1), (2, 1, 1)]) |
| 323 | |
| 324 | |
| 325 | class InventoryScoringTests(unittest.TestCase): |
| 326 | """Unit tests for `_score_repair_set()`.""" |
| 327 | |
| 328 | def setUp(self): |
| 329 | super(InventoryScoringTests, self).setUp() |
| 330 | |
| 331 | |
| 332 | def _make_buffer_counts(self, *counts): |
| 333 | """Create a dictionary suitable as `buffer_counts`. |
| 334 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 335 | @param counts List of tuples with model count data. |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 336 | """ |
| 337 | self._buffer_counts = dict(counts) |
| 338 | |
| 339 | |
| 340 | def _make_history_list(self, repair_counts): |
| 341 | """Create a list suitable as `repair_list`. |
| 342 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 343 | @param repair_counts List of (model, count) tuples. |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 344 | """ |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 345 | pool = lab_inventory.SPARE_POOL |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 346 | histories = [] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 347 | for model, count in repair_counts: |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 348 | for i in range(0, count): |
| 349 | histories.append( |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 350 | _FakeHostHistory(model, pool, _BROKEN)) |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 351 | return histories |
| 352 | |
| 353 | |
| 354 | def _check_better(self, repair_a, repair_b): |
| 355 | """Test that repair set A scores better than B. |
| 356 | |
| 357 | Contruct repair sets from `repair_a` and `repair_b`, |
| 358 | and score both of them using the pre-existing |
| 359 | `self._buffer_counts`. Assert that the score for A is |
| 360 | better than the score for B. |
| 361 | |
| 362 | @param repair_a Input data for repair set A |
| 363 | @param repair_b Input data for repair set B |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 364 | """ |
| 365 | score_a = lab_inventory._score_repair_set( |
| 366 | self._buffer_counts, |
| 367 | self._make_history_list(repair_a)) |
| 368 | score_b = lab_inventory._score_repair_set( |
| 369 | self._buffer_counts, |
| 370 | self._make_history_list(repair_b)) |
| 371 | self.assertGreater(score_a, score_b) |
| 372 | |
| 373 | |
| 374 | def _check_equal(self, repair_a, repair_b): |
| 375 | """Test that repair set A scores the same as B. |
| 376 | |
| 377 | Contruct repair sets from `repair_a` and `repair_b`, |
| 378 | and score both of them using the pre-existing |
| 379 | `self._buffer_counts`. Assert that the score for A is |
| 380 | equal to the score for B. |
| 381 | |
| 382 | @param repair_a Input data for repair set A |
| 383 | @param repair_b Input data for repair set B |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 384 | """ |
| 385 | score_a = lab_inventory._score_repair_set( |
| 386 | self._buffer_counts, |
| 387 | self._make_history_list(repair_a)) |
| 388 | score_b = lab_inventory._score_repair_set( |
| 389 | self._buffer_counts, |
| 390 | self._make_history_list(repair_b)) |
| 391 | self.assertEqual(score_a, score_b) |
| 392 | |
| 393 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 394 | def test_improve_worst_model(self): |
| 395 | """Test that improving the worst model improves scoring. |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 396 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 397 | Construct a buffer counts dictionary with all models having |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 398 | different counts. Assert that it is both necessary and |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 399 | sufficient to improve the count of the worst model in order |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 400 | to improve the score. |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 401 | """ |
| 402 | self._make_buffer_counts(('lion', 0), |
| 403 | ('tiger', 1), |
| 404 | ('bear', 2)) |
| 405 | self._check_better([('lion', 1)], [('tiger', 1)]) |
| 406 | self._check_better([('lion', 1)], [('bear', 1)]) |
| 407 | self._check_better([('lion', 1)], [('tiger', 2)]) |
| 408 | self._check_better([('lion', 1)], [('bear', 2)]) |
| 409 | self._check_equal([('tiger', 1)], [('bear', 1)]) |
| 410 | |
| 411 | |
| 412 | def test_improve_worst_case_count(self): |
| 413 | """Test that improving the number of worst cases improves the score. |
| 414 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 415 | Construct a buffer counts dictionary with all models having |
| 416 | the same counts. Assert that improving two models is better |
| 417 | than improving one. Assert that improving any one model is |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 418 | as good as any other. |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 419 | """ |
| 420 | self._make_buffer_counts(('lion', 0), |
| 421 | ('tiger', 0), |
| 422 | ('bear', 0)) |
| 423 | self._check_better([('lion', 1), ('tiger', 1)], [('bear', 2)]) |
| 424 | self._check_equal([('lion', 2)], [('tiger', 1)]) |
| 425 | self._check_equal([('tiger', 1)], [('bear', 1)]) |
| 426 | |
| 427 | |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 428 | # Each item is the number of DUTs in that status. |
| 429 | STATUS_CHOICES = (_WORKING, _BROKEN, _UNUSED) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 430 | StatusCounts = collections.namedtuple('StatusCounts', ['good', 'bad', 'idle']) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 431 | # Each item is a StatusCounts tuple specifying the number of DUTs per status in |
| 432 | # the that pool. |
| 433 | CRITICAL_POOL = lab_inventory.CRITICAL_POOLS[0] |
| 434 | SPARE_POOL = lab_inventory.SPARE_POOL |
| 435 | POOL_CHOICES = (CRITICAL_POOL, SPARE_POOL) |
| 436 | PoolStatusCounts = collections.namedtuple('PoolStatusCounts', |
| 437 | ['critical', 'spare']) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 438 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 439 | def create_inventory(data): |
| 440 | """Create a `_LabInventory` instance for testing. |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 441 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 442 | This function allows the construction of a complete `_LabInventory` |
| 443 | object from a simplified input representation. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 444 | |
| 445 | A single 'critical pool' is arbitrarily chosen for purposes of |
| 446 | testing; there's no coverage for testing arbitrary combinations |
| 447 | in more than one critical pool. |
| 448 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 449 | @param data: dict {key: PoolStatusCounts}. |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 450 | @returns: lab_inventory._LabInventory object. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 451 | """ |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 452 | histories = [] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 453 | for model, counts in data.iteritems(): |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 454 | for p, pool in enumerate(POOL_CHOICES): |
| 455 | for s, status in enumerate(STATUS_CHOICES): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 456 | fake_host = _FakeHostHistory(model, pool, status) |
| 457 | histories.extend([fake_host] * counts[p][s]) |
| 458 | inventory = lab_inventory._LabInventory( |
| 459 | histories, lab_inventory.MANAGED_POOLS) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 460 | return inventory |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 461 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 462 | |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 463 | class LabInventoryTests(unittest.TestCase): |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 464 | """Tests for the basic functions of `_LabInventory`. |
| 465 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 466 | Contains basic coverage to show that after an inventory is created |
| 467 | and DUTs with known status are added, the inventory counts match the |
| 468 | counts of the added DUTs. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 469 | """ |
| 470 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 471 | _MODEL_LIST = ['lion', 'tiger', 'bear'] # Oh, my! |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 472 | |
J. Richard Barnette | f683928 | 2015-06-01 16:00:35 -0700 | [diff] [blame] | 473 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 474 | def _check_inventory_counts(self, inventory, data, msg=None): |
| 475 | """Check that all counts in the inventory match `data`. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 476 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 477 | This asserts that the actual counts returned by the various |
| 478 | accessor functions for `inventory` match the values expected for |
| 479 | the given `data` that created the inventory. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 480 | |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 481 | @param inventory: _LabInventory object to check. |
| 482 | @param data Inventory data to check against. Same type as |
| 483 | `create_inventory`. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 484 | """ |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 485 | self.assertEqual(set(inventory.keys()), set(data.keys())) |
| 486 | for model, histories in inventory.iteritems(): |
| 487 | expected_counts = data[model] |
| 488 | actual_counts = PoolStatusCounts( |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 489 | StatusCounts( |
| 490 | histories.get_working(CRITICAL_POOL), |
| 491 | histories.get_broken(CRITICAL_POOL), |
| 492 | histories.get_idle(CRITICAL_POOL), |
| 493 | ), |
| 494 | StatusCounts( |
| 495 | histories.get_working(SPARE_POOL), |
| 496 | histories.get_broken(SPARE_POOL), |
| 497 | histories.get_idle(SPARE_POOL), |
| 498 | ), |
| 499 | ) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 500 | self.assertEqual(actual_counts, expected_counts, msg) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 501 | |
| 502 | self.assertEqual(len(histories.get_working_list()), |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 503 | sum([p.good for p in expected_counts]), |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 504 | msg) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 505 | self.assertEqual(len(histories.get_broken_list()), |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 506 | sum([p.bad for p in expected_counts]), |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 507 | msg) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 508 | self.assertEqual(len(histories.get_idle_list()), |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 509 | sum([p.idle for p in expected_counts]), |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 510 | msg) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 511 | |
| 512 | |
| 513 | def test_empty(self): |
| 514 | """Test counts when there are no DUTs recorded.""" |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 515 | inventory = create_inventory({}) |
| 516 | self.assertEqual(inventory.get_num_duts(), 0) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 517 | self.assertEqual(inventory.get_boards(), set()) |
| 518 | self._check_inventory_counts(inventory, {}) |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 519 | self.assertEqual(inventory.get_num_models(), 0) |
J. Richard Barnette | 6948ed3 | 2015-05-06 08:57:10 -0700 | [diff] [blame] | 520 | |
| 521 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 522 | def _check_model_count(self, model_count): |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 523 | """Parameterized test for testing a specific number of models.""" |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 524 | msg = '[model: %d]' % (model_count,) |
| 525 | models = self._MODEL_LIST[:model_count] |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 526 | data = { |
| 527 | m: PoolStatusCounts( |
| 528 | StatusCounts(1, 1, 1), |
| 529 | StatusCounts(1, 1, 1), |
| 530 | ) |
| 531 | for m in models |
| 532 | } |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 533 | inventory = create_inventory(data) |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 534 | self.assertEqual(inventory.get_num_duts(), 6 * model_count, msg) |
| 535 | self.assertEqual(inventory.get_num_models(), model_count, msg) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 536 | for pool in [CRITICAL_POOL, SPARE_POOL]: |
| 537 | self.assertEqual(set(inventory.get_pool_models(pool)), |
| 538 | set(models)) |
| 539 | self._check_inventory_counts(inventory, data, msg=msg) |
| 540 | |
| 541 | |
| 542 | def test_model_counts(self): |
| 543 | """Test counts for various numbers of models.""" |
| 544 | self.longMessage = True |
| 545 | for model_count in range(0, len(self._MODEL_LIST)): |
| 546 | self._check_model_count(model_count) |
| 547 | |
| 548 | |
| 549 | def _check_single_dut_counts(self, critical, spare): |
| 550 | """Parmeterized test for single dut counts.""" |
| 551 | self.longMessage = True |
| 552 | counts = PoolStatusCounts(critical, spare) |
| 553 | model = self._MODEL_LIST[0] |
| 554 | data = {model: counts} |
| 555 | msg = '[data: %s]' % (data,) |
| 556 | inventory = create_inventory(data) |
| 557 | self.assertEqual(inventory.get_num_duts(), 1, msg) |
| 558 | self.assertEqual(inventory.get_num_models(), 1, msg) |
| 559 | self._check_inventory_counts(inventory, data, msg=msg) |
Prathmesh Prabhu | a5a0e3d | 2017-11-09 08:53:53 -0800 | [diff] [blame] | 560 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 561 | |
| 562 | def test_single_dut_counts(self): |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 563 | """Test counts when there is a single DUT per board, and it is good.""" |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 564 | status_100 = StatusCounts(1, 0, 0) |
| 565 | status_010 = StatusCounts(0, 1, 0) |
| 566 | status_001 = StatusCounts(0, 0, 1) |
| 567 | status_null = StatusCounts(0, 0, 0) |
| 568 | self._check_single_dut_counts(status_100, status_null) |
| 569 | self._check_single_dut_counts(status_010, status_null) |
| 570 | self._check_single_dut_counts(status_001, status_null) |
| 571 | self._check_single_dut_counts(status_null, status_100) |
| 572 | self._check_single_dut_counts(status_null, status_010) |
| 573 | self._check_single_dut_counts(status_null, status_001) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 574 | |
| 575 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 576 | # MODEL_MESSAGE_TEMPLATE - |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 577 | # This is a sample of the output text produced by |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 578 | # _generate_model_inventory_message(). This string is parsed by the |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 579 | # tests below to construct a sample inventory that should produce |
| 580 | # the output, and then the output is generated and checked against |
| 581 | # this original sample. |
| 582 | # |
| 583 | # Constructing inventories from parsed sample text serves two |
| 584 | # related purposes: |
| 585 | # - It provides a way to see what the output should look like |
| 586 | # without having to run the script. |
| 587 | # - It helps make sure that a human being will actually look at |
| 588 | # the output to see that it's basically readable. |
| 589 | # This should also help prevent test bugs caused by writing tests |
| 590 | # that simply parrot the original output generation code. |
| 591 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 592 | _MODEL_MESSAGE_TEMPLATE = ''' |
| 593 | Model Avail Bad Idle Good Spare Total |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 594 | lion -1 13 2 11 12 26 |
| 595 | tiger -1 5 2 9 4 16 |
| 596 | bear 0 5 2 10 5 17 |
| 597 | platypus 4 2 2 20 6 24 |
| 598 | aardvark 7 2 2 6 9 10 |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 599 | ''' |
| 600 | |
| 601 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 602 | class PoolSetInventoryTests(unittest.TestCase): |
| 603 | """Tests for `_generate_model_inventory_message()`. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 604 | |
| 605 | The tests create various test inventories designed to match the |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 606 | counts in `_MODEL_MESSAGE_TEMPLATE`, and asserts that the |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 607 | generated message text matches the original message text. |
| 608 | |
| 609 | Message text is represented as a list of strings, split on the |
| 610 | `'\n'` separator. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 611 | """ |
| 612 | |
| 613 | def setUp(self): |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 614 | self.maxDiff = None |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 615 | lines = [x.strip() for x in _MODEL_MESSAGE_TEMPLATE.split('\n') if |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 616 | x.strip()] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 617 | self._header, self._model_lines = lines[0], lines[1:] |
| 618 | self._model_data = [] |
| 619 | for l in self._model_lines: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 620 | items = l.split() |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 621 | model = items[0] |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 622 | bad, idle, good, spare = [int(x) for x in items[2:-1]] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 623 | self._model_data.append((model, (good, bad, idle, spare))) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 624 | |
| 625 | |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 626 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 627 | def _make_minimum_spares(self, counts): |
| 628 | """Create a counts tuple with as few spare DUTs as possible.""" |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 629 | good, bad, idle, spares = counts |
| 630 | if spares > bad + idle: |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 631 | return PoolStatusCounts( |
| 632 | StatusCounts(good + bad +idle - spares, 0, 0), |
| 633 | StatusCounts(spares - bad - idle, bad, idle), |
| 634 | ) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 635 | elif spares < bad: |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 636 | return PoolStatusCounts( |
| 637 | StatusCounts(good, bad - spares, idle), |
| 638 | StatusCounts(0, spares, 0), |
| 639 | ) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 640 | else: |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 641 | return PoolStatusCounts( |
| 642 | StatusCounts(good, 0, idle + bad - spares), |
| 643 | StatusCounts(0, bad, spares - bad), |
| 644 | ) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 645 | |
| 646 | |
| 647 | def _make_maximum_spares(self, counts): |
| 648 | """Create a counts tuple with as many spare DUTs as possible.""" |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 649 | good, bad, idle, spares = counts |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 650 | if good > spares: |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 651 | return PoolStatusCounts( |
| 652 | StatusCounts(good - spares, bad, idle), |
| 653 | StatusCounts(spares, 0, 0), |
| 654 | ) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 655 | elif good + bad > spares: |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 656 | return PoolStatusCounts( |
| 657 | StatusCounts(0, good + bad - spares, idle), |
| 658 | StatusCounts(good, spares - good, 0), |
| 659 | ) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 660 | else: |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 661 | return PoolStatusCounts( |
| 662 | StatusCounts(0, 0, good + bad + idle - spares), |
| 663 | StatusCounts(good, bad, spares - good - bad), |
| 664 | ) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 665 | |
| 666 | |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 667 | def _check_message(self, message): |
| 668 | """Checks that message approximately matches expected string.""" |
| 669 | message = [x.strip() for x in message.split('\n') if x.strip()] |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 670 | self.assertIn(self._header, message) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 671 | body = message[message.index(self._header) + 1:] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 672 | self.assertEqual(body, self._model_lines) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 673 | |
| 674 | |
| 675 | def test_minimum_spares(self): |
| 676 | """Test message generation when the spares pool is low.""" |
| 677 | data = { |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 678 | model: self._make_minimum_spares(counts) |
| 679 | for model, counts in self._model_data |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 680 | } |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 681 | inventory = create_inventory(data) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 682 | message = lab_inventory._generate_model_inventory_message(inventory) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 683 | self._check_message(message) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 684 | |
| 685 | def test_maximum_spares(self): |
| 686 | """Test message generation when the critical pool is low.""" |
| 687 | data = { |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 688 | model: self._make_maximum_spares(counts) |
| 689 | for model, counts in self._model_data |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 690 | } |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 691 | inventory = create_inventory(data) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 692 | message = lab_inventory._generate_model_inventory_message(inventory) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 693 | self._check_message(message) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 694 | |
| 695 | |
| 696 | def test_ignore_no_spares(self): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 697 | """Test that messages ignore models with no spare pool.""" |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 698 | data = { |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 699 | model: self._make_maximum_spares(counts) |
| 700 | for model, counts in self._model_data |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 701 | } |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 702 | data['elephant'] = ((5, 4, 0), (0, 0, 0)) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 703 | inventory = create_inventory(data) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 704 | message = lab_inventory._generate_model_inventory_message(inventory) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 705 | self._check_message(message) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 706 | |
| 707 | |
| 708 | def test_ignore_no_critical(self): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 709 | """Test that messages ignore models with no critical pools.""" |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 710 | data = { |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 711 | model: self._make_maximum_spares(counts) |
| 712 | for model, counts in self._model_data |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 713 | } |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 714 | data['elephant'] = ((0, 0, 0), (1, 5, 1)) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 715 | inventory = create_inventory(data) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 716 | message = lab_inventory._generate_model_inventory_message(inventory) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 717 | self._check_message(message) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 718 | |
| 719 | |
J. Richard Barnette | ea5a4ba | 2016-02-18 16:34:50 -0800 | [diff] [blame] | 720 | def test_ignore_no_bad(self): |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 721 | """Test that messages ignore models with no bad DUTs.""" |
J. Richard Barnette | ea5a4ba | 2016-02-18 16:34:50 -0800 | [diff] [blame] | 722 | data = { |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 723 | model: self._make_maximum_spares(counts) |
| 724 | for model, counts in self._model_data |
J. Richard Barnette | ea5a4ba | 2016-02-18 16:34:50 -0800 | [diff] [blame] | 725 | } |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 726 | data['elephant'] = ((5, 0, 1), (5, 0, 1)) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 727 | inventory = create_inventory(data) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 728 | message = lab_inventory._generate_model_inventory_message(inventory) |
Prathmesh Prabhu | 58aede8 | 2017-11-09 13:34:25 -0800 | [diff] [blame] | 729 | self._check_message(message) |
J. Richard Barnette | ea5a4ba | 2016-02-18 16:34:50 -0800 | [diff] [blame] | 730 | |
| 731 | |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 732 | class _PoolInventoryTestBase(unittest.TestCase): |
| 733 | """Parent class for tests relating to generating pool inventory messages. |
| 734 | |
| 735 | Func `setUp` in the class parses a given |message_template| to obtain |
| 736 | header and body. |
| 737 | """ |
| 738 | def _read_template(self, message_template): |
| 739 | """Read message template for PoolInventoryTest and IdleInventoryTest. |
| 740 | |
| 741 | @param message_template: the input template to be parsed into: header |
| 742 | and content (report_lines). |
| 743 | |
| 744 | """ |
| 745 | message_lines = message_template.split('\n') |
| 746 | self._header = message_lines[1] |
| 747 | self._report_lines = message_lines[2:-1] |
| 748 | |
| 749 | |
| 750 | def _check_report_no_info(self, text): |
| 751 | """Test a message body containing no reported info. |
| 752 | |
| 753 | The input `text` was created from a query to an inventory, which has |
| 754 | no objects meet the query and leads to an `empty` return. Assert that |
| 755 | the text consists of a single line starting with '(' and ending with ')'. |
| 756 | |
| 757 | @param text: Message body text to be tested. |
| 758 | |
| 759 | """ |
| 760 | self.assertTrue(len(text) == 1 and |
| 761 | text[0][0] == '(' and |
| 762 | text[0][-1] == ')') |
| 763 | |
| 764 | |
| 765 | def _check_report(self, text): |
| 766 | """Test a message against the passed |expected_content|. |
| 767 | |
| 768 | @param text: Message body text to be tested. |
| 769 | @param expected_content: The ground-truth content to be compared with. |
| 770 | |
| 771 | """ |
| 772 | self.assertEqual(text, self._report_lines) |
| 773 | |
| 774 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 775 | # _POOL_MESSAGE_TEMPLATE - |
| 776 | # This is a sample of the output text produced by |
| 777 | # _generate_pool_inventory_message(). This string is parsed by the |
| 778 | # tests below to construct a sample inventory that should produce |
| 779 | # the output, and then the output is generated and checked against |
| 780 | # this original sample. |
| 781 | # |
| 782 | # See the comments on _BOARD_MESSAGE_TEMPLATE above for the |
| 783 | # rationale on using sample text in this way. |
| 784 | |
| 785 | _POOL_MESSAGE_TEMPLATE = ''' |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 786 | Model Bad Idle Good Total |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 787 | lion 5 2 6 13 |
| 788 | tiger 4 1 5 10 |
| 789 | bear 3 0 7 10 |
| 790 | aardvark 2 0 0 2 |
| 791 | platypus 1 1 1 3 |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 792 | ''' |
| 793 | |
J. Richard Barnette | 4845fcf | 2015-04-20 14:26:25 -0700 | [diff] [blame] | 794 | _POOL_ADMIN_URL = 'http://go/cros-manage-duts' |
| 795 | |
| 796 | |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 797 | class PoolInventoryTests(_PoolInventoryTestBase): |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 798 | """Tests for `_generate_pool_inventory_message()`. |
| 799 | |
| 800 | The tests create various test inventories designed to match the |
| 801 | counts in `_POOL_MESSAGE_TEMPLATE`, and assert that the |
| 802 | generated message text matches the format established in the |
| 803 | original message text. |
| 804 | |
| 805 | The output message text is parsed against the following grammar: |
J. Richard Barnette | 4845fcf | 2015-04-20 14:26:25 -0700 | [diff] [blame] | 806 | <message> -> <intro> <pool> { "blank line" <pool> } |
| 807 | <intro> -> |
| 808 | Instructions to depty mentioning the admin page URL |
| 809 | A blank line |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 810 | <pool> -> |
| 811 | <description> |
| 812 | <header line> |
| 813 | <message body> |
| 814 | <description> -> |
| 815 | Any number of lines describing one pool |
| 816 | <header line> -> |
| 817 | The header line from `_POOL_MESSAGE_TEMPLATE` |
| 818 | <message body> -> |
| 819 | Any number of non-blank lines |
| 820 | |
| 821 | After parsing messages into the parts described above, various |
| 822 | assertions are tested against the parsed output, including |
| 823 | that the message body matches the body from |
| 824 | `_POOL_MESSAGE_TEMPLATE`. |
| 825 | |
| 826 | Parse message text is represented as a list of strings, split on |
| 827 | the `'\n'` separator. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 828 | """ |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 829 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 830 | def setUp(self): |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 831 | super(PoolInventoryTests, self)._read_template(_POOL_MESSAGE_TEMPLATE) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 832 | self._model_data = [] |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 833 | for l in self._report_lines: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 834 | items = l.split() |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 835 | model = items[0] |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 836 | bad = int(items[1]) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 837 | idle = int(items[2]) |
| 838 | good = int(items[3]) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 839 | self._model_data.append((model, (good, bad, idle))) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 840 | |
| 841 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 842 | def _create_histories(self, pools, model_data): |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 843 | """Return a list suitable to create a `_LabInventory` object. |
| 844 | |
| 845 | Creates a list of `_FakeHostHistory` objects that can be |
| 846 | used to create a lab inventory. `pools` is a list of strings |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 847 | naming pools, and `model_data` is a list of tuples of the |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 848 | form |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 849 | `(model, (goodcount, badcount))` |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 850 | where |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 851 | `model` is a model name. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 852 | `goodcount` is the number of working DUTs in the pool. |
| 853 | `badcount` is the number of broken DUTs in the pool. |
| 854 | |
| 855 | @param pools List of pools for which to create |
| 856 | histories. |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 857 | @param model_data List of tuples containing models and DUT |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 858 | counts. |
| 859 | @return A list of `_FakeHostHistory` objects that can be |
| 860 | used to create a `_LabInventory` object. |
| 861 | |
| 862 | """ |
| 863 | histories = [] |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 864 | status_choices = (_WORKING, _BROKEN, _UNUSED) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 865 | for pool in pools: |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 866 | for model, counts in model_data: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 867 | for status, count in zip(status_choices, counts): |
| 868 | for x in range(0, count): |
| 869 | histories.append( |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 870 | _FakeHostHistory(model, pool, status)) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 871 | return histories |
| 872 | |
| 873 | |
| 874 | def _parse_pool_summaries(self, histories): |
| 875 | """Parse message output according to the grammar above. |
| 876 | |
| 877 | Create a lab inventory from the given `histories`, and |
| 878 | generate the pool inventory message. Then parse the message |
| 879 | and return a dictionary mapping each pool to the message |
| 880 | body parsed after that pool. |
| 881 | |
| 882 | Tests the following assertions: |
| 883 | * Each <description> contains a mention of exactly one |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 884 | pool in the `CRITICAL_POOLS` list. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 885 | * Each pool is mentioned in exactly one <description>. |
| 886 | Note that the grammar requires the header to appear once |
| 887 | for each pool, so the parsing implicitly asserts that the |
| 888 | output contains the header. |
| 889 | |
| 890 | @param histories Input used to create the test |
| 891 | `_LabInventory` object. |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 892 | @return A dictionary mapping model names to the output |
| 893 | (a list of lines) for the model. |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 894 | |
| 895 | """ |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 896 | inventory = lab_inventory._LabInventory( |
| 897 | histories, lab_inventory.MANAGED_POOLS) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 898 | message = lab_inventory._generate_pool_inventory_message( |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 899 | inventory).split('\n') |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 900 | poolset = set(lab_inventory.CRITICAL_POOLS) |
J. Richard Barnette | 4845fcf | 2015-04-20 14:26:25 -0700 | [diff] [blame] | 901 | seen_url = False |
| 902 | seen_intro = False |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 903 | description = '' |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 904 | model_text = {} |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 905 | current_pool = None |
| 906 | for line in message: |
J. Richard Barnette | 4845fcf | 2015-04-20 14:26:25 -0700 | [diff] [blame] | 907 | if not seen_url: |
| 908 | if _POOL_ADMIN_URL in line: |
| 909 | seen_url = True |
| 910 | elif not seen_intro: |
| 911 | if not line: |
| 912 | seen_intro = True |
| 913 | elif current_pool is None: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 914 | if line == self._header: |
| 915 | pools_mentioned = [p for p in poolset |
| 916 | if p in description] |
| 917 | self.assertEqual(len(pools_mentioned), 1) |
| 918 | current_pool = pools_mentioned[0] |
| 919 | description = '' |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 920 | model_text[current_pool] = [] |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 921 | poolset.remove(current_pool) |
| 922 | else: |
| 923 | description += line |
| 924 | else: |
| 925 | if line: |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 926 | model_text[current_pool].append(line) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 927 | else: |
| 928 | current_pool = None |
| 929 | self.assertEqual(len(poolset), 0) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 930 | return model_text |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 931 | |
| 932 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 933 | def test_no_shortages(self): |
| 934 | """Test correct output when no pools have shortages.""" |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 935 | model_text = self._parse_pool_summaries([]) |
| 936 | for text in model_text.values(): |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 937 | self._check_report_no_info(text) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 938 | |
| 939 | |
| 940 | def test_one_pool_shortage(self): |
| 941 | """Test correct output when exactly one pool has a shortage.""" |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 942 | for pool in lab_inventory.CRITICAL_POOLS: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 943 | histories = self._create_histories((pool,), |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 944 | self._model_data) |
| 945 | model_text = self._parse_pool_summaries(histories) |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 946 | for checkpool in lab_inventory.CRITICAL_POOLS: |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 947 | text = model_text[checkpool] |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 948 | if checkpool == pool: |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 949 | self._check_report(text) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 950 | else: |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 951 | self._check_report_no_info(text) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 952 | |
| 953 | |
| 954 | def test_all_pool_shortages(self): |
| 955 | """Test correct output when all pools have a shortage.""" |
| 956 | histories = [] |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 957 | for pool in lab_inventory.CRITICAL_POOLS: |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 958 | histories.extend( |
| 959 | self._create_histories((pool,), |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 960 | self._model_data)) |
| 961 | model_text = self._parse_pool_summaries(histories) |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 962 | for pool in lab_inventory.CRITICAL_POOLS: |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 963 | self._check_report(model_text[pool]) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 964 | |
| 965 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 966 | def test_full_model_ignored(self): |
| 967 | """Test that models at full strength are not reported.""" |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 968 | pool = lab_inventory.CRITICAL_POOLS[0] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 969 | full_model = [('echidna', (5, 0, 0))] |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 970 | histories = self._create_histories((pool,), |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 971 | full_model) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 972 | text = self._parse_pool_summaries(histories)[pool] |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 973 | self._check_report_no_info(text) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 974 | model_data = self._model_data + full_model |
| 975 | histories = self._create_histories((pool,), model_data) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 976 | text = self._parse_pool_summaries(histories)[pool] |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 977 | self._check_report(text) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 978 | |
| 979 | |
| 980 | def test_spare_pool_ignored(self): |
| 981 | """Test that reporting ignores the spare pool inventory.""" |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 982 | spare_pool = lab_inventory.SPARE_POOL |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 983 | spare_data = self._model_data + [('echidna', (0, 5, 0))] |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 984 | histories = self._create_histories((spare_pool,), |
| 985 | spare_data) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 986 | model_text = self._parse_pool_summaries(histories) |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 987 | for pool in lab_inventory.CRITICAL_POOLS: |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 988 | self._check_report_no_info(model_text[pool]) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 989 | |
| 990 | |
| 991 | _IDLE_MESSAGE_TEMPLATE = ''' |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 992 | Hostname Model Pool |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 993 | chromeos4-row12-rack4-host7 tiger bvt |
| 994 | chromeos1-row3-rack1-host2 lion bvt |
| 995 | chromeos3-row2-rack2-host5 lion cq |
| 996 | chromeos2-row7-rack3-host11 platypus suites |
| 997 | ''' |
| 998 | |
| 999 | |
| 1000 | class IdleInventoryTests(_PoolInventoryTestBase): |
| 1001 | """Tests for `_generate_idle_inventory_message()`. |
| 1002 | |
| 1003 | The tests create idle duts that match the counts and pool in |
| 1004 | `_IDLE_MESSAGE_TEMPLATE`. In test, it asserts that the generated |
| 1005 | idle message text matches the format established in |
| 1006 | `_IDLE_MESSAGE_TEMPLATE`. |
| 1007 | |
| 1008 | Parse message text is represented as a list of strings, split on |
| 1009 | the `'\n'` separator. |
| 1010 | |
| 1011 | """ |
| 1012 | |
| 1013 | def setUp(self): |
| 1014 | super(IdleInventoryTests, self)._read_template(_IDLE_MESSAGE_TEMPLATE) |
| 1015 | self._host_data = [] |
| 1016 | for h in self._report_lines: |
| 1017 | items = h.split() |
| 1018 | hostname = items[0] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1019 | model = items[1] |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 1020 | pool = items[2] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1021 | self._host_data.append((hostname, model, pool)) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 1022 | self._histories = [] |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1023 | self._histories.append(_FakeHostHistory('echidna', 'bvt', _BROKEN)) |
| 1024 | self._histories.append(_FakeHostHistory('lion', 'bvt', _WORKING)) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 1025 | |
| 1026 | |
| 1027 | def _add_idles(self): |
| 1028 | """Add idle duts from `_IDLE_MESSAGE_TEMPLATE`.""" |
| 1029 | idle_histories = [_FakeHostHistory( |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1030 | model, pool, _UNUSED, hostname) |
| 1031 | for hostname, model, pool in self._host_data] |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 1032 | self._histories.extend(idle_histories) |
| 1033 | |
| 1034 | |
| 1035 | def _check_header(self, text): |
| 1036 | """Check whether header in the template `_IDLE_MESSAGE_TEMPLATE` is in |
| 1037 | passed text.""" |
| 1038 | self.assertIn(self._header, text) |
| 1039 | |
| 1040 | |
| 1041 | def _get_idle_message(self, histories): |
| 1042 | """Generate idle inventory and obtain its message. |
| 1043 | |
| 1044 | @param histories: Used to create lab inventory. |
| 1045 | |
| 1046 | @return the generated idle message. |
| 1047 | |
| 1048 | """ |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1049 | inventory = lab_inventory._LabInventory( |
| 1050 | histories, lab_inventory.MANAGED_POOLS) |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 1051 | message = lab_inventory._generate_idle_inventory_message( |
| 1052 | inventory).split('\n') |
| 1053 | return message |
| 1054 | |
| 1055 | |
| 1056 | def test_check_idle_inventory(self): |
| 1057 | """Test that reporting all the idle DUTs for every pool, sorted by |
Kevin Cheng | cf0ad2b | 2016-04-19 14:51:39 -0700 | [diff] [blame] | 1058 | lab_inventory.MANAGED_POOLS. |
xixuan | 12ce04f | 2016-03-10 13:16:30 -0800 | [diff] [blame] | 1059 | """ |
| 1060 | self._add_idles() |
| 1061 | |
| 1062 | message = self._get_idle_message(self._histories) |
| 1063 | self._check_header(message) |
| 1064 | self._check_report(message[message.index(self._header) + 1 :]) |
| 1065 | |
| 1066 | |
| 1067 | def test_no_idle_inventory(self): |
| 1068 | """Test that reporting no idle DUTs.""" |
| 1069 | message = self._get_idle_message(self._histories) |
| 1070 | self._check_header(message) |
| 1071 | self._check_report_no_info( |
| 1072 | message[message.index(self._header) + 1 :]) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1073 | |
| 1074 | |
| 1075 | class CommandParsingTests(unittest.TestCase): |
| 1076 | """Tests for command line argument parsing in `_parse_command()`.""" |
| 1077 | |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1078 | # At least one of these options must be specified on every command |
| 1079 | # line; otherwise, the command line parsing will fail. |
Richard Barnette | 1ca30e6 | 2018-04-09 16:45:58 -0700 | [diff] [blame^] | 1080 | _REPORT_OPTIONS = [ |
| 1081 | '--model-notify=', '--pool-notify=', '--report-untestable' |
| 1082 | ] |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1083 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1084 | def setUp(self): |
| 1085 | dirpath = '/usr/local/fubar' |
| 1086 | self._command_path = os.path.join(dirpath, |
| 1087 | 'site_utils', |
| 1088 | 'arglebargle') |
| 1089 | self._logdir = os.path.join(dirpath, lab_inventory._LOGDIR) |
| 1090 | |
| 1091 | |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1092 | def _parse_arguments(self, argv): |
| 1093 | """Test parsing with explictly passed report options.""" |
| 1094 | full_argv = [self._command_path] + argv |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1095 | return lab_inventory._parse_command(full_argv) |
| 1096 | |
| 1097 | |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1098 | def _parse_non_report_arguments(self, argv): |
| 1099 | """Test parsing for non-report command-line options.""" |
| 1100 | return self._parse_arguments(argv + self._REPORT_OPTIONS) |
| 1101 | |
| 1102 | |
| 1103 | def _check_non_report_defaults(self, report_option): |
| 1104 | arguments = self._parse_arguments([report_option]) |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1105 | self.assertEqual(arguments.duration, |
| 1106 | lab_inventory._DEFAULT_DURATION) |
Richard Barnette | cf5d834 | 2017-10-24 18:13:11 -0700 | [diff] [blame] | 1107 | self.assertIsNone(arguments.recommend) |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1108 | self.assertFalse(arguments.debug) |
| 1109 | self.assertEqual(arguments.logdir, self._logdir) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1110 | self.assertEqual(arguments.modelnames, []) |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1111 | return arguments |
| 1112 | |
| 1113 | |
| 1114 | def test_empty_arguments(self): |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1115 | """Test that no reports requested is an error.""" |
| 1116 | arguments = self._parse_arguments([]) |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1117 | self.assertIsNone(arguments) |
| 1118 | |
| 1119 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1120 | def test_argument_defaults(self): |
| 1121 | """Test that option defaults match expectations.""" |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1122 | for report in self._REPORT_OPTIONS: |
| 1123 | arguments = self._check_non_report_defaults(report) |
| 1124 | |
| 1125 | |
| 1126 | def test_model_notify_defaults(self): |
| 1127 | """Test defaults when `--model-notify` is specified alone.""" |
| 1128 | arguments = self._parse_arguments(['--model-notify=']) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1129 | self.assertEqual(arguments.model_notify, ['']) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1130 | self.assertEqual(arguments.pool_notify, []) |
Richard Barnette | 1ca30e6 | 2018-04-09 16:45:58 -0700 | [diff] [blame^] | 1131 | self.assertFalse(arguments.report_untestable) |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1132 | |
| 1133 | |
| 1134 | def test_pool_notify_defaults(self): |
| 1135 | """Test defaults when `--pool-notify` is specified alone.""" |
| 1136 | arguments = self._parse_arguments(['--pool-notify=']) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1137 | self.assertEqual(arguments.model_notify, []) |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1138 | self.assertEqual(arguments.pool_notify, ['']) |
Richard Barnette | 1ca30e6 | 2018-04-09 16:45:58 -0700 | [diff] [blame^] | 1139 | self.assertFalse(arguments.report_untestable) |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1140 | |
| 1141 | |
Richard Barnette | 1ca30e6 | 2018-04-09 16:45:58 -0700 | [diff] [blame^] | 1142 | def test_report_untestable_defaults(self): |
| 1143 | """Test defaults when `--report-untestable` is specified alone.""" |
| 1144 | arguments = self._parse_arguments(['--report-untestable']) |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1145 | self.assertEqual(arguments.model_notify, []) |
| 1146 | self.assertEqual(arguments.pool_notify, []) |
Richard Barnette | 1ca30e6 | 2018-04-09 16:45:58 -0700 | [diff] [blame^] | 1147 | self.assertTrue(arguments.report_untestable) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1148 | |
| 1149 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1150 | def test_model_arguments(self): |
| 1151 | """Test that non-option arguments are returned in `modelnames`.""" |
| 1152 | modellist = ['aardvark', 'echidna'] |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1153 | arguments = self._parse_non_report_arguments(modellist) |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1154 | self.assertEqual(arguments.modelnames, modellist) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1155 | |
| 1156 | |
Richard Barnette | cf5d834 | 2017-10-24 18:13:11 -0700 | [diff] [blame] | 1157 | def test_recommend_option(self): |
| 1158 | """Test parsing of the `--recommend` option.""" |
| 1159 | for opt in ['-r', '--recommend']: |
| 1160 | for recommend in ['5', '55']: |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1161 | arguments = self._parse_non_report_arguments([opt, recommend]) |
Richard Barnette | cf5d834 | 2017-10-24 18:13:11 -0700 | [diff] [blame] | 1162 | self.assertEqual(arguments.recommend, int(recommend)) |
| 1163 | |
| 1164 | |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1165 | def test_debug_option(self): |
| 1166 | """Test parsing of the `--debug` option.""" |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1167 | arguments = self._parse_non_report_arguments(['--debug']) |
J. Richard Barnette | 02e8243 | 2015-10-13 16:02:47 -0700 | [diff] [blame] | 1168 | self.assertTrue(arguments.debug) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1169 | |
| 1170 | |
| 1171 | def test_duration(self): |
| 1172 | """Test parsing of the `--duration` option.""" |
Richard Barnette | cf5d834 | 2017-10-24 18:13:11 -0700 | [diff] [blame] | 1173 | for opt in ['-d', '--duration']: |
| 1174 | for duration in ['1', '11']: |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1175 | arguments = self._parse_non_report_arguments([opt, duration]) |
Richard Barnette | cf5d834 | 2017-10-24 18:13:11 -0700 | [diff] [blame] | 1176 | self.assertEqual(arguments.duration, int(duration)) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1177 | |
| 1178 | |
| 1179 | def _check_email_option(self, option, getlist): |
| 1180 | """Test parsing of e-mail address options. |
| 1181 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1182 | This is a helper function to test the `--model-notify` and |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1183 | `--pool-notify` options. It tests the following cases: |
| 1184 | * `--option a1` gives the list [a1] |
| 1185 | * `--option ' a1 '` gives the list [a1] |
| 1186 | * `--option a1 --option a2` gives the list [a1, a2] |
| 1187 | * `--option a1,a2` gives the list [a1, a2] |
| 1188 | * `--option 'a1, a2'` gives the list [a1, a2] |
| 1189 | |
| 1190 | @param option The option to be tested. |
| 1191 | @param getlist A function to return the option's value from |
| 1192 | parsed command line arguments. |
| 1193 | |
| 1194 | """ |
| 1195 | a1 = 'mumble@mumbler.com' |
| 1196 | a2 = 'bumble@bumbler.org' |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1197 | arguments = self._parse_arguments([option, a1]) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1198 | self.assertEqual(getlist(arguments), [a1]) |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1199 | arguments = self._parse_arguments([option, ' ' + a1 + ' ']) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1200 | self.assertEqual(getlist(arguments), [a1]) |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1201 | arguments = self._parse_arguments([option, a1, option, a2]) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1202 | self.assertEqual(getlist(arguments), [a1, a2]) |
| 1203 | arguments = self._parse_arguments( |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1204 | [option, ','.join([a1, a2])]) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1205 | self.assertEqual(getlist(arguments), [a1, a2]) |
| 1206 | arguments = self._parse_arguments( |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1207 | [option, ', '.join([a1, a2])]) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1208 | self.assertEqual(getlist(arguments), [a1, a2]) |
| 1209 | |
| 1210 | |
Richard Barnette | 5de01eb | 2017-12-15 09:53:42 -0800 | [diff] [blame] | 1211 | def test_model_notify(self): |
| 1212 | """Test parsing of the `--model-notify` option.""" |
| 1213 | self._check_email_option('--model-notify', |
| 1214 | lambda a: a.model_notify) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1215 | |
| 1216 | |
| 1217 | def test_pool_notify(self): |
| 1218 | """Test parsing of the `--pool-notify` option.""" |
| 1219 | self._check_email_option('--pool-notify', |
| 1220 | lambda a: a.pool_notify) |
| 1221 | |
| 1222 | |
Richard Barnette | cf5d834 | 2017-10-24 18:13:11 -0700 | [diff] [blame] | 1223 | def test_logdir_option(self): |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1224 | """Test parsing of the `--logdir` option.""" |
| 1225 | logdir = '/usr/local/whatsis/logs' |
Richard Barnette | 7bfcb03 | 2018-02-26 11:46:56 -0800 | [diff] [blame] | 1226 | arguments = self._parse_non_report_arguments(['--logdir', logdir]) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1227 | self.assertEqual(arguments.logdir, logdir) |
| 1228 | |
| 1229 | |
| 1230 | if __name__ == '__main__': |
J. Richard Barnette | f60a1ee | 2015-06-02 10:52:37 -0700 | [diff] [blame] | 1231 | # Some of the functions we test log messages. Prevent those |
| 1232 | # messages from showing up in test output. |
| 1233 | logging.getLogger().setLevel(logging.CRITICAL) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame] | 1234 | unittest.main() |