Add vnfd validity check
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / verifyvnfd / verifyvnfd.py
1 # Copyright 2016 ZTE Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import json
16 import os
17 import logging
18 import jsonschema
19 from lcm.pub.exceptions import NFLCMException
20
21 logger = logging.getLogger(__name__)
22
23
24 def verify(new_vnfd):
25     errors_found = []
26     vnfd_schema_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "vnf_vnfd_schema.json")
27     with open(vnfd_schema_path, "r") as fvnfd_schema:
28         vnfd_schema = json.load(fvnfd_schema)
29         vnfd_validator = jsonschema.validators.Draft4Validator(schema=vnfd_schema)
30         for error in vnfd_validator.iter_errors(new_vnfd):
31             logger.error("vnfd verify fail:%s" % error)
32             errors_found.append(error)
33         if len(errors_found) > 0:
34             raise NFLCMException(errors_found)
35         return errors_found