Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug: ConfigDBConnector.get_table does not work in python3 (sonic-…
…net#92) `ConfigDBConnector` is not working well under python3, for example: ``` Oct 29 21:56:58.496505 sonic INFO hostcfgd[20662]: Traceback (most recent call last): Oct 29 21:56:58.496724 sonic INFO hostcfgd[20662]: File "/usr/bin/hostcfgd", line 387, in <module> Oct 29 21:56:58.496873 sonic INFO hostcfgd[20662]: main() Oct 29 21:56:58.497014 sonic INFO hostcfgd[20662]: File "/usr/bin/hostcfgd", line 382, in main Oct 29 21:56:58.497147 sonic INFO hostcfgd[20662]: daemon = HostConfigDaemon() Oct 29 21:56:58.497939 sonic INFO hostcfgd[20662]: File "/usr/bin/hostcfgd", line 237, in __init__ Oct 29 21:56:58.498103 sonic INFO hostcfgd[20662]: tacacs_server = self.config_db.get_table('TACPLUS_SERVER') Oct 29 21:56:58.498236 sonic INFO hostcfgd[20662]: File "/usr/local/lib/python3.7/dist-packages/swsssdk/configdb.py", line 269, in get_table Oct 29 21:56:58.498388 sonic INFO hostcfgd[20662]: entry = self.raw_to_typed(client.hgetall(key)) Oct 29 21:56:58.498523 sonic INFO hostcfgd[20662]: File "/usr/local/lib/python3.7/dist-packages/swsssdk/configdb.py", line 123, in raw_to_typed Oct 29 21:56:58.498649 sonic INFO hostcfgd[20662]: key = raw_key.decode() Oct 29 21:56:58.498779 sonic INFO hostcfgd[20662]: AttributeError: 'str' object has no attribute 'decode' ``` So I will force parent class `SonicV2Connector` to handle all the `encode` / `decode` by specify `decode_responses=True` in its constructor parameters. But the class `ConfigDBConnector` will refuse contructed by `decode_responses=False`, which is okay to existing code base. Tested in DUT: ``` Python 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from swsssdk import ConfigDBConnector >>> db = ConfigDBConnector() >>> db.dbintf.redis_kwargs {'host': '127.0.0.1', 'decode_responses': True} >>> db.connect() >>> db.get_table('TACPLUS_SERVER') {'10.10.10.10': {'priority': '1', 'tcp_port': '49'}} ```
- Loading branch information