Skip to content
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

Throw exception when not use swsssdk in UT. #126

Merged
merged 14 commits into from
Oct 9, 2022
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
'hiredis>=0.1.4'
]

console_scripts={
'sonic-db-load = swsssdk:sonic_db_dump_load',
'sonic-db-dump = swsssdk:sonic_db_dump_load',
}

setup(
name='swsssdk',
version='2.0.1',
Expand All @@ -26,12 +31,7 @@
extras_require={
'high_perf': high_performance_deps
},
entry_points={
'console_scripts': [
Copy link
Contributor

Choose a reason for hiding this comment

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

console_scripts

Let's define a new var console_scripts in order to keep some history trace, and entry_points={}

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for misleading. console_scripts variable should be defined at file global scope. It is not a parameter for setup function.

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.

'sonic-db-load = swsssdk:sonic_db_dump_load',
'sonic-db-dump = swsssdk:sonic_db_dump_load',
],
},
entry_points={},
classifiers=[
'Intended Audience :: Developers',
'Operating System :: Linux',
Expand Down
8 changes: 8 additions & 0 deletions src/swsssdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
"""
Utility library for Switch-state Redis database access and syslog reporting.
"""
import sys
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(logging.NullHandler())

if ('unittest' not in sys.modules.keys() and
'mockredis' not in sys.modules.keys() and
'mock' not in sys.modules.keys()):
msg = "sonic-py-swsssdk been deprecated, please switch to sonic-swss-common."
logger.exception(msg)
raise ImportError("sonic-py-swsssdk been deprecated, please switch to sonic-swss-common.")

try:
from .dbconnector import SonicDBConfig, SonicV2Connector
from .configdb import ConfigDBConnector, ConfigDBPipeConnector
Expand Down
9 changes: 8 additions & 1 deletion test/test_moduleLoad.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
sys.path.insert(0, os.path.join(modules_path, 'src'))

from unittest import TestCase

import subprocess

class Test_load_sonic_db_config(TestCase):
def test__db_map_attributes(self):
Expand Down Expand Up @@ -34,3 +34,10 @@ def test__dbConfig(self):
for namespace in list(dbConfig.get_ns_list()):
self.assertEqual(dbConfig.get_dbid('PFC_WD_DB', namespace), 5)
self.assertEqual(dbConfig.get_dbid('APPL_DB', namespace), 0)

def test_BlockUseSwsssdk():
# Import swsssdk will throw exception with deprecated message.
swsssdk_path = os.path.join(modules_path, 'src')
result = subprocess.run(["python", "-c", "import swsssdk;exit()"], capture_output=True, cwd=swsssdk_path)

assert "deprecated" in result.stderr.decode("utf-8")
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved