Fix aria validation error in import case 83/42383/1 2.0.0-ONAP beijing 2.0.0-ONAP
authorLianhao Lu <lianhao.lu@intel.com>
Fri, 23 Mar 2018 16:04:37 +0000 (00:04 +0800)
committerLianhao Lu <lianhao.lu@intel.com>
Thu, 12 Apr 2018 02:35:13 +0000 (10:35 +0800)
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 <lianhao.lu@intel.com>
tests/resources/test_import.csar [new file with mode: 0644]
tests/validator/test_aria_validator.py [new file with mode: 0644]
vnfsdk_pkgtools/validator/aria_validator.py

diff --git a/tests/resources/test_import.csar b/tests/resources/test_import.csar
new file mode 100644 (file)
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 (file)
index 0000000..8ae5eab
--- /dev/null
@@ -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)
index 83d7dfe..b4b947c 100644 (file)
@@ -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():