Skip to content

Commit 4a47b3f

Browse files
authored
[config] Support load_minigraph command for multi NPU platform (sonic-net#896)
- Modify the load_minigraph command handler to support multi NPU platforms
1 parent 057c72a commit 4a47b3f

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

config/main.py

+41-18
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
SYSTEMCTL_ACTION_RESTART="restart"
3737
SYSTEMCTL_ACTION_RESET_FAILED="reset-failed"
3838

39+
DEFAULT_NAMESPACE = ''
3940
# ========================== Syslog wrappers ==========================
4041

4142
def log_debug(msg):
@@ -632,6 +633,8 @@ def config():
632633
if os.geteuid() != 0:
633634
exit("Root privileges are required for this operation")
634635

636+
SonicDBConfig.load_sonic_global_db_config()
637+
635638

636639
config.add_command(aaa.aaa)
637640
config.add_command(aaa.tacacs)
@@ -915,26 +918,46 @@ def load_minigraph():
915918
log_info("'load_minigraph' stopping services...")
916919
_stop_services()
917920

918-
config_db = ConfigDBConnector()
919-
config_db.connect()
920-
client = config_db.get_redis_client(config_db.CONFIG_DB)
921-
client.flushdb()
922-
if os.path.isfile('/etc/sonic/init_cfg.json'):
923-
command = "{} -H -m -j /etc/sonic/init_cfg.json --write-to-db".format(SONIC_CFGGEN_PATH)
924-
else:
925-
command = "{} -H -m --write-to-db".format(SONIC_CFGGEN_PATH)
926-
run_command(command, display_cmd=True)
927-
client.set(config_db.INIT_INDICATOR, 1)
928-
if device_type != 'MgmtToRRouter':
929-
run_command('pfcwd start_default', display_cmd=True)
921+
# For Single Asic platform the namespace list has the empty string
922+
# for mulit Asic platform the empty string to generate the config
923+
# for host
924+
namespace_list = [DEFAULT_NAMESPACE]
925+
num_npus = sonic_device_util.get_num_npus()
926+
if num_npus > 1:
927+
namespace_list += sonic_device_util.get_namespaces()
928+
929+
for namespace in namespace_list:
930+
if namespace is DEFAULT_NAMESPACE:
931+
config_db = ConfigDBConnector()
932+
cfggen_namespace_option = " "
933+
ns_cmd_prefix = " "
934+
else:
935+
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
936+
cfggen_namespace_option = " -n {}".format(namespace)
937+
ns_cmd_prefix = "sudo ip netns exec {}".format(namespace)
938+
config_db.connect()
939+
client = config_db.get_redis_client(config_db.CONFIG_DB)
940+
client.flushdb()
941+
if os.path.isfile('/etc/sonic/init_cfg.json'):
942+
command = "{} -H -m -j /etc/sonic/init_cfg.json {} --write-to-db".format(SONIC_CFGGEN_PATH, cfggen_namespace_option)
943+
else:
944+
command = "{} -H -m --write-to-db {} ".format(SONIC_CFGGEN_PATH,cfggen_namespace_option)
945+
run_command(command, display_cmd=True)
946+
client.set(config_db.INIT_INDICATOR, 1)
947+
948+
# These commands are not run for host on multi asic platform
949+
if num_npus == 1 or namespace is not DEFAULT_NAMESPACE:
950+
if device_type != 'MgmtToRRouter':
951+
run_command('{} pfcwd start_default'.format(ns_cmd_prefix), display_cmd=True)
952+
run_command("{} config qos reload".format(ns_cmd_prefix), display_cmd=True)
953+
954+
# Write latest db version string into db
955+
db_migrator='/usr/bin/db_migrator.py'
956+
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
957+
run_command(db_migrator + ' -o set_version' + cfggen_namespace_option)
958+
930959
if os.path.isfile('/etc/sonic/acl.json'):
931960
run_command("acl-loader update full /etc/sonic/acl.json", display_cmd=True)
932-
run_command("config qos reload", display_cmd=True)
933-
934-
# Write latest db version string into db
935-
db_migrator='/usr/bin/db_migrator.py'
936-
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
937-
run_command(db_migrator + ' -o set_version')
938961

939962
# We first run "systemctl reset-failed" to remove the "failed"
940963
# status from all services before we attempt to restart them

0 commit comments

Comments
 (0)