Skip to content

Replace py-swsssdk with swsscommon #5926

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

Merged
merged 4 commits into from
Jul 13, 2022
Merged
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
12 changes: 9 additions & 3 deletions ansible/library/acl_capabilities_facts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python

import swsssdk
from sonic_py_common import multi_asic
DOCUMENTATION = '''
module: acl_capabilities_facts
Expand All @@ -9,6 +8,12 @@
short_description: Retrieve ACL capability information
'''

# swsssdk will be deprecate after 202205
try:
from swsssdk import SonicDBConfig, SonicV2Connector
except ImportError:
from swsscommon.swsscommon import SonicDBConfig, SonicV2Connector

EXAMPLES = '''
- name: Get ACL capability facts
acl_capabilities_facts:
Expand All @@ -32,8 +37,9 @@ def run(self):
"""
self.facts['acl_capabilities'] = {}
namespace_list = multi_asic.get_namespace_list()
swsssdk.SonicDBConfig.load_sonic_global_db_config()
conn = swsssdk.SonicV2Connector(namespace=namespace_list[0])

SonicDBConfig.load_sonic_global_db_config()
conn = SonicV2Connector(namespace=namespace_list[0])
conn.connect(conn.STATE_DB)
keys = conn.keys(conn.STATE_DB, 'ACL_STAGE_CAPABILITY_TABLE|*') or []

Expand Down
12 changes: 9 additions & 3 deletions ansible/library/switch_capabilities_facts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python

import swsssdk
from sonic_py_common import multi_asic
DOCUMENTATION = '''
module: switch_capability_facts
Expand All @@ -9,6 +8,12 @@
short_description: Retrieve switch capability information
'''

# swsssdk will be deprecate after 202205
try:
from swsssdk import SonicDBConfig, SonicV2Connector
except ImportError:
from swsscommon.swsscommon import SonicDBConfig, SonicV2Connector

EXAMPLES = '''
- name: Get switch capability facts
switch_capability_facts:
Expand All @@ -33,8 +38,9 @@ def run(self):
"""
self.facts['switch_capabilities'] = {}
namespace_list = multi_asic.get_namespace_list()
swsssdk.SonicDBConfig.load_sonic_global_db_config()
conn = swsssdk.SonicV2Connector(namespace=namespace_list[0])

SonicDBConfig.load_sonic_global_db_config()
conn = SonicV2Connector(namespace=namespace_list[0])
conn.connect(conn.STATE_DB)
keys = conn.keys(conn.STATE_DB, 'SWITCH_CAPABILITY|*')

Expand Down
12 changes: 10 additions & 2 deletions tests/sflow/test_sflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@ def get_ifindex(duthost, port):

def get_port_index(duthost, port):
py_version = 'python' if '201911' in duthost.os_version else 'python3'
Copy link
Contributor

Choose a reason for hiding this comment

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

201911

If the code is testing an old image (such as 201911 branch image), will it break?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.
Add code to check if the sonic_py_common.port_util class exist.

cmd = "{} -c \"from swsssdk import port_util; print(port_util.get_index_from_str(\'{}\'))\""
index = duthost.shell(cmd.format(py_version, port))['stdout']

# if sonic_py_common.port_util exist, use port_util from sonic_py_common.
util_lib = "swsssdk"
cmd = "{} -c \"import pkgutil; print(pkgutil.find_loader(\'sonic_py_common.port_util\'))\"".format(py_version)
class_exist = duthost.shell(cmd)['stdout']
if class_exist != "None":
util_lib = "sonic_py_common"

cmd = "{} -c \"from {} import port_util; print(port_util.get_index_from_str(\'{}\'))\""
index = duthost.shell(cmd.format(py_version, util_lib, port))['stdout']
return index

# ----------------------------------------------------------------------------------
Expand Down