Skip to content

Commit d27462a

Browse files
authored
Revert "[202012] Update load minigraph to load backend acl (#2235)"
This reverts commit ecca18f.
1 parent f0a9f4f commit d27462a

File tree

2 files changed

+2
-83
lines changed

2 files changed

+2
-83
lines changed

config/main.py

+2-40
Original file line numberDiff line numberDiff line change
@@ -938,40 +938,6 @@ def validate_ipv4_address(ctx, param, ip_addr):
938938
except ValueError as e:
939939
raise click.UsageError(str(e))
940940

941-
def _is_storage_device(cfg_db):
942-
"""
943-
Check if the device is a storage device or not
944-
"""
945-
device_metadata = cfg_db.get_entry("DEVICE_METADATA", "localhost")
946-
return device_metadata.get("storage_device", "Unknown") == "true"
947-
948-
def _is_acl_table_present(cfg_db, acl_table_name):
949-
"""
950-
Check if acl table exists
951-
"""
952-
return acl_table_name in cfg_db.get_keys("ACL_TABLE")
953-
954-
def load_backend_acl(cfg_db, device_type):
955-
"""
956-
Load acl on backend storage device
957-
"""
958-
959-
BACKEND_ACL_TEMPLATE_FILE = os.path.join('/', "usr", "share", "sonic", "templates", "backend_acl.j2")
960-
BACKEND_ACL_FILE = os.path.join('/', "etc", "sonic", "backend_acl.json")
961-
962-
if device_type and device_type == "BackEndToRRouter" and _is_storage_device(cfg_db) and _is_acl_table_present(cfg_db, "DATAACL"):
963-
if os.path.isfile(BACKEND_ACL_TEMPLATE_FILE):
964-
clicommon.run_command(
965-
"{} -d -t {},{}".format(
966-
SONIC_CFGGEN_PATH,
967-
BACKEND_ACL_TEMPLATE_FILE,
968-
BACKEND_ACL_FILE
969-
),
970-
display_cmd=True
971-
)
972-
if os.path.isfile(BACKEND_ACL_FILE):
973-
clicommon.run_command("acl-loader update incremental {}".format(BACKEND_ACL_FILE), display_cmd=True)
974-
975941

976942
# This is our main entrypoint - the main 'config' command
977943
@click.group(cls=clicommon.AbbreviationGroup, context_settings=CONTEXT_SETTINGS)
@@ -1346,12 +1312,6 @@ def load_minigraph(db, no_service_restart):
13461312
if os.path.isfile('/etc/sonic/acl.json'):
13471313
clicommon.run_command("acl-loader update full /etc/sonic/acl.json", display_cmd=True)
13481314

1349-
# get the device type
1350-
device_type = _get_device_type()
1351-
1352-
# Load backend acl
1353-
load_backend_acl(db.cfgdb, device_type)
1354-
13551315
# Load port_config.json
13561316
try:
13571317
load_port_config(db.cfgdb, '/etc/sonic/port_config.json')
@@ -1361,6 +1321,8 @@ def load_minigraph(db, no_service_restart):
13611321
# generate QoS and Buffer configs
13621322
clicommon.run_command("config qos reload --no-dynamic-buffer", display_cmd=True)
13631323

1324+
# get the device type
1325+
device_type = _get_device_type()
13641326
if device_type != 'MgmtToRRouter' and device_type != 'MgmtTsToR' and device_type != 'BmcMgmtToRRouter' and device_type != 'EPMS':
13651327
clicommon.run_command("pfcwd start_default", display_cmd=True)
13661328

tests/config_test.py

-43
Original file line numberDiff line numberDiff line change
@@ -141,49 +141,6 @@ def test_load_minigraph_with_port_config(self, get_cmd_module, setup_single_broa
141141
port_config = [{"PORT": {"Ethernet0": {"admin_status": "up"}}}]
142142
self.check_port_config(db, config, port_config, "config interface startup Ethernet0")
143143

144-
def test_load_backend_acl(self, get_cmd_module, setup_single_broadcom_asic):
145-
db = Db()
146-
db.cfgdb.set_entry("DEVICE_METADATA", "localhost", {"storage_device": "true"})
147-
self.check_backend_acl(get_cmd_module, db, device_type='BackEndToRRouter', condition=True)
148-
149-
def test_load_backend_acl_not_storage(self, get_cmd_module, setup_single_broadcom_asic):
150-
db = Db()
151-
self.check_backend_acl(get_cmd_module, db, device_type='BackEndToRRouter', condition=False)
152-
153-
def test_load_backend_acl_storage_leaf(self, get_cmd_module, setup_single_broadcom_asic):
154-
db = Db()
155-
db.cfgdb.set_entry("DEVICE_METADATA", "localhost", {"storage_device": "true"})
156-
self.check_backend_acl(get_cmd_module, db, device_type='BackEndLeafRouter', condition=False)
157-
158-
def test_load_backend_acl_storage_no_dataacl(self, get_cmd_module, setup_single_broadcom_asic):
159-
db = Db()
160-
db.cfgdb.set_entry("DEVICE_METADATA", "localhost", {"storage_device": "true"})
161-
db.cfgdb.set_entry("ACL_TABLE", "DATAACL", None)
162-
self.check_backend_acl(get_cmd_module, db, device_type='BackEndToRRouter', condition=False)
163-
164-
def check_backend_acl(self, get_cmd_module, db, device_type='BackEndToRRouter', condition=True):
165-
def is_file_side_effect(filename):
166-
return True if 'backend_acl' in filename else False
167-
with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
168-
with mock.patch('config.main._get_device_type', mock.MagicMock(return_value=device_type)):
169-
with mock.patch(
170-
"utilities_common.cli.run_command",
171-
mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
172-
(config, show) = get_cmd_module
173-
runner = CliRunner()
174-
result = runner.invoke(config.config.commands["load_minigraph"], ["-y"], obj=db)
175-
print(result.exit_code)
176-
expected_output = ['Running command: acl-loader update incremental /etc/sonic/backend_acl.json',
177-
'Running command: /usr/local/bin/sonic-cfggen -d -t /usr/share/sonic/templates/backend_acl.j2,/etc/sonic/backend_acl.json'
178-
]
179-
print(result.output)
180-
assert result.exit_code == 0
181-
output = result.output.split('\n')
182-
if condition:
183-
assert set(expected_output).issubset(set(output))
184-
else:
185-
assert not(set(expected_output).issubset(set(output)))
186-
187144
def check_port_config(self, db, config, port_config, expected_output):
188145
def read_json_file_side_effect(filename):
189146
return port_config

0 commit comments

Comments
 (0)