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

Exposing config-check logic to CLI #291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,29 @@ def save(filename):
command = "{} -d --print-data > {}".format(SONIC_CFGGEN_PATH, filename)
run_command(command, display_cmd=True)

@cli.command()
@click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path(exists=True))
def check(filename):
"""Verifies that the configuration in the json file is correct."""

command = "{} -j {} --check-json".format(SONIC_CFGGEN_PATH, filename)
run_command(command, display_cmd=True)
print "Valid configuration found in " + filename + " file"

@cli.command()
@click.option('-y', '--yes', is_flag=True)
@click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path(exists=True))
def load(filename, yes):
"""Import a previous saved config DB dump file."""

if not yes:
click.confirm('Load config from the file %s?' % filename, abort=True)

# Validating passed json configuration file
command = "{} -j {} --check-json".format(SONIC_CFGGEN_PATH, filename)
run_command(command, display_cmd=True)

# Proceeding to load changes into DB
command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename)
run_command(command, display_cmd=True)

Expand All @@ -205,6 +221,11 @@ def reload(filename, yes):
"""Clear current configuration and import a previous saved config DB dump file."""
if not yes:
click.confirm('Clear current config and reload config from the file %s?' % filename, abort=True)

# Validating passed json configuration file
command = "{} -j {} --check-json".format(SONIC_CFGGEN_PATH, filename)
run_command(command, display_cmd=True)

#Stop services before config push
_stop_services()
config_db = ConfigDBConnector()
Expand Down