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

Fix: no need to decode() after redis client scan, so it will work for both python2 and python3 #96

Merged
merged 1 commit into from
Nov 18, 2020

Conversation

qiluo-msft
Copy link
Contributor

@qiluo-msft qiluo-msft commented Nov 18, 2020

The original code was tested in python2, which convert a str to a unicode str. It is working but not needed.

>>> client.hgetall('QUEUE|Ethernet100|1')
{'scheduler': '[SCHEDULER|scheduler.0]'}
>>> client.hgetall(u'QUEUE|Ethernet100|1')
{'scheduler': '[SCHEDULER|scheduler.0]'}
>>> a = {}
>>> a['b'] = 'c'
>>> a[u'b'] = 'cc'
>>> a
{'b': 'cc'}

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 SonicV2Connector, ConfigDBPipeConnector
>>> cfg = ConfigDBPipeConnector()
>>> cfg.connect()
>>> cfg.get_config().keys()
dict_keys(['QUEUE', 'DEVICE_NEIGHBOR', 'INTERFACE', 'BGP_NEIGHBOR', 'FEATURE', 'BUFFER_QUEUE', 'DEVICE_NEIGHBOR_METADATA', 'BUFFER_PORT_EGRESS_PROFILE_LIST', 'DHCP_SERVER', 'FLEX_COUNTER_TABLE', 'RESTAPI', 'PORT_QOS_MAP', 'BUFFER_PG', 'PORT', 'ACL_TABLE', 'BUFFER_PORT_INGRESS_PROFILE_LIST', 'NTP_SERVER', 'DSCP_TO_TC_MAP', 'BUFFER_PROFILE', 'TC_TO_PRIORITY_GROUP_MAP', 'BUFFER_POOL', 'LOOPBACK_INTERFACE', 'TELEMETRY', 'WRED_PROFILE', 'MAP_PFC_PRIORITY_TO_QUEUE', 'SYSLOG_SERVER', 'PFC_PRIORITY_TO_PRIORITY_GROUP_MAP', 'TACPLUS_SERVER', 'SCHEDULER', 'DEVICE_METADATA', 'CRM', 'MGMT_INTERFACE', 'VERSIONS', 'CABLE_LENGTH', 'TC_TO_QUEUE_MAP', 'MGMT_PORT'])

Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from swsssdk import SonicV2Connector, ConfigDBPipeConnector
>>> cfg = ConfigDBPipeConnector()
>>> cfg.connect()
>>> cfg.get_config().keys()
[u'TACPLUS_SERVER', u'DEVICE_METADATA', u'MAP_PFC_PRIORITY_TO_QUEUE', u'QUEUE', u'FLEX_COUNTER_TABLE', u'PORT', u'SYSLOG_SERVER', u'CRM', u'BUFFER_PG', u'BGP_NEIGHBOR', u'VERSIONS', u'BUFFER_PORT_INGRESS_PROFILE_LIST', u'MGMT_INTERFACE', u'PORT_QOS_MAP', u'DHCP_SERVER', u'NTP_SERVER', u'BUFFER_QUEUE', u'WRED_PROFILE', u'TC_TO_PRIORITY_GROUP_MAP', u'DEVICE_NEIGHBOR_METADATA', u'TELEMETRY', u'DEVICE_NEIGHBOR', u'FEATURE', u'INTERFACE', u'DSCP_TO_TC_MAP', u'PFC_PRIORITY_TO_PRIORITY_GROUP_MAP', u'LOOPBACK_INTERFACE', u'TC_TO_QUEUE_MAP', u'MGMT_PORT', u'RESTAPI', u'ACL_TABLE', u'CABLE_LENGTH', u'SCHEDULER', u'BUFFER_PORT_EGRESS_PROFILE_LIST', u'BUFFER_POOL', u'BUFFER_PROFILE']

both python2 and python3.

The original code was tested in python2, which convert a str to a
unicode str. It is working but not needed.

```python
>>> client.hgetall('QUEUE|Ethernet100|1')
{'scheduler': '[SCHEDULER|scheduler.0]'}
>>> client.hgetall(u'QUEUE|Ethernet100|1')
{'scheduler': '[SCHEDULER|scheduler.0]'}
>>> a = {}
>>> a['b'] = 'c'
>>> a[u'b'] = 'cc'
>>> a
{'b': 'cc'}
```
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.

3 participants