Skip to content
Snippets Groups Projects
Commit eb0de08b authored by calvinosanch's avatar calvinosanch Committed by calvinosanch
Browse files

Adding checks to upgrade and validation tools


Signed-off-by: default avatargcalvino <guillermo.calvinosanchez@altran.com>
parent dbada22a
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment