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

[multi-asic][sonic-config-engine]: Get PORT table from namespace config db #7632

Merged
merged 8 commits into from
Jun 7, 2021
9 changes: 1 addition & 8 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


from portconfig import get_port_config
from sonic_py_common.multi_asic import get_asic_id_from_name
from sonic_py_common.interface import backplane_prefix

# TODO: Remove this once we no longer support Python 2
Expand Down Expand Up @@ -1183,12 +1182,6 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
local_devices = []
kube_data = {}

# hostname is the asic_name, get the asic_id from the asic_name
if asic_name is not None:
asic_id = get_asic_id_from_name(asic_name)
else:
asic_id = None

hwsku_qn = QName(ns, "HwSku")
hostname_qn = QName(ns, "Hostname")
docker_routing_config_mode_qn = QName(ns, "DockerRoutingConfigMode")
Expand All @@ -1200,7 +1193,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
if child.tag == str(docker_routing_config_mode_qn):
docker_routing_config_mode = child.text

(ports, alias_map, alias_asic_map) = get_port_config(hwsku=hwsku, platform=platform, port_config_file=port_config_file, asic=asic_id, hwsku_config_file=hwsku_config_file)
(ports, alias_map, alias_asic_map) = get_port_config(hwsku=hwsku, platform=platform, port_config_file=port_config_file, asic_name=asic_name, hwsku_config_file=hwsku_config_file)
port_alias_map.update(alias_map)
port_alias_asic_map.update(alias_asic_map)

Expand Down
39 changes: 32 additions & 7 deletions src/sonic-config-engine/portconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
import re
import sys

from swsscommon.swsscommon import ConfigDBConnector
from swsscommon import swsscommon
from sonic_py_common import device_info
from sonic_py_common.multi_asic import get_asic_id_from_name
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

try:
if os.environ["CFGGEN_UNIT_TESTING"] == "2":
modules_path = os.path.join(os.path.dirname(__file__), ".")
tests_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
import mock_tables.dbconnector
mock_tables.dbconnector.load_namespace_config()

except KeyError:
pass

# Global Variable
PLATFORM_ROOT_PATH = '/usr/share/sonic/device'
PLATFORM_ROOT_PATH_DOCKER = '/usr/share/sonic/platform'
Expand Down Expand Up @@ -45,11 +58,16 @@ def readJson(filename):
print("error occurred while parsing json: {}".format(sys.exc_info()[1]))
return None

def db_connect_configdb():
def db_connect_configdb(namespace=None):
"""
Connect to configdb
"""
config_db = ConfigDBConnector()
try:
if namespace is not None:
swsscommon.SonicDBConfig.load_sonic_global_db_config(namespace=namespace)
config_db = swsscommon.ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
except Exception as e:
return None
if config_db is None:
return None
try:
Expand Down Expand Up @@ -77,8 +95,8 @@ def get_hwsku_file_name(hwsku=None, platform=None):
return candidate
return None

def get_port_config(hwsku=None, platform=None, port_config_file=None, hwsku_config_file=None, asic=None):
config_db = db_connect_configdb()
def get_port_config(hwsku=None, platform=None, port_config_file=None, hwsku_config_file=None, asic_name=None):
config_db = db_connect_configdb(asic_name)
# If available, Read from CONFIG DB first
if config_db is not None and port_config_file is None:

