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

Side by Side Diff: appengine/gce-backend/config.py

Issue 2698153002: Enforce limits on configs (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | appengine/gce-backend/config_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The LUCI Authors. All rights reserved. 1 # Copyright 2016 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Utilities for reading GCE Backend configuration.""" 5 """Utilities for reading GCE Backend configuration."""
6 6
7 import collections 7 import collections
8 import logging 8 import logging
9 9
10 from components import utils 10 from components import utils
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 # We don't do any GCE-specific validation here. Just require globally 124 # We don't do any GCE-specific validation here. Just require globally
125 # unique base name because base name is used as the key in the datastore. 125 # unique base name because base name is used as the key in the datastore.
126 base_names = set() 126 base_names = set()
127 valid = True 127 valid = True
128 for template in config.templates: 128 for template in config.templates:
129 if template.base_name in base_names: 129 if template.base_name in base_names:
130 context.error('base_name %s is not globally unique.', template.base_name) 130 context.error('base_name %s is not globally unique.', template.base_name)
131 valid = False 131 valid = False
132 else: 132 else:
133 base_names.add(template.base_name) 133 base_names.add(template.base_name)
134 if len(base_names) > 10:
135 context.error('Too many instance templates.')
136 valid = False
134 metrics.config_valid.set(valid, fields={'config': TEMPLATES_CFG_FILENAME}) 137 metrics.config_valid.set(valid, fields={'config': TEMPLATES_CFG_FILENAME})
135 138
136 139
137 @validation.self_rule( 140 @validation.self_rule(
138 MANAGERS_CFG_FILENAME, config_pb2.InstanceGroupManagerConfig) 141 MANAGERS_CFG_FILENAME, config_pb2.InstanceGroupManagerConfig)
139 def validate_manager_config(config, context): 142 def validate_manager_config(config, context):
140 """Validates an InstanceGroupManagerConfig instance.""" 143 """Validates an InstanceGroupManagerConfig instance."""
141 # We don't do any GCE-specific validation here. Just require per-template 144 # We don't do any GCE-specific validation here. Just require per-template
142 # unique zone because template+zone is used as a key in the datastore. 145 # unique zone because template+zone is used as a key in the datastore.
143 zones = collections.defaultdict(set) 146 zones = collections.defaultdict(set)
144 valid = True 147 valid = True
145 for manager in config.managers: 148 for manager in config.managers:
146 if manager.zone in zones[manager.template_base_name]: 149 if manager.zone in zones[manager.template_base_name]:
147 context.error( 150 context.error(
148 'zone %s is not unique in template %s.', 151 'zone %s is not unique in template %s.',
149 manager.zone, 152 manager.zone,
150 manager.template_base_name, 153 manager.template_base_name,
151 ) 154 )
152 valid = False 155 valid = False
153 else: 156 else:
154 zones[manager.template_base_name].add(manager.zone) 157 zones[manager.template_base_name].add(manager.zone)
158 if manager.minimum_size > manager.maximum_size:
159 context.error(
160 'minimum_size > maximum_size for zone %s in template %s.',
161 manager.zone,
162 manager.template_base_name,
163 )
164 valid = False
165 if manager.maximum_size > 1000:
166 # A GCE InstanceGroup is limited to 1000 instances.
167 context.error(
168 'maximum_size > 1000 for zone %s in template %s.',
169 manager.zone,
170 manager.template_base_name,
171 )
172 valid = False
155 metrics.config_valid.set(valid, fields={'config': MANAGERS_CFG_FILENAME}) 173 metrics.config_valid.set(valid, fields={'config': MANAGERS_CFG_FILENAME})
156 174
157 175
158 @validation.self_rule(SETTINGS_CFG_FILENAME, config_pb2.SettingsCfg) 176 @validation.self_rule(SETTINGS_CFG_FILENAME, config_pb2.SettingsCfg)
159 def validate_settings_config(config, context): 177 def validate_settings_config(config, context):
160 if config.HasField('mp_server'): 178 if config.HasField('mp_server'):
161 if not validation.is_valid_secure_url(config.mp_server): 179 if not validation.is_valid_secure_url(config.mp_server):
162 context.error( 180 context.error(
163 'mp_server must start with "https://" or "http://localhost"') 181 'mp_server must start with "https://" or "http://localhost"')
164 182
(...skipping 11 matching lines...) Expand all
176 if cfg.mp_server != current_config.instance_url: 194 if cfg.mp_server != current_config.instance_url:
177 logging.info('Updating Machine Provider server to %s', cfg.mp_server) 195 logging.info('Updating Machine Provider server to %s', cfg.mp_server)
178 current_config.modify(instance_url=cfg.mp_server) 196 current_config.modify(instance_url=cfg.mp_server)
179 return rev, cfg 197 return rev, cfg
180 198
181 199
182 @utils.cache_with_expiration(60) 200 @utils.cache_with_expiration(60)
183 def settings(): 201 def settings():
184 """Loads settings from an NDB-based cache or a default one if not present.""" 202 """Loads settings from an NDB-based cache or a default one if not present."""
185 return _get_settings()[1] 203 return _get_settings()[1]
OLDNEW
« no previous file with comments | « no previous file | appengine/gce-backend/config_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698