Refactor ns.py so that RO uses the IP profile as it comes from LCM 66/12966/2
authorGabriel Cuba <gcuba@whitestack.com>
Tue, 14 Feb 2023 17:43:32 +0000 (12:43 -0500)
committeraticig <gulsum.atici@canonical.com>
Tue, 28 Feb 2023 18:58:31 +0000 (19:58 +0100)
Change-Id: I36983c86d7c76ad8a9b93eb6eae254f844717e0e
Signed-off-by: Gabriel Cuba <gcuba@whitestack.com>
NG-RO/osm_ng_ro/ns.py
NG-RO/osm_ng_ro/tests/test_ns.py
releasenotes/notes/refactor_ip_profile-7678dd97cac685c4.yaml [new file with mode: 0644]

index 4e88cc4..a555672 100644 (file)
@@ -862,44 +862,6 @@ class Ns(object):
 
         return extra_dict
 
-    @staticmethod
-    def _ip_profile_to_ro(
-        ip_profile: Dict[str, Any],
-    ) -> Dict[str, Any]:
-        """[summary]
-
-        Args:
-            ip_profile (Dict[str, Any]): [description]
-
-        Returns:
-            Dict[str, Any]: [description]
-        """
-        if not ip_profile:
-            return None
-
-        ro_ip_profile = {
-            "ip_version": "IPv4"
-            if "v4" in ip_profile.get("ip-version", "ipv4")
-            else "IPv6",
-            "subnet_address": ip_profile.get("subnet-address"),
-            "gateway_address": ip_profile.get("gateway-address"),
-            "dhcp_enabled": ip_profile.get("dhcp-params", {}).get("enabled", False),
-            "dhcp_start_address": ip_profile.get("dhcp-params", {}).get(
-                "start-address", None
-            ),
-            "dhcp_count": ip_profile.get("dhcp-params", {}).get("count", None),
-        }
-
-        if ip_profile.get("dns-server"):
-            ro_ip_profile["dns_address"] = ";".join(
-                [v["address"] for v in ip_profile["dns-server"] if v.get("address")]
-            )
-
-        if ip_profile.get("security-group"):
-            ro_ip_profile["security_group"] = ip_profile["security-group"]
-
-        return ro_ip_profile
-
     @staticmethod
     def _process_net_params(
         target_vld: Dict[str, Any],
@@ -963,7 +925,7 @@ class Ns(object):
                 "net_name": (
                     f"{indata.get('name')[:16]}-{target_vld.get('name', target_vld.get('id'))[:16]}"
                 ),
-                "ip_profile": Ns._ip_profile_to_ro(vim_info.get("ip_profile")),
+                "ip_profile": vim_info.get("ip_profile"),
                 "provider_network_profile": vim_info.get("provider_network"),
             }
 
index d2fdc4d..d96d6a2 100644 (file)
@@ -2421,213 +2421,8 @@ class TestNs(unittest.TestCase):
         self.assertTrue(epa_params.called)
         self.assertDictEqual(result, expected_result)
 
