X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_nbi%2Fdescriptor_topics.py;h=969586653487455895d317c88d7935f108b811f5;hb=refs%2Fchanges%2F12%2F13912%2F1;hp=2814653075319bddcec773e78e8ca4ee74a6df95;hpb=f2af4a100d308e07f355d61b94fb27d1ccc97aa2;p=osm%2FNBI.git diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index 28146530..96958665 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -20,6 +20,7 @@ import copy import os import shutil import functools +import re # import logging from deepdiff import DeepDiff @@ -51,10 +52,14 @@ from osm_nbi import utils __author__ = "Alfonso Tierno " +valid_helm_chart_re = re.compile( + r"^[a-z0-9]([-a-z0-9]*[a-z0-9]/)?([a-z0-9]([-a-z0-9]*[a-z0-9])?)*$" +) + class DescriptorTopic(BaseTopic): def __init__(self, db, fs, msg, auth): - BaseTopic.__init__(self, db, fs, msg, auth) + super().__init__(db, fs, msg, auth) def _validate_input_new(self, indata, storage_params, force=False): return indata @@ -437,7 +442,7 @@ class DescriptorTopic(BaseTopic): indata = json.load(content) else: error_text = "Invalid yaml format " - indata = yaml.load(content, Loader=yaml.SafeLoader) + indata = yaml.safe_load(content) # Need to close the file package here so it can be copied from the # revision to the current, unrevisioned record @@ -676,7 +681,7 @@ class DescriptorTopic(BaseTopic): # to preserve current expected behaviour if "userDefinedData" in indata: data = indata.pop("userDefinedData") - if type(data) == dict: + if isinstance(data, dict): indata["_admin"]["userDefinedData"] = data else: raise EngineException( @@ -847,9 +852,23 @@ class VnfdTopic(DescriptorTopic): self.validate_internal_virtual_links(indata) self.validate_monitoring_params(indata) self.validate_scaling_group_descriptor(indata) + self.validate_helm_chart(indata) return indata + @staticmethod + def validate_helm_chart(indata): + kdus = indata.get("kdu", []) + for kdu in kdus: + helm_chart_value = kdu.get("helm-chart") + if not helm_chart_value: + continue + if not valid_helm_chart_re.match(helm_chart_value): + raise EngineException( + "helm-chart '{}' is not valid".format(helm_chart_value), + http_code=HTTPStatus.UNPROCESSABLE_ENTITY, + ) + @staticmethod def validate_mgmt_interface_connection_point(indata): if not indata.get("vdu"): @@ -1323,11 +1342,9 @@ class VnfdTopic(DescriptorTopic): with self.fs.file_open( (old_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as old_descriptor_file: - with self.fs.file_open( (new_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as new_descriptor_file: - old_content = yaml.safe_load(old_descriptor_file.read()) new_content = yaml.safe_load(new_descriptor_file.read()) @@ -1377,7 +1394,7 @@ class NsdTopic(DescriptorTopic): topic_msg = "nsd" def __init__(self, db, fs, msg, auth): - DescriptorTopic.__init__(self, db, fs, msg, auth) + super().__init__(db, fs, msg, auth) def pyangbind_validation(self, item, data, force=False): if self._descriptor_data_is_in_old_format(data): @@ -1507,7 +1524,7 @@ class NsdTopic(DescriptorTopic): # to preserve current expected behaviour if "userDefinedData" in indata: data = indata.pop("userDefinedData") - if type(data) == dict: + if isinstance(data, dict): indata["_admin"]["userDefinedData"] = data else: raise EngineException( @@ -1719,11 +1736,9 @@ class NsdTopic(DescriptorTopic): with self.fs.file_open( (old_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as old_descriptor_file: - with self.fs.file_open( (new_descriptor_directory.rstrip("/"), descriptor_file_name), "r" ) as new_descriptor_file: - old_content = yaml.safe_load(old_descriptor_file.read()) new_content = yaml.safe_load(new_descriptor_file.read())