|
3 | 3 | # Licensed under a 3-clause BSD style license (see LICENSE) |
4 | 4 | import difflib |
5 | 5 | import os |
| 6 | +import re |
6 | 7 |
|
7 | 8 | import click |
8 | 9 | import yaml |
|
35 | 36 |
|
36 | 37 | IGNORE_DEFAULT_INSTANCE = {'ceph', 'dotnetclr', 'gunicorn', 'marathon', 'pgbouncer', 'process', 'supervisord'} |
37 | 38 |
|
38 | | -TEMPLATES = ['default', 'openmetrics_legacy', 'openmetrics', 'jmx'] |
39 | | - |
40 | 39 |
|
41 | 40 | @click.command(context_settings=CONTEXT_SETTINGS, short_help='Validate default configuration files') |
42 | 41 | @click.argument('check', shell_complete=complete_valid_checks, required=False) |
@@ -113,6 +112,7 @@ def config(ctx, check, sync, verbose): |
113 | 112 |
|
114 | 113 | if not validate_default_template(spec_file_content): |
115 | 114 | message = "Missing default template in init_config or instances section" |
| 115 | + files_failed[spec_file_path] = True |
116 | 116 | check_display_queue.append(lambda message=message, **kwargs: echo_failure(message, **kwargs)) |
117 | 117 | annotate_error(spec_file_path, message) |
118 | 118 |
|
@@ -186,13 +186,13 @@ def validate_default_template(spec_file): |
186 | 186 | if 'template: init_config' not in spec_file or 'template: instances' not in spec_file: |
187 | 187 | # This config spec does not have init_config or instances |
188 | 188 | return True |
189 | | - for line in spec_file.split('\n'): |
190 | | - has_default_templates = any("init_config/{}".format(template) in line for template in TEMPLATES) and any( |
191 | | - "instances/{}".format(template) in line for template in TEMPLATES |
192 | | - ) |
193 | | - if has_default_templates: |
194 | | - return True |
195 | | - return False |
| 189 | + |
| 190 | + templates = { |
| 191 | + 'intances': [f'template: init_config/{t}' for t in ['default', 'openmetrics_legacy', 'openmetrics', 'jmx']], |
| 192 | + 'init_config': [f'template: init_config/{t}' for t in ['default', 'openmetrics_legacy', 'openmetrics', 'jmx']], |
| 193 | + } |
| 194 | + # We want both instances and init_config to have at least one template present. |
| 195 | + return all(any(re.search(t, spec_file) for t in tpls) for tpls in templates) |
196 | 196 |
|
197 | 197 |
|
198 | 198 | def validate_config_legacy(check, check_display_queue, files_failed, files_warned, file_counter): |
|
0 commit comments