Skip to content

Commit

Permalink
[openwrt] Renamed enabled to disabled in OpenVPN secion
Browse files Browse the repository at this point in the history
In order to be consistent with the rest of the codebase,
the "enabled" attribute in the OpenVPN section of the
OpenWrt backend has been renamed to "disabled" and defaults
to False.
  • Loading branch information
nemesifier committed Jan 17, 2017
1 parent 88ef58c commit ffc4583
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/source/backends/openwrt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ The ``OpenWrt`` backend adds a few properties to the OpenVPN schema, see below.
+--------------------------+---------+--------------+-------------------------------------------------------------+
| key name | type | default | allowed values |
+==========================+=========+==============+=============================================================+
| ``enabled`` | boolean | ``True`` | |
| ``disabled`` | boolean | ``False`` | |
+--------------------------+---------+--------------+-------------------------------------------------------------+
OpenVPN example
Expand All @@ -2020,7 +2020,7 @@ The following *configuration dictionary*:
"dev": "tap0",
"dev_type": "tap",
"dh": "dh.pem",
"enabled": True,
"disabled": False,
"key": "key.pem",
"mode": "server",
"name": "test-vpn-server",
Expand Down
6 changes: 5 additions & 1 deletion netjsonconfig/backends/openwrt/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ class OpenVpnRenderer(BaseOpenWrtRenderer, BaseOpenVpnRenderer):
"""
def _transform_vpn(self, vpn):
config = super(OpenVpnRenderer, self)._transform_vpn(vpn)
if 'enabled' not in config:
if 'disabled' in config:
config['enabled'] = not config['disabled']
del config['disabled']
# TODO: keep 'enabled' check until 0.6 and then drop it
elif 'disabled' not in config and 'enabled' not in config:
config['enabled'] = True
return config
8 changes: 4 additions & 4 deletions netjsonconfig/backends/openwrt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@
"definitions": {
"tunnel": {
"properties": {
"enabled": {
"title": "enabled",
"description": "uncheck this to disable this VPN without deleting its configuration",
"disabled": {
"title": "disabled",
"description": "disable this VPN without deleting its configuration",
"type": "boolean",
"default": True,
"default": False,
"format": "checkbox",
"propertyOrder": 1
}
Expand Down
52 changes: 52 additions & 0 deletions tests/openwrt/test_openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,5 +404,57 @@ def test_server_bridge_routed(self):
option proto 'udp'
option server '10.8.0.0 255.255.0.0'
option tls_server '1'
""")
self.assertEqual(c.render(), expected)

def test_disabled(self):
c = OpenWrt({
"openvpn": [{
"ca": "ca.pem",
"cert": "cert.pem",
"dev": "tap0",
"dev_type": "tap",
"dh": "dh.pem",
"disabled": True,
"key": "key.pem",
"mode": "server",
"name": "test-properties",
"proto": "udp",
"tls_server": True
}]
})
self.assertIn("option enabled '0'", c.render())

def test_disabled_and_enabled(self):
# disabled wins over enabled since 0.5.3
c = OpenWrt({
"openvpn": [{
"ca": "ca.pem",
"cert": "cert.pem",
"dev": "tap0",
"dev_type": "tap",
"dh": "dh.pem",
"disabled": True,
"enabled": True,
"key": "key.pem",
"mode": "server",
"name": "test-properties",
"proto": "udp",
"tls_server": True
}]
})
expected = self._tabs("""package openvpn
config openvpn 'test_properties'
option ca 'ca.pem'
option cert 'cert.pem'
option dev 'tap0'
option dev_type 'tap'
option dh 'dh.pem'
option enabled '0'
option key 'key.pem'
option mode 'server'
option proto 'udp'
option tls_server '1'
""")
self.assertEqual(c.render(), expected)

0 comments on commit ffc4583

Please sign in to comment.