Skip to content

Use unix socket path in ConfigDBConnector for some components #10179

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sonic-host-services/scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ class HostConfigDaemon:
def __init__(self):
# Just a sanity check to verify if the CONFIG_DB has been initialized
# before moving forward
self.config_db = ConfigDBConnector()
self.config_db = ConfigDBConnector(use_unix_socket_path=True)
self.config_db.connect(wait_for_init=True, retry_on=True)
self.dbconn = DBConnector(CFG_DB, 0)
self.selector = Select()
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

def get_localhost_info(field):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_localhost_info

If you intention is to fix hostcfgd, you do not need to modify this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is not the main intension. Please see the following back trace:

Traceback (most recent call last):', '  File "/usr/local/bin/sonic-installer", line 5, in <module>, 
    from sonic_installer.main import sonic_installer', '  File "/usr/local/lib/python3.9/dist-packages/sonic_installer/main.py", line 7, in <module>', 
    import utilities_common.cli as clicommon', '  File "/usr/local/lib/python3.9/dist-packages/utilities_common/cli.py", line 189, in <module>',
     iface_alias_converter = InterfaceAliasConverter()', '  File "/usr/local/lib/python3.9/dist-packages/utilities_common/cli.py", line 126, in __init__', 
    self.port_dict = multi_asic.get_port_table()', '  File "/usr/local/lib/python3.9/dist-packages/sonic_py_common/multi_asic.py", line 301, in get_port_table',
     ports = get_port_table_for_asic(ns)', '  File "/usr/local/lib/python3.9/dist-packages/sonic_py_common/multi_asic.py", line 315, in get_port_table_for_asic',
     config_db = connect_config_db_for_ns(namespace)', '  File "/usr/local/lib/python3.9/dist-packages/sonic_py_common/multi_asic.py", line 47, in connect_config_db_for_ns',
     config_db.connect()',
   File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1829, in connect', 
   return _swsscommon.ConfigDBConnector_Native_connect(self, wait_for_init, retry_on)', 
'RuntimeError: Unable to connect to redis: Cannot assign requested address

try:
config_db = ConfigDBConnector()
config_db = ConfigDBConnector(use_unix_socket_path=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use_unix_socket_path

Changing default behavior will cause a permission issue to non privilege users.

config_db.connect()

metadata = config_db.get_table('DEVICE_METADATA')
Expand Down Expand Up @@ -356,7 +356,7 @@ def get_platform_info():
hw_info_dict['asic_count'] = get_num_asics()

try:
config_db = ConfigDBConnector()
config_db = ConfigDBConnector(use_unix_socket_path=True)
config_db.connect()

metadata = config_db.get_table('DEVICE_METADATA')["localhost"]
Expand Down
18 changes: 9 additions & 9 deletions src/sonic-py-common/sonic_py_common/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# to prevent duplicate connections from being opened
config_db_handle = {}

def connect_config_db_for_ns(namespace=DEFAULT_NAMESPACE):
def connect_config_db_for_ns(namespace=DEFAULT_NAMESPACE, use_unix_socket_path=False):
"""
The function connects to the config DB for a given namespace and
returns the handle
Expand All @@ -43,17 +43,17 @@ def connect_config_db_for_ns(namespace=DEFAULT_NAMESPACE):
Returns:
handle to the config_db for a namespace
"""
config_db = swsscommon.ConfigDBConnector(namespace=namespace)
config_db = swsscommon.ConfigDBConnector(namespace=namespace, use_unix_socket_path=use_unix_socket_path)
config_db.connect()
return config_db


def connect_to_all_dbs_for_ns(namespace=DEFAULT_NAMESPACE):
def connect_to_all_dbs_for_ns(namespace=DEFAULT_NAMESPACE, use_unix_socket_path=False):
"""
The function connects to the DBs for a given namespace and
returns the handle
For voq chassis systems, the db list includes databases from
returns the handle

For voq chassis systems, the db list includes databases from
supervisor card. Avoid connecting to these databases from linecards

If no namespace is provided, it will connect to the db in the
Expand All @@ -65,7 +65,7 @@ def connect_to_all_dbs_for_ns(namespace=DEFAULT_NAMESPACE):
Returns:
handle to all the dbs for a namespaces
"""
db = swsscommon.SonicV2Connector(namespace=namespace)
db = swsscommon.SonicV2Connector(namespace=namespace, use_unix_socket_path=use_unix_socket_path)
db_list = list(db.get_db_list())
if not is_supervisor():
try:
Expand Down Expand Up @@ -242,7 +242,7 @@ def get_all_namespaces():
for asic in range(num_asics):
namespace = "{}{}".format(ASIC_NAME_PREFIX, asic)
if namespace not in config_db_handle:
config_db_handle[namespace] = connect_config_db_for_ns(namespace)
config_db_handle[namespace] = connect_config_db_for_ns(namespace, use_unix_socket_path=True)
config_db = config_db_handle[namespace]

metadata = config_db.get_table('DEVICE_METADATA')
Expand Down Expand Up @@ -312,7 +312,7 @@ def get_port_entry_for_asic(port, namespace):

def get_port_table_for_asic(namespace):

config_db = connect_config_db_for_ns(namespace)
config_db = connect_config_db_for_ns(namespace, use_unix_socket_path=True)
ports = config_db.get_table(PORT_CFG_DB_TABLE)
return ports

Expand Down