[macsec-cli]: Fixing to config MACsec on the port will clear port attributes in config db (#10903)
Why I did it There is a bug that the Port attributes in CONFIG_DB will be cleared if using sudo config macsec port add Ethernet0 or sudo config macsec port del Ethernet0 How I did it To fetch the port attributes before set/remove MACsec field in port table. Signed-off-by: Ze Gan <ganze718@gmail.com>
This commit is contained in:
parent
8f7ef1e593
commit
0156c21eff
@ -9,6 +9,7 @@ def mock_cfgdb():
|
||||
CONFIG = {
|
||||
'PORT': {
|
||||
'Ethernet0': {
|
||||
"admin_status": "up"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ class TestConfigMACsec(object):
|
||||
port_table = db.cfgdb.get_entry("PORT", "Ethernet0")
|
||||
assert port_table
|
||||
assert port_table["macsec"] == "test"
|
||||
assert port_table["admin_status"] == "up"
|
||||
|
||||
result = runner.invoke(macsec.macsec.commands["profile"].commands["del"], ["test"], obj=db)
|
||||
assert result.exit_code != 0
|
||||
@ -123,7 +124,8 @@ class TestConfigMACsec(object):
|
||||
result = runner.invoke(macsec.macsec.commands["port"].commands["del"], ["Ethernet0"], obj=db)
|
||||
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
|
||||
port_table = db.cfgdb.get_entry("PORT", "Ethernet0")
|
||||
assert not port_table["macsec"]
|
||||
assert "macsec" not in port_table or not port_table["macsec"]
|
||||
assert port_table["admin_status"] == "up"
|
||||
|
||||
|
||||
def test_macsec_invalid_operation(self, mock_cfgdb):
|
||||
|
@ -42,7 +42,13 @@ def add_port(db, port, profile):
|
||||
if len(profile_entry) == 0:
|
||||
ctx.fail("profile {} doesn't exist".format(profile))
|
||||
|
||||
db.cfgdb.set_entry("PORT", port, {'macsec': profile})
|
||||
port_entry = db.cfgdb.get_entry('PORT', port)
|
||||
if len(port_entry) == 0:
|
||||
ctx.fail("port {} doesn't exist".format(port))
|
||||
|
||||
port_entry['macsec'] = profile
|
||||
|
||||
db.cfgdb.set_entry("PORT", port, port_entry)
|
||||
|
||||
|
||||
#
|
||||
@ -64,7 +70,13 @@ def del_port(db, port):
|
||||
if port is None:
|
||||
ctx.fail("cannot find port name for alias {}".format(alias))
|
||||
|
||||
db.cfgdb.set_entry("PORT", port, {'macsec': ""})
|
||||
port_entry = db.cfgdb.get_entry('PORT', port)
|
||||
if len(port_entry) == 0:
|
||||
ctx.fail("port {} doesn't exist".format(port))
|
||||
|
||||
del port_entry['macsec']
|
||||
|
||||
db.cfgdb.set_entry("PORT", port, port_entry)
|
||||
|
||||
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user