From 6e6fec40da88519c4f1562cdb4bde171c39bc0d2 Mon Sep 17 00:00:00 2001 From: Wataru Juso Date: Thu, 19 May 2022 21:22:22 +0900 Subject: [PATCH] Support primary and dependencies definition The definition of implementation support the single artifact case. For support the multi artifact case, implement the primary and dependencies definitions to the implementation. Implements: blueprint support-multi-artifacts Change-Id: Ie118add5c1829e54b3e16ea6ea4375bf7f3f9e50 --- toscaparser/prereq/csar.py | 109 +++++++++++------- .../csar_wordpress_invalid_artifact_multi.zip | Bin 0 -> 6265 bytes .../csar_wordpress_valid_artifact_multi.zip | Bin 0 -> 6260 bytes toscaparser/tests/test_prereq.py | 21 ++++ 4 files changed, 88 insertions(+), 42 deletions(-) create mode 100644 toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact_multi.zip create mode 100644 toscaparser/tests/data/CSAR/csar_wordpress_valid_artifact_multi.zip diff --git a/toscaparser/prereq/csar.py b/toscaparser/prereq/csar.py index 337806dd..ec98d122 100644 --- a/toscaparser/prereq/csar.py +++ b/toscaparser/prereq/csar.py @@ -205,52 +205,60 @@ class CSAR(object): def _validate_template(self, template_data, template): if 'topology_template' in template_data: topology_template = template_data['topology_template'] - if 'node_templates' in topology_template: node_templates = topology_template['node_templates'] 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 = 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: - ExceptionCollector.appendException( - ValueError(_('Unexpected artifact ' - 'definition for "%s".') - % artifact_key)) + self._validate_artifacts( + node_template, node_templates, template) if 'interfaces' in node_template: - interfaces = node_template['interfaces'] - for interface_key in interfaces: - interface = interfaces[interface_key] - for opertation_key in interface: - 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'], - False) + self._validate_interfaces( + node_template, node_templates, template) + + def _validate_artifacts(self, node_template, node_templates, template): + artifacts = node_template['artifacts'] + for artifact_key in artifacts: + 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: + ExceptionCollector.appendException( + ValueError(_('Unexpected artifact definition for "%s".') + % artifact_key)) + + def _validate_interfaces(self, node_template, node_templates, template): + interfaces = node_template['interfaces'] + for interface_key in interfaces: + interface = interfaces[interface_key] + for operation_key in interface: + operation = interface[operation_key] + if isinstance(operation, str): + self._validate_external_reference( + node_templates, template, operation, False) + elif isinstance(operation, dict): + if 'implementation' in operation: + if isinstance(operation['implementation'], dict): + implement = operation['implementation'] + if 'primary' in implement: + self._validate_external_reference( + node_templates, template, + implement['primary'], False) + elif 'dependencies' in implement: + self._validate_external_reference( + node_templates, template, + implement['dependencies'], False) + else: + self._validate_external_reference( + node_templates, template, + operation['implementation'], False) def _validate_external_reference(self, node_templates, tpl_file, resource_file, raise_exc=True): @@ -370,13 +378,13 @@ class CSAR(object): return True def _validate_artifact_name(self, node_templates): - artifact_name = "none" + artifact_name = [] 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 + artifact_name.append(artifact_key) if 'interfaces' in node_template: interfaces = node_template['interfaces'] @@ -384,7 +392,24 @@ class CSAR(object): interface = interfaces[interface_key] for operation_key in interface: operation = interface[operation_key] - if 'implementation' in operation: - if artifact_name == operation['implementation']: + if isinstance(operation, str): + if operation in artifact_name: return True + elif isinstance(operation, dict): + if 'implementation' in operation: + if isinstance(operation['implementation'], + dict): + implement = operation['implementation'] + if 'primary' in implement: + if (implement['primary'] in + artifact_name): + return True + elif 'dependencies' in implement: + if (implement['dependencies'] in + artifact_name): + return True + else: + if (operation['implementation'] in + artifact_name): + return True return False diff --git a/toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact_multi.zip b/toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact_multi.zip new file mode 100644 index 0000000000000000000000000000000000000000..2dab2367d1591a9a8274ac10e0b802804bd6f697 GIT binary patch literal 6265 zcmb_h2{_bSA0EqCrm{sOSbWb8V3& zxd_Qpi9)j9RP=>pN#B3?zH25^>3P1H=M0`P@9%fs^Pb=DJ!eeNEUXX^^&w+)*<$sV z|GsPmiGXx)Zk~8gvL^vgQna+-1hELacsYvz!#{8fh>7)Y77%Fl#RNd%2R_HKiem2# zSE>Wvn%D{gDSd-NCXig597vvccORUCC!R!h!n@!cP7;W&encFJ1PgNV_4y|fHQG0k zYOMS4eTR5X&0DvzA2R4?L*zw+GqUWV6rYl}u!tM7tTtJ`HIP;OR6*bWJ)(1t+LSQFf-W~gH*q|U70T(0_n zV|A)P5!@Ps%XDipsaa;Wkz2ZKxuRR`exkd=dm?NgA)-rAxkn?R|NPjI{TUwx{NV@# zox^CUGTFx8ZJ)RHrg9-B3LM>d z(qdwJAojlpL`&_G4u-xsrig_xzp893X*eLJclbVREU!ya7|DG2+MYJK!3oU#nsOiJ|h)5rnxyp{o47W?f2hhB|5$|c(!Z&f$0+EMcl>A*qmV1^HAISf-*br z1zlg^YnUsviMzp}%bBX3e7W78qBfUy*k8Ul;jpr|*l5&3frxpa#+jyyfAcj=}!gD**+c%qdyo`wb`Y zS?HJpc+NHEE zM%iKyI^3Nbnepu+i=Nt7@dV2J*@3&{(P;d~JHqNVDQ#!px?O;=A-b{`A8ORfRaT+j zy!rH+@chCuG@89Kgv71pT>dnYMXXBO=#AXWd3;N-eDTMy^-8gA&mldOaoxcwpl%2; zgFwRHR0;+);bka`6*sHfw>2S+f-q`O+KQalK*F@ZeN(!1qMTV+UHnKy_H)j1^_#D* zN|&l2BPq@Di>C)y%8~Eu*x$vp$QCbdkA+=p!pg~A@YK@$>(FQRF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