Skip to content

[sonic-cfggen] Fix sonic-cfggen crash issue when printing non-exists table/key#4131

Open
zhenggen-xu wants to merge 2 commits intosonic-net:masterfrom
zhenggen-xu:eoiu-check
Open

[sonic-cfggen] Fix sonic-cfggen crash issue when printing non-exists table/key#4131
zhenggen-xu wants to merge 2 commits intosonic-net:masterfrom
zhenggen-xu:eoiu-check

Conversation

@zhenggen-xu
Copy link
Collaborator

@zhenggen-xu zhenggen-xu commented Feb 8, 2020

[sonic-cfggen] Fix sonic-cfggen crash issue when printing non-exists table/key

Fix sonic-cfggen so docker-frr start.sh won't fail if no WARM_RESTART in configDB

In general, instead of sonic-cfggen crashing
we print empty string if we use -v or --var-json for variables not existing

Signed-off-by: Zhenggen Xu <zxu@linkedin.com>

This should be back-ported to 201911 and 201811 branches too.

- What I did
If the configDB has no warm-restart configurations, the start.sh in bgp docker would fail due to python exception as below:

Traceback (most recent call last):
  File "/usr/local/bin/sonic-cfggen", line 322, in <module>
    main()
  File "/usr/local/bin/sonic-cfggen", line 300, in main
    print(template.render(data))
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'WARM_RESTART' is undefined

- How I did it
Check the WARM_RESTART table first. If does not exist, won't check the bgp_eoiu info to avoid crash.

- How to verify it
After the fix:

without any warm restart configured or if we do "sudo config warm-restart bgp_eoiu false"
bgp docker will not start the bgp_eoiu_marker

if we do:  "sudo config warm-restart bgp_eoiu true"
We can see bgp_eoiu_marker started.

Additional tests:

Before fix:

admin@sonic:~$ sonic-cfggen -d -v abcd.ghij
Traceback (most recent call last):
  File "/usr/local/bin/sonic-cfggen", line 318, in <module>
    main()
  File "/usr/local/bin/sonic-cfggen", line 296, in main
    print(template.render(data))
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'abcd' is undefined
admin@sonic:~$ sonic-cfggen -d -v abcd.efgh
Traceback (most recent call last):
  File "/usr/local/bin/sonic-cfggen", line 318, in <module>
    main()
  File "/usr/local/bin/sonic-cfggen", line 296, in main
    print(template.render(data))
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'abcd' is undefined

admin@sonic:~$ sonic-cfggen -d --var-json abcd
Traceback (most recent call last):
  File "/usr/local/bin/sonic-cfggen", line 318, in <module>
    main()
  File "/usr/local/bin/sonic-cfggen", line 302, in main
    print(json.dumps(FormatConverter.to_serialized(data[args.var_json]), indent=4, cls=minigraph_encoder))
KeyError: 'abcd'

After fix:

admin@sonic:~$ sonic-cfggen -d -v abcd.efgh

admin@sonic:~$ sonic-cfggen -d --var-json abcd

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@zhenggen-xu zhenggen-xu changed the title [docker-frr] Fix the start.sh where it fails in case no WARM_RESTART in configDB [sonic-cfggen/docker-frr] Fix sonic-cfggen so docker-frr start.sh won't fail if no WARM_RESTART in configDB Feb 13, 2020
pavel-shirshov
pavel-shirshov previously approved these changes Feb 14, 2020
lguohan
lguohan previously approved these changes Apr 25, 2020
@lguohan
Copy link
Collaborator

lguohan commented Apr 25, 2020

@zhenggen-xu , it looks like your proposed change breaks the test. I do not whether we should change the test or your patch. any opinion?

@zhenggen-xu
Copy link
Collaborator Author

zhenggen-xu commented Apr 26, 2020

@lguohan it looks like the upstream merge broke some changes:
if args.var_json != None and args.var_json in data:

changed to:
if args.var_json != None

We need revert that line and see.

…'t fail if no WARM_RESTART in configDB

In general, instead of sonic-cfggen crashing
we print empty string if we use -v or --var-json for variables not existing

Signed-off-by: Zhenggen Xu <zxu@linkedin.com>
@zhenggen-xu
Copy link
Collaborator Author

Just reverted the merge issue and let's see the results.

Copy link
Contributor

@pavel-shirshov pavel-shirshov left a comment

Choose a reason for hiding this comment

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

I'd suggest to use is not None instead of != None

…table/key

Address review feedback

Signed-off-by: Zhenggen Xu <zxu@linkedin.com>
@zhenggen-xu zhenggen-xu changed the title [sonic-cfggen/docker-frr] Fix sonic-cfggen so docker-frr start.sh won't fail if no WARM_RESTART in configDB [sonic-cfggen] Fix sonic-cfggen crash issue when printing non-exists table/key Aug 14, 2020
@zhenggen-xu
Copy link
Collaborator Author

I'd suggest to use is not None instead of != None

In general, I might want to leave that to different PR, as the fix here was to handle exceptions not fixing existing style issue. I see many places in the file using "!= None", we probably should have some PR to address them all together. Anyway, I changed it so to get the PR moving forward.

@pavel-shirshov

@pavel-shirshov
Copy link
Contributor

@zhenggen-xu

Your code catches all exceptions. How can we find an issue if we have one? I'd suggest you to make except more specific, also as output something on the error, like "variable wasn't found" or "error on template rendering"? Also I'd suggest to return some exit code on the issue.

@zhenggen-xu zhenggen-xu requested a review from a team as a code owner June 10, 2022 02:01
mssonicbld added a commit that referenced this pull request Jan 31, 2026
…lly (#25253)

#### Why I did it
src/sonic-swss
```
* 9b237a2e - (HEAD -> master, origin/master, origin/HEAD) [vnet/vxlan]: Handle SAI failures without crashing swss (#3908) (4 hours ago) [prabhataravind]
* 1d348170 - Enabling the FEC histogram for gbsyncd counters (#4067) (9 hours ago) [arpit-nexthop]
* 2ee85de5 - [ci] fix docker slave name (#4090) (29 hours ago) [yijingyan2]
* 0f99a399 - Merge pull request #4089 from divyagayathri-hcl/6_multicast (34 hours ago) [StephenWangGoogle]
|\ 
| failure_prs.log skip_prs.log 0cb64f2d - [P4Orch] Implement functions to process/drain multicast router interface table entries. (2 days ago) [mint570]
|/ 
* 76f9b4b7 - Merge pull request #4087 from divyagayathri-hcl/5_multicast (3 days ago) [StephenWangGoogle]
|\ 
| failure_prs.log skip_prs.log 69e09ff0 - [P4Orch] Implement functions for both deleting and updating a multicast router interface table entries. (4 days ago) [mint570]
|/ 
* b60191c9 - This PR adds communication statistics recording and debugging utilities to countersyncd for analyzing online issues and performance. The changes introduce a new utilities module with functions for formatting hex dumps and tracking inter-actor channel statistics. Changes: Added utilities module with hex formatting and channel statistics tracking Instrumented all actor message receive points to record queue lengths Added debug logging for raw netlink message payloads Reviewed changes (7 days ago) [Ze Gan]
* 61724451 - Add drop monitor attributes to supported debug counter attributes (#4120) (7 days ago) [manish1-arista]
* 48c3c201 - [Vnetorch] Relax attr parsing for vnet route table (#4150) (7 days ago) [Jing Zhang]
* 8b18beef - Merge pull request #4085 from divyagayathri-hcl/3_multicast (7 days ago) [StephenWangGoogle]
|\ 
| failure_prs.log skip_prs.log 6125fc55 - [P4Orch] Implement functions to add multicast router interface table entries. (8 days ago) [mint570]
| failure_prs.log skip_prs.log 2571bbb8 - [P4Orch] Add L3MulticastManager class definition and begin to populate its unit test. (8 days ago) [mint570]
|/ 
* a8d968c9 - Update the COUNTER_DB with the new Port Object-Id when the Port is removed and created when the Port Speed is changed dynamically via GCU (#3977) (9 days ago) [saksarav-nokia]
* 416a0eb8 - [countersyncd]: Add retry between client and otel collector (#4131) (10 days ago) [Janet Cui]
* 5fdb2456 - Merge pull request #4083 from divyagayathri-hcl/1_multicast (10 days ago) [StephenWangGoogle]
* 8e72c3d9 - [P4Orch] Add support for SAI functions needed for swss multicast support. (12 days ago) [mint570]
```
#### How I did it
#### How to verify it
#### Description for the changelog
xincunli-sonic pushed a commit to xincunli-sonic/sonic-buildimage that referenced this pull request Feb 2, 2026
…lly (sonic-net#25253)

#### Why I did it
src/sonic-swss
```
* 9b237a2e - (HEAD -> master, origin/master, origin/HEAD) [vnet/vxlan]: Handle SAI failures without crashing swss (sonic-net#3908) (4 hours ago) [prabhataravind]
* 1d348170 - Enabling the FEC histogram for gbsyncd counters (sonic-net#4067) (9 hours ago) [arpit-nexthop]
* 2ee85de5 - [ci] fix docker slave name (sonic-net#4090) (29 hours ago) [yijingyan2]
* 0f99a399 - Merge pull request sonic-net#4089 from divyagayathri-hcl/6_multicast (34 hours ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 0cb64f2d - [P4Orch] Implement functions to process/drain multicast router interface table entries. (2 days ago) [mint570]
|/
* 76f9b4b7 - Merge pull request sonic-net#4087 from divyagayathri-hcl/5_multicast (3 days ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 69e09ff0 - [P4Orch] Implement functions for both deleting and updating a multicast router interface table entries. (4 days ago) [mint570]
|/
* b60191c9 - This PR adds communication statistics recording and debugging utilities to countersyncd for analyzing online issues and performance. The changes introduce a new utilities module with functions for formatting hex dumps and tracking inter-actor channel statistics. Changes: Added utilities module with hex formatting and channel statistics tracking Instrumented all actor message receive points to record queue lengths Added debug logging for raw netlink message payloads Reviewed changes (7 days ago) [Ze Gan]
* 61724451 - Add drop monitor attributes to supported debug counter attributes (sonic-net#4120) (7 days ago) [manish1-arista]
* 48c3c201 - [Vnetorch] Relax attr parsing for vnet route table (sonic-net#4150) (7 days ago) [Jing Zhang]
* 8b18beef - Merge pull request sonic-net#4085 from divyagayathri-hcl/3_multicast (7 days ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 6125fc55 - [P4Orch] Implement functions to add multicast router interface table entries. (8 days ago) [mint570]
| failure_prs.log skip_prs.log 2571bbb8 - [P4Orch] Add L3MulticastManager class definition and begin to populate its unit test. (8 days ago) [mint570]
|/
* a8d968c9 - Update the COUNTER_DB with the new Port Object-Id when the Port is removed and created when the Port Speed is changed dynamically via GCU (sonic-net#3977) (9 days ago) [saksarav-nokia]
* 416a0eb8 - [countersyncd]: Add retry between client and otel collector (sonic-net#4131) (10 days ago) [Janet Cui]
* 5fdb2456 - Merge pull request sonic-net#4083 from divyagayathri-hcl/1_multicast (10 days ago) [StephenWangGoogle]
* 8e72c3d9 - [P4Orch] Add support for SAI functions needed for swss multicast support. (12 days ago) [mint570]
```
#### How I did it
#### How to verify it
#### Description for the changelog

Signed-off-by: Xincun Li <stli@microsoft.com>
FengPan-Frank pushed a commit to FengPan-Frank/sonic-buildimage that referenced this pull request Mar 6, 2026
…lly (sonic-net#25253)

#### Why I did it
src/sonic-swss
```
* 9b237a2e - (HEAD -> master, origin/master, origin/HEAD) [vnet/vxlan]: Handle SAI failures without crashing swss (sonic-net#3908) (4 hours ago) [prabhataravind]
* 1d348170 - Enabling the FEC histogram for gbsyncd counters (sonic-net#4067) (9 hours ago) [arpit-nexthop]
* 2ee85de5 - [ci] fix docker slave name (sonic-net#4090) (29 hours ago) [yijingyan2]
* 0f99a399 - Merge pull request sonic-net#4089 from divyagayathri-hcl/6_multicast (34 hours ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 0cb64f2d - [P4Orch] Implement functions to process/drain multicast router interface table entries. (2 days ago) [mint570]
|/
* 76f9b4b7 - Merge pull request sonic-net#4087 from divyagayathri-hcl/5_multicast (3 days ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 69e09ff0 - [P4Orch] Implement functions for both deleting and updating a multicast router interface table entries. (4 days ago) [mint570]
|/
* b60191c9 - This PR adds communication statistics recording and debugging utilities to countersyncd for analyzing online issues and performance. The changes introduce a new utilities module with functions for formatting hex dumps and tracking inter-actor channel statistics. Changes: Added utilities module with hex formatting and channel statistics tracking Instrumented all actor message receive points to record queue lengths Added debug logging for raw netlink message payloads Reviewed changes (7 days ago) [Ze Gan]
* 61724451 - Add drop monitor attributes to supported debug counter attributes (sonic-net#4120) (7 days ago) [manish1-arista]
* 48c3c201 - [Vnetorch] Relax attr parsing for vnet route table (sonic-net#4150) (7 days ago) [Jing Zhang]
* 8b18beef - Merge pull request sonic-net#4085 from divyagayathri-hcl/3_multicast (7 days ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 6125fc55 - [P4Orch] Implement functions to add multicast router interface table entries. (8 days ago) [mint570]
| failure_prs.log skip_prs.log 2571bbb8 - [P4Orch] Add L3MulticastManager class definition and begin to populate its unit test. (8 days ago) [mint570]
|/
* a8d968c9 - Update the COUNTER_DB with the new Port Object-Id when the Port is removed and created when the Port Speed is changed dynamically via GCU (sonic-net#3977) (9 days ago) [saksarav-nokia]
* 416a0eb8 - [countersyncd]: Add retry between client and otel collector (sonic-net#4131) (10 days ago) [Janet Cui]
* 5fdb2456 - Merge pull request sonic-net#4083 from divyagayathri-hcl/1_multicast (10 days ago) [StephenWangGoogle]
* 8e72c3d9 - [P4Orch] Add support for SAI functions needed for swss multicast support. (12 days ago) [mint570]
```
#### How I did it
#### How to verify it
#### Description for the changelog

Signed-off-by: Feng Pan <fenpan@microsoft.com>
dprital pushed a commit that referenced this pull request Mar 19, 2026
…lly (#25253)

#### Why I did it
src/sonic-swss
```
* 9b237a2e - (HEAD -> master, origin/master, origin/HEAD) [vnet/vxlan]: Handle SAI failures without crashing swss (#3908) (4 hours ago) [prabhataravind]
* 1d348170 - Enabling the FEC histogram for gbsyncd counters (#4067) (9 hours ago) [arpit-nexthop]
* 2ee85de5 - [ci] fix docker slave name (#4090) (29 hours ago) [yijingyan2]
* 0f99a399 - Merge pull request #4089 from divyagayathri-hcl/6_multicast (34 hours ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 0cb64f2d - [P4Orch] Implement functions to process/drain multicast router interface table entries. (2 days ago) [mint570]
|/
* 76f9b4b7 - Merge pull request #4087 from divyagayathri-hcl/5_multicast (3 days ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 69e09ff0 - [P4Orch] Implement functions for both deleting and updating a multicast router interface table entries. (4 days ago) [mint570]
|/
* b60191c9 - This PR adds communication statistics recording and debugging utilities to countersyncd for analyzing online issues and performance. The changes introduce a new utilities module with functions for formatting hex dumps and tracking inter-actor channel statistics. Changes: Added utilities module with hex formatting and channel statistics tracking Instrumented all actor message receive points to record queue lengths Added debug logging for raw netlink message payloads Reviewed changes (7 days ago) [Ze Gan]
* 61724451 - Add drop monitor attributes to supported debug counter attributes (#4120) (7 days ago) [manish1-arista]
* 48c3c201 - [Vnetorch] Relax attr parsing for vnet route table (#4150) (7 days ago) [Jing Zhang]
* 8b18beef - Merge pull request #4085 from divyagayathri-hcl/3_multicast (7 days ago) [StephenWangGoogle]
|\
| failure_prs.log skip_prs.log 6125fc55 - [P4Orch] Implement functions to add multicast router interface table entries. (8 days ago) [mint570]
| failure_prs.log skip_prs.log 2571bbb8 - [P4Orch] Add L3MulticastManager class definition and begin to populate its unit test. (8 days ago) [mint570]
|/
* a8d968c9 - Update the COUNTER_DB with the new Port Object-Id when the Port is removed and created when the Port Speed is changed dynamically via GCU (#3977) (9 days ago) [saksarav-nokia]
* 416a0eb8 - [countersyncd]: Add retry between client and otel collector (#4131) (10 days ago) [Janet Cui]
* 5fdb2456 - Merge pull request #4083 from divyagayathri-hcl/1_multicast (10 days ago) [StephenWangGoogle]
* 8e72c3d9 - [P4Orch] Add support for SAI functions needed for swss multicast support. (12 days ago) [mint570]
```
#### How I did it
#### How to verify it
#### Description for the changelog

Signed-off-by: dprital <drorp@nvidia.com>
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.

3 participants