Fix the issue of unprintable RunAnsibleModuleFail object#1739
Fix the issue of unprintable RunAnsibleModuleFail object#1739wangxin merged 1 commit intosonic-net:masterfrom wangxin:fix-unprintable-exception
Conversation
|
@wangxin let's please have this merged ASAP. |
|
@yvolynets-mlnx please have a look. |
|
@wangxin I think it's better to reuse the stdout callback plugin from ansible to convet the result obj to strings, since stdout callback would like to filter out some internal vars of ansible for us. So, i mean just catch the exception when converting the error obj to strings in 'dump_ansible_results'. |
|
This pull request introduces 1 alert when merging 4aad8a84cf035dbd88b4b865c033bbe117cb5697 into d09d6d2 - view on LGTM.com new alerts:
|
|
can you provide examples? |
|
The fix was tested using a script like this: test_example.py: Log of running this script: |
|
retest this please |
|
retest vsimage please |
Fix issue #1731 Signed-off-by: Xin Wang <[email protected]>
|
Resolved the merge conflicts. |
Issue #1731 was not fully fixed by PR #1739. When RunAnsibleModuleFail exception is raised by running ptf script, the unprintable exception issue was still observed. The reason is that the ansible result may contain unicode string. Concatenating ascii string with unicode string may raise uncaught exception and cause this issue. The fix is to concatenate unicode string with the ansible result. Then encode it to ascii string. Signed-off-by: Xin Wang <[email protected]>
8b149a3 Load the database global_db only once for show cli (sonic-net#1712) cd0e560 [config][interface][speed] Fixed the config interface speed in multiasic issue (sonic-net#1739) b595ba6 [fast-reboot] revert the change of disabling counter polling before fast-reboot (sonic-net#1744) 8518820 [minigraph] Donot enable PFC watchdog for MgmtTsToR (sonic-net#1734) 2213774 [CLI][show][bgp] Fix the show ip bgp network command (sonic-net#1733) 3526507 [configlet] Python3 compatible syntax for extracting a key from the dict (sonic-net#1721) 5b56b97 [sonic_installer] don't print errors when installing an image not supporting app ext (sonic-net#1719) a581955 [LLDP] Fix lldpshow script to enable display multiple MAC addresses on the same remote physical interface (sonic-net#1657)
Description of PR
Summary:
Fixes #1731
Type of change
Approach
What is the motivation for this PR?
Fix issue #1731
How did you do it?
The possible reason is that exception is raised in str method of the RunAnsibleModuleFail class. The change is to catch any possible error of json.dumps while converting the ansible module result to human friendly string. If the json.dumps call failed, use the safer builtin str() function to convert the ansible result to a less human friendly string as a fall back method.
How did you verify/test it?
The original issue is not reproducible on my side. That's why I make this PR as a draft at this point.
What I tested:
Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation