-
Notifications
You must be signed in to change notification settings - Fork 114
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
[Namespace] Fix interfaces counters in InterfacesMIB RFC 2863 #141
Changes from 10 commits
815fc67
216ef86
7baa245
964a353
f8c6ade
6772fa1
14353e2
5f49791
4ed96fd
b91863b
ff5d7b8
5a54bdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,30 @@ def mgmt_if_entry_table_state_db(if_name): | |
|
||
return b'MGMT_PORT_TABLE|' + if_name | ||
|
||
def get_sai_id_key(namespace, sai_id): | ||
""" | ||
inputs: | ||
namespace - string | ||
sai id - bytes | ||
Return type: | ||
bytes | ||
Return value: namespace:sai id or sai id | ||
""" | ||
if namespace != '': | ||
return namespace.encode() + b':' + sai_id | ||
else: | ||
return sai_id | ||
|
||
def split_sai_id_key(sai_id_key): | ||
""" | ||
Input - bytes | ||
Return namespace string and sai id in byte string. | ||
""" | ||
if b':' in sai_id_key: | ||
namespace, sai_id = sai_id_key.split(b':') | ||
return namespace.decode(), sai_id | ||
else: | ||
return '', sai_id_key | ||
|
||
def config(**kwargs): | ||
global redis_kwargs | ||
|
@@ -221,7 +245,11 @@ def init_sync_d_interface_tables(db_conn): | |
if_name_map = {if_name: sai_id for if_name, sai_id in if_name_map.items() if \ | ||
(re.match(port_util.SONIC_ETHERNET_RE_PATTERN, if_name.decode()) or \ | ||
re.match(port_util.SONIC_ETHERNET_BP_RE_PATTERN, if_name.decode()))} | ||
if_id_map = {sai_id: if_name for sai_id, if_name in if_id_map.items() if \ | ||
# As sai_id is not unique in multi-asic platform, concatenate it with | ||
# namespace to get a unique key. Assuming that ':' is not present in namespace | ||
# string or in sai id. | ||
# sai_id_key = namespace : sai_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a new assumption that ':' will not appear in name space or sai_id. Please add code comment. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using '|' which is widely used in Redis keys In reply to: 453139692 [](ancestors = 453139692) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comment. |
||
if_id_map = {get_sai_id_key(db_conn.namespace, sai_id): if_name for sai_id, if_name in if_id_map.items() if \ | ||
(re.match(port_util.SONIC_ETHERNET_RE_PATTERN, if_name.decode()) or \ | ||
re.match(port_util.SONIC_ETHERNET_BP_RE_PATTERN, if_name.decode()))} | ||
logger.debug("Port name map:\n" + pprint.pformat(if_name_map, indent=2)) | ||
|
@@ -520,14 +548,24 @@ def get_oidvalue(self, oid): | |
class Namespace: | ||
@staticmethod | ||
def init_namespace_dbs(): | ||
db_conn= [] | ||
db_conn = [] | ||
SonicDBConfig.load_sonic_global_db_config() | ||
for namespace in SonicDBConfig.get_ns_list(): | ||
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace) | ||
db_conn.append(db) | ||
|
||
return db_conn | ||
|
||
@staticmethod | ||
def get_namespace_db_map(dbs): | ||
""" | ||
Return a map of namespace:db_conn | ||
""" | ||
db_map = {} | ||
for db_conn in dbs: | ||
db_map[db_conn.namespace] = db_conn | ||
return db_map | ||
|
||
@staticmethod | ||
def connect_all_dbs(dbs, db_name): | ||
for db_conn in dbs: | ||
|
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.
you can split first and check result len().
This will scan the string only once. #Closed
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.
Updated as per comment.