Skip to content

Commit cbecd15

Browse files
committed
[connections] Added support for management interface
1 parent 14dfbf4 commit cbecd15

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

openwisp_controller/config/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def get_default_templates(request, organization_id):
1313
"""
1414
user = request.user
1515
authenticated = user.is_authenticated
16-
if callable(authenticated):
16+
if callable(authenticated): # pragma: nocover
1717
authenticated = authenticated()
1818
if not authenticated and not user.is_staff:
1919
return HttpResponse(status=403)

openwisp_controller/connection/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import ipaddress
33
import logging
44

5-
from django.core.exceptions import ObjectDoesNotExist, ValidationError
5+
from django.core.exceptions import ValidationError
66
from django.db import models
77
from django.utils import timezone
88
from django.utils.encoding import python_2_unicode_compatible
@@ -142,10 +142,10 @@ def get_addresses(self):
142142
else:
143143
for interface in get_interfaces():
144144
address_list.append('{0}%{1}'.format(address, interface))
145-
try:
146-
address_list.append(self.device.config.last_ip)
147-
except ObjectDoesNotExist:
148-
pass
145+
if self.device.management_ip:
146+
address_list.append(self.device.management_ip)
147+
if self.device.last_ip:
148+
address_list.append(self.device.last_ip)
149149
return address_list
150150

151151
def get_params(self):

openwisp_controller/connection/tests/test_models.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ def test_device_connection_schema(self):
129129
else:
130130
self.fail('ValidationError not raised')
131131

132-
def _prepare_address_list_test(self, addresses):
132+
def _prepare_address_list_test(self, addresses,
133+
last_ip=None,
134+
management_ip=None):
133135
update_strategy = app_settings.UPDATE_STRATEGIES[0][0]
134-
device = self._create_device(organization=self._create_org())
136+
device = self._create_device(organization=self._create_org(),
137+
last_ip=last_ip,
138+
management_ip=management_ip)
135139
dc = self._create_device_connection(device=device,
136140
update_strategy=update_strategy)
137141
for index, address in enumerate(addresses):
@@ -147,13 +151,16 @@ def test_address_list(self):
147151
'192.168.40.1'
148152
])
149153

150-
def test_address_list_with_config_last_ip(self):
151-
dc = self._prepare_address_list_test(['192.168.40.1'])
152-
self._create_config(device=dc.device,
153-
last_ip='10.40.0.2')
154+
def test_address_list_with_device_ip(self):
155+
dc = self._prepare_address_list_test(
156+
['192.168.40.1'],
157+
management_ip='10.0.0.2',
158+
last_ip='84.32.46.153',
159+
)
154160
self.assertEqual(dc.get_addresses(), [
155161
'192.168.40.1',
156-
'10.40.0.2',
162+
'10.0.0.2',
163+
'84.32.46.153'
157164
])
158165

159166
def test_address_list_link_local_ip(self):

0 commit comments

Comments
 (0)