Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update load minigraph to load backend acl #2236

Merged
merged 4 commits into from
Jul 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unit tests for backend acl load
Signed-off-by: Neetha John <nejo@microsoft.com>
neethajohn committed Jun 27, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8398e8e25313b43fde901db30eefc2a24d6fe531
33 changes: 33 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
@@ -321,6 +321,39 @@ def test_load_minigraph_with_port_config(self, get_cmd_module, setup_single_broa
port_config = [{"PORT": {"Ethernet0": {"admin_status": "up"}}}]
self.check_port_config(db, config, port_config, "config interface startup Ethernet0")

def test_load_backend_acl(self, get_cmd_module, setup_single_broadcom_asic):
self.check_backend_acl(get_cmd_module, storage_device=True, device_type='BackEndToRRouter', condition=True)

def test_load_backend_acl_not_storage(self, get_cmd_module, setup_single_broadcom_asic):
self.check_backend_acl(get_cmd_module, storage_device=False, device_type='BackEndToRRouter', condition=False)

def test_load_backend_acl_storage_leaf(self, get_cmd_module, setup_single_broadcom_asic):
self.check_backend_acl(get_cmd_module, storage_device=True, device_type='BackEndLeafRouter', condition=False)

def check_backend_acl(self, get_cmd_module, storage_device=True, device_type='BackEndToRRouter', condition=True):
with mock.patch('config.main._is_storage_device', mock.MagicMock(return_value=storage_device)):
def is_file_side_effect(filename):
return True if 'backend_acl' in filename else False
with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
with mock.patch('config.main._get_device_type', mock.MagicMock(return_value=device_type)):
with mock.patch(
"utilities_common.cli.run_command",
mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
(config, show) = get_cmd_module
runner = CliRunner()
result = runner.invoke(config.config.commands["load_minigraph"], ["-y"])
print(result.exit_code)
expected_output = ['Running command: acl-loader update incremental /etc/sonic/backend_acl.json',
'Running command: /usr/local/bin/sonic-cfggen -d -t /usr/share/sonic/templates/backend_acl.j2,/etc/sonic/backend_acl.json'
]
print(result.output)
assert result.exit_code == 0
output = result.output.split('\n')
if condition:
assert set(expected_output).issubset(set(output))
else:
assert not(set(expected_output).issubset(set(output)))

def check_port_config(self, db, config, port_config, expected_output):
def read_json_file_side_effect(filename):
return port_config