-
Notifications
You must be signed in to change notification settings - Fork 665
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
[config]Support multi-asic Golden Config override #2738
Changes from 6 commits
0009fa0
0bedc63
334433b
81c9d7e
479181c
d9a2ef3
2b21d11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1875,6 +1875,33 @@ def override_config_by(golden_config_path): | |
return | ||
|
||
|
||
def generate_sysinfo(config_input, ns=None): | ||
# Generate required sysinfo for Golden Config. | ||
device_metadata = config_input.get('DEVICE_METADATA') | ||
|
||
if not device_metadata or 'localhost' not in device_metadata: | ||
return | ||
|
||
if ns: | ||
asic_role = device_metadata.get('localhost', {}).get('sub_role') | ||
switch_type = device_metadata.get('localhost', {}).get('switch_type') | ||
|
||
if ((switch_type is not None and switch_type.lower() == "chassis-packet") or | ||
(asic_role is not None and asic_role.lower() == "backend")): | ||
mac = device_info.get_system_mac(namespace=ns) | ||
else: | ||
mac = device_info.get_system_mac() | ||
else: | ||
mac = device_info.get_system_mac() | ||
|
||
platform = device_info.get_platform() | ||
|
||
device_metadata['localhost']['mac'] = mac | ||
device_metadata['localhost']['platform'] = platform | ||
|
||
return | ||
|
||
|
||
# | ||
# 'override-config-table' command ('config override-config-table ...') | ||
# | ||
|
@@ -1902,36 +1929,43 @@ def override_config_table(db, input_config_db, dry_run): | |
fg='magenta') | ||
sys.exit(1) | ||
|
||
config_db = db.cfgdb | ||
|
||
# Read config from configDB | ||
current_config = config_db.get_config() | ||
# Serialize to the same format as json input | ||
sonic_cfggen.FormatConverter.to_serialized(current_config) | ||
cfgdb_clients = db.cfgdb_clients | ||
|
||
updated_config = update_config(current_config, config_input) | ||
for ns, config_db in cfgdb_clients.items(): | ||
# Read config from configDB | ||
current_config = config_db.get_config() | ||
# Serialize to the same format as json input | ||
sonic_cfggen.FormatConverter.to_serialized(current_config) | ||
|
||
yang_enabled = device_info.is_yang_config_validation_enabled(config_db) | ||
if yang_enabled: | ||
# The ConfigMgmt will load YANG and running | ||
# config during initialization. | ||
try: | ||
cm = ConfigMgmt() | ||
cm.validateConfigData() | ||
except Exception as ex: | ||
click.secho("Failed to validate running config. Error: {}".format(ex), fg="magenta") | ||
sys.exit(1) | ||
if multi_asic.is_multi_asic(): | ||
ns_config_input = config_input[ns] | ||
generate_sysinfo(ns_config_input, ns) | ||
else: | ||
ns_config_input = config_input | ||
generate_sysinfo(ns_config_input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the generated sysinfo should have less priority than existing one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will submit another PR for sysinfo generation about override. |
||
updated_config = update_config(current_config, ns_config_input) | ||
|
||
yang_enabled = device_info.is_yang_config_validation_enabled(config_db) | ||
if yang_enabled: | ||
# The ConfigMgmt will load YANG and running | ||
# config during initialization. | ||
try: | ||
cm = ConfigMgmt(configdb=config_db) | ||
cm.validateConfigData() | ||
except Exception as ex: | ||
click.secho("Failed to validate running config. Error: {}".format(ex), fg="magenta") | ||
sys.exit(1) | ||
|
||
# Validate input config | ||
validate_config_by_cm(cm, config_input, "config_input") | ||
# Validate updated whole config | ||
validate_config_by_cm(cm, updated_config, "updated_config") | ||
# Validate input config | ||
validate_config_by_cm(cm, ns_config_input, "config_input") | ||
# Validate updated whole config | ||
validate_config_by_cm(cm, updated_config, "updated_config") | ||
|
||
if dry_run: | ||
print(json.dumps(updated_config, sort_keys=True, | ||
indent=4, cls=minigraph_encoder)) | ||
else: | ||
override_config_db(config_db, config_input) | ||
if dry_run: | ||
print(json.dumps(updated_config, sort_keys=True, | ||
indent=4, cls=minigraph_encoder)) | ||
else: | ||
override_config_db(config_db, ns_config_input) | ||
|
||
|
||
def validate_config_by_cm(cm, config_json, jname): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"": { | ||
"DEVICE_METADATA": { | ||
"localhost": { | ||
"default_bgp_status": "down", | ||
"default_pfcwd_status": "enable", | ||
"deployment_id": "1", | ||
"docker_routing_config_mode": "separated", | ||
"hostname": "sonic-switch", | ||
"hwsku": "Mellanox-SN3800-D112C8", | ||
"peer_switch": "sonic-switch", | ||
"type": "ToRRouter", | ||
"suppress-fib-pending": "enabled" | ||
} | ||
} | ||
}, | ||
"asic0": { | ||
"DEVICE_METADATA": { | ||
"localhost": { | ||
"asic_id": "01.00.0", | ||
"asic_name": "asic0", | ||
"bgp_asn": "65100", | ||
"cloudtype": "None", | ||
"default_bgp_status": "down", | ||
"default_pfcwd_status": "enable", | ||
"deployment_id": "None", | ||
"docker_routing_config_mode": "separated", | ||
"hostname": "sonic", | ||
"hwsku": "multi_asic", | ||
"region": "None", | ||
"sub_role": "FrontEnd", | ||
"type": "LeafRouter" | ||
} | ||
} | ||
}, | ||
"asic1": { | ||
"DEVICE_METADATA": { | ||
"localhost": { | ||
"asic_id": "08:00.0", | ||
"asic_name": "asic1", | ||
"bgp_asn": "65100", | ||
"cloudtype": "None", | ||
"default_bgp_status": "down", | ||
"default_pfcwd_status": "enable", | ||
"deployment_id": "None", | ||
"docker_routing_config_mode": "separated", | ||
"hostname": "sonic", | ||
"hwsku": "multi_asic", | ||
"region": "None", | ||
"sub_role": "BackEnd", | ||
"type": "LeafRouter" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"": { | ||
"DEVICE_METADATA": {} | ||
}, | ||
"asic0": { | ||
"DEVICE_METADATA": {} | ||
}, | ||
"asic1": { | ||
"DEVICE_METADATA": {} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"": { | ||
"MACSEC_PROFILE": { | ||
"profile": { | ||
"key": "value" | ||
} | ||
} | ||
}, | ||
"asic0": { | ||
"MACSEC_PROFILE": { | ||
"profile": { | ||
"key": "value" | ||
} | ||
} | ||
}, | ||
"asic1": { | ||
"MACSEC_PROFILE": { | ||
"profile": { | ||
"key": "value" | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice code duplication of https://github.com/sonic-net/sonic-buildimage/blob/d74055e12ca0ac4f44342e74ea097f03720663f7/src/sonic-config-engine/sonic-cfggen#L382-L388.
Possible to reuse code? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove code dup in next PR?