From 83718c231c4060394c6cf7f8620da4af0f9a1fea Mon Sep 17 00:00:00 2001 From: eugene-yujinwu Date: Fri, 3 Apr 2026 12:25:43 +0800 Subject: [PATCH 1/7] providers/base: fix race condition in turn_down_nm_connections nmcli returns exit code 10 when a connection is not active. There is a race condition where _get_nm_wireless_connections() reports a connection as 'activated', but by the time 'nmcli c down ' is called the connection has already gone inactive. This caused sp.check_call() to raise CalledProcessError, failing the test. Replace sp.check_call() with sp.call() and treat exit code 10 as success, since the goal (connection is down) has already been achieved. Any other non-zero exit code still raises CalledProcessError. Add a unit test to cover the race condition (exit code 10 must not raise). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- providers/base/bin/wifi_nmcli_test.py | 5 ++- providers/base/tests/test_wifi_nmcli_test.py | 34 ++++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/providers/base/bin/wifi_nmcli_test.py b/providers/base/bin/wifi_nmcli_test.py index 31affc98bb..0c6242b2df 100755 --- a/providers/base/bin/wifi_nmcli_test.py +++ b/providers/base/bin/wifi_nmcli_test.py @@ -100,7 +100,10 @@ def turn_down_nm_connections(): print("Turn down connection", name) cmd = "nmcli c down {}".format(uuid) print_cmd(cmd) - sp.check_call(shlex.split(cmd)) + ret = sp.call(shlex.split(cmd)) + # exit code 10: connection is not active — already down, that's fine + if ret not in (0, 10): + raise sp.CalledProcessError(ret, cmd) print("{} {} is down now".format(name, uuid)) print() diff --git a/providers/base/tests/test_wifi_nmcli_test.py b/providers/base/tests/test_wifi_nmcli_test.py index 26683277c0..efabb1bf63 100644 --- a/providers/base/tests/test_wifi_nmcli_test.py +++ b/providers/base/tests/test_wifi_nmcli_test.py @@ -149,7 +149,7 @@ def test_no_connections_to_turn_down( self.assertEqual(get_connections_mock.call_count, 1) sp_call_mock.assert_not_called() - @patch("wifi_nmcli_test.sp.check_call") + @patch("wifi_nmcli_test.sp.call", return_value=0) @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={ @@ -158,31 +158,45 @@ def test_no_connections_to_turn_down( }, ) def test_turn_down_single_connection( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_call_mock ): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_check_call_mock.assert_called_once_with( + sp_call_mock.assert_called_once_with( "nmcli c down uuid1".split() ) - @patch("wifi_nmcli_test.sp.check_call") + @patch("wifi_nmcli_test.sp.call", return_value=10) + @patch( + "wifi_nmcli_test._get_nm_wireless_connections", + return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, + ) + def test_turn_down_connection_already_inactive( + self, get_connections_mock, sp_call_mock + ): + # exit code 10 means connection is not active — should not raise + turn_down_nm_connections() + self.assertEqual(get_connections_mock.call_count, 1) + sp_call_mock.assert_called_once_with( + "nmcli c down uuid1".split() + ) + + @patch("wifi_nmcli_test.sp.call", return_value=1) @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, ) def test_turn_down_single_connection_with_exception( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_call_mock ): - sp_check_call_mock.side_effect = subprocess.CalledProcessError("", 1) with self.assertRaises(subprocess.CalledProcessError): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_check_call_mock.assert_called_once_with( + sp_call_mock.assert_called_once_with( "nmcli c down uuid1".split() ) - @patch("wifi_nmcli_test.sp.check_call") + @patch("wifi_nmcli_test.sp.call", return_value=0) @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={ @@ -191,7 +205,7 @@ def test_turn_down_single_connection_with_exception( }, ) def test_turn_down_multiple_connections( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_call_mock ): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) @@ -199,7 +213,7 @@ def test_turn_down_multiple_connections( call("nmcli c down uuid1".split()), call("nmcli c down uuid2".split()), ] - sp_check_call_mock.assert_has_calls(calls, any_order=True) + sp_call_mock.assert_has_calls(calls, any_order=True) class TestDeleteTestApSsidConnection(unittest.TestCase): From a8e61583bd3e08ef2ffab11d4e92bd6d121c65bd Mon Sep 17 00:00:00 2001 From: eugene-yujinwu Date: Fri, 3 Apr 2026 17:08:50 +0800 Subject: [PATCH 2/7] providers/base: fix black formatting in test_wifi_nmcli_test.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- providers/base/tests/test_wifi_nmcli_test.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/providers/base/tests/test_wifi_nmcli_test.py b/providers/base/tests/test_wifi_nmcli_test.py index efabb1bf63..4d398212c6 100644 --- a/providers/base/tests/test_wifi_nmcli_test.py +++ b/providers/base/tests/test_wifi_nmcli_test.py @@ -162,9 +162,7 @@ def test_turn_down_single_connection( ): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_call_mock.assert_called_once_with( - "nmcli c down uuid1".split() - ) + sp_call_mock.assert_called_once_with("nmcli c down uuid1".split()) @patch("wifi_nmcli_test.sp.call", return_value=10) @patch( @@ -177,9 +175,7 @@ def test_turn_down_connection_already_inactive( # exit code 10 means connection is not active — should not raise turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_call_mock.assert_called_once_with( - "nmcli c down uuid1".split() - ) + sp_call_mock.assert_called_once_with("nmcli c down uuid1".split()) @patch("wifi_nmcli_test.sp.call", return_value=1) @patch( @@ -192,9 +188,7 @@ def test_turn_down_single_connection_with_exception( with self.assertRaises(subprocess.CalledProcessError): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_call_mock.assert_called_once_with( - "nmcli c down uuid1".split() - ) + sp_call_mock.assert_called_once_with("nmcli c down uuid1".split()) @patch("wifi_nmcli_test.sp.call", return_value=0) @patch( From 7cdd029fdabc94ed09392ab03d39b05f080c4f0a Mon Sep 17 00:00:00 2001 From: eugene-yujinwu Date: Tue, 14 Apr 2026 13:42:23 +0800 Subject: [PATCH 3/7] providers/base: refactor turn_down_nm_connections to use try/except Replace sp.call() + manual return code check with sp.check_call() wrapped in a try/except block, as suggested in code review. This is more Pythonic: check_call() expresses the expectation of success, while the except clause clearly documents the one tolerated exception (exit code 10: connection already inactive). Also use bare 'raise' instead of 'raise e' to preserve the original traceback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- providers/base/bin/wifi_nmcli_test.py | 10 +++--- providers/base/tests/test_wifi_nmcli_test.py | 32 +++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/providers/base/bin/wifi_nmcli_test.py b/providers/base/bin/wifi_nmcli_test.py index 0c6242b2df..636f242b3b 100755 --- a/providers/base/bin/wifi_nmcli_test.py +++ b/providers/base/bin/wifi_nmcli_test.py @@ -100,10 +100,12 @@ def turn_down_nm_connections(): print("Turn down connection", name) cmd = "nmcli c down {}".format(uuid) print_cmd(cmd) - ret = sp.call(shlex.split(cmd)) - # exit code 10: connection is not active — already down, that's fine - if ret not in (0, 10): - raise sp.CalledProcessError(ret, cmd) + try: + sp.check_call(shlex.split(cmd)) + except sp.CalledProcessError as e: + # exit code 10: connection is not active — already down, that's fine + if e.returncode != 10: + raise print("{} {} is down now".format(name, uuid)) print() diff --git a/providers/base/tests/test_wifi_nmcli_test.py b/providers/base/tests/test_wifi_nmcli_test.py index 4d398212c6..999fd50e5d 100644 --- a/providers/base/tests/test_wifi_nmcli_test.py +++ b/providers/base/tests/test_wifi_nmcli_test.py @@ -140,16 +140,16 @@ def test_connection_activation_fails_due_to_exception( class TestTurnDownNmConnections(unittest.TestCase): - @patch("wifi_nmcli_test.sp.call") + @patch("wifi_nmcli_test.sp.check_call") @patch("wifi_nmcli_test._get_nm_wireless_connections", return_value={}) def test_no_connections_to_turn_down( - self, get_connections_mock, sp_call_mock + self, get_connections_mock, sp_check_call_mock ): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_call_mock.assert_not_called() + sp_check_call_mock.assert_not_called() - @patch("wifi_nmcli_test.sp.call", return_value=0) + @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={ @@ -158,39 +158,41 @@ def test_no_connections_to_turn_down( }, ) def test_turn_down_single_connection( - self, get_connections_mock, sp_call_mock + self, get_connections_mock, sp_check_call_mock ): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) - @patch("wifi_nmcli_test.sp.call", return_value=10) + @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, ) def test_turn_down_connection_already_inactive( - self, get_connections_mock, sp_call_mock + self, get_connections_mock, sp_check_call_mock ): # exit code 10 means connection is not active — should not raise + sp_check_call_mock.side_effect = subprocess.CalledProcessError(10, "") turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) - @patch("wifi_nmcli_test.sp.call", return_value=1) + @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, ) def test_turn_down_single_connection_with_exception( - self, get_connections_mock, sp_call_mock + self, get_connections_mock, sp_check_call_mock ): + sp_check_call_mock.side_effect = subprocess.CalledProcessError(1, "") with self.assertRaises(subprocess.CalledProcessError): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) - sp_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) - @patch("wifi_nmcli_test.sp.call", return_value=0) + @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={ @@ -199,7 +201,7 @@ def test_turn_down_single_connection_with_exception( }, ) def test_turn_down_multiple_connections( - self, get_connections_mock, sp_call_mock + self, get_connections_mock, sp_check_call_mock ): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) @@ -207,7 +209,7 @@ def test_turn_down_multiple_connections( call("nmcli c down uuid1".split()), call("nmcli c down uuid2".split()), ] - sp_call_mock.assert_has_calls(calls, any_order=True) + sp_check_call_mock.assert_has_calls(calls, any_order=True) class TestDeleteTestApSsidConnection(unittest.TestCase): From 6cd177280b8f11d331e3a96bda0518fb2e868fd3 Mon Sep 17 00:00:00 2001 From: eugene-yujinwu Date: Tue, 14 Apr 2026 16:44:30 +0800 Subject: [PATCH 4/7] providers/base: fix race condition by pre-checking UUID state before turn down Instead of catching exit code 10 from 'nmcli c down', re-check the specific connection's state via UUID right before issuing the down command: nmcli -t -f GENERAL.STATE c show If the connection is no longer activated (e.g. it was deactivated by NM automatically after another connection was brought down), skip it with a warning instead of calling 'nmcli c down'. This avoids relying on exit code interpretation and makes the intent explicit. Updated tests mock sp.check_output for the per-UUID state check and add a dedicated test case for the already-inactive scenario. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- providers/base/bin/wifi_nmcli_test.py | 19 +++++--- providers/base/tests/test_wifi_nmcli_test.py | 47 +++++++++++++++----- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/providers/base/bin/wifi_nmcli_test.py b/providers/base/bin/wifi_nmcli_test.py index 636f242b3b..82b3ec6a44 100755 --- a/providers/base/bin/wifi_nmcli_test.py +++ b/providers/base/bin/wifi_nmcli_test.py @@ -98,14 +98,21 @@ def turn_down_nm_connections(): continue uuid = value["uuid"] print("Turn down connection", name) + # Re-check this specific UUID's state right before calling down + # to handle the race condition where a connection becomes inactive + # between the initial query and this point (e.g. another connection + # was brought down first, causing NM to deactivate this one too). + check_cmd = "nmcli -t -f GENERAL.STATE c show {}".format(uuid) + print_cmd(check_cmd) + current_state = sp.check_output( + shlex.split(check_cmd), universal_newlines=True + ).strip() + if current_state != "GENERAL.STATE:activated": + print("WARN: {} is no longer active, skipping".format(name)) + continue cmd = "nmcli c down {}".format(uuid) print_cmd(cmd) - try: - sp.check_call(shlex.split(cmd)) - except sp.CalledProcessError as e: - # exit code 10: connection is not active — already down, that's fine - if e.returncode != 10: - raise + sp.check_call(shlex.split(cmd)) print("{} {} is down now".format(name, uuid)) print() diff --git a/providers/base/tests/test_wifi_nmcli_test.py b/providers/base/tests/test_wifi_nmcli_test.py index 999fd50e5d..b6c77686a3 100644 --- a/providers/base/tests/test_wifi_nmcli_test.py +++ b/providers/base/tests/test_wifi_nmcli_test.py @@ -140,15 +140,21 @@ def test_connection_activation_fails_due_to_exception( class TestTurnDownNmConnections(unittest.TestCase): + @patch("wifi_nmcli_test.sp.check_output") @patch("wifi_nmcli_test.sp.check_call") @patch("wifi_nmcli_test._get_nm_wireless_connections", return_value={}) def test_no_connections_to_turn_down( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_check_call_mock, sp_check_output_mock ): turn_down_nm_connections() self.assertEqual(get_connections_mock.call_count, 1) + sp_check_output_mock.assert_not_called() sp_check_call_mock.assert_not_called() + @patch( + "wifi_nmcli_test.sp.check_output", + return_value="GENERAL.STATE:activated", + ) @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", @@ -158,40 +164,56 @@ def test_no_connections_to_turn_down( }, ) def test_turn_down_single_connection( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_check_call_mock, sp_check_output_mock ): turn_down_nm_connections() - self.assertEqual(get_connections_mock.call_count, 1) + sp_check_output_mock.assert_called_once_with( + "nmcli -t -f GENERAL.STATE c show uuid1".split(), + universal_newlines=True, + ) sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + @patch( + "wifi_nmcli_test.sp.check_output", + return_value="GENERAL.STATE:deactivated", + ) @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, ) def test_turn_down_connection_already_inactive( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_check_call_mock, sp_check_output_mock ): - # exit code 10 means connection is not active — should not raise - sp_check_call_mock.side_effect = subprocess.CalledProcessError(10, "") + # UUID state re-check shows connection already inactive — skip down turn_down_nm_connections() - self.assertEqual(get_connections_mock.call_count, 1) - sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + sp_check_output_mock.assert_called_once_with( + "nmcli -t -f GENERAL.STATE c show uuid1".split(), + universal_newlines=True, + ) + sp_check_call_mock.assert_not_called() + @patch( + "wifi_nmcli_test.sp.check_output", + return_value="GENERAL.STATE:activated", + ) @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, ) def test_turn_down_single_connection_with_exception( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_check_call_mock, sp_check_output_mock ): sp_check_call_mock.side_effect = subprocess.CalledProcessError(1, "") with self.assertRaises(subprocess.CalledProcessError): turn_down_nm_connections() - self.assertEqual(get_connections_mock.call_count, 1) sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + @patch( + "wifi_nmcli_test.sp.check_output", + return_value="GENERAL.STATE:activated", + ) @patch("wifi_nmcli_test.sp.check_call") @patch( "wifi_nmcli_test._get_nm_wireless_connections", @@ -201,10 +223,11 @@ def test_turn_down_single_connection_with_exception( }, ) def test_turn_down_multiple_connections( - self, get_connections_mock, sp_check_call_mock + self, get_connections_mock, sp_check_call_mock, sp_check_output_mock ): turn_down_nm_connections() - self.assertEqual(get_connections_mock.call_count, 1) + # one UUID state check per activated connection + self.assertEqual(sp_check_output_mock.call_count, 2) calls = [ call("nmcli c down uuid1".split()), call("nmcli c down uuid2".split()), From 05dee4a7a4fd8b783ebf00cf0891210f334248e1 Mon Sep 17 00:00:00 2001 From: eugene-yujinwu Date: Tue, 14 Apr 2026 18:12:41 +0800 Subject: [PATCH 5/7] providers/base: fix black formatting in test_wifi_nmcli_test.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- providers/base/tests/test_wifi_nmcli_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/providers/base/tests/test_wifi_nmcli_test.py b/providers/base/tests/test_wifi_nmcli_test.py index b6c77686a3..fd5a23d1db 100644 --- a/providers/base/tests/test_wifi_nmcli_test.py +++ b/providers/base/tests/test_wifi_nmcli_test.py @@ -171,7 +171,9 @@ def test_turn_down_single_connection( "nmcli -t -f GENERAL.STATE c show uuid1".split(), universal_newlines=True, ) - sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + sp_check_call_mock.assert_called_once_with( + "nmcli c down uuid1".split() + ) @patch( "wifi_nmcli_test.sp.check_output", @@ -208,7 +210,9 @@ def test_turn_down_single_connection_with_exception( sp_check_call_mock.side_effect = subprocess.CalledProcessError(1, "") with self.assertRaises(subprocess.CalledProcessError): turn_down_nm_connections() - sp_check_call_mock.assert_called_once_with("nmcli c down uuid1".split()) + sp_check_call_mock.assert_called_once_with( + "nmcli c down uuid1".split() + ) @patch( "wifi_nmcli_test.sp.check_output", From b90e2db0e9377959a0898f93c59c0f1ef43f8e1f Mon Sep 17 00:00:00 2001 From: eugene-yujinwu Date: Tue, 14 Apr 2026 18:34:31 +0800 Subject: [PATCH 6/7] providers/base: handle exit code 10 from nmcli c down as success The pre-check (nmcli -t -f GENERAL.STATE c show ) reduces the race window, but a connection can still become inactive in the narrow gap between the pre-check and the actual 'nmcli c down' call. Add a try/except around check_call to treat exit code 10 as success in that case, and add a dedicated test to cover this path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- providers/base/bin/wifi_nmcli_test.py | 10 ++++++++- providers/base/tests/test_wifi_nmcli_test.py | 23 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/providers/base/bin/wifi_nmcli_test.py b/providers/base/bin/wifi_nmcli_test.py index 82b3ec6a44..b531f0050b 100755 --- a/providers/base/bin/wifi_nmcli_test.py +++ b/providers/base/bin/wifi_nmcli_test.py @@ -112,7 +112,15 @@ def turn_down_nm_connections(): continue cmd = "nmcli c down {}".format(uuid) print_cmd(cmd) - sp.check_call(shlex.split(cmd)) + try: + sp.check_call(shlex.split(cmd)) + except sp.CalledProcessError as e: + # The connection may have gone inactive in the narrow window + # between the state pre-check and this call. Exit code 10 + # ("connection/device/AP does not exist") means it is already + # down — treat as success. + if e.returncode != 10: + raise print("{} {} is down now".format(name, uuid)) print() diff --git a/providers/base/tests/test_wifi_nmcli_test.py b/providers/base/tests/test_wifi_nmcli_test.py index fd5a23d1db..6f5bad9e79 100644 --- a/providers/base/tests/test_wifi_nmcli_test.py +++ b/providers/base/tests/test_wifi_nmcli_test.py @@ -195,6 +195,29 @@ def test_turn_down_connection_already_inactive( ) sp_check_call_mock.assert_not_called() + @patch( + "wifi_nmcli_test.sp.check_output", + return_value="GENERAL.STATE:activated", + ) + @patch("wifi_nmcli_test.sp.check_call") + @patch( + "wifi_nmcli_test._get_nm_wireless_connections", + return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, + ) + def test_turn_down_connection_goes_inactive_during_down( + self, get_connections_mock, sp_check_call_mock, sp_check_output_mock + ): + # Pre-check passes (activated), but nmcli c down returns exit code 10 + # because the connection went inactive in the narrow window between + # the pre-check and the down call — should not raise. + sp_check_call_mock.side_effect = subprocess.CalledProcessError( + 10, "nmcli c down uuid1" + ) + turn_down_nm_connections() + sp_check_call_mock.assert_called_once_with( + "nmcli c down uuid1".split() + ) + @patch( "wifi_nmcli_test.sp.check_output", return_value="GENERAL.STATE:activated", From c14a863f158cfbbf9e397af01bed9406a7c81334 Mon Sep 17 00:00:00 2001 From: eugene-yujinwu Date: Tue, 14 Apr 2026 18:41:01 +0800 Subject: [PATCH 7/7] providers/base: revert exit code 10 handling from nmcli c down If nmcli c down returns exit code 10 in the narrow window after the pre-check, let it fail rather than silently ignoring it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- providers/base/bin/wifi_nmcli_test.py | 10 +-------- providers/base/tests/test_wifi_nmcli_test.py | 23 -------------------- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/providers/base/bin/wifi_nmcli_test.py b/providers/base/bin/wifi_nmcli_test.py index b531f0050b..82b3ec6a44 100755 --- a/providers/base/bin/wifi_nmcli_test.py +++ b/providers/base/bin/wifi_nmcli_test.py @@ -112,15 +112,7 @@ def turn_down_nm_connections(): continue cmd = "nmcli c down {}".format(uuid) print_cmd(cmd) - try: - sp.check_call(shlex.split(cmd)) - except sp.CalledProcessError as e: - # The connection may have gone inactive in the narrow window - # between the state pre-check and this call. Exit code 10 - # ("connection/device/AP does not exist") means it is already - # down — treat as success. - if e.returncode != 10: - raise + sp.check_call(shlex.split(cmd)) print("{} {} is down now".format(name, uuid)) print() diff --git a/providers/base/tests/test_wifi_nmcli_test.py b/providers/base/tests/test_wifi_nmcli_test.py index 6f5bad9e79..fd5a23d1db 100644 --- a/providers/base/tests/test_wifi_nmcli_test.py +++ b/providers/base/tests/test_wifi_nmcli_test.py @@ -195,29 +195,6 @@ def test_turn_down_connection_already_inactive( ) sp_check_call_mock.assert_not_called() - @patch( - "wifi_nmcli_test.sp.check_output", - return_value="GENERAL.STATE:activated", - ) - @patch("wifi_nmcli_test.sp.check_call") - @patch( - "wifi_nmcli_test._get_nm_wireless_connections", - return_value={"Wireless1": {"uuid": "uuid1", "state": "activated"}}, - ) - def test_turn_down_connection_goes_inactive_during_down( - self, get_connections_mock, sp_check_call_mock, sp_check_output_mock - ): - # Pre-check passes (activated), but nmcli c down returns exit code 10 - # because the connection went inactive in the narrow window between - # the pre-check and the down call — should not raise. - sp_check_call_mock.side_effect = subprocess.CalledProcessError( - 10, "nmcli c down uuid1" - ) - turn_down_nm_connections() - sp_check_call_mock.assert_called_once_with( - "nmcli c down uuid1".split() - ) - @patch( "wifi_nmcli_test.sp.check_output", return_value="GENERAL.STATE:activated",