Skip to content

Commit 722b796

Browse files
authored
Fixed ip6table internal_docker_ip_traffic rule command for multi-asic (#94)
* Fixed ip6table internal_docker_ip_traffic rule command for multi-asic * Added test coverage Signed-off-by: anamehra <anamehra@cisco.com>
1 parent b9600f1 commit 722b796

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

scripts/caclmgrd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
336336
allow_internal_docker_ip_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['ip6tables', '-A', 'INPUT', '-s', self.namespace_docker_mgmt_ipv6[namespace], '-d', self.namespace_docker_mgmt_ipv6[namespace], '-j', 'ACCEPT'])
337337
allow_internal_docker_ip_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['iptables', '-A', 'INPUT', '-s', self.namespace_mgmt_ip, '-d', self.namespace_docker_mgmt_ip[namespace], '-j', 'ACCEPT'])
338338

339-
allow_internal_docker_ip_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['ip6tables', '-A', 'INPUT', '-s', self.namespace_mgmt_ipv6, '-d', 'self.namespace_docker_mgmt_ipv6[namespace]', '-j', 'ACCEPT'])
339+
allow_internal_docker_ip_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['ip6tables', '-A', 'INPUT', '-s', self.namespace_mgmt_ipv6, '-d', self.namespace_docker_mgmt_ipv6[namespace], '-j', 'ACCEPT'])
340340

341341
else:
342342

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import sys
3+
4+
from parameterized import parameterized
5+
from sonic_py_common.general import load_module_from_source
6+
from unittest import TestCase, mock
7+
from pyfakefs.fake_filesystem_unittest import patchfs
8+
9+
from .test_internal_docker_ip_traffic_vectors import CACLMGRD_INTERNAL_DOCKER_IP_TEST_VECTOR
10+
11+
12+
class TestCaclmgrdGenerateInternalDockerIp(TestCase):
13+
"""
14+
Test caclmgrd multi-asic generate internal docker ip allow rule
15+
"""
16+
def setUp(self):
17+
test_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18+
modules_path = os.path.dirname(test_path)
19+
scripts_path = os.path.join(modules_path, "scripts")
20+
sys.path.insert(0, modules_path)
21+
caclmgrd_path = os.path.join(scripts_path, 'caclmgrd')
22+
self.caclmgrd = load_module_from_source('caclmgrd', caclmgrd_path)
23+
self.maxDiff = None
24+
25+
@parameterized.expand(CACLMGRD_INTERNAL_DOCKER_IP_TEST_VECTOR)
26+
@patchfs
27+
def test_caclmgrd_internal_docker_ip_traffic(self, test_name, test_data, fs):
28+
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ip = mock.MagicMock()
29+
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ipv6 = mock.MagicMock()
30+
caclmgrd_daemon = self.caclmgrd.ControlPlaneAclManager("caclmgrd")
31+
caclmgrd_daemon.iptables_cmd_ns_prefix['asic0'] = ['ip', 'netns', 'exec', 'asic0']
32+
caclmgrd_daemon.namespace_docker_mgmt_ip['asic0'] = '1.1.1.1/32'
33+
caclmgrd_daemon.namespace_mgmt_ip = '2.2.2.2/32'
34+
caclmgrd_daemon.namespace_docker_mgmt_ipv6['asic0'] = 'fd::01/128'
35+
caclmgrd_daemon.namespace_mgmt_ipv6 = 'fd::02/128'
36+
37+
ret = caclmgrd_daemon.generate_allow_internal_docker_ip_traffic_commands('asic0')
38+
self.assertListEqual(test_data["return"], ret)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from unittest.mock import call
2+
3+
"""
4+
caclmgrd internal docker ip traffic test vector
5+
"""
6+
CACLMGRD_INTERNAL_DOCKER_IP_TEST_VECTOR = [
7+
[
8+
"Allow internal docker traffic",
9+
{
10+
"return": [
11+
['ip', 'netns', 'exec', 'asic0', 'iptables', '-A', 'INPUT', '-s', '1.1.1.1/32', '-d', '1.1.1.1/32', '-j', 'ACCEPT'],
12+
['ip', 'netns', 'exec', 'asic0', 'ip6tables', '-A', 'INPUT', '-s', 'fd::01/128', '-d', 'fd::01/128', '-j', 'ACCEPT'],
13+
['ip', 'netns', 'exec', 'asic0', 'iptables', '-A', 'INPUT', '-s', '2.2.2.2/32', '-d', '1.1.1.1/32', '-j', 'ACCEPT'],
14+
['ip', 'netns', 'exec', 'asic0', 'ip6tables', '-A', 'INPUT', '-s', 'fd::02/128', '-d', 'fd::01/128', '-j', 'ACCEPT']
15+
]
16+
}
17+
]
18+
]

0 commit comments

Comments
 (0)