Skip to content
Permalink
Browse files

[OpenWrt] Allow to override general dns and dns_search settings

  • Loading branch information
nemesisdesign committed Mar 31, 2016
1 parent 05e00c7 commit a5f63f0ba1aab1d8d243e492a9f5fdcd838a9dd1
Showing with 54 additions and 4 deletions.
  1. +13 −4 netjsonconfig/backends/openwrt/renderers.py
  2. +41 −0 tests/openwrt/test_network.py
@@ -77,8 +77,8 @@ def _get_interfaces(self):
'name': name,
'ifname': interface['name'],
'proto': proto,
'dns': self.__get_dns_servers(),
'dns_search': self.__get_dns_search()
'dns': self.__get_dns_servers(uci_interface),
'dns_search': self.__get_dns_search(uci_interface)
})
# bridging
if is_bridge:
@@ -126,6 +126,7 @@ def __get_proto(self, interface, address):
else:
# allow override
return interface['proto']

def _get_routes(self):
routes = self.config.get('routes', [])
# results container
@@ -175,12 +176,20 @@ def _get_ip_rules(self):
uci_rules.append(sorted_dict(uci_rule))
return uci_rules

def __get_dns_servers(self):
def __get_dns_servers(self, uci):
# allow override
if 'dns' in uci:
return uci['dns']
# general setting
dns = self.config.get('dns_servers', None)
if dns:
return ' '.join(dns)

def __get_dns_search(self):
def __get_dns_search(self, uci):
# allow override
if 'dns_search' in uci:
return uci['dns_search']
# general setting
dns_search = self.config.get('dns_search', None)
if dns_search:
return ' '.join(dns_search)
@@ -948,3 +948,44 @@ def test_address_list_option(self):
""")
self.assertEqual(o.render(), expected)

def test_dns_override(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"dns": ["8.8.8.8", "8.8.4.4"]
}
],
"dns_servers": ["192.168.3.1", "192.168.3.2"]
})
expected = self._tabs("""package network
config interface 'eth0'
list dns '8.8.8.8'
list dns '8.8.4.4'
option ifname 'eth0'
option proto 'none'
""")
self.assertEqual(o.render(), expected)

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

0 comments on commit a5f63f0

Please sign in to comment.
You can’t perform that action at this time.