Skip to content

Commit

Permalink
Use SonicV2Connector/ConfigDBConnector/SonicDBConfig from swsscommon …
Browse files Browse the repository at this point in the history
…instread of swsssdk (sonic-net#1392)

- What I did
Use SonicV2Connector/ConfigDBConnector/SonicDBConfig from swsscommon instread of swsssdk

- How to verify it
Unit test and test impacted command lines on DUT.
  • Loading branch information
qiluo-msft authored Feb 2, 2021
1 parent 28d358f commit 2e1f354
Show file tree
Hide file tree
Showing 47 changed files with 150 additions and 144 deletions.
3 changes: 1 addition & 2 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import pyangbind.lib.pybindJSON as pybindJSON
from natsort import natsorted
from sonic_py_common import device_info
from swsssdk import ConfigDBConnector, SonicDBConfig
from swsscommon.swsscommon import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig


def info(msg):
Expand Down
2 changes: 1 addition & 1 deletion config/aaa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import click
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import ConfigDBConnector
import utilities_common.cli as clicommon

def add_table_kv(table, entry, key, val):
Expand Down
12 changes: 6 additions & 6 deletions config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

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

# 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 Expand Up @@ -190,8 +190,8 @@ def readConfigDB(self):
'''
self.sysLog(doPrint=True, msg='Reading data from Redis configDb')
# Read from config DB on sonic switch
db_kwargs = dict(); data = dict()
configdb = ConfigDBConnector(**db_kwargs)
data = dict()
configdb = ConfigDBConnector()
configdb.connect()
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))
self.configdbJsonIn = FormatConverter.to_serialized(data)
Expand All @@ -211,8 +211,8 @@ def writeConfigDB(self, jDiff):
void
'''
self.sysLog(doPrint=True, msg='Writing in Config DB')
db_kwargs = dict(); data = dict()
configdb = ConfigDBConnector(**db_kwargs)
data = dict()
configdb = ConfigDBConnector()
configdb.connect(False)
deep_update(data, FormatConverter.to_deserialized(jDiff))
self.sysLog(msg="Write in DB: {}".format(data))
Expand Down
2 changes: 1 addition & 1 deletion config/kdump.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import click
import utilities_common.cli as clicommon
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import ConfigDBConnector

@click.group(cls=clicommon.AbbreviationGroup, name="kdump")
def kdump():
Expand Down
13 changes: 6 additions & 7 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
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, SonicDBConfig
from swsscommon.swsscommon import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig
from utilities_common.db import Db
from utilities_common.intf_filter import parse_interface_in_filter
import utilities_common.cli as clicommon
Expand Down Expand Up @@ -1882,14 +1881,14 @@ def is_dynamic_buffer_enabled(config_db):
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
def warm_restart(ctx, redis_unix_socket_path):
"""warm_restart-related configuration tasks"""
kwargs = {}
if redis_unix_socket_path:
kwargs['unix_socket_path'] = redis_unix_socket_path
config_db = ConfigDBConnector(**kwargs)
# Note: redis_unix_socket_path is a path string, and the ground truth is now from database_config.json.
# We only use it as a bool indicator on either unix_socket_path or tcp port
use_unix_socket_path = bool(redis_unix_socket_path)
config_db = ConfigDBConnector(use_unix_socket_path=use_unix_socket_path)
config_db.connect(wait_for_init=False)

# warm restart enable/disable config is put in stateDB, not persistent across cold reboot, not saved to config_DB.json file
state_db = SonicV2Connector(host='127.0.0.1')
state_db = SonicV2Connector(use_unix_socket_path=use_unix_socket_path)
state_db.connect(state_db.STATE_DB, False)
TABLE_NAME_SEPARATOR = '|'
prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR
Expand Down
5 changes: 2 additions & 3 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import click
import utilities_common.cli as clicommon
from sonic_py_common import multi_asic
from swsssdk import ConfigDBConnector
from swsscommon import swsscommon
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from tabulate import tabulate
from utilities_common import platform_sfputil_helper

Expand Down Expand Up @@ -123,7 +122,7 @@ def mode(state, port, json_output):
# replace these with correct macros
per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
per_npu_configdb[asic_id].connect()
per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)

mux_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE")
Expand Down
3 changes: 1 addition & 2 deletions config/nat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import ipaddress

import click
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector


def is_valid_ipv4_address(address):
Expand Down
34 changes: 17 additions & 17 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click
import json
import swsssdk
from swsscommon.swsscommon import ConfigDBConnector
from tabulate import tabulate

