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

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: Redone to actually work 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='',
51 bot_config_script_content='')
50 52
51 EXPECTED_GROUP_2 = bot_groups_config._make_bot_group_config( 53 EXPECTED_GROUP_2 = bot_groups_config._make_bot_group_config(
52 require_luci_machine_token=False, 54 require_luci_machine_token=False,
53 require_service_account=u'a@example.com', 55 require_service_account=u'a@example.com',
54 ip_whitelist=u'', 56 ip_whitelist=u'',
55 owners=(), 57 owners=(),
56 dimensions={u'pool': []}) 58 dimensions={u'pool': []},
59 bot_config_script='',
60 bot_config_script_content='')
57 61
58 EXPECTED_GROUP_3 = bot_groups_config._make_bot_group_config( 62 EXPECTED_GROUP_3 = bot_groups_config._make_bot_group_config(
59 require_luci_machine_token=False, 63 require_luci_machine_token=False,
60 require_service_account=u'', 64 require_service_account=u'',
61 ip_whitelist=u'bots', 65 ip_whitelist=u'bots',
62 owners=(), 66 owners=(),
63 dimensions={u'pool': [u'default']}) 67 dimensions={u'pool': [u'default']},
68 bot_config_script='',
69 bot_config_script_content='')
64 70
65 71
66 DEFAULT_AUTH_CFG = bots_pb2.BotAuth(ip_whitelist='bots') 72 DEFAULT_AUTH_CFG = bots_pb2.BotAuth(ip_whitelist='bots')
67 73
68 74
69 class BotGroupsConfigTest(test_case.TestCase): 75 class BotGroupsConfigTest(test_case.TestCase):
70 def validator_test(self, cfg, messages): 76 def validator_test(self, cfg, messages):
71 ctx = validation.Context() 77 ctx = validation.Context()
72 bot_groups_config.validate_settings(cfg, ctx) 78 bot_groups_config.validate_settings(cfg, ctx)
73 self.assertEquals(ctx.result().messages, [ 79 self.assertEquals(ctx.result().messages, [
74 validation.Message(severity=logging.ERROR, text=m) 80 validation.Message(severity=logging.ERROR, text=m)
75 for m in messages 81 for m in messages
76 ]) 82 ])
77 83
78 def mock_config(self, cfg): 84 def mock_config(self, cfg):
79 def get_self_config_mock(path, cls, **_kwargs): 85 def get_self_config_mock(path, cls, **_kwargs):
80 self.assertEquals('bots.cfg', path) 86 self.assertEquals('bots.cfg', path)
81 self.assertEquals(cls, bots_pb2.BotsCfg) 87 self.assertEquals(cls, bots_pb2.BotsCfg)
82 return None, cfg 88 return None, cfg
83 self.mock(config, 'get_self_config', get_self_config_mock) 89 self.mock(config, 'get_self_config', get_self_config_mock)
84 utils.clear_cache(bot_groups_config._fetch_bot_groups) 90 utils.clear_cache(bot_groups_config._fetch_bot_groups)
85 91
86 def test_version(self): 92 def test_version(self):
87 self.assertEqual('hash:4564ed4cc34544', EXPECTED_GROUP_1.version) 93 self.assertEqual('hash:be689c69320bcf', EXPECTED_GROUP_1.version)
88 self.assertEqual('hash:18206c33fffaa8', EXPECTED_GROUP_2.version) 94 self.assertEqual('hash:ebaa32cc494672', EXPECTED_GROUP_2.version)
89 95
90 def test_expand_bot_id_expr_success(self): 96 def test_expand_bot_id_expr_success(self):
91 def check(expected, expr): 97 def check(expected, expr):
92 self.assertEquals( 98 self.assertEquals(
93 expected, list(bot_groups_config._expand_bot_id_expr(expr))) 99 expected, list(bot_groups_config._expand_bot_id_expr(expr)))
94 check(['abc'], 'abc') 100 check(['abc'], 'abc')
95 check(['abc1def', 'abc2def'], 'abc{1,2}def') 101 check(['abc1def', 'abc2def'], 'abc{1,2}def')
96 check(['abc1def', 'abc2def', 'abc3def'], 'abc{1..3}def') 102 check(['abc1def', 'abc2def', 'abc3def'], 'abc{1..3}def')
97 103
98 def test_expand_bot_id_expr_fail(self): 104 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' 438 'bot_group #0: machine_type #0: target_size must be positive'
433 ]) 439 ])
434 440
435 441
436 if __name__ == '__main__': 442 if __name__ == '__main__':
437 if '-v' in sys.argv: 443 if '-v' in sys.argv:
438 unittest.TestCase.maxDiff = None 444 unittest.TestCase.maxDiff = None
439 logging.basicConfig( 445 logging.basicConfig(
440 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) 446 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
441 unittest.main() 447 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698