Skip to content

Commit d5ddb82

Browse files
authored
[dvs/chassis] Bring up SONiC interfaces in virtual chassis (#1410)
Signed-off-by: Danny Allen <[email protected]>
1 parent 25d071b commit d5ddb82

File tree

1 file changed

+96
-42
lines changed

1 file changed

+96
-42
lines changed

tests/conftest.py

+96-42
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ def handle_request(self):
12261226
self.create_vct_ctn(ctndir)
12271227
if "neighbor_connections" in self.virt_topo:
12281228
self.handle_neighconn()
1229+
self.handle_chassis_connections()
12291230
retry = 0
12301231
while self.verify_vct() is False and retry < 10:
12311232
print("wait for chassis to be ready")
@@ -1266,13 +1267,13 @@ def handle_bridge(self, brName):
12661267

12671268
def create_vct_ctn(self, ctndir):
12681269
cwd = os.getcwd()
1269-
cfgdir = cwd + "/virtual_chassis/" + ctndir
1270-
cfgfile = cfgdir + "/default_config.json"
1271-
with open(cfgfile, "r") as cfg:
1270+
chassis_config_dir = cwd + "/virtual_chassis/" + ctndir
1271+
chassis_config_file = chassis_config_dir + "/default_config.json"
1272+
with open(chassis_config_file, "r") as cfg:
12721273
defcfg = json.load(cfg)["DEVICE_METADATA"]["localhost"]
12731274
ctnname = defcfg["hostname"] + "." + self.ns
12741275
vol = {}
1275-
vol[cfgdir] = {"bind": "/usr/share/sonic/virtual_chassis", "mode": "ro"}
1276+
vol[chassis_config_dir] = {"bind": "/usr/share/sonic/virtual_chassis", "mode": "ro"}
12761277

12771278
# pass self.ns into the vs to be use for vs restarts by swss conftest.
12781279
# connection to chassbr is setup by chassis_connect.py within the vs
@@ -1300,57 +1301,110 @@ def get_inband(self, ctnname):
13001301
return {}
13011302

13021303
def get_topo_neigh(self):
1303-
cwd = os.getcwd()
1304-
neighs_by_ctn = {}
1304+
instance_to_neighbor_map = {}
13051305
if "neighbor_connections" not in self.virt_topo:
1306-
return neighs_by_ctn
1307-
for nck, ncv in self.virt_topo["neighbor_connections"].items():
1308-
ctndir = nck.split("-")[0]
1309-
nbrctndir = nck.split("-")[1]
1310-
nbrvethintf = int(ncv[nbrctndir].split("eth")[1])
1311-
nbrintf = "ethernet%d|" % ((nbrvethintf - 1) * 4)
1312-
vethintf = int(ncv[ctndir].split("eth")[1])
1313-
cfgdir = cwd + "/virtual_chassis/" + ctndir
1314-
cfgfile = cfgdir + "/default_config.json"
1315-
ctnname = ""
1316-
with open(cfgfile, "r") as cfg:
1317-
defcfg = json.load(cfg)["DEVICE_METADATA"]["localhost"]
1318-
ctnname = defcfg["hostname"] + "." + self.ns
1319-
cfgfile = cwd + "/virtual_chassis/" + nbrctndir + "/default_config.json"
1320-
with open(cfgfile, "r") as cfg:
1321-
intfCfg = json.load(cfg)["INTERFACE"]
1322-
for key in intfCfg:
1323-
nbraddr = ""
1324-
if key.lower().startswith(nbrintf):
1325-
intfaddr = re.split("/|\\|", key)
1326-
if len(intfaddr) > 1:
1327-
nbraddr = intfaddr[1]
1328-
if nbraddr == "":
1306+
return instance_to_neighbor_map
1307+
1308+
working_dir = os.getcwd()
1309+
for conn, endpoints in self.virt_topo["neighbor_connections"].items():
1310+
chassis_instance = conn.split('-')[0]
1311+
neighbor_instance = conn.split('-')[1]
1312+
1313+
chassis_config_dir = os.path.join(working_dir, "virtual_chassis", chassis_instance)
1314+
chassis_config_file = os.path.join(chassis_config_dir, "default_config.json")
1315+
chassis_container_name = ""
1316+
with open(chassis_config_file, "r") as cfg:
1317+
device_info = json.load(cfg)["DEVICE_METADATA"]["localhost"]
1318+
chassis_container_name = device_info["hostname"] + "." + self.ns
1319+
1320+
neighbor_veth_intf = int(endpoints[neighbor_instance].split("eth")[1])
1321+
neighbor_host_intf = f"Ethernet{(neighbor_veth_intf - 1) * 4}"
1322+
chassis_veth_intf = int(endpoints[chassis_instance].split("eth")[1])
1323+
1324+
neighbor_config_file = os.path.join(working_dir, "virtual_chassis", neighbor_instance, "default_config.json")
1325+
with open(neighbor_config_file, "r") as cfg:
1326+
intf_config = json.load(cfg)["INTERFACE"]
1327+
for key in intf_config:
1328+
neighbor_address = ""
1329+
if key.lower().startswith(f"{neighbor_host_intf}|"):
1330+
host_intf_address = re.split("/|\\|", key)
1331+
1332+
if len(host_intf_address) > 1:
1333+
neighbor_address = host_intf_address[1]
1334+
1335+
if neighbor_address == "":
13291336
continue
1330-
if ctnname not in neighs_by_ctn:
1331-
neighs_by_ctn[ctnname] = []
1332-
neighs_by_ctn[ctnname].append((vethintf - 1, nbraddr))
1333-
return neighs_by_ctn
1337+
1338+
if chassis_container_name not in instance_to_neighbor_map:
1339+
instance_to_neighbor_map[chassis_container_name] = []
1340+
1341+
instance_to_neighbor_map[chassis_container_name].append((chassis_veth_intf - 1,
1342+
neighbor_address))
1343+
1344+
return instance_to_neighbor_map
13341345

13351346
def handle_neighconn(self):
13361347
if self.oper != "create":
13371348
return
1338-
neighs_by_ctn = self.get_topo_neigh()
1339-
for ctnname, nbraddrs in neighs_by_ctn.items():
1349+
1350+
instance_to_neighbor_map = self.get_topo_neigh()
1351+
for ctnname, nbraddrs in instance_to_neighbor_map.items():
13401352
if ctnname not in self.dvss:
13411353
continue
1342-
for idx, nbraddr in nbraddrs:
1343-
self.dvss[ctnname].servers[idx].runcmd("ifconfig eth0 down ")
1344-
self.dvss[ctnname].servers[idx].runcmd("ifconfig eth0 up")
1345-
self.dvss[ctnname].servers[idx].runcmd("ifconfig eth0 " + nbraddr)
1346-
return
1354+
1355+
for server, neighbor_address in nbraddrs:
1356+
self.dvss[ctnname].servers[server].runcmd("ifconfig eth0 down")
1357+
self.dvss[ctnname].servers[server].runcmd("ifconfig eth0 up")
1358+
self.dvss[ctnname].servers[server].runcmd(f"ifconfig eth0 {neighbor_address}")
1359+
1360+
def get_chassis_instance_port_statuses(self):
1361+
instance_to_port_status_map = {}
1362+
if "neighbor_connections" not in self.virt_topo:
1363+
return instance_to_neighbor_map
1364+
1365+
working_dir = os.getcwd()
1366+
for conn, endpoints in self.virt_topo["neighbor_connections"].items():
1367+
chassis_instance = conn.split('-')[0]
1368+
1369+
chassis_config_dir = os.path.join(working_dir, "virtual_chassis", chassis_instance)
1370+
chassis_config_file = os.path.join(chassis_config_dir, "default_config.json")
1371+
with open(chassis_config_file, "r") as cfg:
1372+
config = json.load(cfg)
1373+
device_info = config["DEVICE_METADATA"]["localhost"]
1374+
chassis_container_name = device_info["hostname"] + "." + self.ns
1375+
1376+
port_info = config["PORT"]
1377+
1378+
for port, config in port_info.items():
1379+
if "admin_status" not in config:
1380+
continue
1381+
1382+
if chassis_container_name not in instance_to_port_status_map:
1383+
instance_to_port_status_map[chassis_container_name] = []
1384+
1385+
instance_to_port_status_map[chassis_container_name].append((port, config.get("admin_status")))
1386+
1387+
return instance_to_port_status_map
1388+
1389+
def handle_chassis_connections(self):
1390+
if self.oper != "create":
1391+
return
1392+
1393+
instance_to_port_status_map = self.get_chassis_instance_port_statuses()
1394+
for chassis_instance, port_statuses in instance_to_port_status_map.items():
1395+
if chassis_instance not in self.dvss:
1396+
continue
1397+
1398+
for port, status in port_statuses:
1399+
command = "startup" if status == "up" else "shutdown"
1400+
self.dvss[chassis_instance].runcmd(f"config interface {command} {port}")
13471401

13481402
def verify_conns(self):
13491403
passed = True
13501404
if "neighbor_connections" not in self.virt_topo:
13511405
return passed
1352-
neighs_by_ctn = self.get_topo_neigh()
1353-
for ctnname, nbraddrs in neighs_by_ctn.items():
1406+
instance_to_neighbor_map = self.get_topo_neigh()
1407+
for ctnname, nbraddrs in instance_to_neighbor_map.items():
13541408
for item in nbraddrs:
13551409
nbraddr = item[1]
13561410
print("verify neighbor connectivity from %s to %s nbrAddr " % (

0 commit comments

Comments
 (0)