Skip to content

[acl-loader]: acl-loader integration. #1000

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

Merged
merged 4 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 0 additions & 24 deletions dockers/docker-orchagent/mirror.json.j2

This file was deleted.

1 change: 0 additions & 1 deletion dockers/docker-orchagent/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mkdir -p /etc/swss/config.d/

sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/switch.json.j2 > /etc/swss/config.d/switch.json
sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json
sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/mirror.json.j2 > /etc/swss/config.d/mirror.json
sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json

export platform=`sonic-cfggen -v platform`
Expand Down
16 changes: 1 addition & 15 deletions dockers/docker-orchagent/swssconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@

set -e

function config_acl {
if [ -f "/etc/sonic/acl.json" ]; then
mkdir -p /etc/swss/config.d/acl
rm -rf /etc/swss/config.d/acl/*
translate_acl -m /etc/sonic/minigraph.xml -o /etc/swss/config.d/acl /etc/sonic/acl.json
for filename in /etc/swss/config.d/acl/*.json; do
[ -e "$filename" ] || break
swssconfig $filename
done
fi
}

function fast_reboot {
case "$(cat /proc/cmdline)" in
*fast-reboot*)
Expand All @@ -39,7 +27,7 @@ fast_reboot

HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -d -v "DEVICE_METADATA['localhost']['hwsku']"`

SWSSCONFIG_ARGS="00-copp.config.json ipinip.json mirror.json ports.json switch.json "
SWSSCONFIG_ARGS="00-copp.config.json ipinip.json ports.json switch.json "

if [ "$HWSKU" == "Force10-S6000" ]; then
SWSSCONFIG_ARGS+="td2.32ports.buffers.json td2.32ports.qos.json "
Expand All @@ -56,5 +44,3 @@ for file in $SWSSCONFIG_ARGS; do
swssconfig /etc/swss/config.d/$file
sleep 1
done

config_acl
14 changes: 7 additions & 7 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class minigraph_encoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, (
ipaddress.IPv4Network, ipaddress.IPv6Network,
ipaddress.IPv4Network, ipaddress.IPv6Network,
ipaddress.IPv4Address, ipaddress.IPv6Address
)):
return str(obj)
Expand Down Expand Up @@ -129,7 +129,7 @@ def parse_dpg(dpg, hname):
intfname = lointf.find(str(QName(ns, "AttachTo"))).text
ipprefix = lointf.find(str(QName(ns1, "PrefixStr"))).text
lo_intfs[(intfname, ipprefix)] = {}

mgmtintfs = child.find(str(QName(ns, "ManagementIPInterfaces")))
mgmt_intf = {}
for mgmtintf in mgmtintfs.findall(str(QName(ns1, "ManagementIPInterface"))):
Expand Down Expand Up @@ -175,7 +175,7 @@ def parse_dpg(dpg, hname):
aclintfs = child.find(str(QName(ns, "AclInterfaces")))
acls = {}
for aclintf in aclintfs.findall(str(QName(ns, "AclInterface"))):
aclname = aclintf.find(str(QName(ns, "InAcl"))).text.lower().replace(" ", "_").replace("-", "_")
aclname = aclintf.find(str(QName(ns, "InAcl"))).text.upper().replace(" ", "_").replace("-", "_")
aclattach = aclintf.find(str(QName(ns, "AttachTo"))).text.split(';')
acl_intfs = []
is_mirror = False
Expand All @@ -193,7 +193,7 @@ def parse_dpg(dpg, hname):
acl_intfs = port_alias_map.values()
break;
if acl_intfs:
acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'mirror' if is_mirror else 'L3'}
acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'MIRROR' if is_mirror else 'L3'}
return intfs, lo_intfs, mgmt_intf, vlans, pcs, acls
return None, None, None, None, None, None

Expand Down Expand Up @@ -358,7 +358,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
port_speeds = parse_deviceinfo(child, hwsku)

results = {}
results['DEVICE_METADATA'] = {'localhost': {
results['DEVICE_METADATA'] = {'localhost': {
'bgp_asn': bgp_asn,
'deployment_id': deployment_id,
'hostname': hostname,
Expand Down Expand Up @@ -423,13 +423,13 @@ def parse_device_desc_xml(filename):
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type) = parse_device(root)

results = {}
results['DEVICE_METADATA'] = {'localhost': {
results['DEVICE_METADATA'] = {'localhost': {
'hostname': hostname,
'hwsku': hwsku,
}}

results['LOOPBACK_INTERFACE'] = {('lo', lo_prefix): {}}

mgmt_intf = {}
mgmtipn = ipaddress.IPNetwork(mgmt_prefix)
gwaddr = ipaddress.IPAddress(int(mgmtipn.network) + 1)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_test_suite():
author_email='[email protected]',
url='https://github.com/Azure/sonic-buildimage',
py_modules=['portconfig', 'minigraph', 'openconfig_acl', 'sonic_platform'],
scripts=['sonic-cfggen', 'translate_acl'],
scripts=['sonic-cfggen'],
install_requires=['lxml', 'jinja2', 'netaddr', 'ipaddr', 'pyyaml', 'pyangbind'],
test_suite='setup.get_test_suite',
)
14 changes: 0 additions & 14 deletions src/sonic-config-engine/tests/sample_output/mirror.json

This file was deleted.

46 changes: 0 additions & 46 deletions src/sonic-config-engine/tests/sample_output/rules_for_dataacl.json

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/sonic-config-engine/tests/sample_output/table_dataacl.json

This file was deleted.

10 changes: 0 additions & 10 deletions src/sonic-config-engine/tests/sample_output/table_everflow.json

This file was deleted.

58 changes: 0 additions & 58 deletions src/sonic-config-engine/tests/test_acl.py

This file was deleted.

16 changes: 8 additions & 8 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

class TestCfgGen(TestCase):

def setUp(self):
self.test_dir = os.path.dirname(os.path.realpath(__file__))
self.script_file = os.path.join(self.test_dir, '..', 'sonic-cfggen')
Expand All @@ -29,7 +29,7 @@ def test_dummy_run(self):
argument = ''
output = self.run_script(argument)
self.assertEqual(output, '')

def test_device_desc(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -M "' + self.sample_device_desc + '"'
output = self.run_script(argument)
Expand All @@ -44,17 +44,17 @@ def test_minigraph_sku(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -m "' + self.sample_graph + '"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'Force10-Z9100')

def test_print_data(self):
argument = '-m "' + self.sample_graph + '" --print-data'
output = self.run_script(argument)
self.assertTrue(len(output.strip()) > 0)

def test_jinja_expression(self):
argument = '-m "' + self.sample_graph + '" -v "DEVICE_METADATA[\'localhost\'][\'type\']"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'LeafRouter')

def test_additional_json_data(self):
argument = '-a \'{"key1":"value1"}\' -v key1'
output = self.run_script(argument)
Expand All @@ -64,7 +64,7 @@ def test_read_yaml(self):
argument = '-v yml_item -y ' + os.path.join(self.test_dir, 'test.yml')
output = self.run_script(argument)
self.assertEqual(output.strip(), '[\'value1\', \'value2\']')

def test_render_template(self):
argument = '-y ' + os.path.join(self.test_dir, 'test.yml') + ' -t ' + os.path.join(self.test_dir, 'test.j2')
output = self.run_script(argument)
Expand All @@ -73,13 +73,13 @@ def test_render_template(self):
def test_minigraph_acl(self):
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'dataacl': {'type': 'L3', 'policy_desc': 'dataacl', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
self.assertEqual(output.strip(), "{'DATAACL': {'type': 'L3', 'policy_desc': 'DATAACL', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")

def test_minigraph_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v \'INTERFACE.keys()\''
output = self.run_script(argument)
self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), ('Ethernet0', 'FC00::75/126')]")

def test_minigraph_vlans(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN'
output = self.run_script(argument)
Expand Down
13 changes: 2 additions & 11 deletions src/sonic-config-engine/tests/test_j2files.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def test_alias_map(self):
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + alias_map_template
output = self.run_script(argument)
data = json.loads(output)
self.assertEqual(data["Ethernet4"], "fortyGigE0/4")
self.assertEqual(data["Ethernet4"], "fortyGigE0/4")

def test_lldp(self):
lldpd_conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-lldp-sv2', 'lldpd.conf.j2')
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + lldpd_conf_template + ' > ' + self.output_file
self.run_script(argument)
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'lldpd.conf'), self.output_file))

def test_teamd(self):

def test_render_teamd(self, pc, minigraph, sample_output):
Expand Down Expand Up @@ -77,15 +77,6 @@ def test_ipinip(self):

assert filecmp.cmp(sample_output_file, self.output_file)

def test_everflow(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this test? We still need the minigraph parser to be able to generate mirror sessions from minigraph.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To work with config DB format

everflow_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-orchagent', 'mirror.json.j2')
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + everflow_file + ' > ' + self.output_file
self.run_script(argument)

sample_output_file = os.path.join(self.test_dir, 'sample_output', 'mirror.json')

assert filecmp.cmp(sample_output_file, self.output_file)

def test_msn27xx_32ports_buffers(self):
buffer_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-orchagent', 'msn27xx.32ports.buffers.json.j2')
argument = '-m ' + self.t1_mlnx_minigraph + ' -p ' + self.mlnx_port_config + ' -t ' + buffer_file + ' > ' + self.output_file
Expand Down
Loading