Skip to content

Commit

Permalink
Merge d4090f0 into 2bae0da
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Jul 31, 2023
2 parents 2bae0da + d4090f0 commit d3a4a9b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
7 changes: 4 additions & 3 deletions netjsonconfig/backends/openwrt/converters/zerotier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ class ZeroTier(OpenWrtConverter, BaseZeroTier):
def __intermediate_vpn(self, vpn):
vpn.update(
{
'.name': self._get_uci_name(vpn.pop('name')),
'.name': self._get_uci_name('ow_zt'),
'.type': 'zerotier',
'join': vpn.pop('id'),
'enabled': not vpn.pop('disabled', False),
}
)
del vpn['name']
return super().__intermediate_vpn(vpn, remove=[''])

def __netjson_vpn(self, vpn):
vpn['id'] = vpn.pop('join')
vpn['name'] = vpn.pop('.name').replace('_', '-')
# 'disabled' defaults to False in OpenWRT
vpn['name'] = vpn.pop('.name')
# 'enabled' defaults to False in OpenWRT
vpn['disabled'] = vpn.pop('enabled', '0') == '0'
del vpn['.type']
return super().__netjson_vpn(vpn)
5 changes: 3 additions & 2 deletions netjsonconfig/backends/zerotier/zerotier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class ZeroTier(BaseVpnBackend):
config_suffix = config_suffix

@classmethod
def auto_client(cls, name='', nwid=None, disabled=False):
def auto_client(cls, nwid=None, identity_secret=None, disabled=False):
nwid = nwid or ['']
return {
'id': nwid,
'name': name,
'name': 'ow_zt',
'secret': identity_secret,
'disabled': disabled,
}
10 changes: 7 additions & 3 deletions tests/openwrt/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,22 +548,26 @@ def test_vxlan_wireguard_auto_client(self):

def test_zerotier_auto_client(self):
with self.subTest('No arguments provided'):
expected = {'zerotier': [{'id': [''], 'name': '', 'disabled': False}]}
expected = {
'zerotier': [
{'id': [''], 'name': 'ow_zt', 'disabled': False, 'secret': None}
]
}
self.assertDictEqual(OpenWrt.zerotier_auto_client(), expected)
with self.subTest('Required arguments provided'):
expected = {
'zerotier': [
{
'id': ['9536600adf654321'],
'name': 'zerotier-openwisp-network',
'name': 'ow_zt',
'disabled': False,
'secret': None,
}
]
}
self.assertDictEqual(
OpenWrt.zerotier_auto_client(
nwid=['9536600adf654321'],
name='zerotier-openwisp-network',
),
expected,
)
8 changes: 4 additions & 4 deletions tests/openwrt/test_zerotier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestZeroTier(unittest.TestCase, _TabsMixin):
"zerotier": [
{
"id": ["9536600adf654321", "9536600adf654322"],
"name": "zerotier-openwisp-network",
"name": "ow_zt",
},
]
}
Expand All @@ -20,7 +20,7 @@ def test_render_zerotier(self):
expected = self._tabs(
"""package zerotier
config zerotier 'zerotier_openwisp_network'
config zerotier 'ow_zt'
option enabled '1'
list join '9536600adf654321'
list join '9536600adf654322'
Expand All @@ -32,7 +32,7 @@ def test_parse_zerotier(self):
native = self._tabs(
"""package zerotier
config zerotier 'zerotier_openwisp_network'
config zerotier 'ow_zt'
option enabled '0'
list join '9536600adf654321'
list join '9536600adf654322'
Expand All @@ -42,7 +42,7 @@ def test_parse_zerotier(self):
"zerotier": [
{
"id": ["9536600adf654321", "9536600adf654322"],
"name": "zerotier-openwisp-network",
"name": "ow_zt",
"disabled": True,
},
]
Expand Down
4 changes: 2 additions & 2 deletions tests/zerotier/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,14 @@ def test_generate(self):
def test_auto_client(self):
expected = {
"id": ["9536600adf654321"],
"name": "zerotier-openwisp-network",
"name": "ow_zt",
"disabled": False,
"secret": None,
}
test_config = self._TEST_CONFIG["zerotier"][0]
self.assertEqual(
ZeroTier.auto_client(
nwid=[test_config['id']],
name=test_config['name'],
),
expected,
)

0 comments on commit d3a4a9b

Please sign in to comment.