From: gcalvino Date: Fri, 15 Jun 2018 07:51:34 +0000 (+0200) Subject: Adding checks to upgrade and validation tools X-Git-Tag: v5.0.0~131 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=eb0de08b5ed14d15755ab3af7061cb4993a914e8;p=osm%2Fdevops.git Adding checks to upgrade and validation tools Signed-off-by: gcalvino --- diff --git a/descriptor-packages/tools/upgrade_descriptor_version.py b/descriptor-packages/tools/upgrade_descriptor_version.py index e33d2345..66bdbb18 100755 --- a/descriptor-packages/tools/upgrade_descriptor_version.py +++ b/descriptor-packages/tools/upgrade_descriptor_version.py @@ -129,6 +129,16 @@ if __name__=="__main__": if "vnfd:vnfd-catalog" in data or "vnfd-catalog" in data: descriptor = "VNF" + #Check if mgmt-interface is defined: + remove_prefix(data, "vnfd:") + vnfd_descriptor = data["vnfd-catalog"] + vnfd_list = vnfd_descriptor["vnfd"] + mgmt_iface = False + for vnfd in vnfd_list: + if vnfd.get("mgmt-interface"): + mgmt_iface = True + if not mgmt_iface: + raise KeyError("'mgmt-iface' is a mandatory field and it is not defined") myvnfd = vnfd_catalog.vnfd() pybindJSONDecoder.load_ietf_json(data, None, None, obj=myvnfd) elif "nsd:nsd-catalog" in data or "nsd-catalog" in data: @@ -192,6 +202,8 @@ if __name__=="__main__": error_position.append("external-interface") for external_interface in external_interface_list: error_position[-1] = "external-interface[{}]".format(external_interface["name"]) + if "rw-vnfd:floating-ip-needed" in external_interface: + del external_interface["rw-vnfd:floating-ip-needed"] external_interface["type"] = "EXTERNAL" external_interface["external-connection-point-ref"] = \ external_interface.pop("vnfd-connection-point-ref") @@ -210,6 +222,14 @@ if __name__=="__main__": internal_interface.pop("vdu-internal-connection-point-ref") interface_list.append(internal_interface) error_position.pop() + + #Removing "rw-vnfd:floating-ip-needed" items from V3 descriptors + interfaces = vdu.pop("interface", ()) + for iface in interfaces: + if "rw-vnfd:floating-ip-needed" in iface: + del iface["rw-vnfd:floating-ip-needed"] + interface_list.append(iface) + # order interface alphabetically and set position if interface_list: interface_list = sorted(interface_list, diff --git a/descriptor-packages/tools/validate_descriptor.py b/descriptor-packages/tools/validate_descriptor.py index 36e7c8d4..d2888c30 100755 --- a/descriptor-packages/tools/validate_descriptor.py +++ b/descriptor-packages/tools/validate_descriptor.py @@ -46,6 +46,28 @@ def usage(): print(" -i|--input FILE: (same as param FILE) descriptor file to be upgraded") return +def remove_prefix(desc, prefix): + """ + Recursively removes prefix from keys + :param desc: dictionary or list to change + :param prefix: prefix to remove. Must + :return: None, param desc is changed + """ + prefix_len = len(prefix) + if isinstance(desc, dict): + prefixed_list=[] + for k,v in desc.items(): + if isinstance(v, (list, tuple, dict)): + remove_prefix(v, prefix) + if isinstance(k, str) and k.startswith(prefix) and k != prefix: + prefixed_list.append(k) + for k in prefixed_list: + desc[k[prefix_len:]] = desc.pop(k) + elif isinstance(desc, (list, tuple)): + for i in desc: + if isinstance(desc, (list, tuple, dict)): + remove_prefix(i, prefix) + if __name__=="__main__": error_position = [] format_output_yaml = True @@ -91,6 +113,16 @@ if __name__=="__main__": if "vnfd:vnfd-catalog" in data or "vnfd-catalog" in data: descriptor = "VNF" + # Check if mgmt-interface is defined: + remove_prefix(data, "vnfd:") + vnfd_descriptor = data["vnfd-catalog"] + vnfd_list = vnfd_descriptor["vnfd"] + mgmt_iface = False + for vnfd in vnfd_list: + if vnfd.get("mgmt-interface"): + mgmt_iface = True + if not mgmt_iface: + raise KeyError("'mgmt-iface' is a mandatory field and it is not defined") myvnfd = vnfd_catalog.vnfd() pybindJSONDecoder.load_ietf_json(data, None, None, obj=myvnfd) elif "nsd:nsd-catalog" in data or "nsd-catalog" in data: