Add configurable deckhand render validation
Currently deckhand render validation is disabled by default with no option to override that behavior from the command line. Resolve this by: 1. Adding CLI render flag 'validate', default=True 2. Updating CLI documentation 3. Update pegleg.engine.site.render method to include configurable validate flag 4. Update pegleg.engine.util.deckhand.deckhand_render method to validate=True by default (previously False) 5. Update pegleg.engine.util.deckhand.deckhand_render method to perform deckhand's validate all function on rendered documents NOTE: Validation logic is handled in deckhand, see https://opendev.org/airship/deckhand/src/branch/master/deckhand/engine/layering.py https://opendev.org/airship/deckhand/src/branch/master/deckhand/engine/document_validation.py Change-Id: I042fad4b2bf08c88e3a2eef6a54dede5d45c28f5
This commit is contained in:
parent
291c114493
commit
9f824f878d
@ -337,6 +337,12 @@ Name of site.
|
||||
|
||||
Where to output.
|
||||
|
||||
**-v/--validate** (Optional). Default is True.
|
||||
|
||||
Whether to pre-validate documents using built-in schema validation.
|
||||
Skips over externally registered DataSchema documents to avoid
|
||||
false positives.
|
||||
|
||||
::
|
||||
|
||||
./pegleg <command> <options> render site_name
|
||||
|
@ -313,9 +313,19 @@ def show(*, output_stream, site_name):
|
||||
default=sys.stdout,
|
||||
show_default=True,
|
||||
help='Where to output.')
|
||||
@click.option(
|
||||
'-v',
|
||||
'--validate',
|
||||
'validate',
|
||||
is_flag=True,
|
||||
default=True,
|
||||
show_default=True,
|
||||
help='Whether to pre-validate documents using built-in schema validation. '
|
||||
'Skips over externally registered DataSchema documents to avoid '
|
||||
'false positives.')
|
||||
@SITE_REPOSITORY_ARGUMENT
|
||||
def render(*, output_stream, site_name):
|
||||
engine.site.render(site_name, output_stream)
|
||||
def render(*, output_stream, site_name, validate):
|
||||
engine.site.render(site_name, output_stream, validate)
|
||||
|
||||
|
||||
@site.command('lint', help='Lint a given site in a repository')
|
||||
|
@ -83,14 +83,14 @@ def collect(site_name, save_location):
|
||||
_collect_to_stdout(site_name)
|
||||
|
||||
|
||||
def render(site_name, output_stream):
|
||||
def render(site_name, output_stream, validate):
|
||||
documents = []
|
||||
for filename in util.definition.site_files(site_name):
|
||||
with open(filename) as f:
|
||||
documents.extend(list(yaml.safe_load_all(f)))
|
||||
|
||||
rendered_documents, errors = util.deckhand.deckhand_render(
|
||||
documents=documents)
|
||||
documents=documents, validate=validate)
|
||||
err_msg = ''
|
||||
if errors:
|
||||
for err in errors:
|
||||
|
@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
from deckhand.engine import document_validation
|
||||
from deckhand.engine import layering
|
||||
from deckhand import errors as dh_errors
|
||||
|
||||
@ -43,7 +44,7 @@ def load_schemas_from_docs(documents):
|
||||
|
||||
def deckhand_render(documents=None,
|
||||
fail_on_missing_sub_src=False,
|
||||
validate=False):
|
||||
validate=True):
|
||||
documents = documents or []
|
||||
errors = []
|
||||
rendered_documents = []
|
||||
@ -57,6 +58,17 @@ def deckhand_render(documents=None,
|
||||
fail_on_missing_sub_src=fail_on_missing_sub_src,
|
||||
validate=validate)
|
||||
rendered_documents = [dict(d) for d in deckhand_eng.render()]
|
||||
if validate:
|
||||
validator = document_validation.DocumentValidation(
|
||||
rendered_documents)
|
||||
results = validator.validate_all()
|
||||
for result in results:
|
||||
if result['errors']:
|
||||
errors.append(
|
||||
(DECKHAND_RENDER_EXCEPTION,
|
||||
'During rendering Deckhand was unable to validate '
|
||||
'the following document, details: %s.' % (
|
||||
result['errors'])))
|
||||
except dh_errors.DeckhandException as e:
|
||||
errors.append(
|
||||
(DECKHAND_RENDER_EXCEPTION,
|
||||
|
Loading…
Reference in New Issue
Block a user