From 1210f741d01f26609b687e6680e5180fb1be5efe Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Sat, 24 Mar 2018 00:04:37 +0800 Subject: Fix aria validation error in import case Previously, we assume all the yaml files in the csar package are located under definition directory. This is not always true according to SOL-004. We need to change the way how we call aria to validate the vnfd content within the csar pacakge. Also added the unit test for vnfsdk_pkgtools/validator. Issue-ID: VNFSDK-231 Change-Id: Ia112b21b3bbf64ab980dd4e98aab0e87131f28e0 Signed-off-by: Lianhao Lu --- tests/resources/test_import.csar | Bin 0 -> 1074 bytes tests/validator/test_aria_validator.py | 27 +++++++++++++++++++++++++++ vnfsdk_pkgtools/validator/aria_validator.py | 9 +++++---- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/resources/test_import.csar create mode 100644 tests/validator/test_aria_validator.py diff --git a/tests/resources/test_import.csar b/tests/resources/test_import.csar new file mode 100644 index 0000000..90bb629 Binary files /dev/null and b/tests/resources/test_import.csar differ diff --git a/tests/validator/test_aria_validator.py b/tests/validator/test_aria_validator.py new file mode 100644 index 0000000..8ae5eab --- /dev/null +++ b/tests/validator/test_aria_validator.py @@ -0,0 +1,27 @@ +# Copyright (c) 2018 Intel Corp. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +import logging +import os + +from vnfsdk_pkgtools.packager import csar +from vnfsdk_pkgtools.validator import aria_validator + +CSAR_PATH = 'tests/resources/test_import.csar' + +def test_validate(tmpdir): + reader = csar._CSARReader(CSAR_PATH, str(tmpdir.mkdir('validate')), logging) + validator = aria_validator.AriaValidator() + validator.validate(reader) diff --git a/vnfsdk_pkgtools/validator/aria_validator.py b/vnfsdk_pkgtools/validator/aria_validator.py index 83d7dfe..b4b947c 100644 --- a/vnfsdk_pkgtools/validator/aria_validator.py +++ b/vnfsdk_pkgtools/validator/aria_validator.py @@ -15,7 +15,7 @@ import os -from aria.parser.loading import LiteralLocation +from aria.parser.loading import UriLocation from aria.parser.consumption import ( ConsumptionContext, ConsumerChain, @@ -31,9 +31,10 @@ from vnfsdk_pkgtools import validator class AriaValidator(validator.ValidatorBase): def validate(self, reader): context = ConsumptionContext() - context.loading.prefixes += [os.path.join(reader.destination, 'definitions')] - context.presentation.location = LiteralLocation(reader.entry_definitions_yaml) - print reader.entry_definitions_yaml + service_template_path = os.path.join(reader.destination, + reader.entry_definitions) + context.presentation.location = UriLocation(service_template_path) + print(reader.entry_definitions_yaml) chain = ConsumerChain(context, (Read, Validate, ServiceTemplate, ServiceInstance)) chain.consume() if context.validation.dump_issues(): -- cgit 1.2.3-korg