Support "Implementation" definition as Artifact Name
In the Node templates interfaces definition, Tosca parser only recognizes implementation as a file and not as an artifact name. ETSI SOL definition provides that Implementation may be an artifact name, and that the artifact definition will specify the artifact type and the file. This modification will allow both artifact name and file to be placed as value in "Implementation" definition. This is essential to allow onboarding of VNFD packages containing the Management Driver definition that specifies both Implementation definition value as the Artifact Name. https://review.opendev.org/#/c/740896/ Change-Id: I192d36499e7b731bbefaf3845f23f85d1e649ca5
This commit is contained in:
parent
3c5d2b6441
commit
df16f011f0
@ -217,11 +217,13 @@ class CSAR(object):
|
||||
artifact = artifacts[artifact_key]
|
||||
if isinstance(artifact, str):
|
||||
self._validate_external_reference(
|
||||
node_templates,
|
||||
template,
|
||||
artifact)
|
||||
elif isinstance(artifact, dict):
|
||||
if 'file' in artifact:
|
||||
self._validate_external_reference(
|
||||
node_templates,
|
||||
template,
|
||||
artifact['file'])
|
||||
else:
|
||||
@ -238,22 +240,27 @@ class CSAR(object):
|
||||
operation = interface[opertation_key]
|
||||
if isinstance(operation, str):
|
||||
self._validate_external_reference(
|
||||
node_templates,
|
||||
template,
|
||||
operation,
|
||||
False)
|
||||
elif isinstance(operation, dict):
|
||||
if 'implementation' in operation:
|
||||
self._validate_external_reference(
|
||||
node_templates,
|
||||
template,
|
||||
operation['implementation'])
|
||||
operation['implementation'],
|
||||
False)
|
||||
|
||||
def _validate_external_reference(self, tpl_file, resource_file,
|
||||
raise_exc=True):
|
||||
def _validate_external_reference(self, node_templates, tpl_file,
|
||||
resource_file, raise_exc=True):
|
||||
"""Verify that the external resource exists
|
||||
|
||||
If resource_file is a URL verify that the URL is valid.
|
||||
If resource_file is a relative path verify that the path is valid
|
||||
considering base folder (self.temp_dir) and tpl_file.
|
||||
If resource_file is not a path verify that it is a valid
|
||||
implementation name by matching the artifact name.
|
||||
Note that in a CSAR resource_file cannot be an absolute path.
|
||||
"""
|
||||
if UrlUtils.validate_url(resource_file):
|
||||
@ -273,6 +280,10 @@ class CSAR(object):
|
||||
os.path.dirname(tpl_file),
|
||||
resource_file)):
|
||||
return
|
||||
elif self._validate_artifact_name(node_templates):
|
||||
return
|
||||
else:
|
||||
raise_exc = True
|
||||
|
||||
if raise_exc:
|
||||
ExceptionCollector.appendException(
|
||||
@ -357,3 +368,23 @@ class CSAR(object):
|
||||
self.metadata = template_data.get('metadata')
|
||||
self.main_template_file_name = root_files[0]
|
||||
return True
|
||||
|
||||
def _validate_artifact_name(self, node_templates):
|
||||
artifact_name = "none"
|
||||
for node_template_key in node_templates:
|
||||
node_template = node_templates[node_template_key]
|
||||
if 'artifacts' in node_template:
|
||||
artifacts = node_template['artifacts']
|
||||
for artifact_key in artifacts:
|
||||
artifact_name = artifact_key
|
||||
|
||||
if 'interfaces' in node_template:
|
||||
interfaces = node_template['interfaces']
|
||||
for interface_key in interfaces:
|
||||
interface = interfaces[interface_key]
|
||||
for operation_key in interface:
|
||||
operation = interface[operation_key]
|
||||
if 'implementation' in operation:
|
||||
if artifact_name == operation['implementation']:
|
||||
return True
|
||||
return False
|
||||
|
BIN
toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact.zip
Normal file
BIN
toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact.zip
Normal file
Binary file not shown.
BIN
toscaparser/tests/data/CSAR/csar_wordpress_valid_artifact.zip
Normal file
BIN
toscaparser/tests/data/CSAR/csar_wordpress_valid_artifact.zip
Normal file
Binary file not shown.
@ -303,3 +303,22 @@ class CSARPrereqTest(TestCase):
|
||||
'cirros-0.4.0-x86_64-disk.img', str(error))
|
||||
self.assertTrue(csar.temp_dir is None or
|
||||
not os.path.exists(csar.temp_dir))
|
||||
|
||||
def test_csar_valid_artifact(self):
|
||||
path = os.path.join(self.base_path,
|
||||
"data/CSAR/csar_wordpress_valid_artifact.zip")
|
||||
csar = CSAR(path)
|
||||
self.assertTrue(csar.validate())
|
||||
self.assertTrue(csar.temp_dir is None or
|
||||
not os.path.exists(csar.temp_dir))
|
||||
|
||||
def test_csar_invalid_artifact(self):
|
||||
path = os.path.join(self.base_path,
|
||||
"data/CSAR/csar_wordpress_invalid_artifact.zip")
|
||||
csar = CSAR(path)
|
||||
error = self.assertRaises(ValueError, csar.validate)
|
||||
self.assertTrue(
|
||||
str(error) == _('The resource "Scripts/WordPress/configure.sh" '
|
||||
'does not exist.'))
|
||||
self.assertTrue(csar.temp_dir is None or
|
||||
not os.path.exists(csar.temp_dir))
|
||||
|
Loading…
x
Reference in New Issue
Block a user