X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Ftests%2Ftest_lcm_utils.py;fp=osm_lcm%2Ftests%2Ftest_lcm_utils.py;h=20ec63e76262a26aeed4f4fa167662cce3cd4757;hb=c773744f338d3c019b4978b0fc591d14c614b4cf;hp=32abbf5b429849a3f75ea22c8e52049c87c8a998;hpb=86d80c694ea72220c1da0872c38c4c880d895cd1;p=osm%2FLCM.git 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)