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

[macsec-cli]: Fixing to config MACsec on the port will clear port attributes in config db #10903

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dockers/docker-macsec/cli-plugin-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def mock_cfgdb():
CONFIG = {
'PORT': {
'Ethernet0': {
"admin_status": "up"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ def test_macsec_port(self, mock_cfgdb):
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

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):
Expand Down
16 changes: 14 additions & 2 deletions dockers/docker-macsec/cli/config/plugins/macsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


#
Expand All @@ -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)


#
Expand Down