-
-
Notifications
You must be signed in to change notification settings - Fork 288
[fix] Invalidate controller views cache when org/group context variables change #1070 #1308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4e0ea20
707151e
97cbf14
a3abade
4aff88c
c8a3ecb
1a0bb83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,6 +433,67 @@ def test_changing_group_variable_invalidates_cache(self): | |
| new_checksum = config.get_cached_checksum() | ||
| self.assertNotEqual(old_checksum, new_checksum) | ||
|
|
||
| def test_status_update_on_org_variable_change(self): | ||
| org = self._get_org() | ||
| cs = OrganizationConfigSettings.objects.create(organization=org, context={}) | ||
| c1 = self._create_config(organization=org) | ||
| c1.templates.add( | ||
| self._create_template( | ||
| name="t-with-var", | ||
| config={"interfaces": [{"name": "{{ ssid }}", "type": "ethernet"}]}, | ||
| default_values={"ssid": "eth0"}, | ||
| ) | ||
| ) | ||
| c1.set_status_applied() | ||
| d2 = self._create_device( | ||
| organization=org, name="d2", mac_address="00:11:22:33:44:56" | ||
| ) | ||
| c2 = self._create_config(device=d2) | ||
| c2.set_status_applied() | ||
| cs.context = {"ssid": "OrgA"} | ||
| cs.full_clean() | ||
| cs.save() | ||
| c1.refresh_from_db() | ||
| c2.refresh_from_db() | ||
| with self.subTest("affected config changes to modified"): | ||
| self.assertEqual(c1.status, "modified") | ||
| with self.subTest("unaffected config remains applied"): | ||
| self.assertEqual(c2.status, "applied") | ||
|
Comment on lines
+436
to
+461
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider adding explicit mock assertion for org-level cache invalidation. The organization variable change test validates the status transition correctly, but unlike 💡 Suggested addition cs.context = {"ssid": "OrgA"}
cs.full_clean()
- cs.save()
+ patch_path = (
+ "openwisp_controller.config.base.multitenancy"
+ ".invalidate_controller_views_cache"
+ )
+ with mock.patch(patch_path) as mocked_task:
+ cs.save()
+ mocked_task.delay.assert_called_once_with(str(org.id))
c1.refresh_from_db()🤖 Prompt for AI Agents |
||
|
|
||
| def test_status_update_on_group_variable_change(self): | ||
| org = self._get_org() | ||
| dg = self._create_device_group(organization=org, context={}) | ||
| d1 = self._create_device(organization=org, group=dg) | ||
| c1 = self._create_config(device=d1) | ||
| c1.templates.add( | ||
| self._create_template( | ||
| name="t-with-var", | ||
| config={"interfaces": [{"name": "{{ ssid }}", "type": "ethernet"}]}, | ||
| default_values={"ssid": "eth0"}, | ||
| ) | ||
| ) | ||
| c1.set_status_applied() | ||
| d2 = self._create_device( | ||
| organization=org, group=dg, name="d2", mac_address="00:11:22:33:44:56" | ||
| ) | ||
| c2 = self._create_config(device=d2) | ||
| c2.set_status_applied() | ||
| dg.context = {"ssid": "OrgA"} | ||
| dg.full_clean() | ||
| patch_path = ( | ||
| "openwisp_controller.config.base.device_group" | ||
| ".invalidate_controller_views_for_group" | ||
| ) | ||
| with mock.patch(patch_path) as mocked_task: | ||
| dg.save() | ||
| mocked_task.delay.assert_called_once_with(str(dg.id)) | ||
| c1.refresh_from_db() | ||
| c2.refresh_from_db() | ||
| with self.subTest("affected config changes to modified"): | ||
| self.assertEqual(c1.status, "modified") | ||
| with self.subTest("unaffected config remains applied"): | ||
| self.assertEqual(c2.status, "applied") | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_management_ip_changed_not_emitted_on_creation(self): | ||
| with catch_signal(management_ip_changed) as handler: | ||
| self._create_device(organization=self._get_org()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider adding
soft_time_limitfor consistency with similar tasks.The new task lacks the
soft_time_limitparameter that other iteration-based tasks in this file use (e.g.,invalidate_controller_views_cacheimplicitly inherits defaults, but tasks likeupdate_template_related_config_statusexplicitly setsoft_time_limit=7200). For large device groups, this task could run longer than expected without a safeguard.💡 Suggested fix
🤖 Prompt for AI Agents