-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from dgsudharsan/vxlan_allow
[caclmgrd]Allow Vxlan udp port on receiving vxlan tunnel configuration
- Loading branch information
1 parent
63fed10
commit b1f3b21
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os | ||
import sys | ||
from swsscommon import swsscommon | ||
|
||
from parameterized import parameterized | ||
from sonic_py_common.general import load_module_from_source | ||
from unittest import TestCase, mock | ||
from pyfakefs.fake_filesystem_unittest import patchfs | ||
|
||
from .test_vxlan_vectors import CACLMGRD_VXLAN_TEST_VECTOR | ||
from tests.common.mock_configdb import MockConfigDb | ||
from unittest.mock import MagicMock, patch | ||
|
||
DBCONFIG_PATH = '/var/run/redis/sonic-db/database_config.json' | ||
|
||
class TestCaclmgrdVxlan(TestCase): | ||
""" | ||
Test caclmgrd vxlan | ||
""" | ||
def setUp(self): | ||
swsscommon.ConfigDBConnector = MockConfigDb | ||
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) | ||
|
||
@parameterized.expand(CACLMGRD_VXLAN_TEST_VECTOR) | ||
@patchfs | ||
def test_caclmgrd_vxlan(self, test_name, test_data, fs): | ||
if not os.path.exists(DBCONFIG_PATH): | ||
fs.create_file(DBCONFIG_PATH) # fake database_config.json | ||
|
||
MockConfigDb.set_config_db(test_data["config_db"]) | ||
|
||
with mock.patch("caclmgrd.ControlPlaneAclManager.run_commands_pipe", return_value='sonic'): | ||
with mock.patch("caclmgrd.subprocess") as mocked_subprocess: | ||
popen_mock = mock.Mock() | ||
popen_attrs = test_data["popen_attributes"] | ||
popen_mock.configure_mock(**popen_attrs) | ||
mocked_subprocess.Popen.return_value = popen_mock | ||
mocked_subprocess.PIPE = -1 | ||
|
||
call_rc = test_data["call_rc"] | ||
mocked_subprocess.call.return_value = call_rc | ||
|
||
caclmgrd_daemon = self.caclmgrd.ControlPlaneAclManager("caclmgrd") | ||
ret = caclmgrd_daemon.allow_vxlan_port('', []) | ||
assert ret == False | ||
caclmgrd_daemon.block_vxlan_port('') | ||
assert ret == False | ||
data = test_data["input"] | ||
caclmgrd_daemon.allow_vxlan_port('', data) | ||
mocked_subprocess.Popen.assert_has_calls(test_data["expected_add_subprocess_calls"], any_order=True) | ||
caclmgrd_daemon.block_vxlan_port('') | ||
mocked_subprocess.Popen.assert_has_calls(test_data["expected_del_subprocess_calls"], any_order=True) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from unittest.mock import call | ||
import subprocess | ||
|
||
""" | ||
caclmgrd bfd test vector | ||
""" | ||
CACLMGRD_VXLAN_TEST_VECTOR = [ | ||
[ | ||
"VXLAN_TUNNEL_TEST_V4", | ||
{ | ||
"config_db": { | ||
"DEVICE_METADATA": { | ||
"localhost": { | ||
"subtype": "DualToR", | ||
"type": "ToRRouter", | ||
} | ||
}, | ||
"FEATURE": { | ||
"bgp": { | ||
"auto_restart": "enabled", | ||
"state": "enabled", | ||
} | ||
}, | ||
}, | ||
"input" : [("src_ip", "10.1.1.1")], | ||
"expected_add_subprocess_calls": [ | ||
call(['iptables', '-I', 'INPUT', '2', '-p', 'udp', '-d', '10.1.1.1', '--dport', '4789', '-j', 'ACCEPT'], universal_newlines=True, stdout=subprocess.PIPE)], | ||
"expected_del_subprocess_calls": [ | ||
call(['iptables', '-D', 'INPUT', '-p', 'udp', '-d', '10.1.1.1', '--dport', '4789', '-j', 'ACCEPT'], universal_newlines=True, stdout=subprocess.PIPE) | ||
], | ||
"popen_attributes": { | ||
'communicate.return_value': ('output', 'error'), | ||
}, | ||
"call_rc": 0, | ||
} | ||
], | ||
[ | ||
"VXLAN_TUNNEL_TEST_V6", | ||
{ | ||
"config_db": { | ||
"DEVICE_METADATA": { | ||
"localhost": { | ||
"subtype": "DualToR", | ||
"type": "ToRRouter", | ||
} | ||
}, | ||
"FEATURE": { | ||
"bgp": { | ||
"auto_restart": "enabled", | ||
"state": "enabled", | ||
} | ||
}, | ||
}, | ||
"input" : [("src_ip", "2001::1")], | ||
"expected_add_subprocess_calls": [ | ||
call(['ip6tables', '-I', 'INPUT', '2', '-p', 'udp', '-d', '2001::1', '--dport', '4789', '-j', 'ACCEPT'], universal_newlines=True, stdout=subprocess.PIPE)], | ||
"expected_del_subprocess_calls": [ | ||
call(['ip6tables', '-D', 'INPUT', '-p', 'udp', '-d', '2001::1', '--dport', '4789', '-j', 'ACCEPT'], universal_newlines=True, stdout=subprocess.PIPE) | ||
], | ||
"popen_attributes": { | ||
'communicate.return_value': ('output', 'error'), | ||
}, | ||
"call_rc": 0, | ||
} | ||
] | ||
] |