Skip to content

Commit

Permalink
Add acl table presence to the condition
Browse files Browse the repository at this point in the history
Signed-off-by: Neetha John <nejo@microsoft.com>
  • Loading branch information
neethajohn committed Jul 6, 2022
1 parent bfde26f commit f0fe613
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,12 @@ def _is_storage_device(cfg_db):
device_metadata = cfg_db.get_entry("DEVICE_METADATA", "localhost")
return device_metadata.get("storage_device", "Unknown") == "true"

def _is_acl_table_present(cfg_db, acl_table_name):
"""
Check if acl table exists
"""
return acl_table_name in cfg_db.get_keys("ACL_TABLE")

def load_backend_acl(cfg_db, device_type):
"""
Load acl on backend storage device
Expand All @@ -1144,7 +1150,7 @@ def load_backend_acl(cfg_db, device_type):
BACKEND_ACL_TEMPLATE_FILE = os.path.join('/', "usr", "share", "sonic", "templates", "backend_acl.j2")
BACKEND_ACL_FILE = os.path.join('/', "etc", "sonic", "backend_acl.json")

if device_type and device_type == "BackEndToRRouter" and _is_storage_device(cfg_db):
if device_type and device_type == "BackEndToRRouter" and _is_storage_device(cfg_db) and _is_acl_table_present(cfg_db, "DATAACL"):
if os.path.isfile(BACKEND_ACL_TEMPLATE_FILE):
clicommon.run_command(
"{} -d -t {},{}".format(
Expand Down
6 changes: 6 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ def test_load_backend_acl_storage_leaf(self, get_cmd_module, setup_single_broadc
db.cfgdb.set_entry("DEVICE_METADATA", "localhost", {"storage_device": "true"})
self.check_backend_acl(get_cmd_module, db, device_type='BackEndLeafRouter', condition=False)

def test_load_backend_acl_storage_no_dataacl(self, get_cmd_module, setup_single_broadcom_asic):
db = Db()
db.cfgdb.set_entry("DEVICE_METADATA", "localhost", {"storage_device": "true"})
db.cfgdb.set_entry("ACL_TABLE", "DATAACL", None)
self.check_backend_acl(get_cmd_module, db, device_type='BackEndToRRouter', condition=False)

def check_backend_acl(self, get_cmd_module, db, device_type='BackEndToRRouter', condition=True):
def is_file_side_effect(filename):
return True if 'backend_acl' in filename else False
Expand Down

0 comments on commit f0fe613

Please sign in to comment.