-
Notifications
You must be signed in to change notification settings - Fork 712
Update override_config_table for multi-asic platforms #2620
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
Changes from 2 commits
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 |
---|---|---|
|
@@ -1893,36 +1893,37 @@ 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) | ||
|
||
updated_config = update_config(current_config, 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() | ||
cm.validateConfigData() | ||
except Exception as ex: | ||
click.secho("Failed to validate running config. Error: {}".format(ex), fg="magenta") | ||
sys.exit(1) | ||
# Do the yang validation and config override for host namespace and | ||
# other namespaces in case of multi-asic platform | ||
for ns, config_db in db.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) | ||
|
||
updated_config = update_config(current_config, 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() | ||
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, 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(ns, config_db, 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. Updated not to add an additional "ns" parameter |
||
|
||
|
||
def validate_config_by_cm(cm, config_json, jname): | ||
|
@@ -1943,18 +1944,18 @@ def update_config(current_config, config_input): | |
return updated_config | ||
|
||
|
||
def override_config_db(config_db, config_input): | ||
def override_config_db(ns, config_db, 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. |
||
namespace = "Host" if ns is DEFAULT_NAMESPACE else ns | ||
# Deserialized golden config to DB recognized format | ||
sonic_cfggen.FormatConverter.to_deserialized(config_input) | ||
# Delete table from DB then mod_config to apply golden config | ||
click.echo("Removing configDB overriden table first ...") | ||
click.echo("{} namespace - Removing configDB overriden table first ...".format(namespace)) | ||
for table in config_input: | ||
config_db.delete_table(table) | ||
click.echo("Overriding input config to configDB ...") | ||
click.echo("{} namespace - Overriding input config to configDB ...".format(namespace)) | ||
data = sonic_cfggen.FormatConverter.output_to_db(config_input) | ||
config_db.mod_config(data) | ||
click.echo("Overriding completed. No service is restarted.") | ||
|
||
click.echo("{} namespace - Overriding completed. No service is restarted.".format(namespace)) | ||
|
||
# | ||
# 'hostname' command | ||
|
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 understand that
MACSEC_PROFILE
will be in all namespaces in addition to the host namespace. However this is right in general.Can we limit the loop only for
MACSEC_PROFILE
table?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 have updated the logic to have a list of tables which is there per namespace, if any of the tables in the config_input json is present in that list, we do override config for all namespaces. Else only for host. Currently MACSEC_PROFILE is there in that table list.
this logic can be generalized to any table depending on how we plan to go with Virtual connector, to do this action based on table, and have it give back which connector to use, or which namespace the config needs to be overridden.