diff --git a/acl_loader/main.py b/acl_loader/main.py index 4af41023f1..0d8386f5c7 100644 --- a/acl_loader/main.py +++ b/acl_loader/main.py @@ -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): diff --git a/config/aaa.py b/config/aaa.py index 7102227dd5..fb2db721ae 100644 --- a/config/aaa.py +++ b/config/aaa.py @@ -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): diff --git a/config/config_mgmt.py b/config/config_mgmt.py index 772ddd8ee8..a8f933b85a 100644 --- a/config/config_mgmt.py +++ b/config/config_mgmt.py @@ -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. @@ -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) @@ -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)) diff --git a/config/kdump.py b/config/kdump.py index c99a6485b6..61806428d1 100644 --- a/config/kdump.py +++ b/config/kdump.py @@ -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(): diff --git a/config/main.py b/config/main.py index f7cf8e32fc..0e067854d8 100644 --- a/config/main.py +++ b/config/main.py @@ -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 @@ -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 diff --git a/config/muxcable.py b/config/muxcable.py index 2418284692..216da578d3 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -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 @@ -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") diff --git a/config/nat.py b/config/nat.py index d3b0b453ec..99e21b2750 100644 --- a/config/nat.py +++ b/config/nat.py @@ -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): diff --git a/counterpoll/main.py b/counterpoll/main.py index dbbbe7aac5..93daf4df9e 100644 --- a/counterpoll/main.py +++ b/counterpoll/main.py @@ -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" @@ -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: @@ -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' @@ -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' @@ -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: @@ -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' @@ -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' @@ -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: @@ -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 @@ -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 @@ -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: @@ -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' @@ -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' @@ -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 = {} @@ -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' @@ -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' @@ -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') diff --git a/crm/main.py b/crm/main.py index b419cc212f..caf0108b12 100644 --- a/crm/main.py +++ b/crm/main.py @@ -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 @@ -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') @@ -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') @@ -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 diff --git a/pcieutil/main.py b/pcieutil/main.py index 3a8ca57194..3c250e24a7 100644 --- a/pcieutil/main.py +++ b/pcieutil/main.py @@ -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: diff --git a/pfc/main.py b/pfc/main.py index ffcc42a97a..b31d3c755e 100644 --- a/pfc/main.py +++ b/pfc/main.py @@ -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 @@ -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}) @@ -24,7 +24,7 @@ def showPfcAsym(interface): """ header = ('Interface', 'Asymmetric') - configdb = swsssdk.ConfigDBConnector() + configdb = ConfigDBConnector() configdb.connect() if interface: @@ -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'): @@ -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""" diff --git a/scripts/aclshow b/scripts/aclshow index a9ee169209..046cb72efe 100755 --- a/scripts/aclshow +++ b/scripts/aclshow @@ -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 @@ -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): diff --git a/scripts/centralize_database b/scripts/centralize_database index 3ff958117a..c32b19b647 100755 --- a/scripts/centralize_database +++ b/scripts/centralize_database @@ -1,24 +1,24 @@ #!/usr/bin/python from __future__ import print_function import sys -import swsssdk +from swsscommon.swsscommon import SonicDBConfig import redis import argparse def centralize_to_target_db(target_dbname): - target_dbport = swsssdk.SonicDBConfig.get_port(target_dbname) - target_dbhost = swsssdk.SonicDBConfig.get_hostname(target_dbname) + target_dbport = SonicDBConfig.get_port(target_dbname) + target_dbhost = SonicDBConfig.get_hostname(target_dbname) - dblists = swsssdk.SonicDBConfig.get_dblist() + dblists = SonicDBConfig.get_dblist() for dbname in dblists: - dbport = swsssdk.SonicDBConfig.get_port(dbname) - dbhost = swsssdk.SonicDBConfig.get_hostname(dbname) + dbport = SonicDBConfig.get_port(dbname) + dbhost = SonicDBConfig.get_hostname(dbname) # if the db is on the same instance, no need to move if dbport == target_dbport and dbhost == target_dbhost: continue - dbsocket = swsssdk.SonicDBConfig.get_socket(dbname) - dbid = swsssdk.SonicDBConfig.get_dbid(dbname) + dbsocket = SonicDBConfig.get_socket(dbname) + dbid = SonicDBConfig.get_dbid(dbname) r = redis.Redis(host=dbhost, unix_socket_path=dbsocket, db=dbid) @@ -49,7 +49,7 @@ Example : centralize_database APPL_DB if args.target_db: try: centralize_to_target_db(args.target_db) - print(swsssdk.SonicDBConfig.get_instancename(args.target_db)) + print(SonicDBConfig.get_instancename(args.target_db)) except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) diff --git a/scripts/configlet b/scripts/configlet index 4d519d3943..0e201be432 100755 --- a/scripts/configlet +++ b/scripts/configlet @@ -78,7 +78,7 @@ A sample for update: import argparse import json -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector test_only = False diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 5b571ce758..1a31404749 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -7,8 +7,7 @@ import re from sonic_py_common import device_info, logger -from swsssdk import ConfigDBConnector, SonicDBConfig -from swsscommon.swsscommon import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig INIT_CFG_FILE = '/etc/sonic/init_cfg.json' SYSLOG_IDENTIFIER = 'db_migrator' diff --git a/scripts/dropconfig b/scripts/dropconfig index 066aadc232..b7a86043a5 100755 --- a/scripts/dropconfig +++ b/scripts/dropconfig @@ -10,7 +10,6 @@ # - Add more filters to the show commands (e.g. filter by name, alias, etc.) # - Add the ability to change readonly attributes like group, description, etc. -import swsssdk import argparse import os import sys @@ -28,6 +27,9 @@ try: except KeyError: pass +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector + + # CONFIG_DB Tables DEBUG_COUNTER_CONFIG_TABLE = 'DEBUG_COUNTER' DROP_REASON_CONFIG_TABLE = 'DEBUG_COUNTER_DROP_REASON' @@ -52,10 +54,10 @@ class InvalidArgumentError(RuntimeError): class DropConfig(object): def __init__(self): - self.config_db = swsssdk.ConfigDBConnector() + self.config_db = ConfigDBConnector() self.config_db.connect() - self.state_db = swsssdk.SonicV2Connector(host='127.0.0.1') + self.state_db = SonicV2Connector(use_unix_socket_path=False) self.state_db.connect(self.state_db.STATE_DB) # -c show_config diff --git a/scripts/dropstat b/scripts/dropstat index a80269fa48..6766d2a2c1 100755 --- a/scripts/dropstat +++ b/scripts/dropstat @@ -17,7 +17,6 @@ import os import socket import sys -import swsssdk from collections import OrderedDict from natsort import natsorted from tabulate import tabulate @@ -35,6 +34,9 @@ try: except KeyError: pass +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector + + # COUNTERS_DB Tables DEBUG_COUNTER_PORT_STAT_MAP = 'COUNTERS_DEBUG_NAME_PORT_STAT_MAP' DEBUG_COUNTER_SWITCH_STAT_MAP = 'COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP' @@ -84,10 +86,10 @@ def get_dropstat_dir(): class DropStat(object): def __init__(self): - self.config_db = swsssdk.ConfigDBConnector() + self.config_db = ConfigDBConnector() self.config_db.connect() - 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.db.connect(self.db.ASIC_DB) self.db.connect(self.db.APPL_DB) diff --git a/scripts/ecnconfig b/scripts/ecnconfig index 62a14b9106..5b21047a11 100755 --- a/scripts/ecnconfig +++ b/scripts/ecnconfig @@ -52,7 +52,6 @@ import json import os import sys -import swsssdk from tabulate import tabulate # mock the redis for unit test purposes # @@ -67,6 +66,9 @@ try: except KeyError: pass +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector + + WRED_PROFILE_TABLE_NAME = "WRED_PROFILE" WRED_CONFIG_FIELDS = { "gmax": "green_max_threshold", @@ -104,7 +106,7 @@ class EcnConfig(object): self.verbose = verbose # Set up db connections - self.db = swsssdk.ConfigDBConnector() + self.db = ConfigDBConnector() self.db.connect() def list(self): @@ -204,10 +206,10 @@ class EcnQ(object): self.verbose = verbose # Set up db connections - self.config_db = swsssdk.ConfigDBConnector() + self.config_db = ConfigDBConnector() self.config_db.connect() - self.db = swsssdk.SonicV2Connector(host="127.0.0.1") + self.db = SonicV2Connector(use_unix_socket_path=False) self.db.connect(self.db.CONFIG_DB) self.gen_ports_key() diff --git a/scripts/fast-reboot-dump.py b/scripts/fast-reboot-dump.py index 3c655381f4..92b9227a69 100644 --- a/scripts/fast-reboot-dump.py +++ b/scripts/fast-reboot-dump.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import swsssdk +from swsscommon.swsscommon import SonicV2Connector import json import socket import struct @@ -19,7 +19,7 @@ ARP_PAD = binascii.unhexlify('00' * 18) def generate_neighbor_entries(filename, all_available_macs): - db = swsssdk.SonicV2Connector(host='127.0.0.1') + db = SonicV2Connector(use_unix_socket_path=False) db.connect(db.APPL_DB, False) # Make one attempt only arp_output = [] @@ -160,7 +160,7 @@ def get_fdb(db, vlan_name, vlan_id, bridge_id_2_iface): def generate_fdb_entries(filename): fdb_entries = [] - db = swsssdk.SonicV2Connector(host='127.0.0.1') + db = SonicV2Connector(use_unix_socket_path=False) db.connect(db.ASIC_DB, False) # Make one attempt only bridge_id_2_iface = get_map_bridge_port_id_2_iface_name(db) @@ -261,7 +261,7 @@ def get_default_entries(db, route): return obj def generate_default_route_entries(filename): - db = swsssdk.SonicV2Connector(host='127.0.0.1') + db = SonicV2Connector(unix_socket_path=False) db.connect(db.APPL_DB, False) # Make one attempt only default_routes_output = [] diff --git a/scripts/gearboxutil b/scripts/gearboxutil index 22d69853bb..70b33da857 100755 --- a/scripts/gearboxutil +++ b/scripts/gearboxutil @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import swsssdk import sys from tabulate import tabulate from natsort import natsorted @@ -21,6 +20,9 @@ try: except KeyError: pass +from swsscommon.swsscommon import SonicV2Connector + + # ========================== Common gearbox-utils logic ========================== GEARBOX_TABLE_PHY_PREFIX = "_GEARBOX_TABLE:phy:{}" @@ -69,7 +71,7 @@ def get_appl_key_attr(db, key, attr, lane_count=1): return val def db_connect_appl(): - appl_db = swsssdk.SonicV2Connector(host='127.0.0.1') + appl_db = SonicV2Connector(use_unix_socket_path=False) if appl_db is None: return None appl_db.connect(appl_db.APPL_DB) @@ -79,7 +81,7 @@ def db_connect_state(): """ Connect to REDIS STATE DB and get optics info """ - state_db = swsssdk.SonicV2Connector(host='127.0.0.1') + state_db = SonicV2Connector(use_unix_socket_path=False) if state_db is None: return None state_db.connect(state_db.STATE_DB, False) # Make one attempt only diff --git a/scripts/intfstat b/scripts/intfstat index f36cf949a8..a4858019c4 100755 --- a/scripts/intfstat +++ b/scripts/intfstat @@ -11,7 +11,6 @@ import argparse import datetime import sys import os -import swsssdk import sys import time @@ -30,6 +29,8 @@ from collections import namedtuple, OrderedDict from natsort import natsorted from tabulate import tabulate from utilities_common.netstat import ns_diff, ns_brate, ns_prate, table_as_json, STATUS_NA +from swsscommon.swsscommon import SonicV2Connector + NStats = namedtuple("NStats", "rx_b_ok, rx_p_ok, tx_b_ok, tx_p_ok,\ rx_b_err, rx_p_err, tx_b_err, tx_p_err,") @@ -63,7 +64,7 @@ INTF_STATE_DISABLED = 'X' class Intfstat(object): def __init__(self): - 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.db.connect(self.db.APPL_DB) diff --git a/scripts/lldpshow b/scripts/lldpshow index 05ecb9c49e..b6682b8df1 100755 --- a/scripts/lldpshow +++ b/scripts/lldpshow @@ -26,7 +26,7 @@ import sys import xml.etree.ElementTree as ET from sonic_py_common import device_info -from swsssdk import ConfigDBConnector, SonicDBConfig +from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig from tabulate import tabulate BACKEND_ASIC_INTERFACE_NAME_PREFIX = 'Ethernet-BP' diff --git a/scripts/mmuconfig b/scripts/mmuconfig index 96f3af1064..7a1aaf0573 100755 --- a/scripts/mmuconfig +++ b/scripts/mmuconfig @@ -18,16 +18,8 @@ optional arguments: import os import sys import argparse -import swsssdk import tabulate - -BUFFER_POOL_TABLE_NAME = "BUFFER_POOL" -BUFFER_PROFILE_TABLE_NAME = "BUFFER_PROFILE" - -DYNAMIC_THRESHOLD = "dynamic_th" -BUFFER_PROFILE_FIELDS = { - "alpha": DYNAMIC_THRESHOLD -} +import traceback # mock the redis for unit test purposes # try: @@ -41,6 +33,16 @@ try: except KeyError: pass +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector + +BUFFER_POOL_TABLE_NAME = "BUFFER_POOL" +BUFFER_PROFILE_TABLE_NAME = "BUFFER_PROFILE" + +DYNAMIC_THRESHOLD = "dynamic_th" +BUFFER_PROFILE_FIELDS = { + "alpha": DYNAMIC_THRESHOLD +} + class MmuConfig(object): def __init__(self, verbose, config): self.verbose = verbose @@ -48,10 +50,10 @@ class MmuConfig(object): # Set up db connections if self.config: - self.db = swsssdk.ConfigDBConnector() + self.db = ConfigDBConnector() self.db.connect() else: - self.db = swsssdk.SonicV2Connector(host='127.0.0.1') + self.db = SonicV2Connector(use_unix_socket_path=False) self.db.connect(self.db.STATE_DB, False) def get_table(self, tablename): @@ -151,7 +153,8 @@ def main(config): sys.exit(1) except Exception as e: - print("Exception caught:", str(e), file=sys.stderr) + print("Exception caught: ", str(e), file=sys.stderr) + traceback.print_exc() sys.exit(1) if __name__ == "__main__": diff --git a/scripts/natconfig b/scripts/natconfig index e4e88ad580..90d1acdf9a 100644 --- a/scripts/natconfig +++ b/scripts/natconfig @@ -42,7 +42,7 @@ import argparse import sys from tabulate import tabulate -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector class NatConfig(object): diff --git a/scripts/neighbor_advertiser b/scripts/neighbor_advertiser index 62124c7400..c1545646dd 100644 --- a/scripts/neighbor_advertiser +++ b/scripts/neighbor_advertiser @@ -17,8 +17,7 @@ import traceback import warnings from sonic_py_common import logger -from swsssdk import ConfigDBConnector -from swsscommon.swsscommon import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from netaddr import IPAddress, IPNetwork diff --git a/scripts/pcmping b/scripts/pcmping index 521583645a..2ffd3dd0e2 100755 --- a/scripts/pcmping +++ b/scripts/pcmping @@ -12,7 +12,7 @@ import socket import sys import time -import swsssdk +from swsscommon.swsscommon import ConfigDBConnector from scapy.all import * @@ -79,7 +79,7 @@ def find_probe_packet(interface, dst_out, dst_in, sockets, exp_socket, max_iter) sys.exit(0) def get_portchannel(interface): - configdb = swsssdk.ConfigDBConnector() + configdb = ConfigDBConnector() configdb.connect() portchannels = configdb.get_table("PORTCHANNEL") for key, value in portchannels.items(): @@ -97,7 +97,7 @@ def is_ip_prefix_in_key(key): return (isinstance(key, tuple)) def get_portchannel_ipv4(portchannel_name): - configdb = swsssdk.ConfigDBConnector() + configdb = ConfigDBConnector() configdb.connect() config = configdb.get_config() portchannel_interfaces = config["PORTCHANNEL_INTERFACE"] diff --git a/scripts/portconfig b/scripts/portconfig index c850cbe2fe..9a7cc545a3 100755 --- a/scripts/portconfig +++ b/scripts/portconfig @@ -19,7 +19,7 @@ optional arguments: """ import sys import argparse -import swsssdk +from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig PORT_TABLE_NAME = "PORT" PORT_SPEED_CONFIG_FIELD_NAME = "speed" @@ -35,9 +35,9 @@ class portconfig(object): # Set up db connections if namespace is None: - self.db = swsssdk.ConfigDBConnector() + self.db = ConfigDBConnector() else: - self.db = swsssdk.ConfigDBConnector(use_unix_socket_path=True, namespace=namespace) + self.db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace) self.db.connect() # check whether table for this port exists @@ -81,7 +81,7 @@ def main(): args = parser.parse_args() if args.namespace is not None: - swsssdk.SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace) + SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace) try: port = portconfig(args.verbose, args.port, args.namespace) diff --git a/scripts/portstat b/scripts/portstat index 674d0c5aea..7fa37108cf 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -19,12 +19,6 @@ from natsort import natsorted from tabulate import tabulate from sonic_py_common import multi_asic -from utilities_common import constants -from utilities_common.intf_filter import parse_interface_in_filter -import utilities_common.multi_asic as multi_asic_util -from utilities_common.netstat import (ns_brate, ns_diff, ns_prate, ns_util, - table_as_json) - # mock the redis for unit test purposes # try: if os.environ["UTILITIES_UNIT_TESTING"] == "2": @@ -40,6 +34,13 @@ try: except KeyError: pass +from utilities_common import constants +from utilities_common.intf_filter import parse_interface_in_filter +import utilities_common.multi_asic as multi_asic_util +from utilities_common.netstat import (ns_brate, ns_diff, ns_prate, ns_util, + table_as_json) + + PORT_RATE = 40 """ diff --git a/scripts/queuestat b/scripts/queuestat index 078e4a099e..24369c82a5 100755 --- a/scripts/queuestat +++ b/scripts/queuestat @@ -10,7 +10,7 @@ import _pickle as pickle import argparse import datetime import os.path -import swsssdk +from swsscommon.swsscommon import SonicV2Connector import sys from collections import namedtuple, OrderedDict @@ -49,7 +49,7 @@ cnstat_fqn_file = 'N/A' class Queuestat(object): def __init__(self): - self.db = swsssdk.SonicV2Connector(host='127.0.0.1') + self.db = SonicV2Connector(use_unix_socket_path=False) self.db.connect(self.db.COUNTERS_DB) def get_queue_port(table_id): diff --git a/scripts/sonic-kdump-config b/scripts/sonic-kdump-config index 7dbde1d708..8dc1a553b1 100755 --- a/scripts/sonic-kdump-config +++ b/scripts/sonic-kdump-config @@ -23,7 +23,7 @@ import shlex import os import subprocess import json -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector aboot_cfg_template ="/host/image-%s/kernel-cmdline" grub_cfg = "/host/grub/grub.cfg" diff --git a/scripts/watermarkcfg b/scripts/watermarkcfg index 274727f70e..c3a8b0961c 100644 --- a/scripts/watermarkcfg +++ b/scripts/watermarkcfg @@ -8,7 +8,7 @@ import argparse import sys -import swsssdk +from swsscommon.swsscommon import ConfigDBConnector class Watermarkcfg(object): @@ -17,13 +17,13 @@ class Watermarkcfg(object): pass def set_interval(self, interval): - configdb = swsssdk.ConfigDBConnector() + configdb = ConfigDBConnector() configdb.connect() configdb.mod_entry('WATERMARK_TABLE', 'TELEMETRY_INTERVAL', {'interval': interval}) def show_interval(self): - configdb = swsssdk.ConfigDBConnector() + configdb = ConfigDBConnector() configdb.connect() wm_info = configdb.get_entry('WATERMARK_TABLE', 'TELEMETRY_INTERVAL') diff --git a/scripts/watermarkstat b/scripts/watermarkstat index b9df56ca89..bae72821c7 100755 --- a/scripts/watermarkstat +++ b/scripts/watermarkstat @@ -11,7 +11,6 @@ import json import os import sys -import swsssdk from natsort import natsorted from tabulate import tabulate @@ -27,6 +26,9 @@ try: except KeyError: pass +from swsscommon.swsscommon import SonicV2Connector + + headerBufferPool = ['Pool', 'Bytes'] @@ -59,11 +61,11 @@ COUNTERS_BUFFER_POOL_NAME_MAP = "COUNTERS_BUFFER_POOL_NAME_MAP" class Watermarkstat(object): def __init__(self): - self.counters_db = swsssdk.SonicV2Connector(host='127.0.0.1') + self.counters_db = SonicV2Connector(use_unix_socket_path=False) self.counters_db.connect(self.counters_db.COUNTERS_DB) # connect APP DB for clear notifications - self.app_db = swsssdk.SonicV2Connector(host='127.0.0.1') + self.app_db = SonicV2Connector(use_unix_socket_path=False) self.app_db.connect(self.counters_db.APPL_DB) def get_queue_type(table_id): diff --git a/show/fgnhg.py b/show/fgnhg.py index 6ed0b68939..a8b12787ce 100644 --- a/show/fgnhg.py +++ b/show/fgnhg.py @@ -3,8 +3,7 @@ import click import utilities_common.cli as clicommon -from swsssdk import ConfigDBConnector -from swsscommon.swsscommon import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from tabulate import tabulate diff --git a/show/kdump.py b/show/kdump.py index 9039162836..d846792797 100644 --- a/show/kdump.py +++ b/show/kdump.py @@ -1,6 +1,6 @@ import click import utilities_common.cli as clicommon -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector # # 'kdump command ("show kdump ...") diff --git a/show/main.py b/show/main.py index d7b0fdaac3..05e5deafad 100644 --- a/show/main.py +++ b/show/main.py @@ -10,8 +10,7 @@ import utilities_common.multi_asic as multi_asic_util from natsort import natsorted from sonic_py_common import device_info, multi_asic -from swsssdk import ConfigDBConnector -from swsscommon.swsscommon import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from tabulate import tabulate from utilities_common.db import Db diff --git a/show/muxcable.py b/show/muxcable.py index 0a099105f8..0dff20b1d7 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -4,8 +4,7 @@ import click import utilities_common.cli as clicommon from sonic_py_common import multi_asic -from swsscommon import swsscommon -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from tabulate import tabulate from utilities_common import platform_sfputil_helper @@ -131,7 +130,7 @@ def status(port, json_output): namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace) + per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB) port_table_keys[asic_id] = per_npu_statedb[asic_id].keys( diff --git a/show/reboot_cause.py b/show/reboot_cause.py index fab98abb19..d1424d8676 100755 --- a/show/reboot_cause.py +++ b/show/reboot_cause.py @@ -4,7 +4,7 @@ import click from tabulate import tabulate -from swsssdk import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector import utilities_common.cli as clicommon diff --git a/show/vnet.py b/show/vnet.py index 4514a9afe4..21d46af7fa 100644 --- a/show/vnet.py +++ b/show/vnet.py @@ -1,8 +1,7 @@ import click import utilities_common.cli as clicommon from natsort import natsorted -from swsssdk import ConfigDBConnector -from swsscommon.swsscommon import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from tabulate import tabulate diff --git a/show/vxlan.py b/show/vxlan.py index a9f18759e3..bb20580689 100644 --- a/show/vxlan.py +++ b/show/vxlan.py @@ -1,8 +1,7 @@ import click import utilities_common.cli as clicommon from natsort import natsorted -from swsssdk import ConfigDBConnector -from swsssdk import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from tabulate import tabulate # diff --git a/show/warm_restart.py b/show/warm_restart.py index 7c2b443236..2d0ea4b69c 100644 --- a/show/warm_restart.py +++ b/show/warm_restart.py @@ -1,7 +1,6 @@ import click import utilities_common.cli as clicommon -from swsssdk import ConfigDBConnector -from swsscommon.swsscommon import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from tabulate import tabulate diff --git a/tests/buffer_test.py b/tests/buffer_test.py index cf32f39d55..e82d9565c9 100644 --- a/tests/buffer_test.py +++ b/tests/buffer_test.py @@ -3,7 +3,7 @@ import sys from click.testing import CliRunner from unittest import TestCase -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector from .mock_tables import dbconnector @@ -93,10 +93,12 @@ def executor(self, testcase): for input in testcase: exec_cmd = show.cli.commands[input['cmd'][0]].commands[input['cmd'][1]] - result = runner.invoke(exec_cmd, []) + result = runner.invoke(exec_cmd, [], catch_exceptions=True) print(result.exit_code) print(result.output) + if result.exception: + print(result.exception) assert result.exit_code == 0 assert result.output == input['rc_output'] diff --git a/tests/conftest.py b/tests/conftest.py index 309e65f055..9a2f30438e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,7 @@ import pytest from sonic_py_common import device_info -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector from .mock_tables import dbconnector from . import show_ip_route_common diff --git a/tests/counterpoll_test.py b/tests/counterpoll_test.py index d179553abc..476fc96de5 100644 --- a/tests/counterpoll_test.py +++ b/tests/counterpoll_test.py @@ -2,7 +2,6 @@ import json import os import pytest -import swsssdk import sys import time from click.testing import CliRunner diff --git a/tests/mock_tables/dbconnector.py b/tests/mock_tables/dbconnector.py index ae94561868..646b3b055b 100644 --- a/tests/mock_tables/dbconnector.py +++ b/tests/mock_tables/dbconnector.py @@ -8,7 +8,7 @@ import redis import swsssdk from sonic_py_common import multi_asic -from swsssdk import SonicDBConfig, SonicV2Connector +from swsssdk import SonicDBConfig, SonicV2Connector, ConfigDBConnector, ConfigDBPipeConnector from swsscommon import swsscommon @@ -146,3 +146,5 @@ def keys(self, pattern='*'): redis.StrictRedis = SwssSyncClient SonicV2Connector.connect = connect_SonicV2Connector swsscommon.SonicV2Connector = SonicV2Connector +swsscommon.ConfigDBConnector = ConfigDBConnector +swsscommon.ConfigDBPipeConnector = ConfigDBPipeConnector diff --git a/tests/neighbor_advertiser_test.py b/tests/neighbor_advertiser_test.py index 3a3aeba39f..2310a3bf65 100644 --- a/tests/neighbor_advertiser_test.py +++ b/tests/neighbor_advertiser_test.py @@ -1,7 +1,7 @@ import sys import os import pytest -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector test_path = os.path.dirname(os.path.abspath(__file__)) modules_path = os.path.dirname(test_path) diff --git a/tests/show_breakout_test.py b/tests/show_breakout_test.py index 0493d7e293..0072b9d2f1 100644 --- a/tests/show_breakout_test.py +++ b/tests/show_breakout_test.py @@ -2,7 +2,7 @@ import sys from click.testing import CliRunner from unittest import TestCase -from swsssdk import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector test_path = os.path.dirname(os.path.abspath(__file__)) modules_path = os.path.dirname(test_path) diff --git a/utilities_common/db.py b/utilities_common/db.py index f6b4189190..7842b4dcdd 100644 --- a/utilities_common/db.py +++ b/utilities_common/db.py @@ -1,5 +1,5 @@ from sonic_py_common import multi_asic -from swsssdk import ConfigDBConnector, SonicV2Connector +from swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector from utilities_common import constants from utilities_common.multi_asic import multi_asic_ns_choices