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.
[caclmgrd]: Add infrastructure to support adding feature specific acls (
sonic-net#11367) Why I did it Add infrastructure to support adding feature specific acls. If feature specific ACLs has to be added: if feature_name in self.feature_present and self.feature_present.get('feature_name'): add_feature_specific_acls() How I did it Add function to get features present in feature table. How to verify it unit-test passes.
- Loading branch information
1 parent
9aac067
commit 5713280
Showing
4 changed files
with
91 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
50 changes: 50 additions & 0 deletions
50
src/sonic-host-services/tests/caclmgrd/caclmgrd_feature_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,50 @@ | ||
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_bfd_vectors import CACLMGRD_BFD_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 TestFeature(TestCase): | ||
""" | ||
Test caclmgrd feature present | ||
""" | ||
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_BFD_TEST_VECTOR) | ||
@patchfs | ||
def test_feature_present(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.update_feature_present() | ||
self.assertTrue("bgp" in caclmgrd_daemon.feature_present) | ||
self.assertEqual(caclmgrd_daemon.feature_present["bgp"], 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
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