Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openwisp_controller/config/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_config(self):
return config
c = deepcopy(config)
is_config = not any([self.__template__, self.__vpn__])
if 'hostname' not in c.get('general', {}) and is_config:
if all(('hostname' not in c.get('general', {}), is_config, self.name)):
c.setdefault('general', {})
c['general']['hostname'] = self.name.replace(':', '-')
return c
Expand Down
2 changes: 1 addition & 1 deletion openwisp_controller/config/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def _should_use_dsa(self):

# Check if the device is using stock OpenWrt.
openwrt_match = re.search(
'[oO][pP][eE][nN][wW][rR][tT]\s*([\d.]+)', self.device.os
r'[oO][pP][eE][nN][wW][rR][tT]\s*([\d.]+)', self.device.os
)
if openwrt_match:
if version.parse(openwrt_match.group(1)) >= version.parse('21'):
Expand Down
5 changes: 5 additions & 0 deletions openwisp_controller/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ def test_auto_hostname(self):
c.refresh_from_db()
self.assertDictEqual(c.config, {'general': {}})

with self.subTest('missing name shall not raise exception'):
c.device.name = None
del c.backend_instance
self.assertDictEqual(c.backend_instance.config, {'general': {}})

def test_config_context(self):
config = {
'general': {
Expand Down
8 changes: 4 additions & 4 deletions openwisp_controller/config/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.utils.translation import gettext_lazy as _

key_validator = RegexValidator(
_lazy_re_compile('^[^\s/\.]+$'),
_lazy_re_compile(r'^[^\s/\.]+$'),
message=_('Key must not contain spaces, dots or slashes.'),
code='invalid',
)
Expand All @@ -16,9 +16,9 @@

# device name must either be a hostname or a valid mac address
hostname_regex = (
'^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}'
'[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9]'
'[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$'
r'^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}'
r'[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9]'
r'[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$'
)
device_name_validator = RegexValidator(
_lazy_re_compile('{0}|{1}'.format(hostname_regex, mac_address_regex)),
Expand Down
2 changes: 1 addition & 1 deletion openwisp_controller/connection/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
'type': 'string',
'minLength': 6,
'maxLength': 30,
'pattern': '[\S]',
'pattern': r'[\S]',
}
},
},
Expand Down
Loading