Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenWRT Parse/Native - Error parsing route with no Gateway assigned #290

Closed
shbatm opened this issue Nov 30, 2023 · 1 comment · Fixed by #295
Closed

OpenWRT Parse/Native - Error parsing route with no Gateway assigned #290

shbatm opened this issue Nov 30, 2023 · 1 comment · Fixed by #295
Assignees
Labels

Comments

@shbatm
Copy link

shbatm commented Nov 30, 2023

Received an error trying to parse my OpenWRT config (open native) because there was a route that does not have a gateway assigned (wan exit route to reach the modem).

>>> router = OpenWrt(native=open('./backup-sc-router-2023-11-30.tar.gz'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/c/Users/timjb/src/router/venv/lib/python3.11/site-packages/netjsonconfig/backends/openwrt/openwrt.py", line 51, in __init__
    super().__init__(config, native, templates, context)
  File "/mnt/c/Users/timjb/src/router/venv/lib/python3.11/site-packages/netjsonconfig/backends/base/backend.py", line 51, in __init__
    self.parse(native)
  File "/mnt/c/Users/timjb/src/router/venv/lib/python3.11/site-packages/netjsonconfig/backends/base/backend.py", line 329, in parse
    self.to_netjson()
  File "/mnt/c/Users/timjb/src/router/venv/lib/python3.11/site-packages/netjsonconfig/backends/base/backend.py", line 342, in to_netjson
    value = converter.to_netjson()
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/timjb/src/router/venv/lib/python3.11/site-packages/netjsonconfig/backends/base/converter.py", line 116, in to_netjson
    result = self.to_netjson_loop(block, result, index + 1)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/timjb/src/router/venv/lib/python3.11/site-packages/netjsonconfig/backends/openwrt/converters/routes.py", line 39, in to_netjson_loop
    rule = self.__netjson_route(block, index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/timjb/src/router/venv/lib/python3.11/site-packages/netjsonconfig/backends/openwrt/converters/routes.py", line 57, in __netjson_route
    "next": route.pop('gateway'),
            ^^^^^^^^^^^^^^^^^^^^
KeyError: 'gateway'

Valid config from OpenWRT:

config route
	option interface 'wan'
	option target '192.168.100.1'
	option netmask '255.255.255.255'
@nemesifier
Copy link
Member

Thanks for reporting @shbatm. Pull request #290 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

2 participants