Skip to content

Fill entry['gateway'] for default IPv6 routes#1041

Closed
andgein wants to merge 1 commit into
canonical:mainfrom
andgein:patch-1
Closed

Fill entry['gateway'] for default IPv6 routes#1041
andgein wants to merge 1 commit into
canonical:mainfrom
andgein:patch-1

Conversation

@andgein
Copy link
Copy Markdown
Contributor

@andgein andgein commented Sep 29, 2021

Fill entry['gateway'] for default IPv6 routes

Otherwise this code (https://github.com/canonical/cloud-init/blob/main/cloudinit/netinfo.py#L478) fails with

failed run of stage init                                                                                     
------------------------------------------------------------                         
Traceback (most recent call last):                                                                           
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 652, in status_wrapper
    ret = functor(name, args)                                                                                
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 283, in main_init                        
    sys.stderr.write("%s\n" % (netinfo.debug_info()))                                                                                                                                                                      
  File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 496, in debug_info                        
    route_lines = route_pformat().splitlines()                                                               
  File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 480, in route_pformat                     
    r['gateway'], r['iface'], r['flags']])                                                                   
KeyError: 'gateway'                                                                                                                                                                                                        
------------------------------------------------------------   

Test Steps

  1. Create machine with custom default IPv6 route, i.e.
root@host:~# ip -o -6 route list table all
...                   
default dev eth1 proto static metric 50 pref medium 
...
  1. Run cloud-init init

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

Otherwise this code (https://github.com/canonical/cloud-init/blob/main/cloudinit/netinfo.py#L478) fails with

```
failed run of stage init                                                                                     
------------------------------------------------------------                         
Traceback (most recent call last):                                                                           
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 652, in status_wrapper
    ret = functor(name, args)                                                                                
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 283, in main_init                        
    sys.stderr.write("%s\n" % (netinfo.debug_info()))                                                                                                                                                                      
  File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 496, in debug_info                        
    route_lines = route_pformat().splitlines()                                                               
  File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 480, in route_pformat                     
    r['gateway'], r['iface'], r['flags']])                                                                   
KeyError: 'gateway'                                                                                                                                                                                                        
------------------------------------------------------------   
```
@andgein andgein changed the title Fill entry['gateway'] for IPv6 routes Fill entry['gateway'] for default IPv6 routes Sep 29, 2021
@andgein
Copy link
Copy Markdown
Contributor Author

andgein commented Sep 29, 2021

CLA signing pull request: #1042

@TheRealFalcon
Copy link
Copy Markdown
Contributor

@andgein , thanks for this.

Additionally, can you add a unit test at the end of test_netinfo.py? The last three tests are dealing with route_pformat, so hopefully it shouldn't be too hard to use them as examples for an additional test.

Also, just for context, this issue has come up before but never got over the finish line: #746 . Feel free to take any suggestions mentioned there, but personally, I don't think they are necessary because:

  1. We default ipv4 gateway to 0.0.0.0 even if it's not specified
  2. Other tools like route will print :: as the default gateway if not specified and don't seem to have a problem with it.

@github-actions
Copy link
Copy Markdown

Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close.

If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging mitechie, and he will ensure that someone takes a look soon.

(If the pull request is closed and you would like to continue working on it, please do tag mitechie to reopen it.)

@github-actions github-actions Bot added the stale-pr Pull request is stale; will be auto-closed soon label Oct 14, 2021
@github-actions github-actions Bot closed this Oct 21, 2021
@zykovd zykovd mentioned this pull request May 11, 2023
3 tasks
TheRealFalcon pushed a commit that referenced this pull request May 12, 2023
This fixes KeyError on specific network configuration when running
cloud-init on "network" stage. The same problem was mentioned in
#746 and #1041.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale-pr Pull request is stale; will be auto-closed soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants