|
3 | 3 | import os
|
4 | 4 |
|
5 | 5 | from swsscommon.swsscommon import SonicV2Connector
|
6 |
| -from swsssdk import SonicDBConfig |
| 6 | +from swsscommon.swsscommon import SonicDBConfig |
7 | 7 | from swsssdk import port_util
|
8 | 8 | from swsssdk.port_util import get_index_from_str
|
9 | 9 | from ax_interface.mib import MIBUpdater
|
10 | 10 | from ax_interface.util import oid2tuple
|
11 | 11 | from sonic_ax_impl import logger
|
| 12 | +from sonic_py_common import multi_asic |
12 | 13 |
|
13 | 14 | COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP'
|
14 | 15 | COUNTERS_QUEUE_NAME_MAP = 'COUNTERS_QUEUE_NAME_MAP'
|
@@ -218,7 +219,12 @@ def init_db():
|
218 | 219 | Connects to DB
|
219 | 220 | :return: db_conn
|
220 | 221 | """
|
221 |
| - SonicDBConfig.load_sonic_global_db_config() |
| 222 | + if not SonicDBConfig.isInit(): |
| 223 | + if multi_asic.is_multi_asic(): |
| 224 | + # Load the global config file database_global.json once. |
| 225 | + SonicDBConfig.load_sonic_global_db_config() |
| 226 | + else: |
| 227 | + SonicDBConfig.load_sonic_db_config() |
222 | 228 | # SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS.
|
223 | 229 | # Redis PubSub objects (such as those within swsssdk) are NOT thread-safe.
|
224 | 230 | db_conn = SonicV2Connector(**redis_kwargs)
|
@@ -538,10 +544,20 @@ class Namespace:
|
538 | 544 | @staticmethod
|
539 | 545 | def init_namespace_dbs():
|
540 | 546 | db_conn = []
|
541 |
| - SonicDBConfig.load_sonic_global_db_config() |
542 |
| - for namespace in SonicDBConfig.get_ns_list(): |
543 |
| - db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace, decode_responses=True) |
| 547 | + if not SonicDBConfig.isInit(): |
| 548 | + if multi_asic.is_multi_asic(): |
| 549 | + SonicDBConfig.load_sonic_global_db_config() |
| 550 | + else: |
| 551 | + SonicDBConfig.load_sonic_db_config() |
| 552 | + host_namespace_idx = 0 |
| 553 | + for idx, namespace in enumerate(SonicDBConfig.get_ns_list()): |
| 554 | + if namespace == multi_asic.DEFAULT_NAMESPACE: |
| 555 | + host_namespace_idx = idx |
| 556 | + db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace) |
544 | 557 | db_conn.append(db)
|
| 558 | + # Ensure that db connector of default namespace is the first element of |
| 559 | + # db_conn list. |
| 560 | + db_conn[0], db_conn[host_namespace_idx] = db_conn[host_namespace_idx], db_conn[0] |
545 | 561 |
|
546 | 562 | Namespace.connect_namespace_dbs(db_conn)
|
547 | 563 | return db_conn
|
|
0 commit comments