Skip to content
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

Update override_config_table for multi-asic platforms #2620

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,37 +1893,53 @@ 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)
# List of Tables that needs to be populated in host and asic namespaces
tables_per_namespace = {"MACSEC_PROFILE"}

updated_config = update_config(current_config, config_input)
# Get the namespace db connector where we really need to override the config.
# if any of the table in config_input is part of the list tables_per_namespace
# we override config in all namespaces, else do it only in host namespace.
db_list = {}
db_list[DEFAULT_NAMESPACE] = db.cfgdb
for table in config_input:
if table in tables_per_namespace:
db_list = db.cfgdb_clients
break

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_list.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)

# 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")
updated_config = update_config(current_config, config_input)

if dry_run:
print(json.dumps(updated_config, sort_keys=True,
indent=4, cls=minigraph_encoder))
else:
override_config_db(config_db, 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")

if dry_run:
print(json.dumps(updated_config, sort_keys=True,
indent=4, cls=minigraph_encoder))
else:
namespace = "Host" if ns is DEFAULT_NAMESPACE else ns
click.echo("Working in {} namespace :".format(namespace))
override_config_db(config_db, config_input)

def validate_config_by_cm(cm, config_json, jname):
tmp_config_json = copy.deepcopy(config_json)
Expand All @@ -1947,14 +1963,13 @@ def override_config_db(config_db, config_input):
# 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(" - Removing configDB overriden table first ...")
for table in config_input:
config_db.delete_table(table)
click.echo("Overriding input config to configDB ...")
click.echo(" - Overriding input config to configDB ...")
data = sonic_cfggen.FormatConverter.output_to_db(config_input)
config_db.mod_config(data)
click.echo("Overriding completed. No service is restarted.")

click.echo(" - Overriding completed. No service is restarted.")

#
# 'hostname' command
Expand Down