-
Notifications
You must be signed in to change notification settings - Fork 86
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
Support hierarchical keys #12
Conversation
@taoyl-ms, |
src/swsssdk/configdb.py
Outdated
@@ -84,7 +85,7 @@ def listen(self): | |||
if item['type'] == 'pmessage': | |||
key = item['channel'].split(':', 1)[1] | |||
try: | |||
(table, row) = key.split(':', 1) | |||
(table, row) = key.split('|', 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'|' [](start = 45, length = 3)
can you use a variable? #Resolved
as a general comment, we need unit test for this configdb class. #WontFix |
src/swsssdk/configdb.py
Outdated
@@ -117,16 +123,30 @@ def __typed_to_raw(self, typed_data): | |||
raw_data[key] = value | |||
return raw_data | |||
|
|||
@staticmethod | |||
def serialize_key(key): | |||
string_types = str if sys.version_info[0] == 3 else basestring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string_types = str if sys.version_info[0] == 3 else basestring [](start = 8, length = 62)
in general, I found such shortcut conditional not quite readable, I prefer traditional if else condition. #Resolved
src/swsssdk/configdb.py
Outdated
@staticmethod | ||
def deserialize_key(key): | ||
tokens = key.split('|') | ||
return tuple(tokens) if len(tokens) > 1 else tokens[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eturn tuple(tokens) if len(tokens) > 1 else tokens[0] [](start = 9, length = 53)
not readable, I think we should try to avoid to keep the code more readable. #Resolved
Agree. Will add in later PRs. In reply to: 326614104 [](ancestors = 326614104) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* msft_github/master: Commond utility functions for bridge/port mapping (sonic-net#14) [configdb] Support hierarchical keys (sonic-net#12) Add attribute retry_on for configdb connection (sonic-net#11)
…t raise exception when DB has not RIF data (#117) **Why I did this?** port_util.get_vlan_interface_oid_map would raise exception when there is no RIF configured, and it would causes snmpagent not work. This PR is to fix it. ``` #012Traceback (most recent call last): #012File "/usr/local/lib/python3.7/dist-packages/ax_interface/mib.py", line 37, in start #12 self.reinit_data()#12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/ietf/rfc1213.py", line 233, in reinit_data #12 self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn) #12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 651, in get_sync_d_from_all_namespace #12 ns_tuple = per_namespace_func(db_conn) #12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 341, in init_sync_d_vlan_tables #12 vlan_name_map = port_util.get_vlan_interface_oid_map(db_conn) #12 File "/usr/local/lib/python3.7/dist-packages/swsssdk/port_util.py", line 167, in get_vlan_interface_oid_map #12 rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=True) #12 File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1751, in get_all #12 return dict(super(SonicV2Connector, self).get_all(db_name, _hash, blocking)) #12 File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1708, in get_all #12 return _swsscommon.SonicV2Connector_Native_get_all(self, db_name, _hash, blocking) #012RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}' ``` **How I did this:** check redis key exists first before calling get_all.
…t raise exception when DB has not RIF data (#117) **Why I did this?** port_util.get_vlan_interface_oid_map would raise exception when there is no RIF configured, and it would causes snmpagent not work. This PR is to fix it. ``` #012Traceback (most recent call last): #012File "/usr/local/lib/python3.7/dist-packages/ax_interface/mib.py", line 37, in start #12 self.reinit_data()#12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/ietf/rfc1213.py", line 233, in reinit_data #12 self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn) #12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 651, in get_sync_d_from_all_namespace #12 ns_tuple = per_namespace_func(db_conn) #12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 341, in init_sync_d_vlan_tables #12 vlan_name_map = port_util.get_vlan_interface_oid_map(db_conn) #12 File "/usr/local/lib/python3.7/dist-packages/swsssdk/port_util.py", line 167, in get_vlan_interface_oid_map #12 rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=True) #12 File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1751, in get_all #12 return dict(super(SonicV2Connector, self).get_all(db_name, _hash, blocking)) #12 File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1708, in get_all #12 return _swsscommon.SonicV2Connector_Native_get_all(self, db_name, _hash, blocking) #012RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}' ``` **How I did this:** check redis key exists first before calling get_all.
|
instead of:
for separator in redis key, and support hierarchical multiple keys.data == {}
) with a"NULL": "NULL"
placeholder.set_entry
now support delete entry withdata == None
.