Skip to content

Commit

Permalink
Replace swsssdk.SonicV2Connector with swsscommon.SonicV2Connector (SW…
Browse files Browse the repository at this point in the history
…IG wrapper of C++ implementation) in production code (sonic-net#1217)

**- What I did**
This is the following step for merging sonic-py-swsssdk into sonic-swss-common sonic-net/sonic-swss-common#387

**- How I did it**

**- How to verify it**
Unit test and tested in DUT

* Replace swsssdk.SonicV2Connector with swsscommon.SonicV2Connector (SWIG wrapper of C++ implementation) in production code
* Remove extra statement
* Move back the import to original place
  • Loading branch information
qiluo-msft authored Nov 6, 2020
1 parent ee6bc49 commit 0d49a85
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 19 deletions.
3 changes: 2 additions & 1 deletion acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import pyangbind.lib.pybindJSON as pybindJSON
from natsort import natsorted
from sonic_py_common import device_info
from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig
from swsssdk import ConfigDBConnector, SonicDBConfig
from swsscommon.swsscommon import SonicV2Connector


def info(msg):
Expand Down
3 changes: 2 additions & 1 deletion config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

# SONiC specific imports
import sonic_yang
from swsssdk import ConfigDBConnector, SonicV2Connector, port_util
from swsssdk import ConfigDBConnector, port_util
from swsscommon.swsscommon import SonicV2Connector

# Using load_source to 'import /usr/local/bin/sonic-cfggen as sonic_cfggen'
# since /usr/local/bin/sonic-cfggen does not have .py extension.
Expand Down
3 changes: 2 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from portconfig import get_child_ports
from sonic_py_common import device_info, multi_asic
from sonic_py_common.interface import get_interface_table_name, get_port_table_name
from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig
from swsssdk import ConfigDBConnector, SonicDBConfig
from swsscommon.swsscommon import SonicV2Connector
from utilities_common.db import Db
from utilities_common.intf_filter import parse_interface_in_filter
import utilities_common.cli as clicommon
Expand Down
2 changes: 1 addition & 1 deletion config/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import click
import ipaddress
from swsssdk import ConfigDBConnector
from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector

def is_valid_ipv4_address(address):
"""Check if the given ipv4 address is valid"""
Expand Down
3 changes: 2 additions & 1 deletion scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import traceback

from sonic_py_common import device_info, logger
from swsssdk import ConfigDBConnector, SonicDBConfig, SonicV2Connector
from swsssdk import ConfigDBConnector, SonicDBConfig
from swsscommon.swsscommon import SonicV2Connector

INIT_CFG_FILE = '/etc/sonic/init_cfg.json'
SYSLOG_IDENTIFIER = 'db_migrator'
Expand Down
2 changes: 1 addition & 1 deletion scripts/fanshow
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ from __future__ import print_function
import os
import sys
from tabulate import tabulate
from swsssdk import SonicV2Connector
from natsort import natsorted

# mock the redis for unit test purposes #
Expand All @@ -21,6 +20,7 @@ try:
except KeyError:
pass

from swsscommon.swsscommon import SonicV2Connector

header = ['Drawer', 'LED', 'FAN', 'Speed', 'Direction', 'Presence', 'Status', 'Timestamp']

Expand Down
2 changes: 1 addition & 1 deletion scripts/fdbclear
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import argparse
import json
import sys

from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector

class FdbClear(object):

Expand Down
3 changes: 2 additions & 1 deletion scripts/fdbshow
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import json
import sys

from natsort import natsorted
from swsssdk import SonicV2Connector, port_util
from swsssdk import port_util
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate

class FdbShow(object):
Expand Down
2 changes: 1 addition & 1 deletion scripts/natclear
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import argparse
import json
import sys

from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector

class NatClear(object):

Expand Down
2 changes: 1 addition & 1 deletion scripts/natshow
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import json
import sys
import re

from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate

class NatShow(object):
Expand Down
3 changes: 2 additions & 1 deletion scripts/nbrshow
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import subprocess
import re

from natsort import natsorted
from swsssdk import SonicV2Connector, port_util
from swsssdk import port_util
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate

"""
Expand Down
3 changes: 2 additions & 1 deletion scripts/neighbor_advertiser
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import traceback
import warnings

from sonic_py_common import logger
from swsssdk import ConfigDBConnector, SonicV2Connector
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import SonicV2Connector
from netaddr import IPAddress, IPNetwork


Expand Down
3 changes: 2 additions & 1 deletion scripts/psushow
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import argparse
import sys
import os
from swsssdk import SonicV2Connector
from tabulate import tabulate

# mock the redis for unit test purposes #
Expand All @@ -17,6 +16,8 @@ try:
except KeyError:
pass

from swsscommon.swsscommon import SonicV2Connector

def psu_status_show(index):
db = SonicV2Connector(host="127.0.0.1")
db.connect(db.STATE_DB)
Expand Down
2 changes: 1 addition & 1 deletion scripts/tempershow
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import print_function

from tabulate import tabulate
from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector
from natsort import natsorted


Expand Down
2 changes: 1 addition & 1 deletion show/fgnhg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import click
import utilities_common.cli as clicommon
from swsssdk import ConfigDBConnector
from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate


Expand Down
3 changes: 2 additions & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import fgnhg

from sonic_py_common import device_info, multi_asic
from swsssdk import ConfigDBConnector, SonicV2Connector
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate
from utilities_common.db import Db
import utilities_common.multi_asic as multi_asic_util
Expand Down
2 changes: 1 addition & 1 deletion sonic_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import click
from sonic_py_common import logger
from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector

from .bootloader import get_bootloader
from .common import run_command, run_command_or_raise
Expand Down
6 changes: 4 additions & 2 deletions tests/mock_tables/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import mock
import mockredis
import swsssdk.interface
import redis
import swsssdk
from sonic_py_common import multi_asic
from swsssdk import SonicDBConfig, SonicV2Connector
from swsssdk.interface import redis
from swsscommon import swsscommon

topo = None

Expand Down Expand Up @@ -137,3 +138,4 @@ def keys(self, pattern='*'):
mockredis.MockRedis.config_set = config_set
redis.StrictRedis = SwssSyncClient
SonicV2Connector.connect = connect_SonicV2Connector
swsscommon.SonicV2Connector = SonicV2Connector

0 comments on commit 0d49a85

Please sign in to comment.