BUFFER_POOL_WATERMARK = "BUFFER_POOL_WATERMARK"
Expand All @@ -24,7 +24,7 @@ def queue():
@click.argument('poll_interval', type=click.IntRange(100, 30000))
def interval(poll_interval):
""" Set queue counter query interval """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
queue_info = {}
if poll_interval is not None:
Expand All @@ -34,7 +34,7 @@ def interval(poll_interval):
@queue.command()
def enable():
""" Enable queue counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
queue_info = {}
queue_info['FLEX_COUNTER_STATUS'] = 'enable'
Expand All @@ -43,7 +43,7 @@ def enable():
@queue.command()
def disable():
""" Disable queue counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
queue_info = {}
queue_info['FLEX_COUNTER_STATUS'] = 'disable'
Expand All @@ -58,7 +58,7 @@ def port():
@click.argument('poll_interval', type=click.IntRange(100, 30000))
def interval(poll_interval):
""" Set queue counter query interval """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
port_info = {}
if poll_interval is not None:
Expand All @@ -68,7 +68,7 @@ def interval(poll_interval):
@port.command()
def enable():
""" Enable port counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
port_info = {}
port_info['FLEX_COUNTER_STATUS'] = 'enable'
Expand All @@ -77,7 +77,7 @@ def enable():
@port.command()
def disable():
""" Disable port counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
port_info = {}
port_info['FLEX_COUNTER_STATUS'] = 'disable'
Expand All @@ -98,7 +98,7 @@ def interval(poll_interval):
This is a short term solution and
should be changed once the performance is enhanced
"""
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
port_info = {}
if poll_interval:
Expand All @@ -108,7 +108,7 @@ def interval(poll_interval):
@port_buffer_drop.command()
def enable():
""" Enable port counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
port_info = {}
port_info['FLEX_COUNTER_STATUS'] = ENABLE
Expand All @@ -117,7 +117,7 @@ def enable():
@port_buffer_drop.command()
def disable():
""" Disable port counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
port_info = {}
port_info['FLEX_COUNTER_STATUS'] = DISABLE
Expand All @@ -132,7 +132,7 @@ def rif():
@click.argument('poll_interval')
def interval(poll_interval):
""" Set rif counter query interval """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
rif_info = {}
if poll_interval is not None:
Expand All @@ -142,7 +142,7 @@ def interval(poll_interval):
@rif.command()
def enable():
""" Enable rif counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
rif_info = {}
rif_info['FLEX_COUNTER_STATUS'] = 'enable'
Expand All @@ -151,7 +151,7 @@ def enable():
@rif.command()
def disable():
""" Disable rif counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
rif_info = {}
rif_info['FLEX_COUNTER_STATUS'] = 'disable'
Expand All @@ -166,7 +166,7 @@ def watermark():
@click.argument('poll_interval', type=click.IntRange(1000, 30000))
def interval(poll_interval):
""" Set watermark counter query interval for both queue and PG watermarks """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
queue_wm_info = {}
pg_wm_info = {}
Expand All @@ -182,7 +182,7 @@ def interval(poll_interval):
@watermark.command()
def enable():
""" Enable watermark counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
fc_info = {}
fc_info['FLEX_COUNTER_STATUS'] = 'enable'
Expand All @@ -193,7 +193,7 @@ def enable():
@watermark.command()
def disable():
""" Disable watermark counter query """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
fc_info = {}
fc_info['FLEX_COUNTER_STATUS'] = 'disable'
Expand All @@ -204,7 +204,7 @@ def disable():
@cli.command()
def show():
""" Show the counter configuration """
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()
queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE')
port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PORT')
Expand Down
8 changes: 4 additions & 4 deletions crm/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import click
import swsssdk
from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig
from tabulate import tabulate
from utilities_common import multi_asic as multi_asic_util
from sonic_py_common import multi_asic
Expand Down Expand Up @@ -34,7 +34,7 @@ def show_summary(self):
# Get the namespace list
namespaces = multi_asic.get_namespace_list()

configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0])
configdb = ConfigDBConnector(namespace=namespaces[0])
configdb.connect()

crm_info = configdb.get_entry('CRM', 'Config')
Expand All @@ -58,7 +58,7 @@ def show_thresholds(self, resource):
# Get the namespace list
namespaces = multi_asic.get_namespace_list()

configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0])
configdb = ConfigDBConnector(namespace=namespaces[0])
configdb.connect()

crm_info = configdb.get_entry('CRM', 'Config')
Expand Down Expand Up @@ -218,7 +218,7 @@ def cli(ctx):
ctx.obj = context

# Load the global config file database_global.json once.
swsssdk.SonicDBConfig.load_sonic_global_db_config()
SonicDBConfig.load_sonic_global_db_config()

@cli.group()
@click.pass_context
Expand Down
2 changes: 1 addition & 1 deletion pcieutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import click
from sonic_py_common import device_info, logger
from swsssdk import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate
import utilities_common.cli as clicommon
except ImportError as e:
Expand Down
10 changes: 5 additions & 5 deletions pfc/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import click
import swsssdk
from swsscommon.swsscommon import ConfigDBConnector
from tabulate import tabulate
from natsort import natsorted

Expand All @@ -12,7 +12,7 @@ def configPfcAsym(interface, pfc_asym):
"""
PFC handler to configure asymmentric PFC.
"""
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()

configdb.mod_entry("PORT", interface, {'pfc_asym': pfc_asym})
Expand All @@ -24,7 +24,7 @@ def showPfcAsym(interface):
"""
header = ('Interface', 'Asymmetric')

configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()

if interface:
Expand All @@ -50,7 +50,7 @@ def showPfcAsym(interface):
click.echo()

def configPfcPrio(status, interface, priority):
configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()

if interface not in configdb.get_keys('PORT_QOS_MAP'):
Expand Down Expand Up @@ -91,7 +91,7 @@ def showPfcPrio(interface):
header = ('Interface', 'Lossless priorities')
table = []

configdb = swsssdk.ConfigDBConnector()
configdb = ConfigDBConnector()
configdb.connect()

"""Get all the interfaces with QoS map information"""
Expand Down
6 changes: 3 additions & 3 deletions scripts/aclshow
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ optional arguments:
import argparse
import json
import os
import swsssdk
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
import sys

from tabulate import tabulate
Expand Down Expand Up @@ -60,10 +60,10 @@ class AclStat(object):
self.table_list = tables.split(",")

# Set up db connections
self.db = swsssdk.SonicV2Connector(host="127.0.0.1")
self.db = SonicV2Connector(use_unix_socket_path=False)
self.db.connect(self.db.COUNTERS_DB)

self.configdb = swsssdk.ConfigDBConnector()
self.configdb = ConfigDBConnector()
self.configdb.connect()

def previous_counters(self):
Expand Down
Loading

0 comments on commit 2e1f354

Please sign in to comment.