Lianhao Lu | 0af4624 | 2018-08-29 18:17:46 +0800 | [diff] [blame] | 1 | # Copyright (c) 2018 Intel Corp. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # 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, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | # |
| 15 | |
| 16 | import abc |
Lianhao Lu | 40bcf5a | 2018-08-30 10:24:40 +0800 | [diff] [blame] | 17 | import os |
Lianhao Lu | 0af4624 | 2018-08-29 18:17:46 +0800 | [diff] [blame] | 18 | |
| 19 | import six |
| 20 | from stevedore import driver |
| 21 | |
Lianhao Lu | 40bcf5a | 2018-08-30 10:24:40 +0800 | [diff] [blame] | 22 | from vnfsdk_pkgtools.packager import csar |
Lianhao Lu | a2998ff | 2018-08-30 14:42:29 +0800 | [diff] [blame] | 23 | from vnfsdk_pkgtools.validator import toscaparser_validator as tv |
Lianhao Lu | 0af4624 | 2018-08-29 18:17:46 +0800 | [diff] [blame] | 24 | from vnfsdk_pkgtools import vnfreq |
| 25 | |
| 26 | |
| 27 | class R66070(vnfreq.TesterBase): |
| 28 | ID = "R-66070" |
| 29 | DESC = ("The VNF Package MUST include VNF Identification Data to " |
| 30 | "uniquely identify the resource for a given VNF provider. " |
| 31 | "The identification data must include: an identifier for " |
| 32 | "the VNF, the name of the VNF as was given by the VNF " |
| 33 | "provider, VNF description, VNF provider, and version.") |
| 34 | |
| 35 | def _do_check(self, reader, tosca): |
| 36 | if not reader.manifest: |
| 37 | raise vnfreq.VnfRequirementError("No manifest file found") |
| 38 | # Existing reader.manifest already means a valid manifest file |
| 39 | # no futher check needed. |
| 40 | return 0 |
Lianhao Lu | 40bcf5a | 2018-08-30 10:24:40 +0800 | [diff] [blame] | 41 | |
| 42 | |
| 43 | class R77707(vnfreq.TesterBase): |
| 44 | ID = "R-77707" |
| 45 | DESC = ("The VNF provider MUST include a Manifest File that contains " |
| 46 | "a list of all the components in the VNF package.") |
| 47 | |
| 48 | def _do_check(self, reader, tosca): |
| 49 | for root, dirs, files in os.walk(reader.destination): |
| 50 | for file in files: |
| 51 | full_path = os.path.join(root, file) |
| 52 | rel_path = os.path.relpath(full_path, reader.destination) |
| 53 | if rel_path not in (reader.entry_manifest_file, csar.META_FILE): |
| 54 | if rel_path not in reader.manifest.digests: |
| 55 | raise vnfreq.VnfRequirementError("Package component %s not found in manifest file" % rel_path) |
| 56 | return 0 |
Lianhao Lu | 7debff0 | 2018-08-30 11:04:38 +0800 | [diff] [blame] | 57 | |
| 58 | |
| 59 | class R04298(vnfreq.TesterBase): |
| 60 | ID = "R-04298" |
| 61 | DESC = ("The VNF provider MUST provide their testing scripts " |
| 62 | "to support testing.") |
| 63 | |
| 64 | def _do_check(self, reader, tosca): |
| 65 | if not reader.entry_tests_dir: |
| 66 | raise vnfreq.VnfRequirementError("No test directory found") |
| 67 | elif not os.listdir(os.path.join(reader.destination, |
| 68 | reader.entry_tests_dir)): |
| 69 | raise vnfreq.VnfRequirementError("No testing scripts found") |
| 70 | return 0 |
| 71 | |
Lianhao Lu | a2998ff | 2018-08-30 14:42:29 +0800 | [diff] [blame] | 72 | |
| 73 | class R26881(vnfreq.TesterBase): |
| 74 | ID = "R-26881" |
| 75 | DESC = ("The VNF provider MUST provide the binaries and images needed " |
| 76 | "to instantiate the VNF (VNF and VNFC images).") |
| 77 | |
| 78 | def _do_check(self, reader, tosca): |
| 79 | entry_path = os.path.dirname(os.path.join(reader.destination, |
| 80 | reader.entry_definitions)) |
| 81 | valid_artifacts = [] |
| 82 | for node in getattr(tosca.tosca, 'nodetemplates', []): |
| 83 | if tosca.is_type(node, 'tosca.nodes.nfv.Vdu.Compute') or \ |
| 84 | tosca.is_type(node, 'tosca.nodes.nfv.Vdu.VirtualStorage'): |
| 85 | # TODO(llu) nfv-toscaparser now doesn't support artifacts |
| 86 | # yet, we have to hack it for now. |
| 87 | # See https://jira.opnfv.org/browse/PARSER-184. |
Lianhao Lu | 1ee29e0 | 2019-11-01 16:01:34 +0800 | [diff] [blame] | 88 | for name, props in six.iteritems(node.entity_tpl.get('artifacts', {})): |
Lianhao Lu | a2998ff | 2018-08-30 14:42:29 +0800 | [diff] [blame] | 89 | file = props.get('file', None) |
| 90 | if file and \ |
| 91 | os.path.isfile(os.path.join(entry_path, file)) or \ |
| 92 | os.path.isfile(os.path.join(reader.destination, file)): |
| 93 | valid_artifacts.append(file) |
| 94 | if not valid_artifacts: |
| 95 | raise vnfreq.VnfRequirementError("No valid binaries or images for VNF instantion found") |
| 96 | return 0 |
| 97 | |
Lianhao Lu | 5fa8e54 | 2018-08-30 15:02:05 +0800 | [diff] [blame] | 98 | |
| 99 | class R35851(vnfreq.TesterBase): |
| 100 | ID = "R-35851" |
| 101 | DESC = ("The VNF Package MUST include VNF topology that describes " |
| 102 | "basic network and application connectivity internal and " |
| 103 | "external to the VNF including Link type, KPIs, Bandwidth, " |
| 104 | "latency, jitter, QoS (if applicable) for each interface.") |
| 105 | |
| 106 | def _do_check(self, reader, tosca): |
| 107 | # Only check the existence of Cp or VL |
| 108 | # link type, bandwidth are already enfoced by ONAP onbarding DM |
| 109 | # other KPIs are not defined yet. |
| 110 | found = False |
| 111 | for node in getattr(tosca.tosca, 'nodetemplates', []): |
| 112 | if tosca.is_type(node, 'tosca.nodes.nfv.VduCp') or \ |
| 113 | tosca.is_type(node, 'tosca.nodes.nfv.VnfVirtualLink'): |
| 114 | found = True |
| 115 | break |
| 116 | if not found: |
| 117 | raise vnfreq.VnfRequirementError("No basic network or application connectivity found") |
| 118 | return 0 |
| 119 | |