Skip to content

Commit

Permalink
[change] Add VPN subnet CIDR to device system defined variables openw…
Browse files Browse the repository at this point in the history
  • Loading branch information
codesankalp authored Jun 23, 2022
1 parent 7dcc94c commit 5f49f34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openwisp_controller/config/base/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def get_vpn_server_context(self):
context[
context_keys['server_ip_network']
] = f'{self.ip.ip_address}/{self.subnet.subnet.max_prefixlen}'
context[context_keys['vpn_subnet']] = str(self.subnet.subnet)
return context

def get_system_context(self):
Expand Down Expand Up @@ -370,6 +371,7 @@ def _get_auto_context_keys(self):
{
'public_key': 'public_key_{}'.format(pk),
'ip_address': 'ip_address_{}'.format(pk),
'vpn_subnet': 'vpn_subnet_{}'.format(pk),
}
)
if self._is_backend_type('vxlan'):
Expand Down
2 changes: 2 additions & 0 deletions openwisp_controller/config/tests/test_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ def test_auto_peer_configuration(self):
self.assertEqual(context[f'ip_address_{pk}'], '10.0.0.2')
self.assertEqual(context[f'server_ip_address_{pk}'], '10.0.0.1')
self.assertEqual(context[f'server_ip_network_{pk}'], '10.0.0.1/32')
self.assertEqual(context[f'vpn_subnet_{pk}'], '10.0.0.0/16')
self.assertEqual(context[f'public_key_{pk}'], vpn.public_key)

with self.subTest('cache update when a new peer is added'):
Expand Down Expand Up @@ -776,6 +777,7 @@ def test_vxlan_config_creation(self):
self.assertEqual(context[f'ip_address_{pk}'], '10.0.0.2')
self.assertEqual(context[f'server_ip_address_{pk}'], '10.0.0.1')
self.assertEqual(context[f'server_ip_network_{pk}'], '10.0.0.1/32')
self.assertEqual(context[f'vpn_subnet_{pk}'], '10.0.0.0/16')
self.assertEqual(context[f'vni_{pk}'], '1')

with self.subTest('auto_cert=False'):
Expand Down

0 comments on commit 5f49f34

Please sign in to comment.