Skip to content

Commit e30a1e1

Browse files
authored
Throw exception when not use swsssdk in UT. (#126)
#### Why I did it swsssdk been deprecated after 202205 branch, all use should switch to sonic-swss-common. #### How I did it Throw exception when load swsssdk for none UT usage. #### How to verify it Pass all UT. #### Which release branch to backport (provide reason below if selected) #### Description for the changelog Throw exception when load swsssdk for none UT usage. #### Link to config_db schema for YANG module changes #### A picture of a cute animal (not mandatory but encouraged)
1 parent cc847a2 commit e30a1e1

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
'hiredis>=0.1.4'
1010
]
1111

12+
console_scripts={
13+
'sonic-db-load = swsssdk:sonic_db_dump_load',
14+
'sonic-db-dump = swsssdk:sonic_db_dump_load',
15+
}
16+
1217
setup(
1318
name='swsssdk',
1419
version='2.0.1',
@@ -26,12 +31,7 @@
2631
extras_require={
2732
'high_perf': high_performance_deps
2833
},
29-
entry_points={
30-
'console_scripts': [
31-
'sonic-db-load = swsssdk:sonic_db_dump_load',
32-
'sonic-db-dump = swsssdk:sonic_db_dump_load',
33-
],
34-
},
34+
entry_points={},
3535
classifiers=[
3636
'Intended Audience :: Developers',
3737
'Operating System :: Linux',

src/swsssdk/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
"""
22
Utility library for Switch-state Redis database access and syslog reporting.
33
"""
4+
import sys
45
import logging
56

67
logger = logging.getLogger(__name__)
78
logger.setLevel(logging.INFO)
89
logger.addHandler(logging.NullHandler())
910

11+
if ('unittest' not in sys.modules.keys() and
12+
'mockredis' not in sys.modules.keys() and
13+
'mock' not in sys.modules.keys()):
14+
msg = "sonic-py-swsssdk been deprecated, please switch to sonic-swss-common."
15+
logger.exception(msg)
16+
raise ImportError("sonic-py-swsssdk been deprecated, please switch to sonic-swss-common.")
17+
1018
try:
1119
from .dbconnector import SonicDBConfig, SonicV2Connector
1220
from .configdb import ConfigDBConnector, ConfigDBPipeConnector

test/test_moduleLoad.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
sys.path.insert(0, os.path.join(modules_path, 'src'))
66

77
from unittest import TestCase
8-
8+
import subprocess
99

1010
class Test_load_sonic_db_config(TestCase):
1111
def test__db_map_attributes(self):
@@ -34,3 +34,10 @@ def test__dbConfig(self):
3434
for namespace in list(dbConfig.get_ns_list()):
3535
self.assertEqual(dbConfig.get_dbid('PFC_WD_DB', namespace), 5)
3636
self.assertEqual(dbConfig.get_dbid('APPL_DB', namespace), 0)
37+
38+
def test_BlockUseSwsssdk():
39+
# Import swsssdk will throw exception with deprecated message.
40+
swsssdk_path = os.path.join(modules_path, 'src')
41+
result = subprocess.run(["python", "-c", "import swsssdk;exit()"], capture_output=True, cwd=swsssdk_path)
42+
43+
assert "deprecated" in result.stderr.decode("utf-8")

0 commit comments

Comments
 (0)