Skip to content

Commit 436ecb0

Browse files
authored
[GCU Feature Update] Cherry-pick Platform Validator PR to 202205 (sonic-net#2883)
* [GCU] Complete RDMA Platform Validator PR (sonic-net#2857) Cherry-pick PR 2692, 2818, and 2857 to 202205
1 parent 1787410 commit 436ecb0

8 files changed

+614
-65
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,117 @@
1-
from sonic_py_common import device_info
1+
import os
22
import re
3+
import json
4+
import jsonpointer
5+
import subprocess
6+
from sonic_py_common import device_info
7+
from .gu_common import GenericConfigUpdaterError
8+
9+
10+
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
11+
GCU_TABLE_MOD_CONF_FILE = f"{SCRIPT_DIR}/gcu_field_operation_validators.conf.json"
12+
GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
13+
14+
def get_asic_name():
15+
asic = "unknown"
16+
17+
if os.path.exists(GCU_TABLE_MOD_CONF_FILE):
18+
with open(GCU_TABLE_MOD_CONF_FILE, "r") as s:
19+
gcu_field_operation_conf = json.load(s)
20+
else:
21+
raise GenericConfigUpdaterError("GCU table modification validators config file not found")
22+
23+
asic_mapping = gcu_field_operation_conf["helper_data"]["rdma_config_update_validator"]
24+
asic_type = device_info.get_sonic_version_info()['asic_type']
25+
26+
if asic_type == 'cisco-8000':
27+
asic = "cisco-8000"
28+
elif asic_type == 'mellanox' or asic_type == 'vs' or asic_type == 'broadcom':
29+
proc = subprocess.Popen(GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
30+
output, err = proc.communicate()
31+
hwsku = output.rstrip('\n')
32+
if asic_type == 'mellanox' or asic_type == 'vs':
33+
spc1_hwskus = asic_mapping["mellanox_asics"]["spc1"]
34+
if hwsku.lower() in [spc1_hwsku.lower() for spc1_hwsku in spc1_hwskus]:
35+
asic = "spc1"
36+
return asic
37+
if asic_type == 'broadcom' or asic_type == 'vs':
38+
broadcom_asics = asic_mapping["broadcom_asics"]
39+
for asic_shorthand, hwskus in broadcom_asics.items():
40+
if asic != "unknown":
41+
break
42+
for hwsku_cur in hwskus:
43+
if hwsku_cur.lower() in hwsku.lower():
44+
asic = asic_shorthand
45+
break
46+
47+
return asic
348

4-
def rdma_config_update_validator():
5-
version_info = device_info.get_sonic_version_info()
6-
asic_type = version_info.get('asic_type')
749

8-
if (asic_type != 'mellanox' and asic_type != 'broadcom' and asic_type != 'cisco-8000'):
50+
def rdma_config_update_validator(patch_element):
51+
asic = get_asic_name()
52+
if asic == "unknown":
953
return False
54+
version_info = device_info.get_sonic_version_info()
55+
build_version = version_info.get('build_version')
56+
version_substrings = build_version.split('.')
57+
branch_version = None
58+
59+
for substring in version_substrings:
60+
if substring.isdigit() and re.match(r'^\d{8}$', substring):
61+
branch_version = substring
62+
63+
path = patch_element["path"]
64+
table = jsonpointer.JsonPointer(path).parts[0]
65+
66+
# Helper function to return relevant cleaned paths, consdiers case where the jsonpatch value is a dict
67+
# For paths like /PFC_WD/Ethernet112/action, remove Ethernet112 from the path so that we can clearly determine the relevant field (i.e. action, not Ethernet112)
68+
def _get_fields_in_patch():
69+
cleaned_fields = []
70+
71+
field_elements = jsonpointer.JsonPointer(path).parts[1:]
72+
cleaned_field_elements = [elem for elem in field_elements if not any(char.isdigit() for char in elem)]
73+
cleaned_field = '/'.join(cleaned_field_elements).lower()
74+
75+
76+
if 'value' in patch_element.keys() and isinstance(patch_element['value'], dict):
77+
for key in patch_element['value']:
78+
cleaned_fields.append(cleaned_field+ '/' + key)
79+
else:
80+
cleaned_fields.append(cleaned_field)
81+
82+
return cleaned_fields
83+
84+
if os.path.exists(GCU_TABLE_MOD_CONF_FILE):
85+
with open(GCU_TABLE_MOD_CONF_FILE, "r") as s:
86+
gcu_field_operation_conf = json.load(s)
87+
else:
88+
raise GenericConfigUpdaterError("GCU table modification validators config file not found")
89+
90+
tables = gcu_field_operation_conf["tables"]
91+
scenarios = tables[table]["validator_data"]["rdma_config_update_validator"]
92+
93+
cleaned_fields = _get_fields_in_patch()
94+
for cleaned_field in cleaned_fields:
95+
scenario = None
96+
for key in scenarios.keys():
97+
if cleaned_field in scenarios[key]["fields"]:
98+
scenario = scenarios[key]
99+
break
100+
101+
if scenario is None:
102+
return False
103+
104+
if scenario["platforms"][asic] == "":
105+
return False
106+
107+
if patch_element['op'] not in scenario["operations"]:
108+
return False
109+
110+
if branch_version is not None:
111+
if asic in scenario["platforms"]:
112+
if branch_version < scenario["platforms"][asic]:
113+
return False
114+
else:
115+
return False
116+
10117
return True

generic_config_updater/gcu_field_operation_validators.conf.json

+118-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,128 @@
1010
"e.g. 'show.acl.test_acl'",
1111
"",
1212
"field_operation_validators for a given table defines a list of validators that all must pass for modification to the specified field and table to be allowed",
13+
"",
14+
"validator_data provides data relevant to each validator",
1315
""
1416
],
17+
"helper_data": {
18+
"rdma_config_update_validator": {
19+
"mellanox_asics": {
20+
"spc1": [ "ACS-MSN2700", "ACS-MSN2740", "ACS-MSN2100", "ACS-MSN2410", "ACS-MSN2010", "Mellanox-SN2700", "Mellanox-SN2700-D48C8" ]
21+
},
22+
"broadcom_asics": {
23+
"th": [ "Force10-S6100", "Arista-7060CX-32S-C32", "Arista-7060CX-32S-C32-T1", "Arista-7060CX-32S-D48C8", "Celestica-DX010-C32", "Seastone-DX010" ],
24+
"th2": [ "Arista-7260CX3-D108C8", "Arista-7260CX3-C64", "Arista-7260CX3-Q64" ],
25+
"td2": [ "Force10-S6000", "Force10-S6000-Q24S32", "Arista-7050-QX32", "Arista-7050-QX-32S", "Nexus-3164", "Arista-7050QX32S-Q32" ],
26+
"td3": [ "Arista-7050CX3-32S-C32", "Arista-7050CX3-32S-D48C8" ]
27+
}
28+
}
29+
},
1530
"tables": {
1631
"PFC_WD": {
17-
"field_operation_validators": [ "generic_config_updater.field_operation_validators.rdma_config_update_validator" ]
32+
"field_operation_validators": [ "generic_config_updater.field_operation_validators.rdma_config_update_validator" ],
33+
"validator_data": {
34+
"rdma_config_update_validator": {
35+
"PFCWD enable/disable": {
36+
"fields": [
37+
"restoration_time",
38+
"detection_time",
39+
"action",
40+
"global/poll_interval"
41+
],
42+
"operations": ["remove", "add", "replace"],
43+
"platforms": {
44+
"spc1": "20181100",
45+
"td2": "20181100",
46+
"th": "20181100",
47+
"th2": "20181100",
48+
"td3": "20201200",
49+
"cisco-8000": "20201200"
50+
}
51+
}
52+
}
53+
}
54+
},
55+
"BUFFER_POOL": {
56+
"field_operation_validators": [ "generic_config_updater.field_operation_validators.rdma_config_update_validator" ],
57+
"validator_data": {
58+
"rdma_config_update_validator": {
59+
"Shared/headroom pool size changes": {
60+
"fields": [
61+
"ingress_lossless_pool/xoff",
62+
"ingress_lossless_pool/size",
63+
"egress_lossy_pool/size"
64+
],
65+
"operations": ["replace"],
66+
"platforms": {
67+
"spc1": "20191100",
68+
"td2": "",
69+
"th": "20221100",
70+
"th2": "20221100",
71+
"td3": "20221100",
72+
"cisco-8000": ""
73+
}
74+
}
75+
}
76+
}
77+
},
78+
"BUFFER_PROFILE": {
79+
"field_operation_validators": [ "generic_config_updater.field_operation_validators.rdma_config_update_validator" ],
80+
"validator_data": {
81+
"rdma_config_update_validator": {
82+
"Dynamic threshold tuning": {
83+
"fields": [
84+
"dynamic_th"
85+
],
86+
"operations": ["replace"],
87+
"platforms": {
88+
"spc1": "20181100",
89+
"td2": "20181100",
90+
"th": "20181100",
91+
"th2": "20181100",
92+
"td3": "20201200",
93+
"cisco-8000": ""
94+
}
95+
},
96+
"PG headroom modification": {
97+
"fields": [
98+
"xoff"
99+
],
100+
"operations": ["replace"],
101+
"platforms": {
102+
"spc1": "20191100",
103+
"td2": "",
104+
"th": "20221100",
105+
"th2": "20221100",
106+
"td3": "20221100",
107+
"cisco-8000": ""
108+
}
109+
}
110+
}
111+
}
112+
},
113+
"WRED_PROFILE": {
114+
"field_operation_validators": [ "generic_config_updater.field_operation_validators.rdma_config_update_validator" ],
115+
"validator_data": {
116+
"rdma_config_update_validator": {
117+
"ECN tuning": {
118+
"fields": [
119+
"azure_lossless/green_min_threshold",
120+
"azure_lossless/green_max_threshold",
121+
"azure_lossless/green_drop_probability"
122+
],
123+
"operations": ["replace"],
124+
"platforms": {
125+
"spc1": "20181100",
126+
"td2": "20181100",
127+
"th": "20181100",
128+
"th2": "20181100",
129+
"td3": "20201200",
130+
"cisco-8000": ""
131+
}
132+
}
133+
}
134+
}
18135
}
19136
}
20137
}

generic_config_updater/gu_common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ def validate_field_operation(self, old_config, target_config):
166166
if any(op['op'] == operation and field == op['path'] for op in patch):
167167
raise IllegalPatchOperationError("Given patch operation is invalid. Operation: {} is illegal on field: {}".format(operation, field))
168168

169-
def _invoke_validating_function(cmd):
169+
def _invoke_validating_function(cmd, jsonpatch_element):
170170
# cmd is in the format as <package/module name>.<method name>
171171
method_name = cmd.split(".")[-1]
172172
module_name = ".".join(cmd.split(".")[0:-1])
173173
if module_name != "generic_config_updater.field_operation_validators" or "validator" not in method_name:
174174
raise GenericConfigUpdaterError("Attempting to call invalid method {} in module {}. Module must be generic_config_updater.field_operation_validators, and method must be a defined validator".format(method_name, module_name))
175175
module = importlib.import_module(module_name, package=None)
176176
method_to_call = getattr(module, method_name)
177-
return method_to_call()
177+
return method_to_call(jsonpatch_element)
178178

179179
if os.path.exists(GCU_FIELD_OP_CONF_FILE):
180180
with open(GCU_FIELD_OP_CONF_FILE, "r") as s:
@@ -194,7 +194,7 @@ def _invoke_validating_function(cmd):
194194
validating_functions.update(tables.get(table, {}).get("field_operation_validators", []))
195195

196196
for function in validating_functions:
197-
if not _invoke_validating_function(function):
197+
if not _invoke_validating_function(function, element):
198198
raise IllegalPatchOperationError("Modification of {} table is illegal- validating function {} returned False".format(table, function))
199199

200200
def validate_lanes(self, config_db):

0 commit comments

Comments
 (0)