Expand All @@ -88,11 +106,18 @@ def get_port_config(hwsku=None, platform=None, port_config_file=None, hwsku_conf
port_alias_map = {}
port_alias_asic_map = {}
for intf_name in ports.keys():
port_alias_map[ports[intf_name]["alias"]] = intf_name
if "alias" in ports[intf_name]:
port_alias_map[ports[intf_name]["alias"]] = intf_name
return (ports, port_alias_map, port_alias_asic_map)

if asic_name is not None:
asic_id = str(get_asic_id_from_name(asic_name))
else:
asic_id = None

if not port_config_file:
port_config_file = device_info.get_path_to_port_config_file(hwsku, asic)
port_config_file = device_info.get_path_to_port_config_file(hwsku, asic_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

how is it working 201911 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in 201911 and here, we pass "asic_id" like 0/1 to get_path_to_port_config_file() ; That part is not modified.
The change here is that, portconfig.py consumes asic_name instead of asic_id and we get asic_id from asic_name here instead of getting that information in minigraph.py


if not port_config_file:
return ({}, {}, {})

Expand Down
Empty file.
98 changes: 98 additions & 0 deletions src/sonic-config-engine/tests/mock_tables/asic0/config_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"PORT|Ethernet0": {
"index": "0",
"lanes": "33,34,35,36",
"description": "01T2:Ethernet1:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Ethernet1/1",
"admin_status": "up",
"role": "Ext",
"speed": "40000",
"asic_port_name": "Eth0-ASIC0"
},
"PORT|Ethernet4": {
"index": "1",
"lanes": "29,30,31,32",
"description": "01T2:Ethernet2:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Ethernet1/2",
"admin_status": "up",
"role": "Ext",
"speed": "40000",
"asic_port_name": "Eth1-ASIC0"
},
"PORT|Ethernet8": {
"index": "2",
"lanes": "41,42,43,44",
"description": "Ethernet1/3:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Ethernet1/3",
"admin_status": "up",
"role": "Ext",
"speed": "40000",
"asic_port_name": "Eth2-ASIC0"
},
"PORT|Ethernet12": {
"index": "3",
"lanes": "37,38,39,40",
"description": "Ethernet1/4:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Ethernet1/4",
"admin_status": "up",
"role": "Ext",
"speed": "40000",
"asic_port_name": "Eth3-ASIC0"
},
"PORT|Ethernet-BP0": {
"index": "0",
"lanes": "13,14,15,16",
"description": "ASIC2:Eth0-ASIC2:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Eth4-ASIC0",
"admin_status": "up",
"role": "Int",
"speed": "40000",
"asic_port_name": "Eth4-ASIC0"
},
"PORT|Ethernet-BP4": {
"index": "1",
"lanes": "17,18,19,20",
"description": "ASIC2:Eth1-ASIC2:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Eth5-ASIC0",
"admin_status": "up",
"role": "Int",
"speed": "40000",
"asic_port_name": "Eth5-ASIC0"
},
"PORT|Ethernet-BP8": {
"index": "2",
"lanes": "21,22,23,24",
"description": "ASIC3:Eth0-ASIC3:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Eth6-ASIC0",
"admin_status": "up",
"role": "Int",
"speed": "40000",
"asic_port_name": "Eth6-ASIC0"
},
"PORT|Ethernet-BP12": {
"index": "3",
"lanes": "25,26,27,28",
"description": "ASIC3:Eth1-ASIC3:config_db",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Eth7-ASIC0",
"admin_status": "up",
"role": "Int",
"speed": "40000",
"asic_port_name": "Eth7-ASIC0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"INSTANCES": {
"redis": {
"hostname" : "127.0.0.1",
"port" : 6379,
"unix_socket_path" : "/var/run/redis/redis.sock"
}
},
"DATABASES" : {
"APPL_DB" : {
"id" : 0,
"separator": ":",
"instance" : "redis"
},
"ASIC_DB" : {
"id" : 1,
"separator": ":",
"instance" : "redis"
},
"COUNTERS_DB" : {
"id" : 2,
"separator": ":",
"instance" : "redis"
},
"LOGLEVEL_DB" : {
"id" : 3,
"separator": ":",
"instance" : "redis"
},
"CONFIG_DB" : {
"id" : 4,
"separator": "|",
"instance" : "redis"
},
"PFC_WD_DB" : {
"id" : 5,
"separator": ":",
"instance" : "redis"
},
"FLEX_COUNTER_DB" : {
"id" : 5,
"separator": ":",
"instance" : "redis"
},
"STATE_DB" : {
"id" : 6,
"separator": "|",
"instance" : "redis"
},
"SNMP_OVERLAY_DB" : {
"id" : 7,
"separator": "|",
"instance" : "redis"
}
},
"VERSION" : "1.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"INSTANCES": {
"redis": {
"hostname" : "127.0.0.1",
"port" : 6379,
"unix_socket_path" : "/var/run/redis/redis.sock"
}
},
"DATABASES" : {
"APPL_DB" : {
"id" : 0,
"separator": ":",
"instance" : "redis"
},
"ASIC_DB" : {
"id" : 1,
"separator": ":",
"instance" : "redis"
},
"COUNTERS_DB" : {
"id" : 2,
"separator": ":",
"instance" : "redis"
},
"LOGLEVEL_DB" : {
"id" : 3,
"separator": ":",
"instance" : "redis"
},
"CONFIG_DB" : {
"id" : 4,
"separator": "|",
"instance" : "redis"
},
"PFC_WD_DB" : {
"id" : 5,
"separator": ":",
"instance" : "redis"
},
"FLEX_COUNTER_DB" : {
"id" : 5,
"separator": ":",
"instance" : "redis"
},
"STATE_DB" : {
"id" : 6,
"separator": "|",
"instance" : "redis"
},
"SNMP_OVERLAY_DB" : {
"id" : 7,
"separator": "|",
"instance" : "redis"
}
},
"VERSION" : "1.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"INSTANCES": {
"redis": {
"hostname" : "127.0.0.1",
"port" : 6379,
"unix_socket_path" : "/var/run/redis/redis.sock"
}
},
"DATABASES" : {
"APPL_DB" : {
"id" : 0,
"separator": ":",
"instance" : "redis"
},
"ASIC_DB" : {
"id" : 1,
"separator": ":",
"instance" : "redis"
},
"COUNTERS_DB" : {
"id" : 2,
"separator": ":",
"instance" : "redis"
},
"LOGLEVEL_DB" : {
"id" : 3,
"separator": ":",
"instance" : "redis"
},
"CONFIG_DB" : {
"id" : 4,
"separator": "|",
"instance" : "redis"
},
"PFC_WD_DB" : {
"id" : 5,
"separator": ":",
"instance" : "redis"
},
"FLEX_COUNTER_DB" : {
"id" : 5,
"separator": ":",
"instance" : "redis"
},
"STATE_DB" : {
"id" : 6,
"separator": "|",
"instance" : "redis"
},
"SNMP_OVERLAY_DB" : {
"id" : 7,
"separator": "|",
"instance" : "redis"
}
},
"VERSION" : "1.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Loading