Skip to content
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
40 changes: 40 additions & 0 deletions files/scripts/remove_chassisdb_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/python
import json
import os
import syslog
import argparse

database_config_file = "/var/run/redis/sonic-db/database_config.json"
redis_chassis = 'redis_chassis'
chassis_db = 'CHASSIS_DB'

def main():
parser=argparse.ArgumentParser(description=
"Remove chassis_db config from database-config.json")
parser.add_argument("-j", "--json", help="databse-config json file", nargs='?',
const=database_config_file)
args = parser.parse_args()
jsonfile = ""
if args.json != None:
jsonfile = args.json
else:
return
data = {}
if os.path.isfile(jsonfile):
with open(jsonfile, "r") as read_file:
data = json.load(read_file)
else:
syslog.syslog(syslog.LOG_ERR,
'config file {} does notexist'.format(jsonfile))
return
if 'INSTANCES' in data and redis_chassis in data['INSTANCES']:
del data['INSTANCES'][redis_chassis]
if 'DATABASES' in data and chassis_db in data['DATABASES']:
del data['DATABASES'][chassis_db]
with open(jsonfile, "w") as write_file:
json.dump(data, write_file, indent=4, separators=(',', ': '))
syslog.syslog(syslog.LOG_INFO,
'remove chassis_db from config file {}'.format(jsonfile))

if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion platform/vs/docker-sonic-vs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ $(DOCKER_SONIC_VS)_FILES += $(CONFIGDB_LOAD_SCRIPT) \
$(ARP_UPDATE_SCRIPT) \
$(BUFFERS_CONFIG_TEMPLATE) \
$(QOS_CONFIG_TEMPLATE) \
$(SONIC_VERSION)
$(SONIC_VERSION) \
$(RM_CHASSISDB_CONFIG_SCRIPT)

$(DOCKER_SONIC_VS)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER)
SONIC_DOCKER_IMAGES += $(DOCKER_SONIC_VS)
5 changes: 4 additions & 1 deletion platform/vs/docker-sonic-vs/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,16 @@ RUN sed -ri 's/^(save .*$)/# \1/g;
' /etc/redis/redis.conf

COPY ["50-default.conf", "/etc/rsyslog.d/"]
COPY ["start.sh", "orchagent.sh", "/usr/bin/"]
COPY ["start.sh", "orchagent.sh", "files/remove_chassisdb_config", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["files/configdb-load.sh", "/usr/bin/"]
COPY ["files/arp_update", "/usr/bin/"]
COPY ["files/buffers_config.j2", "files/qos_config.j2", "/usr/share/sonic/templates/"]
COPY ["files/sonic_version.yml", "/etc/sonic/"]
COPY ["database_config.json", "/etc/default/sonic-db/"]
COPY ["hostname.j2", "/usr/share/sonic/templates/"]
COPY ["default_chassis_cfg.json", "/etc/default/sonic-db/"]
COPY ["chassis_db.py", "/usr/bin/"]

# Workaround the tcpdump issue
RUN mv /usr/sbin/tcpdump /usr/bin/tcpdump
Expand Down
13 changes: 13 additions & 0 deletions platform/vs/docker-sonic-vs/chassis_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python

import swsssdk
import json
chassisdb = swsssdk.SonicV2Connector(host='10.0.0.200', port='6380')
chassisdb.connect(chassisdb.CHASSIS_DB)
fname='/usr/share/sonic/virtual_chassis/chassis_db.json'
with open(fname) as f:
js = json.load(f)
client=chassisdb.get_redis_client(chassisdb.CHASSIS_DB)
for h, table in js.items():
for k, v in table.items():
client.hset(h, k, v)
11 changes: 11 additions & 0 deletions platform/vs/docker-sonic-vs/database_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"hostname" : "127.0.0.1",
"port" : 6379,
"unix_socket_path" : "/var/run/redis/redis.sock"
},

