diff options
author | Lianhao Lu <lianhao.lu@intel.com> | 2018-08-09 16:45:49 +0800 |
---|---|---|
committer | Lianhao Lu <lianhao.lu@intel.com> | 2018-08-09 16:45:49 +0800 |
commit | 4e3368b279970e4244addbafbf650b316255d69c (patch) | |
tree | b04ccd8eec6f2837d57cb57678218e43398f95ab /vnfsdk_pkgtools | |
parent | 1de1b090628422d1e25da1384a95a81e91cc6e97 (diff) |
Ground work for hpa validation
Added the declarative schema for hpa validation. This is the ground
layering work for hpa validation.
Change-Id: I2ff30489e191ecf187711e1025f6e3faee9946c3
Issue-ID: VNFSDK-194
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Diffstat (limited to 'vnfsdk_pkgtools')
-rw-r--r-- | vnfsdk_pkgtools/validator/__init__.py | 2 | ||||
-rw-r--r-- | vnfsdk_pkgtools/validator/hpa.yaml | 267 | ||||
-rw-r--r-- | vnfsdk_pkgtools/validator/toscaparser_validator.py | 28 | ||||
-rw-r--r-- | vnfsdk_pkgtools/validator/utils.py | 49 |
4 files changed, 345 insertions, 1 deletions
diff --git a/vnfsdk_pkgtools/validator/__init__.py b/vnfsdk_pkgtools/validator/__init__.py index f6d9073..730acf6 100644 --- a/vnfsdk_pkgtools/validator/__init__.py +++ b/vnfsdk_pkgtools/validator/__init__.py @@ -38,7 +38,7 @@ class ValidatorBase(object): """Base class for validators.""" def __init__(self): - pass + self.tosca = None @abc.abstractmethod diff --git a/vnfsdk_pkgtools/validator/hpa.yaml b/vnfsdk_pkgtools/validator/hpa.yaml new file mode 100644 index 0000000..bc551c6 --- /dev/null +++ b/vnfsdk_pkgtools/validator/hpa.yaml @@ -0,0 +1,267 @@ +--- +metadata: + version: "1.0" +schemas: + # schema name + vduCpuRequirements: + # hpa key name + cpuModelSpecificationBinding: + # json encoded key name: reg expression for the valid value + schema-version: &any r'.*' + schema-location: *any + platform-id: &generic r'generic' + mandatory: &bool r'true|false|TRUE|FALSE|True|False' + configuration-value: r'strictBinding|equalOrBetterBinding' + instructionSetRequirements: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + simultaneousMultiThreading: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'enabled|disabled' + hypervisorConfiguration: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + computeRas: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'pciDetectedAndCorrectedErrors|pciDetectedAndUncorrectedErrors' + cpuModel: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + directIoAccessToCache: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + accelerator: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + measuredLaunchEnvironment: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + secureEnclave: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + numVirtualCpu: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+' + virtualCpuClock: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+\w*(Hz|kHz|MHz|GHz)' + logicalCpuPinningPolicy: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'dedicated|shared' + logicalCpuThreadPinningPolicy: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'require|isolate|prefer' + vduMemRequirements: + memoryPageSize: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+\w*(B|kB|KB|KiB|MB|MiB|GB|GiB|TB|TiB)' + numberOfPages: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+' + memoryAllocationPolicy: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'strictLocalAffinity|preferredLocalAffinity' + memoryType: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + memorySpeed: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + memoryRas: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + memoryBandwidth: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+' + processorCacheAllocationType: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + processorCacheAllocationSize: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + vduStorageRequirements: + storageIops: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+' + storageResilencyMechanism: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'erasure|tripleReplication' + processorCacheAllocationSize: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + processorCacheAllocationSize: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + logicalNodeComputeMemoryRequirements: + numberCpu: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+' + localNumaMemorySize: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+\w*(B|kB|KB|KiB|MB|MiB|GB|GiB|TB|TiB)' + logicalNodeIoRequirements: + pciVendorId: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + pciDeviceId: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + pciNumDevices: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'\d+' + pciAddress: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + pciDeviceLocalToNumaNode: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'required|notRequired' + networkInterfaceRequirements: + nicFeature: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + dataProcessingAccelerationLibray: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'DPDK' + dataProcessingAccelerationLibrayVersion: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: *any + interfaceType: + schema-version: *any + schema-location: *any + platform-id: *generic + mandatory: *bool + configuration-value: r'virtio|PCI-Passthrough|SR-IOV|E1000|RTL8139|PCNET' +mappings: +# mapping between property value of a tosca node type and the valid hpa schema +# type: tosca node type +# key: prop1##prop2##...##propN +# Property hierachy within that node type. Prefix of '(capability:)' +# in propI means the value is from capability instead of property. +# Suffix '[] in propI means the value is a list of propI+1. +# schema: schema defined in the above schemas section + - type: tosca.nodes.nfv.Vdu.Compute + key: capability:virtual_compute##logical_node##logical_node_requirements + schema: logicalNodeComputeMemoryRequirements + - type: tosca.nodes.nfv.Vdu.Compute + key: capability:virtual_compute##virtual_cpu##vdu_cpu_requirements + schema: vduCpuRequirements + - type: tosca.nodes.nfv.Vdu.Compute + key: capability:virtual_compute##virtual_memory##vdu_memory_requirements + schema: vduCpuRequirements + - type: tosca.nodes.nfv.Vdu.VirtualStorage + key: vdu_storage_requirements + schema: vduStorageRequirements + - type: tosca.nodes.nfv.VduCp + key: virtual_network_interface_requirements[]##network_interface_requirements##logical_node_requirements + schema: networkInterfaceRequirements + - type: tosca.nodes.nfv.VduCp + key: virtual_network_interface_requirements[]##nic_io_requirements##logical_node_requirements + schema: logicalNodeIoRequirements diff --git a/vnfsdk_pkgtools/validator/toscaparser_validator.py b/vnfsdk_pkgtools/validator/toscaparser_validator.py index bcb3e9e..d1aad30 100644 --- a/vnfsdk_pkgtools/validator/toscaparser_validator.py +++ b/vnfsdk_pkgtools/validator/toscaparser_validator.py @@ -15,18 +15,44 @@ import logging import os +import pkg_resources from toscaparser.common.exception import ValidationError from toscaparser.tosca_template import ToscaTemplate from vnfsdk_pkgtools import validator +from vnfsdk_pkgtools.validator import utils LOG = logging.getLogger(__name__) +class HpaSchemaDefError(ValueError): + pass + + class ToscaparserValidator(validator.ValidatorBase): def __init__(self): super(ToscaparserValidator, self).__init__() + self._load_hpa_definition() + + def _load_hpa_definition(self): + conf = pkg_resources.resource_filename(__name__, "hpa.yaml") + defs = utils.load_definitions(conf, {}) + self.hpa_schema_version = defs.get('metadata', {}).get('version') + self.hpa_schemas = defs.get('schemas', {}) + self.hpa_mappings = defs.get('mappings', []) + #validate schema defined in hpa.yaml is correct + if not self.hpa_schema_version: + msg = "No defined version in metadata" + raise HpaSchemaDefError(msg) + for mapping in self.hpa_mappings: + schema = mapping.get('schema') + if schema not in self.hpa_schemas: + msg = "schema %s not found in hpa schema definitions" % schema + raise HpaSchemaDefError(msg) + if not mapping.get('type') or not mapping.get('key'): + msg = "type or key not defined in hpa mappings" + raise HpaSchemaDefError(msg) def validate(self, reader): entry_path = os.path.join(reader.destination, @@ -40,3 +66,5 @@ class ToscaparserValidator(validator.ValidatorBase): except ValidationError as e: LOG.error(e.message) raise e + + print self.tosca diff --git a/vnfsdk_pkgtools/validator/utils.py b/vnfsdk_pkgtools/validator/utils.py new file mode 100644 index 0000000..b26a290 --- /dev/null +++ b/vnfsdk_pkgtools/validator/utils.py @@ -0,0 +1,49 @@ +# Copyright (c) 2018 Intel Corp Inc. 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 ruamel import yaml + +LOG = logging.getLogger(__name__) + + +def load_definitions(config_file, defaults=None): + if not os.path.exists(config_file): + LOG.info("No definitions configuration file %s found! " + "Using default config.", config_file) + definition_cfg = defaults + else: + LOG.debug("Loading definitions configuration file: %s", config_file) + with open(config_file) as cf: + config = cf.read() + try: + definition_cfg = yaml.safe_load(config) + except yaml.YAMLError as err: + if hasattr(err, 'problem_mark'): + mark = err.problem_mark + errmsg = ("Invalid YAML syntax in Definitions file %(file)s " + "at line: %(line)s, column: %(column)s." % + dict(file=config_file, + line=mark.line + 1, + column=mark.column + 1)) + else: + errmsg = ("YAML error reading Definitions file %s" % config_file) + LOG.error(errmsg) + raise + + LOG.debug("Definitions: %s", definition_cfg) + return definition_cfg |