Skip to content

Commit

Permalink
[DPB] Enhance the code to shutdown interface before delete ports
Browse files Browse the repository at this point in the history
Enhancement done in this commit:
    Check the admin status on the ports to be deleted.
    If the port admin status is up, do shutdown ports.
    If the port admin status is down, do nothing.
    Wait until the admin status of the ports to be removed on state DB has
    changed to down.

Signed-off-by: chiourung_huang [email protected]
  • Loading branch information
chiourung authored and PJHsieh committed Jul 9, 2024
1 parent 276f648 commit 6905870
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
33 changes: 32 additions & 1 deletion config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,31 @@ def _checkNoPortsInAsicDb(self, db, ports, portMap):

return True

def _verifyPortShutdown(self, db, ports, timeout):
self.sysLog(doPrint=True, msg="Verify Port shutdown from State DB, Wait...")

db.connect(db.STATE_DB)
for waitTime in range(timeout):
retry = False
for intf in ports:
_hash = "PORT_TABLE|{}".format(intf)
port_status = db.get(db.STATE_DB, _hash, "admin_status")
if port_status != 'down':
retry = True
continue
if retry:
tsleep(1)
else:
break

if waitTime + 1 == timeout:
for intf in ports:
_hash = "PORT_TABLE|{}".format(intf)
port_status = db.get(db.STATE_DB, _hash, "admin_status")
if port_status != 'down':
self.sysLog(syslog.LOG_CRIT, "Fail to shutdown port {}".format(intf))


def _verifyAsicDB(self, db, ports, portMap, timeout):
'''
Verify in the Asic DB that port are deleted, Keep on trying till timeout
Expand Down Expand Up @@ -457,6 +482,7 @@ def breakOutPort(self, delPorts=list(), portJson=dict(), force=False, \
# -- verify Asic DB for port deletion,
# -- then update addition of ports in config DB.
self._shutdownIntf(delPorts)
self._verifyPortShutdown(dataBase, delPorts, MAX_WAIT)
self.writeConfigDB(delConfigToLoad)
# Verify in Asic DB,
self._verifyAsicDB(db=dataBase, ports=delPorts, portMap=if_name_map, \
Expand Down Expand Up @@ -603,9 +629,14 @@ def _shutdownIntf(self, ports):
Returns:
void
"""
configdb = ConfigDBConnector()
configdb.connect(False)
shutDownConf = dict(); shutDownConf["PORT"] = dict()
for intf in ports:
shutDownConf["PORT"][intf] = {"admin_status": "down"}
port_entry = configdb.get_entry('PORT', intf)
port_status = port_entry.get("admin_status")
if port_status == "up":
shutDownConf["PORT"][intf] = {"admin_status": "down"}
self.sysLog(msg='shutdown Interfaces: {}'.format(shutDownConf))

if len(shutDownConf["PORT"]):
Expand Down
7 changes: 5 additions & 2 deletions tests/config_mgmt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ def test_shutdownIntf_call(self):
args = args[0]
assert "PORT" in args

# {"admin_status": "down"} should be set for all ports in dPorts
assert len(args["PORT"]) == len(dPorts)
# {"admin_status": "down"} should be set for Ethernet8
# The admin_status of Ethernet8 is 'up'.
# Only need to shutdown Ethernet8
assert len(args["PORT"]) == 1
# each port should have {"admin_status": "down"}
for port in args["PORT"].keys():
assert args["PORT"][port]['admin_status'] == 'down'
Expand Down Expand Up @@ -227,6 +229,7 @@ def config_mgmt_dpb(self, curConfig):
# mock funcs
cmdpb.writeConfigDB = mock.MagicMock(return_value=True)
cmdpb._verifyAsicDB = mock.MagicMock(return_value=True)
cmdpb._verifyPortShutdown = mock.MagicMock(return_value=True)
from .mock_tables import dbconnector
return cmdpb

Expand Down
1 change: 1 addition & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"brkout_mode": "1x100G[40G]"
},
"PORT|Ethernet0": {
"admin_status": "up",
"alias": "etp1",
"description": "etp1",
"index": "0",
Expand Down

0 comments on commit 6905870

Please sign in to comment.