Skip to content

Commit fbd0339

Browse files
committed
fixbug: config MACsec on the port will clear port attributes in config db
Signed-off-by: Ze Gan <[email protected]>
1 parent 3928996 commit fbd0339

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

dockers/docker-macsec/cli-plugin-tests/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def mock_cfgdb():
99
CONFIG = {
1010
'PORT': {
1111
'Ethernet0': {
12+
"admin_status": "up"
1213
}
1314
}
1415
}

dockers/docker-macsec/cli-plugin-tests/test_config_macsec.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,16 @@ def test_macsec_port(self, mock_cfgdb):
116116
port_table = db.cfgdb.get_entry("PORT", "Ethernet0")
117117
assert port_table
118118
assert port_table["macsec"] == "test"
119+
assert port_table["admin_status"] == "up"
119120

120121
result = runner.invoke(macsec.macsec.commands["profile"].commands["del"], ["test"], obj=db)
121122
assert result.exit_code != 0
122123

123124
result = runner.invoke(macsec.macsec.commands["port"].commands["del"], ["Ethernet0"], obj=db)
124125
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
125126
port_table = db.cfgdb.get_entry("PORT", "Ethernet0")
126-
assert not port_table["macsec"]
127+
assert "macsec" not in port_table or not port_table["macsec"]
128+
assert port_table["admin_status"] == "up"
127129

128130

129131
def test_macsec_invalid_operation(self, mock_cfgdb):

dockers/docker-macsec/cli/config/plugins/macsec.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ def add_port(db, port, profile):
4242
if len(profile_entry) == 0:
4343
ctx.fail("profile {} doesn't exist".format(profile))
4444

45-
db.cfgdb.set_entry("PORT", port, {'macsec': profile})
45+
port_entry = db.cfgdb.get_entry('PORT', port)
46+
if len(port_entry) == 0:
47+
ctx.fail("port {} doesn't exist".format(port))
48+
49+
port_entry['macsec'] = profile
50+
51+
db.cfgdb.set_entry("PORT", port, port_entry)
4652

4753

4854
#
@@ -64,7 +70,13 @@ def del_port(db, port):
6470
if port is None:
6571
ctx.fail("cannot find port name for alias {}".format(alias))
6672

67-
db.cfgdb.set_entry("PORT", port, {'macsec': ""})
73+
port_entry = db.cfgdb.get_entry('PORT', port)
74+
if len(port_entry) == 0:
75+
ctx.fail("port {} doesn't exist".format(port))
76+
77+
del port_entry['macsec']
78+
79+
db.cfgdb.set_entry("PORT", port, port_entry)
6880

6981

7082
#

0 commit comments

Comments
 (0)