Skip to content

Commit

Permalink
[sonic-cfggen]: Add -p option and add teamd.j2 test (#414)
Browse files Browse the repository at this point in the history
- Add -p --port-config option to feed sonic-cfggen with port_config.ini
  file when necessary.
- Update minigraph.py file to accept the -p option
- Add test_j2files.py test to test config.sh and all .j2 templates
  * Currently test_teamd is added to test both the config.sh and teamd.j2
    file works well with the t0 sample minigraph and sample port config
    file
  * The sample output is added to the folder sample_output for comparison

Signed-off-by: Shuotian Cheng <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng committed Mar 18, 2017
1 parent 4212efd commit 7b7a616
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dockers/docker-teamd/teamd.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"name": "ethtool"
},
"ports": {
{% for member in minigraph_portchannels[pc]['members'] %}
"{{member}}": {}{% if not loop.last %},{% endif %}
{% for member in minigraph_portchannels[pc]['members'] %}
"{{member}}": {}{% if not loop.last %},{% endif %}

{% endfor %}
{% endfor %}
}
}

9 changes: 5 additions & 4 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ def get_mgmt_info(devices, dev, port):

return ret_val

def get_alias_map_list(hwsku, platform=None):
def get_alias_map_list(hwsku, platform=None, port_config_file=None):
port_config_candidates = []
if port_config_file != None:
port_config_candidates.append(port_config_file)
port_config_candidates.append('/usr/share/sonic/hwsku/port_config.ini')
if platform != None:
port_config_candidates.append(os.path.join('/usr/share/sonic/device', platform, hwsku, 'port_config.ini'))
Expand All @@ -354,7 +356,7 @@ def get_alias_map_list(hwsku, platform=None):
alias_map_list.append({'sonic': tokens[0], 'origin': tokens[2].strip()})
return alias_map_list

def parse_xml(filename, platform=None):
def parse_xml(filename, platform=None, port_config_file=None):
root = ET.parse(filename).getroot()
mini_graph_path = filename

Expand Down Expand Up @@ -385,7 +387,7 @@ def parse_xml(filename, platform=None):
if child.tag == str(hostname_qn):
hostname = child.text

alias_map_list = get_alias_map_list(hwsku, platform)
alias_map_list = get_alias_map_list(hwsku, platform, port_config_file)
if alias_map_list != None:
for item in alias_map_list:
port_alias_map[item['origin']] = item['sonic']
Expand Down Expand Up @@ -438,7 +440,6 @@ def parse_xml(filename, platform=None):

port_alias_map = {}


def print_parse_xml(filename):
results = parse_xml(filename)
print(json.dumps(results, indent=3, cls=minigraph_encoder))
Expand Down
Empty file modified src/sonic-config-engine/setup.py
100644 → 100755
Empty file.
11 changes: 9 additions & 2 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def get_machine_info():
def main():
parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.")
parser.add_argument("-m", "--minigraph", help="minigraph xml file")
parser.add_argument("-p", "--port-config", help="port config file, used with -m")
parser.add_argument("-y", "--yaml", help="yaml file that contains addtional variables")
parser.add_argument("-a", "--additional-data", help="addition data, in json string")
group = parser.add_mutually_exclusive_group()
Expand All @@ -83,9 +84,15 @@ def main():
if args.minigraph != None:
minigraph = args.minigraph
if data.has_key('platform'):
data.update(parse_xml(minigraph, data['platform']))
if args.port_config != None:
data.update(parse_xml(minigraph, data['platform'], args.port_config))
else:
data.update(parse_xml(minigraph, data['platform']))
else:
data.update(parse_xml(minigraph))
if args.port_config != None:
data.update(parse_xml(minigraph, port_config_file=args.port_config))
else:
data.update(parse_xml(minigraph))

if args.yaml != None:
with open(args.yaml, 'r') as stream:
Expand Down
1 change: 1 addition & 0 deletions src/sonic-config-engine/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
16 changes: 16 additions & 0 deletions src/sonic-config-engine/tests/sample_output/PortChannel01.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"device": "PortChannel01",
"runner": {
"name": "lacp",
"active": true,
"min_ports": 1,
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
"Ethernet112": {}
}
}

16 changes: 16 additions & 0 deletions src/sonic-config-engine/tests/sample_output/PortChannel02.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"device": "PortChannel02",
"runner": {
"name": "lacp",
"active": true,
"min_ports": 1,
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
"Ethernet116": {}
}
}

16 changes: 16 additions & 0 deletions src/sonic-config-engine/tests/sample_output/PortChannel03.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"device": "PortChannel03",
"runner": {
"name": "lacp",
"active": true,
"min_ports": 1,
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
"Ethernet120": {}
}
}

16 changes: 16 additions & 0 deletions src/sonic-config-engine/tests/sample_output/PortChannel04.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"device": "PortChannel04",
"runner": {
"name": "lacp",
"active": true,
"min_ports": 1,
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
"Ethernet124": {}
}
}

Loading

0 comments on commit 7b7a616

Please sign in to comment.