Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: appengine/swarming/server/bot_groups_config_test.py

Issue 2689483004: swarming: Add server-side implementation for supplemental bot_config (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The LUCI Authors. All rights reserved. 2 # Copyright 2016 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import logging 6 import logging
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 import test_env 10 import test_env
(...skipping 28 matching lines...) Expand all
39 dimensions=['pool:default']), 39 dimensions=['pool:default']),
40 ], 40 ],
41 ) 41 )
42 42
43 43
44 EXPECTED_GROUP_1 = bot_groups_config._make_bot_group_config( 44 EXPECTED_GROUP_1 = bot_groups_config._make_bot_group_config(
45 require_luci_machine_token=True, 45 require_luci_machine_token=True,
46 require_service_account=u'', 46 require_service_account=u'',
47 ip_whitelist=u'', 47 ip_whitelist=u'',
48 owners=(u'owner@example.com',), 48 owners=(u'owner@example.com',),
49 dimensions={u'pool': [u'A', u'B'], u'other': [u'D']}) 49 dimensions={u'pool': [u'A', u'B'], u'other': [u'D']},
50 bot_config_script='')
50 51
51 EXPECTED_GROUP_2 = bot_groups_config._make_bot_group_config( 52 EXPECTED_GROUP_2 = bot_groups_config._make_bot_group_config(
52 require_luci_machine_token=False, 53 require_luci_machine_token=False,
53 require_service_account=u'a@example.com', 54 require_service_account=u'a@example.com',
54 ip_whitelist=u'', 55 ip_whitelist=u'',
55 owners=(), 56 owners=(),
56 dimensions={u'pool': []}) 57 dimensions={u'pool': []},
58 bot_config_script='')
57 59
58 EXPECTED_GROUP_3 = bot_groups_config._make_bot_group_config( 60 EXPECTED_GROUP_3 = bot_groups_config._make_bot_group_config(
59 require_luci_machine_token=False, 61 require_luci_machine_token=False,
60 require_service_account=u'', 62 require_service_account=u'',
61 ip_whitelist=u'bots', 63 ip_whitelist=u'bots',
62 owners=(), 64 owners=(),
63 dimensions={u'pool': [u'default']}) 65 dimensions={u'pool': [u'default']},
66 bot_config_script='')
64 67
65 68
66 DEFAULT_AUTH_CFG = bots_pb2.BotAuth(ip_whitelist='bots') 69 DEFAULT_AUTH_CFG = bots_pb2.BotAuth(ip_whitelist='bots')
67 70
68 71
69 class BotGroupsConfigTest(test_case.TestCase): 72 class BotGroupsConfigTest(test_case.TestCase):
70 def validator_test(self, cfg, messages): 73 def validator_test(self, cfg, messages):
71 ctx = validation.Context() 74 ctx = validation.Context()
72 bot_groups_config.validate_settings(cfg, ctx) 75 bot_groups_config.validate_settings(cfg, ctx)
73 self.assertEquals(ctx.result().messages, [ 76 self.assertEquals(ctx.result().messages, [
74 validation.Message(severity=logging.ERROR, text=m) 77 validation.Message(severity=logging.ERROR, text=m)
75 for m in messages 78 for m in messages
76 ]) 79 ])
77 80
78 def mock_config(self, cfg): 81 def mock_config(self, cfg):
79 def get_self_config_mock(path, cls, **_kwargs): 82 def get_self_config_mock(path, cls, **_kwargs):
80 self.assertEquals('bots.cfg', path) 83 self.assertEquals('bots.cfg', path)
81 self.assertEquals(cls, bots_pb2.BotsCfg) 84 self.assertEquals(cls, bots_pb2.BotsCfg)
82 return None, cfg 85 return None, cfg
83 self.mock(config, 'get_self_config', get_self_config_mock) 86 self.mock(config, 'get_self_config', get_self_config_mock)
84 utils.clear_cache(bot_groups_config._fetch_bot_groups) 87 utils.clear_cache(bot_groups_config._fetch_bot_groups)
85 88
86 def test_version(self): 89 def test_version(self):
87 self.assertEqual('hash:4564ed4cc34544', EXPECTED_GROUP_1.version) 90 self.assertEqual('hash:ed9cb17d3d6552', EXPECTED_GROUP_1.version)
88 self.assertEqual('hash:18206c33fffaa8', EXPECTED_GROUP_2.version) 91 self.assertEqual('hash:73199bbf8cfe47', EXPECTED_GROUP_2.version)
89 92
90 def test_expand_bot_id_expr_success(self): 93 def test_expand_bot_id_expr_success(self):
91 def check(expected, expr): 94 def check(expected, expr):
92 self.assertEquals( 95 self.assertEquals(
93 expected, list(bot_groups_config._expand_bot_id_expr(expr))) 96 expected, list(bot_groups_config._expand_bot_id_expr(expr)))
94 check(['abc'], 'abc') 97 check(['abc'], 'abc')
95 check(['abc1def', 'abc2def'], 'abc{1,2}def') 98 check(['abc1def', 'abc2def'], 'abc{1,2}def')
96 check(['abc1def', 'abc2def', 'abc3def'], 'abc{1..3}def') 99 check(['abc1def', 'abc2def', 'abc3def'], 'abc{1..3}def')
97 100
98 def test_expand_bot_id_expr_fail(self): 101 def test_expand_bot_id_expr_fail(self):
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 'bot_group #0: machine_type #0: target_size must be positive' 435 'bot_group #0: machine_type #0: target_size must be positive'
433 ]) 436 ])
434 437
435 438
436 if __name__ == '__main__': 439 if __name__ == '__main__':
437 if '-v' in sys.argv: 440 if '-v' in sys.argv:
438 unittest.TestCase.maxDiff = None 441 unittest.TestCase.maxDiff = None
439 logging.basicConfig( 442 logging.basicConfig(
440 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) 443 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
441 unittest.main() 444 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698