Skip to content

Commit

Permalink
Fix Sonic-config-engine testcase (sonic-net#47)
Browse files Browse the repository at this point in the history
* Fix Sonic-config-engine testcase

Signed-off-by: Sangita Maity <sangitamaity0211@gmail.com>

* Addressed review comments

Signed-off-by: Sangita Maity <sangitamaity0211@gmail.com>
  • Loading branch information
samaity authored Feb 17, 2020
1 parent aa7d8bf commit c160fc7
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 237 deletions.
7 changes: 5 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def filter_acl_mirror_table_bindings(acls, neighbors, port_channels):
#
###############################################################################

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

Expand Down Expand Up @@ -602,7 +602,10 @@ def parse_xml(filename, platform=None, port_config_file=None):
if child.tag == str(docker_routing_config_mode_qn):
docker_routing_config_mode = child.text

(ports, alias_map) = get_port_config(hwsku, platform, port_config_file)
if hwsku_config_file:
(ports, alias_map) = get_port_config(hwsku, platform, port_config_file, hwsku_config_file)
else:
(ports, alias_map) = get_port_config(hwsku, platform, port_config_file)
port_alias_map.update(alias_map)
for child in root:
if child.tag == str(QName(ns, "DpgDec")):
Expand Down
16 changes: 10 additions & 6 deletions src/sonic-config-engine/portconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ def get_hwsku_file_name(hwsku=None, platform=None):
if hwsku:
if platform:
hwsku_candidates_Json.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, HWSKU_JSON))
hwsku_candidates_Json.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, HWSKU_JSON)
hwsku_candidates_Json.append(os.path.join(SONIC_ROOT_PATH, hwsku, HWSKU_JSON)
hwsku_candidates_Json.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, HWSKU_JSON))
hwsku_candidates_Json.append(os.path.join(SONIC_ROOT_PATH, hwsku, HWSKU_JSON))
for candidate in hwsku_candidates_Json:
if os.path.isfile(candidate):
return candidate
return None

def get_port_config(hwsku=None, platform=None, port_config_file=None):
def get_port_config(hwsku=None, platform=None, port_config_file=None, hwsku_config_file=None):
config_db = db_connect_configdb()

# If available, Read from CONFIG DB first
Expand All @@ -114,11 +114,15 @@ def get_port_config(hwsku=None, platform=None, port_config_file=None):
if not port_config_file:
return ({}, {})


# Read from 'platform.json' file
if port_config_file.endswith('.json'):
hwsku_json_file = get_hwsku_file_name(hwsku, platform)
if not hwsku_json_file:
raise Exception("'hwsku_json' file does not exist!!! This file is necessary to proceed forward.")
if not hwsku_config_file:
hwsku_json_file = get_hwsku_file_name(hwsku, platform)
if not hwsku_json_file:
return ({}, {})
else:
hwsku_json_file = hwsku_config_file

return parse_platform_json_file(hwsku_json_file, port_config_file)

Expand Down
3 changes: 2 additions & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def main():
group.add_argument("-M", "--device-description", help="device description xml file")
group.add_argument("-k", "--hwsku", help="HwSKU")
parser.add_argument("-p", "--port-config", help="port config file, used with -m or -k", nargs='?', const=None)
parser.add_argument("-S", "--hwsku-config", help="hwsku config file, used with -p and -m or -k", nargs='?', const=None)
parser.add_argument("-y", "--yaml", help="yaml file that contains additional variables", action='append', default=[])
parser.add_argument("-j", "--json", help="json file that contains additional variables", action='append', default=[])
parser.add_argument("-a", "--additional-data", help="addition data, in json string")
Expand Down Expand Up @@ -247,7 +248,7 @@ def main():
else:
deep_update(data, parse_xml(minigraph, platform))
else:
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config))
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config, hwsku_config_file=args.hwsku_config))

if args.device_description != None:
deep_update(data, parse_device_desc_xml(args.device_description))
Expand Down
100 changes: 100 additions & 0 deletions src/sonic-config-engine/tests/sample_hwsku.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"interfaces": {
"Ethernet0": {
"default_brkout_mode": "1x100G[40G]"
},
"Ethernet4": {
"default_brkout_mode": "2x50G"
},
"Ethernet8": {
"default_brkout_mode": "4x25G[10G]"
},
"Ethernet12": {
"default_brkout_mode": "2x25G(2)+1x50G(2)"
},
"Ethernet16": {
"default_brkout_mode": "1x50G(2)+2x25G(2)"
},
"Ethernet20": {
"default_brkout_mode": "1x100G[40G]"
},
"Ethernet24": {
"default_brkout_mode": "2x50G"
},
"Ethernet28": {
"default_brkout_mode": "4x25G[10G]"
},
"Ethernet32": {
"default_brkout_mode": "2x25G(2)+1x50G(2)"
},
"Ethernet36": {
"default_brkout_mode": "1x50G(2)+2x25G(2)"
},
"Ethernet40": {
"default_brkout_mode": "1x100G[40G]"
},
"Ethernet44": {
"default_brkout_mode": "2x50G"
},
"Ethernet48": {
"default_brkout_mode": "4x25G[10G]"
},
"Ethernet52": {
"default_brkout_mode": "2x25G(2)+1x50G(2)"
},
"Ethernet56": {
"default_brkout_mode": "1x50G(2)+2x25G(2)"
},
"Ethernet60": {
"default_brkout_mode": "1x100G[40G]"
},
"Ethernet64": {
"default_brkout_mode": "2x50G"
},
"Ethernet68": {
"default_brkout_mode": "4x25G[10G]"
},
"Ethernet72": {
"default_brkout_mode": "2x25G(2)+1x50G(2)"
},
"Ethernet76": {
"default_brkout_mode": "1x50G(2)+2x25G(2)"
},
"Ethernet80": {
"default_brkout_mode": "1x100G[40G]"
},
"Ethernet84": {
"default_brkout_mode": "2x50G"
},
"Ethernet88": {
"default_brkout_mode": "4x25G[10G]"
},
"Ethernet92": {
"default_brkout_mode": "2x25G(2)+1x50G(2)"
},
"Ethernet96": {
"default_brkout_mode": "1x50G(2)+2x25G(2)"
},
"Ethernet100": {
"default_brkout_mode": "1x100G[40G]"
},
"Ethernet104": {
"default_brkout_mode": "2x50G"
},
"Ethernet108": {
"default_brkout_mode": "4x25G[10G]"
},
"Ethernet112": {
"default_brkout_mode": "2x25G(2)+1x50G(2)"
},
"Ethernet116": {
"default_brkout_mode": "1x50G(2)+2x25G(2)"
},
"Ethernet120": {
"default_brkout_mode": "1x100G[40G]"
},
"Ethernet124": {
"default_brkout_mode": "2x50G"
}
}
}
Loading

0 comments on commit c160fc7

Please sign in to comment.