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
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
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',
],
},
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
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved
'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
13 changes: 12 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,14 @@ 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():
# change working folder to import swsssdk in subprocess
swsssdk_path = os.path.join(modules_path, 'src')
wd = os.getcwd()
os.chdir(swsssdk_path)

result = subprocess.run(["python", "-c", "import swsssdk;exit()"], capture_output=True)
assert "deprecated" in result.stderr.decode("utf-8")
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved

os.chdir(wd)