forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 8381313: [202012] Fix caclmgrd crash issue when applying sc…
…ale cacl rules (sonic-net#15630) Cherry pick sonic-net#15630 to internal repo. Related work items: sonic-net#15630, #24449635
- Loading branch information
1 parent
3914416
commit d2a8a8f
Showing
5 changed files
with
1,105 additions
and
33 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
51 changes: 51 additions & 0 deletions
51
src/sonic-host-services/tests/caclmgrd/caclmgrd_scale_test.py
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,51 @@ | ||
import os | ||
import sys | ||
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_scale_vectors import CACLMGRD_SCALE_TEST_VECTOR | ||
from tests.common.mock_configdb import MockConfigDb | ||
|
||
|
||
DBCONFIG_PATH = '/var/run/redis/sonic-db/database_config.json' | ||
|
||
class TestCaclmgrdScale(TestCase): | ||
""" | ||
Test caclmgrd with scale cacl rules | ||
""" | ||
def setUp(self): | ||
swsscommon.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_SCALE_TEST_VECTOR) | ||
@patchfs | ||
def test_caclmgrd_scale(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.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.num_changes[''] = 150 | ||
caclmgrd_daemon.check_and_update_control_plane_acls('', 150) | ||
|
||
mocked_subprocess.Popen.assert_has_calls(test_data["expected_subprocess_calls"], any_order=True) |
Oops, something went wrong.