aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--setup.py3
-rw-r--r--tests/validator/test_toscaparser_validator.py28
-rw-r--r--vnfsdk_pkgtools/cli/__main__.py2
-rw-r--r--vnfsdk_pkgtools/validator/toscaparser_validator.py42
4 files changed, 73 insertions, 2 deletions
diff --git a/setup.py b/setup.py
index 7615d29..b9db75a 100644
--- a/setup.py
+++ b/setup.py
@@ -85,7 +85,8 @@ setup(
'console_scripts': [
'vnfsdk = vnfsdk_pkgtools.cli.__main__:main'],
'vnfsdk.pkgtools.validator': [
- 'aria = vnfsdk_pkgtools.validator.aria_validator:AriaValidator [aria]'
+ 'aria = vnfsdk_pkgtools.validator.aria_validator:AriaValidator [aria]',
+ 'toscaparser = vnfsdk_pkgtools.validator.toscaparser_validator:ToscaparserValidator',
]
},
diff --git a/tests/validator/test_toscaparser_validator.py b/tests/validator/test_toscaparser_validator.py
new file mode 100644
index 0000000..0211026
--- /dev/null
+++ b/tests/validator/test_toscaparser_validator.py
@@ -0,0 +1,28 @@
+# 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 toscaparser_validator
+
+CSAR_PATH = 'tests/resources/test_import.csar'
+
+def test_validate(tmpdir):
+ reader = csar._CSARReader(CSAR_PATH, str(tmpdir.mkdir('validate')), logging)
+ validator = toscaparser_validator.ToscaparserValidator()
+ validator.validate(reader)
+ assert hasattr(validator, 'tosca')
diff --git a/vnfsdk_pkgtools/cli/__main__.py b/vnfsdk_pkgtools/cli/__main__.py
index 7cb4e54..fee321c 100644
--- a/vnfsdk_pkgtools/cli/__main__.py
+++ b/vnfsdk_pkgtools/cli/__main__.py
@@ -107,7 +107,7 @@ def parse_args(args_list):
help='CSAR file location')
csar_validate.add_argument(
'-p', '--parser',
- default='aria',
+ default='toscaparser',
help='use which csar parser to validate')
return parser.parse_args(args_list)
diff --git a/vnfsdk_pkgtools/validator/toscaparser_validator.py b/vnfsdk_pkgtools/validator/toscaparser_validator.py
new file mode 100644
index 0000000..bcb3e9e
--- /dev/null
+++ b/vnfsdk_pkgtools/validator/toscaparser_validator.py
@@ -0,0 +1,42 @@
+# 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 toscaparser.common.exception import ValidationError
+from toscaparser.tosca_template import ToscaTemplate
+
+from vnfsdk_pkgtools import validator
+
+LOG = logging.getLogger(__name__)
+
+
+class ToscaparserValidator(validator.ValidatorBase):
+ def __init__(self):
+ super(ToscaparserValidator, self).__init__()
+
+ def validate(self, reader):
+ entry_path = os.path.join(reader.destination,
+ reader.entry_definitions)
+ try:
+ #TODO set debug_mode due to upstream bug
+ # https://jira.opnfv.org/browse/PARSER-181
+ self.tosca = ToscaTemplate(path=entry_path,
+ no_required_paras_check=True,
+ debug_mode=True)
+ except ValidationError as e:
+ LOG.error(e.message)
+ raise e