This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
sonic-buildimage/src/sonic-device-data/tests/platform_json_checker
Sangita Maity 18263c99dd
[DPB|master] Update Dynamic Port Breakout Logic for flexible alias support a… (#6831)
To fix [DPB| wrong aliases for interfaces](https://github.com/Azure/sonic-buildimage/issues/6024) issue, implimented flexible alias support [design doc](https://github.com/Azure/SONiC/pull/749)

> [[dpb|config] Fix the validation logic of breakout mode](https://github.com/Azure/sonic-utilities/pull/1440) depends on this

#### How I did it

1. Removed `"alias_at_lanes"` from port-configuration file(i.e. platfrom.json) 
2. Added dictionary to "breakout_modes" values. This defines the breakout modes available on the platform for this parent port, and it maps to the alias list. The alias list presents the alias names for individual ports in order under this breakout mode.
```
{
    "interfaces": {
        "Ethernet0": {
            "index": "1,1,1,1",
            "lanes": "0,1,2,3",
            "breakout_modes": {
                "1x100G[40G]": ["Eth1"],
                "2x50G": ["Eth1/1", "Eth1/2"],
                "4x25G[10G]": ["Eth1/1", "Eth1/2", "Eth1/3", "Eth1/4"],
                "2x25G(2)+1x50G(2)": ["Eth1/1", "Eth1/2", "Eth1/3"],
                "1x50G(2)+2x25G(2)": ["Eth1/1", "Eth1/2", "Eth1/3"]
            }
        }
}
```
#### How to verify it
`config interface breakout`

Signed-off-by: Sangita Maity <samaity@linkedin.com>
2021-02-26 00:13:33 -08:00

104 lines
2.9 KiB
Python
Executable File

#!/usr/bin/env python3
import glob
import json
import re
import sys
# Global variable
PORT_ATTRIBUTES = ["index", "lanes", "breakout_modes"]
ATTR_LEN = len(PORT_ATTRIBUTES)
PORT_REG = "Ethernet(\d+)"
PLATFORM_JSON = '*platform.json'
INTF_KEY = "interfaces"
def usage():
print("Usage: " + sys.argv[0] + " <platform_json_file>")
sys.exit(1)
def check_port_attr(port_attr):
for each_key in port_attr:
if each_key not in PORT_ATTRIBUTES:
print("Error: "+ each_key + " is not the correct Port attribute.")
return False
if not port_attr[each_key]:
print("Error: "+ each_key + " has no value.")
return False
if each_key.lower() == "breakout_modes":
brkout_modes = port_attr[each_key]
if not isinstance(brkout_modes, dict):
print("Error:value type of "+ each_key + " must be dictionary.")
return False
else:
if not isinstance(port_attr[each_key], str):
print("Error:value type of "+ each_key + " must be string.")
return False
return True
def check_file(platform_json_file):
try:
platform_cap_file = open(platform_json_file,"r")
platform_file_data = platform_cap_file.read()
port_dict = json.loads(platform_file_data)
for each_port in port_dict[INTF_KEY]:
# Validate port at top level
port_id = re.search(PORT_REG, each_port)
if port_id is None:
print("Error: Unknown Interface " + str(each_port) + " at top level")
return False
total_attr = len(list(port_dict[INTF_KEY][each_port].keys()))
port_attr = port_dict[INTF_KEY][each_port]
if total_attr != ATTR_LEN:
missing_attr = ', '.join(set(PORT_ATTRIBUTES).difference(list(port_attr)))
print("Error: " + missing_attr + " of " + each_port + " is/are missing")
return False
#Validate port attributes for each port
if not check_port_attr(port_attr):
return False
except IOError:
print("Error: Cannot open file " + platform_json_file)
return False
except ValueError as e:
print("Error in parsing json file " + platform_json_file + " ")
print(str(e))
return False
return True
def main(argv):
if len(argv) > 0 and argv[0] == "-h":
usage()
# Load target file
if len(argv) == 0:
files = glob.glob(PLATFORM_JSON)
else:
files = argv
all_good = True
for f in files:
good = check_file(f)
if good:
print("File " + f + " passed validity check")
else:
print("File " + f + " failed validity check")
all_good = all_good and good
if not all_good:
sys.exit(-1)
if __name__ == "__main__":
main(sys.argv[1:])