From 98e1fdf07ba0fd270ed115d0b740022850113f2d Mon Sep 17 00:00:00 2001 From: Ifat Afek Date: Tue, 26 Feb 2019 13:19:10 +0000 Subject: [PATCH] Fixes in the templates code 1. Remove the 'parameters' section after resolving the parameters 2. Give an error code in template validate if the template type was not specified Story: 2004056 Task: 29576 Depends-On: I18af00599461ead7bf9084168aeed7321adfd4c0 Change-Id: If5d03278f6cc4ca9ae071783bf60520d95146eea --- .../contributor/template_validation_status_code.rst | 10 +++++++--- vitrage/evaluator/template_db/template_repository.py | 10 ++++++++-- .../evaluator/template_validation/status_messages.py | 6 ++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/doc/source/contributor/template_validation_status_code.rst b/doc/source/contributor/template_validation_status_code.rst index 2f5567435..e1c318b61 100644 --- a/doc/source/contributor/template_validation_status_code.rst +++ b/doc/source/contributor/template_validation_status_code.rst @@ -49,11 +49,15 @@ The following describes all the possible status code and their messages: +------------------+---------------------------------------------------------+-------------------------------+ | 63 | Unsupported version. Version must be one of: {versions} | content | +------------------+---------------------------------------------------------+-------------------------------+ -| 64 | metadata section must contain a type field in version 2.| content | -| | Type must be one of: {standard, equivalence, definition}| content | +| 64 | metadata section must contain a type field starting | content | +| | from version 2. | | +| | Type must be one of: {standard, equivalence, definition}| | +------------------+---------------------------------------------------------+-------------------------------+ | 65 | Invalid template type. Type must be one of: {standard, | content | -| | equivalence, definition} | content | +| | equivalence, definition} | | ++------------------+---------------------------------------------------------+-------------------------------+ +| 66 | Missing template type. Type must be one of: {standard, | content | +| | equivalence, definition} | | +------------------+---------------------------------------------------------+-------------------------------+ | 80 | scenarios is a mandatory section | syntax | +------------------+---------------------------------------------------------+-------------------------------+ diff --git a/vitrage/evaluator/template_db/template_repository.py b/vitrage/evaluator/template_db/template_repository.py index e161cf395..b734564a2 100644 --- a/vitrage/evaluator/template_db/template_repository.py +++ b/vitrage/evaluator/template_db/template_repository.py @@ -15,13 +15,15 @@ from oslo_log import log from oslo_utils import uuidutils from vitrage.common.constants import TemplateStatus -from vitrage.common.constants import TemplateTopologyFields as TFields from vitrage.common.constants import TemplateTypes as TType from vitrage.common.exception import VitrageError from vitrage.evaluator.base import Template +from vitrage.evaluator.template_fields import TemplateFields as TFields from vitrage.evaluator.template_functions.v2 import resolve_parameters from vitrage.evaluator import template_validation from vitrage.evaluator.template_validation import base +from vitrage.evaluator.template_validation.content.base import \ + get_content_fault_result from vitrage.storage.sqlalchemy import models LOG = log.getLogger(__name__) @@ -42,6 +44,9 @@ def add_templates_to_db(db, templates, cli_type, params=None): result = _validate_template(db, template, final_type, params) if result.is_valid_config: result = resolve_parameters(template, params) + if result.is_valid_config and TFields.PARAMETERS in template: + # remove the 'parameters' section, it is no longer needed + del template[TFields.PARAMETERS] # validate again, with the resolved parameters if result.is_valid_config: @@ -66,7 +71,8 @@ def validate_templates(db, templates, cli_type, params): for template in templates: final_type = template[METADATA].get(TFields.TYPE, cli_type) if not final_type or (cli_type and cli_type != final_type): - results.append(base.Result("", False, "", "Unknown template type")) + results.append( + get_content_fault_result(66, "Unknown template type")) else: results.append( _validate_template(db, template, final_type, params)) diff --git a/vitrage/evaluator/template_validation/status_messages.py b/vitrage/evaluator/template_validation/status_messages.py index e727ecff7..62fd02149 100644 --- a/vitrage/evaluator/template_validation/status_messages.py +++ b/vitrage/evaluator/template_validation/status_messages.py @@ -45,10 +45,12 @@ status_msgs = { 62: 'metadata is a mandatory section.', 63: 'Unsupported version. Version must be one of: {versions}' .format(versions=TemplateSchemaFactory.supported_versions()), - 64: 'metadata section must contain a type field in version 2. Type must be' - ' one of: {types}'.format(types=TemplateTypes.types()), + 64: 'metadata section must contain a type field starting from version 2. ' + 'Type must be one of: {types}'.format(types=TemplateTypes.types()), 65: 'Invalid template type. Type must be one of: {types}' .format(types=TemplateTypes.types()), + 66: 'Missing template type. Type must be one of: {types}' + .format(types=TemplateTypes.types()), # scenarios section status messages 80-99 80: 'scenarios is a mandatory section.',