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

[config] Fix 'config reload -l' command to get filename by default #1611

Merged
merged 3 commits into from
Dec 23, 2021

Conversation

samaity
Copy link
Contributor

@samaity samaity commented May 12, 2021

Signed-off-by: Sangita Maity samaity@linkedin.com

What I did

Fix sonic-net/sonic-buildimage#7433

Right now config reload -l is getting failed due to below error.

admin@lnos-x1-a-asw03:~$ sudo config reload -l
Clear current config and reload config from the default config file(s) ? [y/N]: y
Traceback (most recent call last):
  File "/usr/local/bin/sonic-cfggen", line 431, in <module>
    main()
  File "/usr/local/bin/sonic-cfggen", line 326, in main
    _process_json(args, data)
  File "/usr/local/bin/sonic-cfggen", line 236, in _process_json
    with open(json_file, 'r') as stream:
FileNotFoundError: [Errno 2] No such file or directory: 'None'
Disabling container monitoring ...
Stopping SONiC target ...
Running command: /usr/local/bin/sonic-cfggen -H -k  --write-to-db
usage: sonic-cfggen [-h] [-m [MINIGRAPH] | -M DEVICE_DESCRIPTION | -k HWSKU] [-n [NAMESPACE]] [-p [PORT_CONFIG]]
                    [-S [HWSKU_CONFIG]] [-y YAML] [-j JSON] [-a ADDITIONAL_DATA] [-d] [-H] [-s REDIS_UNIX_SOCK_FILE]
                    [-t TEMPLATE] [-T TEMPLATE_DIR] [-v VAR] [--var-json VAR_JSON] [--preset {t1,l2,empty}]
                    [--print-data | -w | -K KEY]
sonic-cfggen: error: argument -k/--hwsku: expected one argument

I guess the problem is here in sonic-utilities repo. If user does not provide filename with config reload -l, command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename) will not provide cfg_hwsku i.e. hwsku parameter as it should which will later cause problem here command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku) as hwsku is not available around that time.

that's why we notice errors like No such file or directory: 'None' as pasted in this issue.

File "/usr/local/bin/sonic-cfggen", line 328, in main
    _process_json(args, data)
  File "/usr/local/bin/sonic-cfggen", line 236, in _process_json
    with open(json_file, 'r') as stream:
FileNotFoundError: [Errno 2] No such file or directory: 'None'

How I did it

To Fix the issue, moved the part where the code gets cfg_hwsku command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file) to the same location it needed as we get filename by default.

How to verify it

Before the Fix

admin@lnos-x1-a-asw03:~$ sudo config reload -l
Clear current config and reload config from the default config file(s) ? [y/N]: y
Traceback (most recent call last):
  File "/usr/local/bin/sonic-cfggen", line 431, in <module>
    main()
  File "/usr/local/bin/sonic-cfggen", line 326, in main
    _process_json(args, data)
  File "/usr/local/bin/sonic-cfggen", line 236, in _process_json
    with open(json_file, 'r') as stream:
FileNotFoundError: [Errno 2] No such file or directory: 'None'
Disabling container monitoring ...
Stopping SONiC target ...

After the fix

admin@lnos-x1-a-asw03:~$ sudo config reload -l
Clear current config and reload config from the default config file(s) ? [y/N]: y
Disabling container monitoring ...
Stopping SONiC target ...
Running command: /usr/local/bin/sonic-cfggen -H -k Seastone-DX010-25-50 --write-to-db
Running command: /usr/local/bin/sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db
Running command: /usr/local/bin/db_migrator.py -o migrate
Resetting failed status on bgp.service
Resetting failed status on caclmgrd.service
Resetting failed status on dhcp_relay.service
Resetting failed status on hostcfgd.service
Resetting failed status on hostname-config.service
Resetting failed status on interfaces-config.service
Resetting failed status on lldp.service
Resetting failed status on mgmt-framework.timer
Resetting failed status on nat.service
Resetting failed status on ntp-config.service
Resetting failed status on pmon.service
Resetting failed status on procdockerstatsd.service
Resetting failed status on radv.service
Resetting failed status on rsyslog-config.service
Resetting failed status on sflow.service
Resetting failed status on swss.service
Resetting failed status on syncd.service
Resetting failed status on teamd.service
Resetting failed status on telemetry.timer
Restarting SONiC target ...
Enabling container monitoring ...
Reloading Monit configuration ...
Reinitializing monit daemon

Added Test cases.

samaity@973da139a792:/sonic/src/sonic-utilities$ python3 setup.py test --addopts "--capture=no tests/config_test.py::TestConfigReload::test_config_reload"
running pytest
 
running build_ext
 
================================================================================================== test session starts ===================================================================================================
platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0
rootdir: /sonic/src/sonic-utilities/tests, inifile: pytest.ini
plugins: pyfakefs-4.5.0, cov-2.6.0
collected 1 item
 
tests/config_test.py SETUP
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
0
Running command: rm -rf /tmp/dropstat-*
Running command: /usr/local/bin/sonic-cfggen -H -k Seastone-DX010-25-50 --write-to-db
Running command: /usr/local/bin/sonic-cfggen -j /sonic/src/sonic-utilities/tests/config_reload_input/init_cfg.json -j /sonic/src/sonic-utilities/tests/config_reload_input/config_db.json --write-to-db
 
  File "/sonic/src/sonic-utilities/.eggs/Click-7.0-py3.7.egg/click/testing.py", line 326, in invoke
    cli.main(args=args or (), prog_name=prog_name, **extra)
  File "/sonic/src/sonic-utilities/.eggs/Click-7.0-py3.7.egg/click/core.py", line 745, in main
    sys.exit(e.exit_code)
.TEARDOWN
 
