From: Gabriel Cuba Date: Tue, 14 Feb 2023 18:09:18 +0000 (-0500) Subject: Build IP profile using the format RO expects, so no further translation is needed. X-Git-Tag: release-v14.0-start~21 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F69%2F12969%2F4;p=osm%2FLCM.git Build IP profile using the format RO expects, so no further translation is needed. Related RO change: https://osm.etsi.org/gerrit/12966 Change-Id: I5f686f00a5c1d500255d38ae135f81544df32556 Signed-off-by: Gabriel Cuba --- diff --git a/osm_lcm/lcm_utils.py b/osm_lcm/lcm_utils.py index 7ce1841..579a2a5 100644 --- a/osm_lcm/lcm_utils.py +++ b/osm_lcm/lcm_utils.py @@ -173,6 +173,32 @@ def get_ee_id_parts(ee_id): return version, namespace, helm_id +def vld_to_ro_ip_profile(source_data): + if source_data: + return { + "ip_version": "IPv4" + if "v4" in source_data.get("ip-version", "ipv4") + else "IPv6", + "subnet_address": source_data.get("cidr") + or source_data.get("subnet-address"), + "gateway_address": source_data.get("gateway-ip") + or source_data.get("gateway-address"), + "dns_address": ";".join( + [v["address"] for v in source_data["dns-server"] if v.get("address")] + ) + if source_data.get("dns-server") + else None, + "dhcp_enabled": source_data.get("dhcp-params", {}).get("enabled", False) + or source_data.get("dhcp-enabled", False), + "dhcp_start_address": source_data["dhcp-params"].get("start-address") + if source_data.get("dhcp-params") + else None, + "dhcp_count": source_data["dhcp-params"].get("count") + if source_data.get("dhcp-params") + else None, + } + + class LcmBase: def __init__(self, msg, logger): """ diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index 915581f..dd7ff3e 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -61,6 +61,7 @@ from osm_lcm.lcm_utils import ( check_juju_bundle_existence, get_charm_artifact_path, get_ee_id_parts, + vld_to_ro_ip_profile, ) from osm_lcm.data_utils.nsd import ( get_ns_configuration_relation_list, @@ -831,9 +832,9 @@ class NsLcm(LcmBase): target_vim, target_vld, vld_params, target_sdn ): if vld_params.get("ip-profile"): - target_vld["vim_info"][target_vim]["ip_profile"] = vld_params[ - "ip-profile" - ] + target_vld["vim_info"][target_vim]["ip_profile"] = vld_to_ro_ip_profile( + vld_params["ip-profile"] + ) if vld_params.get("provider-network"): target_vld["vim_info"][target_vim]["provider_network"] = vld_params[ "provider-network" @@ -1044,27 +1045,9 @@ class NsLcm(LcmBase): and nsd_vlp.get("virtual-link-protocol-data") and nsd_vlp["virtual-link-protocol-data"].get("l3-protocol-data") ): - ip_profile_source_data = nsd_vlp["virtual-link-protocol-data"][ + vld_params["ip-profile"] = nsd_vlp["virtual-link-protocol-data"][ "l3-protocol-data" ] - ip_profile_dest_data = {} - if "ip-version" in ip_profile_source_data: - ip_profile_dest_data["ip-version"] = ip_profile_source_data[ - "ip-version" - ] - if "cidr" in ip_profile_source_data: - ip_profile_dest_data["subnet-address"] = ip_profile_source_data[ - "cidr" - ] - if "gateway-ip" in ip_profile_source_data: - ip_profile_dest_data["gateway-address"] = ip_profile_source_data[ - "gateway-ip" - ] - if "dhcp-enabled" in ip_profile_source_data: - ip_profile_dest_data["dhcp-params"] = { - "enabled": ip_profile_source_data["dhcp-enabled"] - } - vld_params["ip-profile"] = ip_profile_dest_data # update vld_params with instantiation params vld_instantiation_params = find_in_list( @@ -1130,28 +1113,9 @@ class NsLcm(LcmBase): and vnfd_vlp.get("virtual-link-protocol-data") and vnfd_vlp["virtual-link-protocol-data"].get("l3-protocol-data") ): - ip_profile_source_data = vnfd_vlp["virtual-link-protocol-data"][ + vld_params["ip-profile"] = vnfd_vlp["virtual-link-protocol-data"][ "l3-protocol-data" ] - ip_profile_dest_data = {} - if "ip-version" in ip_profile_source_data: - ip_profile_dest_data["ip-version"] = ip_profile_source_data[ - "ip-version" - ] - if "cidr" in ip_profile_source_data: - ip_profile_dest_data["subnet-address"] = ip_profile_source_data[ - "cidr" - ] - if "gateway-ip" in ip_profile_source_data: - ip_profile_dest_data[ - "gateway-address" - ] = ip_profile_source_data["gateway-ip"] - if "dhcp-enabled" in ip_profile_source_data: - ip_profile_dest_data["dhcp-params"] = { - "enabled": ip_profile_source_data["dhcp-enabled"] - } - - vld_params["ip-profile"] = ip_profile_dest_data # update vld_params with instantiation params if vnf_params: vld_instantiation_params = find_in_list( diff --git a/osm_lcm/tests/test_lcm_utils.py b/osm_lcm/tests/test_lcm_utils.py index 32abbf5..20ec63e 100644 --- a/osm_lcm/tests/test_lcm_utils.py +++ b/osm_lcm/tests/test_lcm_utils.py @@ -24,7 +24,7 @@ from osm_common.msgkafka import MsgKafka from osm_common import fslocal from osm_lcm.data_utils.database.database import Database from osm_lcm.data_utils.filesystem.filesystem import Filesystem -from osm_lcm.lcm_utils import LcmBase, LcmException +from osm_lcm.lcm_utils import LcmBase, LcmException, vld_to_ro_ip_profile from osm_lcm.tests import test_db_descriptors as descriptors import yaml from zipfile import BadZipfile @@ -438,3 +438,93 @@ class TestLcmBase(TestCase): with self.assertRaises(FileNotFoundError): LcmBase.compare_charmdir_hash(charm_dir1, charm_dir2) self.assertEqual(mock_checksum.dirhash.call_count, 1) + + +class TestLcmUtils(TestCase): + def setUp(self): + pass + + def test__vld_to_ro_ip_profile_with_none(self): + vld_data = None + + result = vld_to_ro_ip_profile( + source_data=vld_data, + ) + + self.assertIsNone(result) + + def test__vld_to_ro_ip_profile_with_empty_profile(self): + vld_data = {} + + result = vld_to_ro_ip_profile( + source_data=vld_data, + ) + + self.assertIsNone(result) + + def test__vld_to_ro_ip_profile_with_wrong_profile(self): + vld_data = { + "no-profile": "here", + } + expected_result = { + "ip_version": "IPv4", + "subnet_address": None, + "gateway_address": None, + "dns_address": None, + "dhcp_enabled": False, + "dhcp_start_address": None, + "dhcp_count": None, + } + + result = vld_to_ro_ip_profile( + source_data=vld_data, + ) + + self.assertDictEqual(expected_result, result) + + def test__vld_to_ro_ip_profile_with_ipv4_profile(self): + vld_data = { + "ip-version": "ipv4", + "cidr": "192.168.0.0/24", + "gateway-ip": "192.168.0.254", + "dhcp-enabled": True, + "dns-server": [{"address": "8.8.8.8"}], + } + expected_result = { + "ip_version": "IPv4", + "subnet_address": "192.168.0.0/24", + "gateway_address": "192.168.0.254", + "dns_address": "8.8.8.8", + "dhcp_enabled": True, + "dhcp_start_address": None, + "dhcp_count": None, + } + + result = vld_to_ro_ip_profile( + source_data=vld_data, + ) + + self.assertDictEqual(expected_result, result) + + def test__vld_to_ro_ip_profile_with_ipv6_profile(self): + vld_data = { + "ip-version": "ipv6", + "cidr": "2001:0200:0001::/48", + "gateway-ip": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe", + "dhcp-enabled": True, + } + expected_result = { + "ip_version": "IPv6", + "subnet_address": "2001:0200:0001::/48", + "gateway_address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe", + "dns_address": None, + "dhcp_enabled": True, + "dhcp_start_address": None, + "dhcp_count": None, + } + + result = vld_to_ro_ip_profile( + source_data=vld_data, + ) + + self.assertDictEqual(expected_result, result)