Skip to content

Commit 4d6cad7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feature
2 parents 17d44c2 + bceb13e commit 4d6cad7

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

azure-pipelines.yml

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ stages:
7171
sudo dpkg -i libnl-route-3-200_*.deb
7272
sudo dpkg -i libnl-nf-3-200_*.deb
7373
sudo dpkg -i libhiredis0.14_*.deb
74+
sudo dpkg -i libyang_1.0.73_*.deb
7475
workingDirectory: $(Pipeline.Workspace)/target/debs/buster/
7576
displayName: 'Install Debian dependencies'
7677

scripts/caclmgrd

+23-11
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,26 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
139139

140140
self.config_db_map[front_asic_namespace] = swsscommon.ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespace)
141141
self.config_db_map[front_asic_namespace].connect()
142-
self.iptables_cmd_ns_prefix[front_asic_namespace] = "ip netns exec " + front_asic_namespace + " "
143-
self.namespace_docker_mgmt_ip[front_asic_namespace] = self.get_namespace_mgmt_ip(self.iptables_cmd_ns_prefix[front_asic_namespace],
144-
front_asic_namespace)
145-
self.namespace_docker_mgmt_ipv6[front_asic_namespace] = self.get_namespace_mgmt_ipv6(self.iptables_cmd_ns_prefix[front_asic_namespace],
146-
front_asic_namespace)
142+
self.update_docker_mgmt_ip_acl(front_asic_namespace)
147143

148144
for back_asic_namespace in namespaces['back_ns']:
149145
self.update_thread[back_asic_namespace] = None
150146
self.lock[back_asic_namespace] = threading.Lock()
151147
self.num_changes[back_asic_namespace] = 0
152-
153-
self.iptables_cmd_ns_prefix[back_asic_namespace] = "ip netns exec " + back_asic_namespace + " "
154-
self.namespace_docker_mgmt_ip[back_asic_namespace] = self.get_namespace_mgmt_ip(self.iptables_cmd_ns_prefix[back_asic_namespace],
155-
back_asic_namespace)
156-
self.namespace_docker_mgmt_ipv6[back_asic_namespace] = self.get_namespace_mgmt_ipv6(self.iptables_cmd_ns_prefix[back_asic_namespace],
157-
back_asic_namespace)
148+
self.update_docker_mgmt_ip_acl(back_asic_namespace)
149+
150+
for fabric_asic_namespace in namespaces['fabric_ns']:
151+
self.update_thread[fabric_asic_namespace] = None
152+
self.lock[fabric_asic_namespace] = threading.Lock()
153+
self.num_changes[fabric_asic_namespace] = 0
154+
self.update_docker_mgmt_ip_acl(fabric_asic_namespace)
155+
156+
def update_docker_mgmt_ip_acl(self, namespace):
157+
self.iptables_cmd_ns_prefix[namespace] = "ip netns exec " + namespace + " "
158+
self.namespace_docker_mgmt_ip[namespace] = self.get_namespace_mgmt_ip(self.iptables_cmd_ns_prefix[namespace],
159+
namespace)
160+
self.namespace_docker_mgmt_ipv6[namespace] = self.get_namespace_mgmt_ipv6(self.iptables_cmd_ns_prefix[namespace],
161+
namespace)
158162

159163
def get_namespace_mgmt_ip(self, iptable_ns_cmd_prefix, namespace):
160164
ip_address_get_command = iptable_ns_cmd_prefix + "ip -4 -o addr show " + ("eth0" if namespace else "docker0") +\
@@ -551,6 +555,8 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
551555
ip_protocols = self.ACL_SERVICES[acl_service]["ip_protocols"]
552556
if "dst_ports" in self.ACL_SERVICES[acl_service]:
553557
dst_ports = self.ACL_SERVICES[acl_service]["dst_ports"]
558+
else:
559+
dst_ports = []
554560

555561
acl_rules = {}
556562

@@ -604,6 +610,12 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
604610
self.log_warning("Unable to determine if ACL table '{}' contains IPv4 or IPv6 rules. Skipping table..."
605611
.format(table_name))
606612
continue
613+
# If no destination port found for this ACL table,
614+
# log a message and skip processing this table.
615+
if len(dst_ports) == 0:
616+
self.log_warning("Required destination port not found for ACL table '{}'. Skipping table..."
617+
.format(table_name))
618+
continue
607619
ipv4_src_ip_set = set()
608620
ipv6_src_ip_set = set()
609621
# For each ACL rule in this table (in descending order of priority)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import sys
3+
4+
from sonic_py_common.general import load_module_from_source
5+
from unittest import TestCase, mock
6+
7+
class TestCaclmgrdNamespaceDockerIP(TestCase):
8+
"""
9+
Test caclmgrd Namespace docker management IP
10+
"""
11+
def setUp(self):
12+
test_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13+
modules_path = os.path.dirname(test_path)
14+
scripts_path = os.path.join(modules_path, "scripts")
15+
sys.path.insert(0, modules_path)
16+
caclmgrd_path = os.path.join(scripts_path, 'caclmgrd')
17+
self.caclmgrd = load_module_from_source('caclmgrd', caclmgrd_path)
18+
self.maxDiff = None
19+
20+
def test_caclmgrd_namespace_docker_ip(self):
21+
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ip = mock.MagicMock(return_value=[])
22+
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ipv6 = mock.MagicMock(return_value=[])
23+
with mock.patch('sonic_py_common.multi_asic.get_all_namespaces',
24+
return_value={'front_ns': ['asic0'], 'back_ns': ['asic1'], 'fabric_ns': ['asic2']}):
25+
caclmgrd_daemon = self.caclmgrd.ControlPlaneAclManager("caclmgrd")
26+
self.assertTrue('asic0' in caclmgrd_daemon.namespace_docker_mgmt_ip)
27+
self.assertTrue('asic1' in caclmgrd_daemon.namespace_docker_mgmt_ip)
28+
self.assertTrue('asic2' in caclmgrd_daemon.namespace_docker_mgmt_ip)
29+
self.assertListEqual(caclmgrd_daemon.namespace_docker_mgmt_ip['asic0'], [])

0 commit comments

Comments
 (0)