Skip to content

Commit

Permalink
sonic-config-engine uses libswsscommon instead of swsssdk (#6406)
Browse files Browse the repository at this point in the history
**- Why I did it**
swsssdk will be deprecated. Migrate sonic-config-engine to use libswsscommon library instead

**- How to verify it**
Unit test
  • Loading branch information
qiluo-msft authored Jan 20, 2021
1 parent abb0139 commit 3c16f80
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions platform/vs/docker-sonic-vs/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ if [[ -f /usr/share/sonic/virtual_chassis/default_config.json ]]; then
CHASS_CFG="-j /usr/share/sonic/virtual_chassis/default_config.json"
fi

# Note: libswsscommon requires a dabase_config file in /var/run/redis/sonic-db/
# Prepare this file before any dependent application, such as sonic-cfggen
mkdir -p /var/run/redis/sonic-db
cp /etc/default/sonic-db/database_config.json /var/run/redis/sonic-db/

SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'", "buffer_model": "traditional"}}}' $CHASS_CFG --print-data > /etc/sonic/init_cfg.json

Expand Down Expand Up @@ -68,9 +73,6 @@ else
echo "10.8.1.200 redis_chassis.server" >> /etc/hosts
fi

mkdir -p /var/run/redis/sonic-db
cp /etc/default/sonic-db/database_config.json /var/run/redis/sonic-db/

supervisorctl start redis-server

start_chassis_db=`sonic-cfggen -v DEVICE_METADATA.localhost.start_chassis_db -y $chassisdb_cfg_file`
Expand Down
6 changes: 4 additions & 2 deletions rules/sonic-config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

SONIC_CONFIG_ENGINE_PY2 = sonic_config_engine-1.0-py2-none-any.whl
$(SONIC_CONFIG_ENGINE_PY2)_SRC_PATH = $(SRC_PATH)/sonic-config-engine
$(SONIC_CONFIG_ENGINE_PY2)_DEPENDS += $(SWSSSDK_PY2) $(SONIC_PY_COMMON_PY2)
$(SONIC_CONFIG_ENGINE_PY2)_DEPENDS += $(SONIC_PY_COMMON_PY2)
$(SONIC_CONFIG_ENGINE_PY2)_DEBS_DEPENDS += $(PYTHON_SWSSCOMMON)
$(SONIC_CONFIG_ENGINE_PY2)_PYTHON_VERSION = 2
SONIC_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY2)

# SONIC_CONFIG_ENGINE_PY3 package

SONIC_CONFIG_ENGINE_PY3 = sonic_config_engine-1.0-py3-none-any.whl
$(SONIC_CONFIG_ENGINE_PY3)_SRC_PATH = $(SRC_PATH)/sonic-config-engine
$(SONIC_CONFIG_ENGINE_PY3)_DEPENDS += $(SWSSSDK_PY3) $(SONIC_PY_COMMON_PY3)
$(SONIC_CONFIG_ENGINE_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY3)
$(SONIC_CONFIG_ENGINE_PY3)_DEBS_DEPENDS += $(PYTHON3_SWSSCOMMON)
# Synthetic dependency to avoid building the Python 2 and 3 packages
# simultaneously and any potential conflicts which may arise
$(SONIC_CONFIG_ENGINE_PY3)_DEPENDS += $(SONIC_CONFIG_ENGINE_PY2)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/portconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
import sys

from swsssdk import ConfigDBConnector
from swsscommon.swsscommon import ConfigDBConnector
from sonic_py_common import device_info
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-config-engine/redis_bcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def load_bytecode(self, bucket):
return
code = self._client.get(self._client.LOGLEVEL_DB, self.REDIS_HASH, bucket.key)
if code is not None:
bucket.bytecode_from_string(b64decode(code))
bucket.bytecode_from_string(b64decode(code.encode()))

def dump_bytecode(self, bucket):
if self._client is None:
return
self._client.set(self._client.LOGLEVEL_DB, self.REDIS_HASH,
bucket.key, b64encode(bucket.bytecode_to_string()))
bucket.key, b64encode(bucket.bytecode_to_string()).decode())

2 changes: 1 addition & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ from portconfig import get_port_config, get_breakout_mode
from redis_bcc import RedisBytecodeCache
from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic
from sonic_py_common import device_info
from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector


PY3x = sys.version_info >= (3, 0)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-swss-common

0 comments on commit 3c16f80

Please sign in to comment.