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

Update scripts in sonic-buildimage from py-swsssdk to swsscommon #11215

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dockers/docker-database/flush_unused_database
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python3
import swsssdk
from swsscommon import swsscommon
import redis
import subprocess
import time
Expand All @@ -11,15 +11,15 @@ while(True):
break
time.sleep(1)

instlists = swsssdk.SonicDBConfig.get_instancelist()
instlists = swsscommon.SonicDBConfig.get_instancelist()
for instname, v in instlists.items():
insthost = v['hostname']
instsocket = v['unix_socket_path']

dblists = swsssdk.SonicDBConfig.get_dblist()
dblists = swsscommon.SonicDBConfig.get_dblist()
for dbname in dblists:
dbid = swsssdk.SonicDBConfig.get_dbid(dbname)
dbinst = swsssdk.SonicDBConfig.get_instancename(dbname)
dbid = swsscommon.SonicDBConfig.get_dbid(dbname)
dbinst = swsscommon.SonicDBConfig.get_instancename(dbname)

# this DB is on current instance, skip flush
if dbinst == instname:
Expand Down
6 changes: 3 additions & 3 deletions dockers/docker-orchagent/enable_counters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import time
import swsssdk
from swsscommon import swsscommon

# ALPHA defines the size of the window over which we calculate the average value. ALPHA is 2/(N+1) where N is the interval(window size)
# In this case we configure the window to be 10s. This way if we have a huge 1s spike in traffic,
Expand All @@ -23,7 +23,7 @@ def enable_counter_group(db, name):

def enable_rates():
# set the default interval for rates
counters_db = swsssdk.SonicV2Connector()
counters_db = swsscommon.SonicV2Connector()
counters_db.connect('COUNTERS_DB')
counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_SMOOTH_INTERVAL', DEFAULT_SMOOTH_INTERVAL)
counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_ALPHA', DEFAULT_ALPHA)
Expand All @@ -36,7 +36,7 @@ def enable_rates():


def enable_counters():
db = swsssdk.ConfigDBConnector()
db = swsscommon.ConfigDBConnector()
db.connect()
default_enabled_counters = ['PORT', 'RIF', 'QUEUE', 'PFCWD', 'PG_WATERMARK', 'PG_DROP',
'QUEUE_WATERMARK', 'BUFFER_POOL_WATERMARK', 'PORT_BUFFER_DROP', 'ACL']
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-orchagent/tunnel_packet_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from datetime import datetime
from ipaddress import ip_interface

from swsssdk import ConfigDBConnector, SonicV2Connector
from swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector
from sonic_py_common import logger as log

from pyroute2 import IPRoute
Expand Down
4 changes: 2 additions & 2 deletions dockers/docker-sflow/port_index_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import traceback
from sonic_py_common.logger import Logger
from socket import if_nametoindex
from swsssdk import SonicV2Connector, port_util
from sonic_py_common import port_util
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The port_util change split to another PR, this PR need wait for another PR merge first:
#11347

from swsscommon import swsscommon

SYSLOG_IDENTIFIER = 'port_index_mapper'
Expand All @@ -26,7 +26,7 @@ def __init__(self):
REDIS_TIMEOUT_MS,
True)

self.state_db = SonicV2Connector(host='127.0.0.1', decode_responses=True)
self.state_db = swsscommon.SonicV2Connector(host='127.0.0.1', decode_responses=True)
self.state_db.connect(self.state_db.STATE_DB, False)
self.sel = swsscommon.Select()
self.tbls = [swsscommon.SubscriberStateTable(self.appl_db, t)
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-snmp/snmp_yml_to_configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import yaml
from sonic_py_common.logger import Logger
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import ConfigDBConnector

db = ConfigDBConnector()
db.connect()
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-frr-mgmt-framework/frrcfgd/frrcfgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
import syslog
import os
from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import ConfigDBConnector
import socket
import threading
import queue
Expand Down
8 changes: 5 additions & 3 deletions src/sonic-frr-mgmt-framework/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import re
from unittest.mock import MagicMock, NonCallableMagicMock, patch

swsssdk_module_mock = MagicMock(ConfigDBConnector = NonCallableMagicMock)
swsscommon_module_mock = MagicMock(ConfigDBConnector = NonCallableMagicMock)
# because can’t use dotted names directly in a call, have to create a dictionary and unpack it using **:
mockmapping = {'swsscommon.swsscommon': swsscommon_module_mock}

@patch.dict('sys.modules', swsssdk = swsssdk_module_mock)
@patch.dict('sys.modules', **mockmapping)
def test_contructor():
from frrcfgd.frrcfgd import BGPConfigDaemon
daemon = BGPConfigDaemon()
Expand Down Expand Up @@ -147,7 +149,7 @@ def hdl_confed_peers_cmd(is_del, cmd_list, chk_data):
conf_bgp_af_cmd('Vrf_red', 200, 'ipv6') + ['{}import vrf route-map test_map']),
]

@patch.dict('sys.modules', swsssdk = swsssdk_module_mock)
@patch.dict('sys.modules', **mockmapping)
@patch('frrcfgd.frrcfgd.g_run_command')
def data_set_del_test(test_data, run_cmd):
from frrcfgd.frrcfgd import BGPConfigDaemon
Expand Down
6 changes: 4 additions & 2 deletions src/sonic-frr-mgmt-framework/tests/test_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import pytest
from unittest.mock import MagicMock, NonCallableMagicMock, patch

swsssdk_module_mock = MagicMock(ConfigDBConnector = NonCallableMagicMock)
swsscommon_module_mock = MagicMock(ConfigDBConnector = NonCallableMagicMock)
# because can’t use dotted names directly in a call, have to create a dictionary and unpack it using **:
mockmapping = {'swsscommon.swsscommon': swsscommon_module_mock}

with patch.dict('sys.modules', swsssdk = swsssdk_module_mock):
with patch.dict('sys.modules', **mockmapping):
from frrcfgd.frrcfgd import CachedDataWithOp
from frrcfgd.frrcfgd import BGPPeerGroup
from frrcfgd.frrcfgd import BGPKeyMapInfo
Expand Down