Skip to content

Commit

Permalink
[fix] Fixed parsing route without gateway #290
Browse files Browse the repository at this point in the history
Fixes #290
  • Loading branch information
nemesifier committed May 17, 2024
1 parent 8631f28 commit 052d14c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netjsonconfig/backends/openwrt/converters/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __netjson_route(self, route, i):
{
"device": route.pop('interface'),
"destination": str(ip_interface(network)),
"next": route.pop('gateway'),
"next": route.pop('gateway', ''),
"cost": route.pop(
'metric', self._schema['properties']['cost']['default']
),
Expand Down
34 changes: 34 additions & 0 deletions tests/openwrt/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@ def test_parse_routes(self):
o = OpenWrt(native=self._routes_uci)
self.assertEqual(o.config, self._routes_netjson)

_routes_nogw_netjson = {
"routes": [
{"device": "wan", "destination": "192.168.100.1/32", "next": "", "cost": 0}
]
}
_routes_nogw_uci = """package network
config route 'route1'
option interface 'wan'
option metric '0'
option netmask '255.255.255.255'
option target '192.168.100.1'
"""

def test_render_route_nogw(self):
o = OpenWrt(self._routes_nogw_netjson)
expected = self._tabs(self._routes_nogw_uci)
self.assertEqual(o.render(), expected)

def test_parse_routes_nogw(self):
o = OpenWrt(native=self._routes_nogw_uci)
self.assertEqual(o.config, self._routes_nogw_netjson)

with self.subTest('minimalistic route'):
minimal_uci = """package network
config route 'route1'
option interface 'wan'
option target '192.168.100.1'
option netmask '255.255.255.255'
"""
o = OpenWrt(native=minimal_uci)
self.assertEqual(o.config, self._routes_nogw_netjson)

_rules_netjson = {
"ip_rules": [
{
Expand Down

0 comments on commit 052d14c

Please sign in to comment.