-    def test__ip_profile_to_ro_with_none(self):
-        ip_profile = None
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertIsNone(result)
-
-    def test__ip_profile_to_ro_with_empty_profile(self):
-        ip_profile = {}
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertIsNone(result)
-
-    def test__ip_profile_to_ro_with_wrong_profile(self):
-        ip_profile = {
-            "no-profile": "here",
-        }
-        expected_result = {
-            "ip_version": "IPv4",
-            "subnet_address": None,
-            "gateway_address": None,
-            "dhcp_enabled": False,
-            "dhcp_start_address": None,
-            "dhcp_count": None,
-        }
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertDictEqual(expected_result, result)
-
-    def test__ip_profile_to_ro_with_ipv4_profile(self):
-        ip_profile = {
-            "ip-version": "ipv4",
-            "subnet-address": "192.168.0.0/24",
-            "gateway-address": "192.168.0.254",
-            "dhcp-params": {
-                "enabled": True,
-                "start-address": "192.168.0.10",
-                "count": 25,
-            },
-        }
-        expected_result = {
-            "ip_version": "IPv4",
-            "subnet_address": "192.168.0.0/24",
-            "gateway_address": "192.168.0.254",
-            "dhcp_enabled": True,
-            "dhcp_start_address": "192.168.0.10",
-            "dhcp_count": 25,
-        }
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertDictEqual(expected_result, result)
-
-    def test__ip_profile_to_ro_with_ipv6_profile(self):
-        ip_profile = {
-            "ip-version": "ipv6",
-            "subnet-address": "2001:0200:0001::/48",
-            "gateway-address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
-            "dhcp-params": {
-                "enabled": True,
-                "start-address": "2001:0200:0001::0010",
-                "count": 25,
-            },
-        }
-        expected_result = {
-            "ip_version": "IPv6",
-            "subnet_address": "2001:0200:0001::/48",
-            "gateway_address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
-            "dhcp_enabled": True,
-            "dhcp_start_address": "2001:0200:0001::0010",
-            "dhcp_count": 25,
-        }
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertDictEqual(expected_result, result)
-
-    def test__ip_profile_to_ro_with_dns_server(self):
-        ip_profile = {
-            "ip-version": "ipv4",
-            "subnet-address": "192.168.0.0/24",
-            "gateway-address": "192.168.0.254",
-            "dhcp-params": {
-                "enabled": True,
-                "start-address": "192.168.0.10",
-                "count": 25,
-            },
-            "dns-server": [
-                {
-                    "address": "8.8.8.8",
-                },
-                {
-                    "address": "1.1.1.1",
-                },
-                {
-                    "address": "1.0.0.1",
-                },
-            ],
-        }
-        expected_result = {
-            "ip_version": "IPv4",
-            "subnet_address": "192.168.0.0/24",
-            "gateway_address": "192.168.0.254",
-            "dhcp_enabled": True,
-            "dhcp_start_address": "192.168.0.10",
-            "dhcp_count": 25,
-            "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
-        }
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertDictEqual(expected_result, result)
-
-    def test__ip_profile_to_ro_with_security_group(self):
-        ip_profile = {
-            "ip-version": "ipv4",
-            "subnet-address": "192.168.0.0/24",
-            "gateway-address": "192.168.0.254",
-            "dhcp-params": {
-                "enabled": True,
-                "start-address": "192.168.0.10",
-                "count": 25,
-            },
-            "security-group": {
-                "some-security-group": "here",
-            },
-        }
-        expected_result = {
-            "ip_version": "IPv4",
-            "subnet_address": "192.168.0.0/24",
-            "gateway_address": "192.168.0.254",
-            "dhcp_enabled": True,
-            "dhcp_start_address": "192.168.0.10",
-            "dhcp_count": 25,
-            "security_group": {
-                "some-security-group": "here",
-            },
-        }
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertDictEqual(expected_result, result)
-
-    def test__ip_profile_to_ro(self):
-        ip_profile = {
-            "ip-version": "ipv4",
-            "subnet-address": "192.168.0.0/24",
-            "gateway-address": "192.168.0.254",
-            "dhcp-params": {
-                "enabled": True,
-                "start-address": "192.168.0.10",
-                "count": 25,
-            },
-            "dns-server": [
-                {
-                    "address": "8.8.8.8",
-                },
-                {
-                    "address": "1.1.1.1",
-                },
-                {
-                    "address": "1.0.0.1",
-                },
-            ],
-            "security-group": {
-                "some-security-group": "here",
-            },
-        }
-        expected_result = {
-            "ip_version": "IPv4",
-            "subnet_address": "192.168.0.0/24",
-            "gateway_address": "192.168.0.254",
-            "dhcp_enabled": True,
-            "dhcp_start_address": "192.168.0.10",
-            "dhcp_count": 25,
-            "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
-            "security_group": {
-                "some-security-group": "here",
-            },
-        }
-
-        result = Ns._ip_profile_to_ro(
-            ip_profile=ip_profile,
-        )
-
-        self.assertDictEqual(expected_result, result)
-
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_empty_params(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "name": "vld-name",
@@ -2637,6 +2432,9 @@ class TestNs(unittest.TestCase):
         }
         vim_info = {
             "provider_network": "some-profile-here",
+            "ip_profile": {
+                "some_ip_profile": "here",
+            },
         }
         target_record_id = ""
         expected_result = {
@@ -2650,10 +2448,6 @@ class TestNs(unittest.TestCase):
             }
         }
 
