From df16f011f07563c89f15ea9899b23cd0c87fb15d Mon Sep 17 00:00:00 2001 From: Aldinson Esto Date: Sat, 22 Aug 2020 15:10:06 +0900 Subject: [PATCH] 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 --- toscaparser/prereq/csar.py | 37 ++++++++++++++++-- .../CSAR/csar_wordpress_invalid_artifact.zip | Bin 0 -> 5985 bytes .../CSAR/csar_wordpress_valid_artifact.zip | Bin 0 -> 5977 bytes toscaparser/tests/test_prereq.py | 19 +++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact.zip create mode 100644 toscaparser/tests/data/CSAR/csar_wordpress_valid_artifact.zip diff --git a/toscaparser/prereq/csar.py b/toscaparser/prereq/csar.py index 5ace91b1..337806dd 100644 --- a/toscaparser/prereq/csar.py +++ b/toscaparser/prereq/csar.py @@ -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 diff --git a/toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact.zip b/toscaparser/tests/data/CSAR/csar_wordpress_invalid_artifact.zip new file mode 100644 index 0000000000000000000000000000000000000000..016b01bcc82dd4c7e6e76ea07b2465771feec7a6 GIT binary patch literal 5985 zcmbVQXIPV26Ahivr3fn0MOs1^k!Fx!ASBcXp%)`X2#`b+L4+VGML^0bWmizZpooZ6 zDT;zLQIV>EbXd_vRP2=RjqYv|imTt7=cfF~nVBz^zj(6=`$07V%1A18>{f9GC= z z-`z&{c7EbG?uHR(IhrNpXImXed6?O|*PmaJw;MKVCwb|FC=8NKWQswHg{ubpFU^TK z%n@Z8Hay)|Lp%(PgmK47=;k5(ofL2L36^OkcQ}2FH*Qa!?y)hth6?EwANS64lWNGF z=;AluQrlM+k?^2DqrS=0>16Kw<566+Jqw@I=;o}Qs6O6zdfO!(AE}MGy71LG*9Q9; zFGNIJ#=Yg&kDAe)B@Q~&gJ=wH1M*OE;!t)RK<+jk5J+tWgQP&BmxmkC7w_$lbMwU$ zNgjA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e&#^qs;T?A9KG%$xx1GI;xX`BRo-H0O$FW9E9^A%FIUyY_xreuJUt~rEHbwdQ z`XyB&ZbUHeAZXvpJVHJzJLD}c8_bp&6rL|gfE^ebQRmL0$Y3U&Ol75~b282s}1VD>0>L=qh1Kam&h85QV-w|o^0plgZcSJyK zKxI*;D-c&6jRAb>1o8v?)kko8{L_FLdXInZKn_@?9>{-Sb@d^D-fB1-h~Y@^qbSxE zbxsgH?~5Fuf7?68?$^--8PJS4X=wD*-j8r;xn!L6=%bEb6PLc_{G0{Gp^e^x9C$6y z8P(xOHrD2vk(~uP8#F2XG3zvT7>6l(-w}ZE)e`;d>@ZF;^cEo8Ygzbz*kK$k=xu<2 zORm*X(3`Br_B^U!lq?_aiXC2y=h(S|A!-LFZ}0Wtf2e6G>&M(_Olhl zDB|?~3-Yan`?D29t9?chrngYGriEY0?rO#Tj{jXhw)2Bl>o1U2s#yM@*{)V!dZ&X{ ZgVJm9dhl%Q)a(fXuX*5`y#V#s{{S(T&es3{ literal 0 HcmV?d00001 diff --git a/toscaparser/tests/data/CSAR/csar_wordpress_valid_artifact.zip b/toscaparser/tests/data/CSAR/csar_wordpress_valid_artifact.zip new file mode 100644 index 0000000000000000000000000000000000000000..0558c4ec6ab9cf10beae785f5845c520c3256c1a GIT binary patch literal 5977 zcmbVQc|6qZ79Trf-?F^2mVGVKWE~j|lVPmMIvC7kY%^p_8L2FVL4{J5DGEs4T z?n!eMyI2H`ktn@fH3mg5^A)SN!xGY4Rlmj!FW12SzQ^${sZF`+t8lXBg@-OGDkrg~ zCii!K<~Z!>D8&+;CycYN3ohx*?cEc|ufp36opF#UIw}U$I7eVgM2g31g$6Fa7v1-s zAm1qX!l|BcQ1b|sJ6Rf13=ecw`IAqmS~vZ%>!%d6j`XP>JCkzjh+e5N|6)(s#)9$Z z{8oS5>8p-Qebk@R(CqDctYH4>2qwXqg->=wGH<7KAMc!jlFa@m+M^!se0SaMgyPJW z;u36<|KT@`pN7m32KP09Xbg%2c`%T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1KNM~qNb5&X zFwi6uM-Cw~xVQA+BlJ{nrIWaVI-aHqm1L%KSp{9|Npx@E_&&wq9~1r%JT30;;H)ks zEK%3<2ipCxi-{|m+pPIw#N*b2gGx%@nBl?A@i;6ltrmVgj(JCz-tF8-Qij5izm!5K zTW&}!MJNpFH}pz}JFi6Eal+L?L2e3ytehXpBq8r*EQmcDvHAW?-xk5dEX}gsg@QN` zF7+h<`Ua(bGhQ#S{k&dSb+tf6q|FD6mkU1;0kr{D$6KsGTzMo0@Tn8X2KcLw-t_n< z05kL+|Jp$uuu46MZ(w!xA%Na0kqyLfB-kj5wMCs1M9=#I2k5`;-O=Iq(S#V#^f_s0 z^wZu(xU^g{&U*AwC#;D}-*SG<0^`s|Z$XM{EzcR%VIv!BbIr)kJe>`ily1yAjUC2e zir#lq!1!v3{(W{BCmDJRTe;V=@c*#GI9kx#_`IeKTGRf0_BS!qCLXvvV`PaoQ*4Ay z%K+m#UZ0ywR2?OtW;Fpa6_20h$ D?G(&B literal 0 HcmV?d00001 diff --git a/toscaparser/tests/test_prereq.py b/toscaparser/tests/test_prereq.py index ce12d044..a118e1ca 100644 --- a/toscaparser/tests/test_prereq.py +++ b/toscaparser/tests/test_prereq.py @@ -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))