"redis_chassis":{
"hostname" : "redis_chassis.server",
"port": 6380,
"unix_socket_path": "/var/run/redis/redis_chassis.sock"
}
},
"DATABASES" : {
Expand Down Expand Up @@ -51,6 +57,11 @@
"id" : 7,
"separator": "|",
"instance" : "redis"
},
"CHASSIS_DB" : {
"id" : 8,
"separator": "|",
"instance" : "redis_chassis"
}
},
"VERSION" : "1.0"
Expand Down
7 changes: 7 additions & 0 deletions platform/vs/docker-sonic-vs/default_chassis_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"DEVICE_METADATA": {
"localhost": {
"chassis_db_address" : "10.8.1.200"
}
}
}
3 changes: 3 additions & 0 deletions platform/vs/docker-sonic-vs/hostname.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% if DEVICE_METADATA.localhost.chassis_db_address %}
{{ DEVICE_METADATA.localhost.chassis_db_address }} redis_chassis.server
{% endif %}
34 changes: 33 additions & 1 deletion platform/vs/docker-sonic-vs/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ popd

[ -d /etc/sonic ] || mkdir -p /etc/sonic

if [[ -f /usr/share/sonic/virtual_chassis/default_config.json ]]; then
CHASS_CFG="-j /usr/share/sonic/virtual_chassis/default_config.json"
fi

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

if [ -f /etc/sonic/config_db.json ]; then
sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json
Expand All @@ -46,11 +50,39 @@ rm -f /var/run/rsyslogd.pid

supervisorctl start rsyslogd

supervisord_cfg="/etc/supervisor/conf.d/supervisord.conf"
chassis_cfg_file="/usr/share/sonic/virtual_chassis/default_config.json"
chassis_cfg_file_default="/etc/default/sonic-db/default_chassis_cfg.json"
host_template="/usr/share/sonic/templates/hostname.j2"
db_cfg_file="/var/run/redis/sonic-db/database_config.json"
db_cfg_file_tmp="/var/run/redis/sonic-db/database_config.json.tmp"

if [ -r "$chassis_cfg_file" ]; then
echo $(sonic-cfggen -j $chassis_cfg_file -t $host_template) >> /etc/hosts
else
chassis_cfg_file="$chassis_cfg_file_default"
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 $chassis_cfg_file`
if [[ "$HOSTNAME" == *"supervisor"* ]] || [ "$start_chassis_db" == "1" ]; then
supervisorctl start redis-chassis
python /usr/bin/chassis_db.py
fi

conn_chassis_db=`sonic-cfggen -v DEVICE_METADATA.localhost.connect_to_chassis_db -y $chassis_cfg_file`
if [ "$start_chassis_db" != "1" ] && [ "$conn_chassis_db" != "1" ]; then
cp $db_cfg_file $db_cfg_file_tmp
remove_chassisdb_config -j $db_cfg_file_tmp
cp $db_cfg_file_tmp $db_cfg_file
fi


/usr/bin/configdb-load.sh

supervisorctl start syncd
Expand Down
8 changes: 8 additions & 0 deletions platform/vs/docker-sonic-vs/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog

[program:redis-chassis]
command=/bin/bash -c "{ [[ -s /var/lib/redis_chassis/dump.rdb ]] || rm -f /var/lib/redis_chassis/dump.rdb; } && mkdir -p /var/lib/redis_chassis && exec /usr/bin/redis-server /etc/redis/redis.conf --bind redis_chassis.server --port 6380 --unixsocket /var/run/redis/redis_chassis.sock --pidfile /var/run/redis/redis_chassis.pid --dir /var/lib/redis_chassis"
priority=3
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog

[program:syncd]
command=/usr/bin/syncd_start.sh
priority=4
Expand Down
6 changes: 5 additions & 1 deletion rules/scripts.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT)_PATH = files/scripts
SYSCTL_NET_CONFIG = sysctl-net.conf
$(SYSCTL_NET_CONFIG)_PATH = files/image_config/sysctl

RM_CHASSISDB_CONFIG_SCRIPT = remove_chassisdb_config
$(RM_CHASSISDB_CONFIG_SCRIPT)_PATH = files/scripts

SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \
$(ARP_UPDATE_SCRIPT) \
$(BUFFERS_CONFIG_TEMPLATE) \
$(QOS_CONFIG_TEMPLATE) \
$(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) \
$(SYSCTL_NET_CONFIG)
$(SYSCTL_NET_CONFIG) \
$(RM_CHASSISDB_CONFIG_SCRIPT)