Skip to content

Commit a56d0aa

Browse files
committed
[chores] Miscellaneous improvements
1 parent 4d68f93 commit a56d0aa

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

openwisp_controller/config/base/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@
2323
)
2424
from ..sortedm2m.fields import SortedManyToManyField
2525
from ..utils import get_default_templates_queryset
26-
from .base import BaseConfig, ChecksumCacheMixin
26+
from .base import BaseConfig, ChecksumCacheMixin, get_cached_args_rewrite
2727

2828
logger = logging.getLogger(__name__)
2929

3030

31+
def get_cached_checksum_args_rewrite(config):
32+
"""
33+
DEPRECATED: Use get_cached_args_rewrite instead.
34+
35+
"""
36+
return get_cached_args_rewrite(config)
37+
38+
3139
class TemplatesThrough(object):
3240
"""
3341
Improves string representation of m2m relationship objects

openwisp_controller/config/base/vpn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Meta:
148148
def __init__(self, *args, **kwargs):
149149
super().__init__(*args, **kwargs)
150150
# for internal usage
151-
self._should_send_vpn_modified_after_save = False
151+
self._send_vpn_modified_after_save = False
152152

153153
def clean(self, *args, **kwargs):
154154
super().clean(*args, **kwargs)
@@ -280,10 +280,10 @@ def save(self, *args, **kwargs):
280280
raise e
281281
if create_dh:
282282
transaction.on_commit(lambda: create_vpn_dh.delay(self.id))
283-
if not created and self._should_send_vpn_modified_after_save:
283+
if not created and self._send_vpn_modified_after_save:
284284
self.invalidate_checksum_cache()
285285
self._send_vpn_modified_signal()
286-
self._should_send_vpn_modified_after_save = False
286+
self._send_vpn_modified_after_save = False
287287
# For ZeroTier VPN server, if the
288288
# ZeroTier network is created successfully,
289289
# this method triggers a background task to
@@ -310,7 +310,7 @@ def _check_changes(self):
310310
current = self._meta.model.objects.only(*attrs).get(pk=self.pk)
311311
for attr in attrs:
312312
if getattr(self, attr) != getattr(current, attr):
313-
self._should_send_vpn_modified_after_save = True
313+
self._send_vpn_modified_after_save = True
314314
break
315315

316316
def _send_vpn_modified_signal(self):

openwisp_controller/config/controller/views.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,9 @@ class GetVpnView(SingleObjectMixin, View):
475475
model = Vpn
476476

477477
def get_object(self, *args, **kwargs):
478-
queryset = (
479-
self.model.objects.select_related("organization")
480-
.filter(Q(organization__is_active=True) | Q(organization__isnull=True))
481-
.select_related("ca", "cert", "subnet", "ip")
482-
)
478+
queryset = self.model.objects.select_related(
479+
"organization", "ca", "cert", "subnet", "ip"
480+
).filter(Q(organization__is_active=True) | Q(organization__isnull=True))
483481
return get_object_or_404(queryset, *args, **kwargs)
484482

485483
@cache_memoize(

openwisp_controller/config/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ def invalidate_controller_views_cache(organization_id):
183183
@shared_task(base=OpenwispCeleryTask)
184184
def invalidate_device_checksum_view_cache(organization_id):
185185
"""
186-
Deprecated: Use invalidate_controller_views_cache instead.
186+
DEPRECATED: Use invalidate_controller_views_cache instead.
187187
"""
188188
return invalidate_controller_views_cache(organization_id)

openwisp_controller/config/tests/test_vpn.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import uuid
23
from subprocess import CalledProcessError, TimeoutExpired
34
from unittest import mock
45

@@ -19,7 +20,7 @@
1920
from ..exceptions import ZeroTierIdentityGenerationError
2021
from ..settings import API_TASK_RETRY_OPTIONS
2122
from ..signals import config_modified, vpn_peers_changed, vpn_server_modified
22-
from ..tasks import create_vpn_dh
23+
from ..tasks import create_vpn_dh, trigger_vpn_server_endpoint
2324
from .utils import (
2425
CreateConfigTemplateMixin,
2526
TestVpnX509Mixin,
@@ -715,6 +716,16 @@ def test_cache_invalidation_on_vpn_changes(self):
715716
self.assertNotEqual(initial_checksum, vpn.get_cached_checksum())
716717
self.assertNotEqual(initial_config, vpn.get_cached_configuration())
717718

719+
def test_trigger_vpn_server_endpoint_invalid_vpn_id(self):
720+
with mock.patch("logging.Logger.error") as mocked_logger:
721+
vpn_id = uuid.uuid4().hex
722+
trigger_vpn_server_endpoint(
723+
endpoint="https://vpn_updater", auth_token="secret", vpn_id=vpn_id
724+
)
725+
mocked_logger.assert_called_once_with(
726+
f"VPN Server UUID: {vpn_id} does not exist."
727+
)
728+
718729

719730
class TestWireguardTransaction(BaseTestVpn, TestWireguardVpnMixin, TransactionTestCase):
720731
def test_auto_peer_configuration(self):

0 commit comments

Comments
 (0)