Skip to content
Draft
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: 0 additions & 1 deletion dockers/docker-macsec/cli-plugin-tests/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"description": "Ethernet6/1",
"index": "1",
"lanes": "72,73,74,75,76,77,78,79",
"macsec": "macsec_profile",
"mtu": "9100",
"num_voq": "8",
"pfc_asym": "off",
Expand Down
10 changes: 10 additions & 0 deletions dockers/docker-macsec/cli-plugin-tests/test_show_macsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ def test_show_one_port(self):
result = runner.invoke(show_macsec.macsec,["Ethernet1"])
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)

def test_show_port_deleted_from_config(self):
"""A port whose 'macsec' field was removed from CONFIG_DB but whose
APPL_DB entry has not been cleaned up yet (mid-teardown of
'config macsec port del') is still shown, with an empty profile.
Ethernet5 is in this state in the mock DBs."""
runner = CliRunner()
result = runner.invoke(show_macsec.macsec,[])
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
assert "MACsec port(Ethernet5)" in result.output

def test_show_profile(self):
runner = CliRunner()
result = runner.invoke(show_macsec.macsec,["--profile"])
Expand Down
6 changes: 4 additions & 2 deletions dockers/docker-macsec/cli/show/plugins/show_macsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def dump_str(self, cache = None) -> str:
buffer = self.get_header()

# Add the profile information to the meta dict from config meta dict
self.meta["profile"] = self.cfgMeta["macsec"]
self.meta["profile"] = self.cfgMeta.get("macsec", "")

buffer += tabulate(sorted(self.meta.items(), key=lambda x: x[0]))
return buffer
Expand Down Expand Up @@ -216,7 +216,9 @@ def create_macsec_profile_obj(key: str) -> MACsecCfgMeta:

def create_macsec_objs(interface_name: str) -> typing.List[MACsecAppMeta]:
objs = []
objs.append(create_macsec_obj(MACsecPort.get_appl_table_name() + ":" + interface_name))
port = create_macsec_obj(MACsecPort.get_appl_table_name() + ":" + interface_name)
if port is not None:
objs.append(port)
egress_scs = DB_CONNECTOR.keys(DB_CONNECTOR.APPL_DB, MACsecEgressSC.get_appl_table_name() + ":" + interface_name + ":*")
for sc_name in natsorted(egress_scs):
sc = create_macsec_obj(sc_name)
Expand Down
Loading