Skip to content

Commit

Permalink
add coverage
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya <[email protected]>
  • Loading branch information
vdahiya12 committed Nov 2, 2023
1 parent 512f145 commit 71f5370
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
53 changes: 52 additions & 1 deletion tests/caclmgrd/caclmgrd_soc_rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from unittest import TestCase, mock
from pyfakefs.fake_filesystem_unittest import patchfs

from .test_soc_rules_vectors import CACLMGRD_SOC_TEST_VECTOR
from .test_soc_rules_vectors import CACLMGRD_SOC_TEST_VECTOR, CACLMGRD_SOC_TEST_VECTOR_EMPTY
from tests.common.mock_configdb import MockConfigDb
from unittest.mock import MagicMock, patch

Expand Down Expand Up @@ -51,6 +51,57 @@ def test_caclmgrd_soc(self, test_name, test_data, fs):
caclmgrd_daemon.update_control_plane_nat_acls('', {}, MockConfigDb())
mocked_subprocess.Popen.assert_has_calls(test_data["expected_subprocess_calls"], any_order=True)


@parameterized.expand(CACLMGRD_SOC_TEST_VECTOR_EMPTY)
@patchfs
@patch('caclmgrd.get_ipv4_networks_from_interface_table', MagicMock(return_value=[]))
def test_caclmgrd_soc_no_ips(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")
caclmgrd_daemon.update_control_plane_nat_acls('', {}, MockConfigDb())
mocked_subprocess.Popen.assert_has_calls(test_data["expected_subprocess_calls"], any_order=True)


@parameterized.expand(CACLMGRD_SOC_TEST_VECTOR_EMPTY)
@patchfs
@patch('caclmgrd.get_ipv4_networks_from_interface_table', MagicMock(return_value=['10.10.10.10']))
def test_caclmgrd_soc_ip_string(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")
caclmgrd_daemon.update_control_plane_nat_acls('', {}, MockConfigDb())
mocked_subprocess.Popen.assert_has_calls(test_data["expected_subprocess_calls"], any_order=True)


def test_get_ipv4_networks_from_interface_table(self):
if not os.path.exists(DBCONFIG_PATH):
fs.create_file(DBCONFIG_PATH) # fake database_config.json
Expand Down
40 changes: 40 additions & 0 deletions tests/caclmgrd/test_soc_rules_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,43 @@
}
]
]


CACLMGRD_SOC_TEST_VECTOR_EMPTY = [
[
"SOC_SESSION_TEST",
{
"config_db": {
"DEVICE_METADATA": {
"localhost": {
"subtype": "DualToR",
"type": "ToRRouter",
}
},
"MUX_CABLE": {
"Ethernet4": {
"cable_type": "active-active",
"soc_ipv4": "10.10.11.7/32",
}
},
"VLAN_INTERFACE": {
"Vlan1000|10.10.10.3/24": {
"NULL": "NULL",
}
},
"LOOPBACK_INTERFACE": {
"Loopback3|10.10.10.10/32": {
"NULL": "NULL",
}
},
"FEATURE": {
},
},
"expected_subprocess_calls": [],
"popen_attributes": {
'communicate.return_value': ('output', 'error'),
},
"call_rc": 0,
}
]
]

0 comments on commit 71f5370

Please sign in to comment.