-        ip_profile_to_ro.return_value = {
-            "some_ip_profile": "here",
-        }
-
         result = Ns._process_net_params(
             target_vld=target_vld,
             indata=indata,
@@ -2662,12 +2456,9 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertTrue(ip_profile_to_ro.called)
 
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_vim_info_sdn(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "name": "vld-name",
@@ -2698,12 +2489,9 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertFalse(ip_profile_to_ro.called)
 
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_vim_info_sdn_target_vim(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "name": "vld-name",
@@ -2737,12 +2525,9 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertFalse(ip_profile_to_ro.called)
 
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_vim_network_name(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "name": "vld-name",
@@ -2770,12 +2555,9 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertFalse(ip_profile_to_ro.called)
 
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_vim_network_id(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "name": "vld-name",
@@ -2803,12 +2585,9 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertFalse(ip_profile_to_ro.called)
 
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_mgmt_network(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "id": "vld-id",
@@ -2835,12 +2614,9 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertFalse(ip_profile_to_ro.called)
 
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_underlay_eline(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "name": "vld-name",
@@ -2852,6 +2628,9 @@ class TestNs(unittest.TestCase):
         }
         vim_info = {
             "provider_network": "some-profile-here",
+            "ip_profile": {
+                "some_ip_profile": "here",
+            },
         }
         target_record_id = ""
         expected_result = {
@@ -2865,10 +2644,6 @@ class TestNs(unittest.TestCase):
             }
         }
 
-        ip_profile_to_ro.return_value = {
-            "some_ip_profile": "here",
-        }
-
         result = Ns._process_net_params(
             target_vld=target_vld,
             indata=indata,
@@ -2877,12 +2652,9 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertTrue(ip_profile_to_ro.called)
 
-    @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
     def test__process_net_params_with_underlay_elan(
         self,
-        ip_profile_to_ro,
     ):
         target_vld = {
             "name": "vld-name",
@@ -2894,6 +2666,9 @@ class TestNs(unittest.TestCase):
         }
         vim_info = {
             "provider_network": "some-profile-here",
+            "ip_profile": {
+                "some_ip_profile": "here",
+            },
         }
         target_record_id = ""
         expected_result = {
@@ -2907,10 +2682,6 @@ class TestNs(unittest.TestCase):
             }
         }
 
-        ip_profile_to_ro.return_value = {
-            "some_ip_profile": "here",
-        }
-
         result = Ns._process_net_params(
             target_vld=target_vld,
             indata=indata,
@@ -2919,7 +2690,6 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(expected_result, result)
-        self.assertTrue(ip_profile_to_ro.called)
 
     def test__get_cloud_init_exception(self):
         db_mock = MagicMock(name="database mock")
diff --git a/releasenotes/notes/refactor_ip_profile-7678dd97cac685c4.yaml b/releasenotes/notes/refactor_ip_profile-7678dd97cac685c4.yaml
new file mode 100644 (file)
index 0000000..40ad929
--- /dev/null
@@ -0,0 +1,20 @@
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+---
+other:
+  - |
+     ip_profile is received ready to use from LCM, so the method to translate it and its unit tests are removed