sonic-buildimage/files/scripts/remove_chassisdb_config
BrynXu 311045f01f
[vs]: support virtual-chassis setup in vs docker (#4709)
virtual-chassis test uses multiple vs instances to simulate a
modular switch and a redis-chassis service is required to run on
the vs instance that represents a supervisor card.
This change allows vs docker start redis-chassis service according
to external config file.

**- Why I did it**
To support virtual-chassis setup, so that we can test distributed forwarding feature in virtual sonic environment, see `Distributed forwarding in a VOQ architecture HLD` pull request at https://github.com/Azure/SONiC/pull/622

**- How I did it**
The sonic-vs start.sh is enhanced to start new redis_chassis service if external chassis config file found. The config file doesn't exist in current vs environment, start.sh will behave like before. 

**- How to verify it**
The swss/test still pass. The chassis_db service is verified in virtual-chassis topology and tests which are in following PRs.

Signed-off-by: Honggang Xu <hxu@arista.com>
(cherry picked from commit c1d45cf81ce3238be2dcbccae98c0780944981ce)

Co-authored-by: Honggang Xu <hxu@arista.com>
2020-07-29 14:20:31 -07:00

41 lines
1.3 KiB
Python
Executable File

#!/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()