Skip to content

Commit 137e64b

Browse files
committed
Fix docker-macsec.mk
Signed-off-by: Ze Gan <[email protected]>
1 parent 5b8606e commit 137e64b

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ def set_entry(table, key, data):
2222
CONFIG[table].setdefault(key, {})
2323
CONFIG[table][key] = data
2424

25+
def get_keys(table):
26+
return CONFIG[table].keys()
27+
2528
cfgdb.get_entry = mock.Mock(side_effect=get_entry)
2629
cfgdb.set_entry = mock.Mock(side_effect=set_entry)
30+
cfgdb.get_keys = mock.Mock(side_effect=get_keys)
2731

2832
yield cfgdb
2933

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestConfigMACsec(object):
1818
def test_plugin_registration(self):
1919
cli = mock.MagicMock()
2020
macsec.register(cli)
21-
cli.commands['macsec'].add_command.assert_called_once_with(macsec.macsec)
21+
cli.add_command.assert_called_once_with(macsec.macsec)
2222

2323
def test_default_profile(self, mock_cfgdb):
2424
runner = CliRunner()
@@ -118,6 +118,9 @@ def test_macsec_port(self, mock_cfgdb):
118118
assert port_table
119119
assert port_table["macsec"] == "test"
120120

121+
result = runner.invoke(macsec.macsec.commands["profile"].commands["del"], ["test"], obj=db)
122+
assert result.exit_code != 0
123+
121124
result = runner.invoke(macsec.macsec.commands["port"].commands["del"], ["Ethernet0"], obj=db)
122125
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
123126
port_table = db.cfgdb.get_entry("PORT", "Ethernet0")

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,17 @@ def del_profile(db, profile):
164164
if len(profile_entry) == 0:
165165
ctx.fail("{} doesn't exist".format(profile))
166166

167+
# Check if the profile is being used by any port
168+
for port in db.cfgdb.get_keys('PORT'):
169+
attr = db.cfgdb.get_entry('PORT', port)
170+
if 'macsec' in attr and attr['macsec'] == profile:
171+
ctx.fail("{} is being used by port {}, Please remove the MACsec from the port firstly".format(profile, port))
172+
167173
db.cfgdb.set_entry("MACSEC_PROFILE", profile, None)
168174

169175

170176
def register(cli):
171-
cli.commands['macsec'].add_command(macsec)
177+
cli.add_command(macsec)
172178

173179

174180
if __name__ == '__main__':

rules/docker-macsec.mk

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ $(DOCKER_MACSEC)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BULLSEYE)
1717
$(DOCKER_MACSEC)_INSTALL_PYTHON_WHEELS = $(SONIC_UTILITIES_PY3)
1818
$(DOCKER_MACSEC)_INSTALL_DEBS = $(PYTHON3_SWSSCOMMON) $(LIBYANG_PY3)
1919

20-
ifeq ($(INCLUDE_MACSEC), y)
21-
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_MACSEC)
22-
endif
20+
SONIC_DOCKER_IMAGES += $(DOCKER_MACSEC)
21+
SONIC_DOCKER_DBG_IMAGES += $(DOCKER_MACSEC_DBG)
2322

24-
ifeq ($(INCLUDE_MACSEC), y)
25-
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_MACSEC_DBG)
23+
ifeq ($(INCLUDE_KUBERNETES),y)
24+
$(DOCKER_MACSEC)_DEFAULT_FEATURE_OWNER = kube
2625
endif
2726

27+
$(DOCKER_MACSEC)_DEFAULT_FEATURE_STATE_ENABLED = y
28+
29+
2830
ifeq ($(INCLUDE_MACSEC),y)
2931
ifeq ($(INSTALL_DEBUG_TOOLS),y)
3032
SONIC_PACKAGES_LOCAL += $(DOCKER_MACSEC_DBG)
@@ -41,8 +43,6 @@ $(DOCKER_MACSEC)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
4143
$(DOCKER_MACSEC)_RUN_OPT += -v /host/warmboot:/var/warmboot
4244

4345
$(DOCKER_MACSEC)_CLI_CONFIG_PLUGIN = /cli/config/plugins/macsec.py
46+
# $(DOCKER_MACSEC)_CLI_SHOW_PLUGIN = /cli/show/plugins/show_macsec.py
4447

4548
$(DOCKER_MACSEC)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT)
46-
47-
SONIC_BULLSEYE_DOCKERS += $(DOCKER_MACSEC)
48-
SONIC_BULLSEYE_DBG_DOCKERS += $(DOCKER_MACSEC_DBG)

0 commit comments

Comments
 (0)