Skip to content

Commit

Permalink
Add unit-test and fix typo.
Browse files Browse the repository at this point in the history
Signed-off-by: Suvarna Meenakshi <[email protected]>
  • Loading branch information
SuvarnaMeenakshi committed Sep 2, 2022
1 parent b71e507 commit 35c76cb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/caclmgrd
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
self.update_thread[back_asic_namespace] = None
self.lock[back_asic_namespace] = threading.Lock()
self.num_changes[back_asic_namespace] = 0
self.update_docket_mgmt_ip_acl(back_asic_namespace)
self.update_docker_mgmt_ip_acl(back_asic_namespace)

for fabric_asic_namespace in namespaces['fabric_ns']:
self.update_thread[fabric_asic_namespace] = None
self.lock[fabric_asic_namespace] = threading.Lock()
self.num_changes[fabric_asic_namespace] = 0
self.update_docket_mgmt_ip_acl(fabric_asic_namespace)
self.update_docker_mgmt_ip_acl(fabric_asic_namespace)

def update_docket_mgmt_ip_acl(self, namespace):
def update_docker_mgmt_ip_acl(self, namespace):
self.iptables_cmd_ns_prefix[namespace] = "ip netns exec " + namespace + " "
self.namespace_docker_mgmt_ip[namespace] = self.get_namespace_mgmt_ip(self.iptables_cmd_ns_prefix[namespace],
namespace)
Expand Down
29 changes: 29 additions & 0 deletions tests/caclmgrd/caclmgrd_namespace_docker_ip_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import sys

from sonic_py_common.general import load_module_from_source
from unittest import TestCase, mock

class TestCaclmgrdNamespaceDockerIP(TestCase):
"""
Test caclmgrd Namespace docker management IP
"""
def setUp(self):
test_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
modules_path = os.path.dirname(test_path)
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, modules_path)
caclmgrd_path = os.path.join(scripts_path, 'caclmgrd')
self.caclmgrd = load_module_from_source('caclmgrd', caclmgrd_path)
self.maxDiff = None

def test_caclmgrd_namespace_docker_ip(self):
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ip = mock.MagicMock(return_value=[])
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ipv6 = mock.MagicMock(return_value=[])
with mock.patch('sonic_py_common.multi_asic.get_all_namespaces',
return_value={'front_ns': ['asic0'], 'back_ns': ['asic1'], 'fabric_ns': ['asic2']}):
caclmgrd_daemon = self.caclmgrd.ControlPlaneAclManager("caclmgrd")
self.assertTrue('asic0' in caclmgrd_daemon.namespace_docker_mgmt_ip)
self.assertTrue('asic1' in caclmgrd_daemon.namespace_docker_mgmt_ip)
self.assertTrue('asic2' in caclmgrd_daemon.namespace_docker_mgmt_ip)
self.assertListEqual(caclmgrd_daemon.namespace_docker_mgmt_ip['asic0'], [])

0 comments on commit 35c76cb

Please sign in to comment.