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

CLI command to load config in Yang format #1781

Merged
merged 7 commits into from
Oct 19, 2021

Conversation

arlakshm
Copy link
Contributor

@arlakshm arlakshm commented Aug 25, 2021

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan arlakshm@microsoft.com

What I did

To support loading configuration data in yang schema, the config load command is enchanced with the below options

  • -t --file-format to specify the file-format. The config file can be yang or config_db format
  • -r to restart the services. Currently this option is supported for yang file format only.

How I did it

Add the above mentioned cli options.
Add Unit tests

How to verify it

Verify the command on VS.

admin@vlab-01:~$ sudo config load -y -c yang -r /etc/sonic/yang_cfg.json
Disabling container monitoring ...
Stopping SONiC target ...
Running command: /usr/local/bin/sonic-cfggen -H -Y /etc/sonic/yang_cfg.json -j /etc/sonic/init_cfg.json --write-to-db
Restarting SONiC target ...
Enabling container monitoring ...
Reloading Monit configuration ...
Reinitializing monit daemon
Please note setting loaded from minigraph will be lost after system reboot.To preserve setting, run `config save`.
admin@vlab-01:~$ sudo config load -y -c yang  /etc/sonic/yang_cfg.json
Running command: /usr/local/bin/sonic-cfggen -H -Y /etc/sonic/yang_cfg.json -j /etc/sonic/init_cfg.json --write-to-db
Please note setting loaded from minigraph will be lost after system reboot.To preserve setting, run `config save`.
admin@vlab-01:~$ sudo config load
Load config in config_db format from the default config file(s) ? [y/N]: y
Running command: /usr/local/bin/sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
admin@vlab-01:~$ sudo config load -y
Running command: /usr/local/bin/sonic-cfggen -j /etc/sonic/config_db.json --write-to-db

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@arlakshm arlakshm marked this pull request as ready for review August 26, 2021 01:15
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated
type=click.Choice(['yang', 'config_db']),
show_default=True,
help='specify the file format')
@click.option('-r',
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'-r'

Why require restart in design? #Closed

Copy link
Contributor Author

@arlakshm arlakshm Aug 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command can be used for loading initial and incremental configuration from config_yang file.
When loading initial configuration, the intention is to replicate the behavior of config load_minigraph. The -r is introduced for this purpose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loading initial configuration -> then config reload fit your purpose better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a new SONiC device, there no configuration, the initial config can be loaded yang_config to populate the initial configuration on the device. config load_minigraph does the similar thing.
config reload load the save configuration on the device and may not work in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offline discussed.

  1. for loading initial config, we use config reload --file_format config_yang. It already has an option to restart service.
  2. for incremental config, we use config replace. ref: https://github.com/Azure/SONiC/blob/master/doc/config-generic-update-rollback/SONiC_Generic_Config_Update_and_Rollback_Design.md
  3. the semantice of load for incremental updating purpose is not well defined. It is lack the flexibility, such as removing existing config, so we will not continue implement for file_format config_yang.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this in the latest commit.

config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@arlakshm
Copy link
Contributor Author

if filename is not None:

if filename is not None
->
if not filename

Refers to: config/main.py:1063 in 75f8d18. [](commit_id = 75f8d18, deletion_comment = False)

The existing code is fine, the check if not filename doesnt work

admin@vlab-01:/usr/local/lib/python3.7/dist-packages/config$ python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> filename=None
>>> if not filename:
...   cfg_files  = filename.split(',')
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: 'NoneType' object has no attribute 'split'
>>>

@arlakshm
Copy link
Contributor Author

/Azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@arlakshm
Copy link
Contributor Author

arlakshm commented Sep 1, 2021

the swss test test_PerfAddRemoveRoute is failing consistently. The test doesn't seem to be related to this change. These failures seen on other PRs as well.

Retrying again..

@arlakshm
Copy link
Contributor Author

arlakshm commented Sep 1, 2021

/Azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
config/main.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants