From fc82bd188cf67906c180ecc928bf90b3e9701e59 Mon Sep 17 00:00:00 2001 From: Mai Bui Date: Sun, 24 Sep 2023 08:47:57 -0400 Subject: [PATCH] fix del vlan command (#2995) Signed-off-by: Mai Bui --- config/vlan.py | 15 +++++++-------- tests/vlan_test.py | 8 ++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/config/vlan.py b/config/vlan.py index 75135b3ed7..6cc3193ec0 100644 --- a/config/vlan.py +++ b/config/vlan.py @@ -129,21 +129,20 @@ def del_vlan(db, vid, no_restart_dhcp_relay): vlans = db.cfgdb.get_keys('VLAN') if not vlans: - docker_exec_cmd = "docker exec -i swss {}" - _, rc = clicommon.run_command(docker_exec_cmd.format("supervisorctl status ndppd"), ignore_error=True, return_cmd=True) + docker_exec_cmd = ['docker', 'exec', '-i', 'swss'] + _, rc = clicommon.run_command(docker_exec_cmd + ['supervisorctl', 'status', 'ndppd'], ignore_error=True, return_cmd=True) if rc == 0: click.echo("No VLANs remaining, stopping ndppd service") - clicommon.run_command(docker_exec_cmd.format("supervisorctl stop ndppd"), ignore_error=True, return_cmd=True) - clicommon.run_command(docker_exec_cmd.format("rm -f /etc/supervisor/conf.d/ndppd.conf"), ignore_error=True, return_cmd=True) - clicommon.run_command(docker_exec_cmd.format("supervisorctl update"), return_cmd=True) - + clicommon.run_command(docker_exec_cmd + ['supervisorctl', 'stop', 'ndppd'], ignore_error=True, return_cmd=True) + clicommon.run_command(docker_exec_cmd + ['rm', '-f', '/etc/supervisor/conf.d/ndppd.conf'], ignore_error=True, return_cmd=True) + clicommon.run_command(docker_exec_cmd + ['supervisorctl', 'update'], return_cmd=True) def restart_ndppd(): verify_swss_running_cmd = ['docker', 'container', 'inspect', '-f', '{{.State.Status}}', 'swss'] docker_exec_cmd = ['docker', 'exec', '-i', 'swss'] ndppd_config_gen_cmd = ['sonic-cfggen', '-d', '-t', '/usr/share/sonic/templates/ndppd.conf.j2,/etc/ndppd.conf'] - ndppd_restart_cmd =['supervisorctl', 'restart', 'ndppd'] - ndppd_status_cmd= ["supervisorctl", "status", "ndppd"] + ndppd_restart_cmd = ['supervisorctl', 'restart', 'ndppd'] + ndppd_status_cmd = ["supervisorctl", "status", "ndppd"] ndppd_conf_copy_cmd = ['cp', '/usr/share/sonic/templates/ndppd.conf', '/etc/supervisor/conf.d/'] supervisor_update_cmd = ['supervisorctl', 'update'] diff --git a/tests/vlan_test.py b/tests/vlan_test.py index 9722ced6d0..6dae8be86d 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -419,10 +419,10 @@ def test_config_vlan_del_last_vlan(self): print(result.exit_code) print(result.output) mock_run_command.assert_has_calls([ - mock.call("docker exec -i swss supervisorctl status ndppd", ignore_error=True, return_cmd=True), - mock.call("docker exec -i swss supervisorctl stop ndppd", ignore_error=True, return_cmd=True), - mock.call("docker exec -i swss rm -f /etc/supervisor/conf.d/ndppd.conf", ignore_error=True, return_cmd=True), - mock.call("docker exec -i swss supervisorctl update", return_cmd=True) + mock.call(['docker', 'exec', '-i', 'swss', 'supervisorctl', 'status', 'ndppd'], ignore_error=True, return_cmd=True), + mock.call(['docker', 'exec', '-i', 'swss', 'supervisorctl', 'stop', 'ndppd'], ignore_error=True, return_cmd=True), + mock.call(['docker', 'exec', '-i', 'swss', 'rm', '-f', '/etc/supervisor/conf.d/ndppd.conf'], ignore_error=True, return_cmd=True), + mock.call(['docker', 'exec', '-i', 'swss', 'supervisorctl', 'update'], return_cmd=True) ]) assert result.exit_code == 0