Skip to content

Commit

Permalink
[connections] Added support for management interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Dec 2, 2018
1 parent 14dfbf4 commit cbecd15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion openwisp_controller/config/views.py
Expand Up @@ -13,7 +13,7 @@ def get_default_templates(request, organization_id):
"""
user = request.user
authenticated = user.is_authenticated
if callable(authenticated):
if callable(authenticated): # pragma: nocover
authenticated = authenticated()
if not authenticated and not user.is_staff:
return HttpResponse(status=403)
Expand Down
10 changes: 5 additions & 5 deletions openwisp_controller/connection/models.py
Expand Up @@ -2,7 +2,7 @@
import ipaddress
import logging

from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
Expand Down Expand Up @@ -142,10 +142,10 @@ def get_addresses(self):
else:
for interface in get_interfaces():
address_list.append('{0}%{1}'.format(address, interface))
try:
address_list.append(self.device.config.last_ip)
except ObjectDoesNotExist:
pass
if self.device.management_ip:
address_list.append(self.device.management_ip)
if self.device.last_ip:
address_list.append(self.device.last_ip)
return address_list

def get_params(self):
Expand Down
21 changes: 14 additions & 7 deletions openwisp_controller/connection/tests/test_models.py
Expand Up @@ -129,9 +129,13 @@ def test_device_connection_schema(self):
else:
self.fail('ValidationError not raised')

def _prepare_address_list_test(self, addresses):
def _prepare_address_list_test(self, addresses,
last_ip=None,
management_ip=None):
update_strategy = app_settings.UPDATE_STRATEGIES[0][0]
device = self._create_device(organization=self._create_org())
device = self._create_device(organization=self._create_org(),
last_ip=last_ip,
management_ip=management_ip)
dc = self._create_device_connection(device=device,
update_strategy=update_strategy)
for index, address in enumerate(addresses):
Expand All @@ -147,13 +151,16 @@ def test_address_list(self):
'192.168.40.1'
])

def test_address_list_with_config_last_ip(self):
dc = self._prepare_address_list_test(['192.168.40.1'])
self._create_config(device=dc.device,
last_ip='10.40.0.2')
def test_address_list_with_device_ip(self):
dc = self._prepare_address_list_test(
['192.168.40.1'],
management_ip='10.0.0.2',
last_ip='84.32.46.153',
)
self.assertEqual(dc.get_addresses(), [
'192.168.40.1',
'10.40.0.2',
'10.0.0.2',
'84.32.46.153'
])

def test_address_list_link_local_ip(self):
Expand Down

0 comments on commit cbecd15

Please sign in to comment.