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

fix show acl table exception #2359

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
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
14 changes: 9 additions & 5 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,16 @@ def show_table(self, table_name):
stage = val.get("stage", Stage.INGRESS).lower()

if val["type"] == AclLoader.ACL_TABLE_TYPE_CTRLPLANE:
services = natsorted(val["services"])
data.append([key, val["type"], services[0], val["policy_desc"], stage])
services = val.get("services", [])
pettershao-ragilenetworks marked this conversation as resolved.
Show resolved Hide resolved
if not services:
data.append([key, val["type"], "", val["policy_desc"], stage])
else:
services = natsorted(val["services"])
pettershao-ragilenetworks marked this conversation as resolved.
Show resolved Hide resolved
data.append([key, val["type"], services[0], val["policy_desc"], stage])

if len(services) > 1:
for service in services[1:]:
pettershao-ragilenetworks marked this conversation as resolved.
Show resolved Hide resolved
data.append(["", "", service, "", ""])
if len(services) > 1:
for service in services[1:]:
data.append(["", "", service, "", ""])
else:
if not val["ports"]:
data.append([key, val["type"], "", val["policy_desc"], stage])
Expand Down
37 changes: 37 additions & 0 deletions tests/show_acl_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import imp
import os
import sys
import pytest

import acl_loader.main as acl_loader_show
from acl_loader import *
from acl_loader.main import *

from click.testing import CliRunner
from utilities_common.db import Db
import mock_tables.dbconnector

class TestShowAcl(object):
def test_show_ctrl_table(self):
runner = CliRunner()
aclloader = AclLoader()
aclloader.configdb.set_entry("ACL_TABLE", "CTRL_TEST", {"type": "CTRLPLANE", "policy_desc": "CTRL_TEST", "services": ["SNMP","NTP"]})
aclloader.read_tables_info()
context = {
"acl_loader": aclloader
}
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['table'], ['CTRL_TEST'], obj=context)
assert result.exit_code == 0
assert "CTRL_TEST" in result.output

def test_show_ctrl_table_without_services(self):
runner = CliRunner()
aclloader = AclLoader()
aclloader.configdb.set_entry("ACL_TABLE", "CTRL_TEST", {"type": "CTRLPLANE", "policy_desc": "CTRL_TEST"})
aclloader.read_tables_info()
context = {
"acl_loader": aclloader
}
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['table'], ['CTRL_TEST'], obj=context)
assert result.exit_code == 0
assert "CTRL_TEST" in result.output