Skip to content

Commit

Permalink
[OpenWrt] Avoid adding dns and dns_search if proto is none
Browse files Browse the repository at this point in the history
Avoid adding "dns" and "dns_search" config options for interfaces
that have "proto" set to "none".
  • Loading branch information
nemesifier committed Apr 12, 2016
1 parent 6cf39d2 commit c588e5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions netjsonconfig/backends/openwrt/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def __get_dns_servers(self, uci, address):
# allow override
if 'dns' in uci:
return uci['dns']
# ignore if using DHCP
if address['proto'] == 'dhcp':
# ignore if using DHCP or if "proto" is none
if address['proto'] in ['dhcp', 'none']:
return None
# general setting
dns = self.config.get('dns_servers', None)
Expand All @@ -196,6 +196,9 @@ def __get_dns_search(self, uci, address):
# allow override
if 'dns_search' in uci:
return uci['dns_search']
# ignore if "proto" is none
if address['proto'] == 'none':
return None
# general setting
dns_search = self.config.get('dns_search', None)
if dns_search:
Expand Down
19 changes: 19 additions & 0 deletions tests/openwrt/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,25 @@ def test_dns_dhcpv6_ignored(self):
""")
self.assertEqual(o.render(), expected)

def test_dhcp_ignored_proto_none(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
}
],
"dns_servers": ["10.11.12.13", "8.8.8.8"],
"dns_search": ["netjson.org", "openwisp.org"],
})
expected = self._tabs("""package network
config interface 'eth0'
option ifname 'eth0'
option proto 'none'
""")
self.assertEqual(o.render(), expected)

def test_rules(self):
o = OpenWrt({
"ip_rules": [
Expand Down

0 comments on commit c588e5d

Please sign in to comment.