Skip to content

Commit b4baaca

Browse files
committed
[fix] Add logging and regression test for update_config self-match fix
1 parent 5184471 commit b4baaca

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

openwisp_controller/connection/tasks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def update_config(self, device_id):
5353
logger.warning(f'update_config("{device_id}") failed: {e}')
5454
return
5555
if _is_update_in_progress(device_id, current_task_id=self.request.id):
56+
logger.info(
57+
f"Skipping update_config for device {device_id}"
58+
" because another update task is already running"
59+
)
5660
return
5761
try:
5862
device_conn = DeviceConnection.get_working_connection(device)

openwisp_controller/connection/tests/test_models.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222
from ..exceptions import NoWorkingDeviceConnectionError
2323
from ..signals import is_working_changed
24-
from ..tasks import _TASK_NAME, update_config
24+
from ..tasks import _TASK_NAME, _is_update_in_progress, update_config
2525
from .utils import CreateConnectionsMixin
2626

2727
Config = load_model("config", "Config")
@@ -1047,6 +1047,25 @@ def test_device_update_config_in_progress(
10471047
mocked_get_working_connection.assert_not_called()
10481048
update_config.assert_not_called()
10491049

1050+
def test_update_in_progress_ignores_current_task(self):
1051+
"""Regression test: _is_update_in_progress must not match the
1052+
currently running task, which would cause it to skip itself."""
1053+
conf = self._prepare_conf_object()
1054+
with mock.patch("celery.app.control.Inspect.active") as mocked_active:
1055+
mocked_active.return_value = {
1056+
"worker1": [
1057+
{
1058+
"name": _TASK_NAME,
1059+
"args": [str(conf.device.pk)],
1060+
"id": "current-task-id",
1061+
}
1062+
]
1063+
}
1064+
result = _is_update_in_progress(
1065+
conf.device.pk, current_task_id="current-task-id"
1066+
)
1067+
self.assertFalse(result)
1068+
10501069
@mock.patch("time.sleep")
10511070
@mock.patch.object(DeviceConnection, "update_config")
10521071
@mock.patch.object(DeviceConnection, "get_working_connection")

0 commit comments

Comments
 (0)