| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/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 """Unit tests for config.py.""" | 6 """Unit tests for config.py.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 ), | 100 ), |
| 101 ], | 101 ], |
| 102 ) | 102 ) |
| 103 self.install_mock(template_config=template_config) | 103 self.install_mock(template_config=template_config) |
| 104 | 104 |
| 105 config.update_template_configs() | 105 config.update_template_configs() |
| 106 self.failIf(config.Configuration.cached().template_config) | 106 self.failIf(config.Configuration.cached().template_config) |
| 107 self.failIf(config.Configuration.cached().manager_config) | 107 self.failIf(config.Configuration.cached().manager_config) |
| 108 self.failIf(config.Configuration.cached().revision) | 108 self.failIf(config.Configuration.cached().revision) |
| 109 | 109 |
| 110 def test_too_many_instance_templates(self): |
| 111 template_config = config_pb2.InstanceTemplateConfig( |
| 112 templates=[ |
| 113 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 114 base_name='base-name-1', |
| 115 ), |
| 116 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 117 base_name='base-name-2', |
| 118 ), |
| 119 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 120 base_name='base-name-3', |
| 121 ), |
| 122 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 123 base_name='base-name-4', |
| 124 ), |
| 125 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 126 base_name='base-name-5', |
| 127 ), |
| 128 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 129 base_name='base-name-6', |
| 130 ), |
| 131 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 132 base_name='base-name-7', |
| 133 ), |
| 134 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 135 base_name='base-name-8', |
| 136 ), |
| 137 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 138 base_name='base-name-9', |
| 139 ), |
| 140 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 141 base_name='base-name-10', |
| 142 ), |
| 143 config_pb2.InstanceTemplateConfig.InstanceTemplate( |
| 144 base_name='base-name-11', |
| 145 ), |
| 146 ], |
| 147 ) |
| 148 self.install_mock(template_config=template_config) |
| 149 |
| 150 config.update_template_configs() |
| 151 self.failIf(config.Configuration.cached().template_config) |
| 152 self.failIf(config.Configuration.cached().manager_config) |
| 153 self.failIf(config.Configuration.cached().revision) |
| 154 |
| 110 def test_repeated_zone_different_base_name(self): | 155 def test_repeated_zone_different_base_name(self): |
| 111 """Ensures repeated zones in different base names are valid.""" | 156 """Ensures repeated zones in different base names are valid.""" |
| 112 manager_config = config_pb2.InstanceGroupManagerConfig( | 157 manager_config = config_pb2.InstanceGroupManagerConfig( |
| 113 managers=[ | 158 managers=[ |
| 114 config_pb2.InstanceGroupManagerConfig.InstanceGroupManager( | 159 config_pb2.InstanceGroupManagerConfig.InstanceGroupManager( |
| 115 template_base_name='base-name-1', | 160 template_base_name='base-name-1', |
| 116 zone='us-central1-a', | 161 zone='us-central1-a', |
| 117 ), | 162 ), |
| 118 config_pb2.InstanceGroupManagerConfig.InstanceGroupManager( | 163 config_pb2.InstanceGroupManagerConfig.InstanceGroupManager( |
| 119 template_base_name='base-name-2', | 164 template_base_name='base-name-2', |
| (...skipping 30 matching lines...) Expand all Loading... |
| 150 ), | 195 ), |
| 151 ], | 196 ], |
| 152 ) | 197 ) |
| 153 self.install_mock(manager_config=manager_config) | 198 self.install_mock(manager_config=manager_config) |
| 154 | 199 |
| 155 config.update_template_configs() | 200 config.update_template_configs() |
| 156 self.failIf(config.Configuration.cached().template_config) | 201 self.failIf(config.Configuration.cached().template_config) |
| 157 self.failIf(config.Configuration.cached().manager_config) | 202 self.failIf(config.Configuration.cached().manager_config) |
| 158 self.failIf(config.Configuration.cached().revision) | 203 self.failIf(config.Configuration.cached().revision) |
| 159 | 204 |
| 205 def test_minimum_size_exceeds_maximum_size(self): |
| 206 """Ensures repeated zones in a base name reject the entire config.""" |
| 207 manager_config = config_pb2.InstanceGroupManagerConfig( |
| 208 managers=[ |
| 209 config_pb2.InstanceGroupManagerConfig.InstanceGroupManager( |
| 210 maximum_size=1, |
| 211 minimum_size=2, |
| 212 template_base_name='base-name-1', |
| 213 zone='us-central1-a', |
| 214 ), |
| 215 ], |
| 216 ) |
| 217 self.install_mock(manager_config=manager_config) |
| 218 |
| 219 config.update_template_configs() |
| 220 self.failIf(config.Configuration.cached().template_config) |
| 221 self.failIf(config.Configuration.cached().manager_config) |
| 222 self.failIf(config.Configuration.cached().revision) |
| 223 |
| 224 def test_maximum_size_exceeds_maximum_allowed(self): |
| 225 """Ensures repeated zones in a base name reject the entire config.""" |
| 226 manager_config = config_pb2.InstanceGroupManagerConfig( |
| 227 managers=[ |
| 228 config_pb2.InstanceGroupManagerConfig.InstanceGroupManager( |
| 229 maximum_size=9999, |
| 230 template_base_name='base-name-1', |
| 231 zone='us-central1-a', |
| 232 ), |
| 233 ], |
| 234 ) |
| 235 self.install_mock(manager_config=manager_config) |
| 236 |
| 237 config.update_template_configs() |
| 238 self.failIf(config.Configuration.cached().template_config) |
| 239 self.failIf(config.Configuration.cached().manager_config) |
| 240 self.failIf(config.Configuration.cached().revision) |
| 241 |
| 160 def test_update_template_configs(self): | 242 def test_update_template_configs(self): |
| 161 """Ensures config is updated when revision changes.""" | 243 """Ensures config is updated when revision changes.""" |
| 162 manager_config = config_pb2.InstanceGroupManagerConfig( | 244 manager_config = config_pb2.InstanceGroupManagerConfig( |
| 163 managers=[config_pb2.InstanceGroupManagerConfig.InstanceGroupManager()], | 245 managers=[config_pb2.InstanceGroupManagerConfig.InstanceGroupManager()], |
| 164 ) | 246 ) |
| 165 self.install_mock(revision='revision-1', manager_config=manager_config) | 247 self.install_mock(revision='revision-1', manager_config=manager_config) |
| 166 | 248 |
| 167 config.update_template_configs() | 249 config.update_template_configs() |
| 168 self.failIf(config.Configuration.cached().template_config) | 250 self.failIf(config.Configuration.cached().template_config) |
| 169 self.failUnless(config.Configuration.cached().manager_config) | 251 self.failUnless(config.Configuration.cached().manager_config) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 config_pb2.SettingsCfg(mp_server='http://url'), | 310 config_pb2.SettingsCfg(mp_server='http://url'), |
| 229 ['mp_server must start with "https://" or "http://localhost"']) | 311 ['mp_server must start with "https://" or "http://localhost"']) |
| 230 self.validator_test( | 312 self.validator_test( |
| 231 config.validate_settings_config, | 313 config.validate_settings_config, |
| 232 config_pb2.SettingsCfg(mp_server='url'), | 314 config_pb2.SettingsCfg(mp_server='url'), |
| 233 ['mp_server must start with "https://" or "http://localhost"']) | 315 ['mp_server must start with "https://" or "http://localhost"']) |
| 234 | 316 |
| 235 | 317 |
| 236 if __name__ == '__main__': | 318 if __name__ == '__main__': |
| 237 unittest.main() | 319 unittest.main() |
| OLD | NEW |