================================================================= 1 passed in 1.19 seconds =================================================================
samaity@973da139a792:/sonic/src/sonic-utilities$

@samaity samaity force-pushed the config_reload_fix branch from 25c3f5d to 17744f4 Compare May 12, 2021 22:03
@samaity samaity marked this pull request as ready for review May 13, 2021 01:20
zhenggen-xu
zhenggen-xu previously approved these changes May 13, 2021
liat-grozovik
liat-grozovik previously approved these changes Jun 15, 2021
config/main.py Outdated Show resolved Hide resolved
qiluo-msft
qiluo-msft previously approved these changes Jun 15, 2021
@lguohan
Copy link
Contributor

lguohan commented Jun 15, 2021

please add unit test to prevent further regression. which pr caused the regression?

@zhenggen-xu
Copy link
Collaborator

Based on the log, it should be this PR that caused regression: #877

@samaity samaity dismissed stale reviews from qiluo-msft, liat-grozovik, and zhenggen-xu via c2eb169 July 28, 2021 00:07
@samaity samaity force-pushed the config_reload_fix branch from 17744f4 to c2eb169 Compare July 28, 2021 00:07
@samaity
Copy link
Contributor Author

samaity commented Jul 28, 2021

please add unit test to prevent further regression. which pr caused the regression?

Added Test cases as requested.

@samaity samaity requested a review from qiluo-msft July 28, 2021 22:49
@qiluo-msft qiluo-msft requested a review from judyjoseph July 29, 2021 03:59
config/main.py Outdated Show resolved Hide resolved
zhenggen-xu
zhenggen-xu previously approved these changes Jul 29, 2021
qiluo-msft
qiluo-msft previously approved these changes Aug 6, 2021
@dgsudharsan
Copy link
Collaborator

@samaity Can you please share the status of this PR? When will this be merged?

@zhenggen-xu
Copy link
Collaborator

@samaity Can you sync to the latest code?

Sangita Maity added 3 commits December 21, 2021 18:11
Signed-off-by: Sangita Maity <samaity@linkedin.com>
Signed-off-by: Sangita Maity <samaity@linkedin.com>
Signed-off-by: Sangita Maity <samaity@linkedin.com>
@samaity
Copy link
Contributor Author

samaity commented Dec 21, 2021

@samaity Can you sync to the latest code?

done 👍

@liat-grozovik liat-grozovik merged commit 1a2a9a3 into sonic-net:master Dec 23, 2021
judyjoseph pushed a commit that referenced this pull request Jan 9, 2022
…1611)

Fix sonic-net/sonic-buildimage#7433

Right now config reload -l is getting failed due to an error.
I guess the problem is here in sonic-utilities repo. If user does not provide filename with config reload -l, command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename) will not provide cfg_hwsku i.e. hwsku parameter as it should which will later cause problem here command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku) as hwsku is not available around that time.

that's why we notice errors like No such file or directory: 'None' as pasted in this issue.

- How I did it
To Fix the issue, moved the part where the code gets cfg_hwsku command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file) to the same location it needed as we get filename by default.

- How to verify it
'sudo config reload -l'
Added test cases.

Signed-off-by: Sangita Maity <samaity@linkedin.com>
praveen-li pushed a commit to praveen-li/sonic-utilities that referenced this pull request Feb 8, 2022
…onic-net#1611)

Fix sonic-net/sonic-buildimage#7433

Right now config reload -l is getting failed due to an error.
I guess the problem is here in sonic-utilities repo. If user does not provide filename with config reload -l, command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename) will not provide cfg_hwsku i.e. hwsku parameter as it should which will later cause problem here command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku) as hwsku is not available around that time.

that's why we notice errors like No such file or directory: 'None' as pasted in this issue.

- How I did it
To Fix the issue, moved the part where the code gets cfg_hwsku command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file) to the same location it needed as we get filename by default.

- How to verify it
'sudo config reload -l'
Added test cases.

Signed-off-by: Sangita Maity <samaity@linkedin.com>
 Conflicts:
	tests/config_test.py
praveen-li pushed a commit to praveen-li/sonic-utilities that referenced this pull request Feb 11, 2022
…onic-net#1611)

Fix sonic-net/sonic-buildimage#7433

Right now config reload -l is getting failed due to an error.
I guess the problem is here in sonic-utilities repo. If user does not provide filename with config reload -l, command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename) will not provide cfg_hwsku i.e. hwsku parameter as it should which will later cause problem here command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku) as hwsku is not available around that time.

that's why we notice errors like No such file or directory: 'None' as pasted in this issue.

- How I did it
To Fix the issue, moved the part where the code gets cfg_hwsku command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file) to the same location it needed as we get filename by default.

- How to verify it
'sudo config reload -l'
Added test cases.

Signed-off-by: Sangita Maity <samaity@linkedin.com>
 Conflicts:
	tests/config_test.py
praveen-li pushed a commit to praveen-li/sonic-utilities that referenced this pull request Mar 22, 2022
…onic-net#1611)

Fix sonic-net/sonic-buildimage#7433

Right now config reload -l is getting failed due to an error.
I guess the problem is here in sonic-utilities repo. If user does not provide filename with config reload -l, command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename) will not provide cfg_hwsku i.e. hwsku parameter as it should which will later cause problem here command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku) as hwsku is not available around that time.

that's why we notice errors like No such file or directory: 'None' as pasted in this issue.

- How I did it
To Fix the issue, moved the part where the code gets cfg_hwsku command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file) to the same location it needed as we get filename by default.

- How to verify it
'sudo config reload -l'
Added test cases.

Signed-off-by: Sangita Maity <samaity@linkedin.com>
 Conflicts:
	tests/config_test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

command sudo config reload --load-sysinfo/-l fails
8 participants