Skip to content

Fix KeyError in iproute pformat#3287

Merged
TheRealFalcon merged 3 commits into
canonical:mainfrom
zykovd:fix-key-error-iproute-pformat
May 12, 2023
Merged

Fix KeyError in iproute pformat#3287
TheRealFalcon merged 3 commits into
canonical:mainfrom
zykovd:fix-key-error-iproute-pformat

Conversation

@zykovd
Copy link
Copy Markdown
Contributor

@zykovd zykovd commented May 11, 2023

Fix KeyError in iproute pformat

This fixes KeyError on specific network configuration when running cloud-init on "network" stage. The same problem was mentioned in #746 and #1041.

summary: Fix KeyError in iproute pformat

This fixes KeyError on specific network configuration when 
running cloud-init on "network" stage. 

failed run of stage init
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 767, in status_wrapper
    ret = functor(name, args)
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 367, in main_init
    sys.stderr.write("%s\n" % (netinfo.debug_info()))
  File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 650, in debug_info
    route_lines = route_pformat().splitlines()
  File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 630, in route_pformat
    r["gateway"],
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

@TheRealFalcon TheRealFalcon self-assigned this May 11, 2023
Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @zykovd ! I left small comments inline, but overall this change looks good.

I noticed you added yourself to the CLA signers file, but have you signed the actual CLA too? I'm not seeing your information there. If you did, can you provide the date that you signed it?

Comment thread cloudinit/netinfo.py Outdated
r["flags"],
]
)
except Exception as e:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use KeyError here instead of Exception

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread cloudinit/netinfo.py Outdated
r["flags"],
]
)
except Exception as e:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@zykovd
Copy link
Copy Markdown
Contributor Author

zykovd commented May 11, 2023

Thanks for the contribution, @zykovd ! I left small comments inline, but overall this change looks good.

I noticed you added yourself to the CLA signers file, but have you signed the actual CLA too? I'm not seeing your information there. If you did, can you provide the date that you signed it?

I signed the CLA today, 05/11/2023

@zykovd zykovd requested a review from TheRealFalcon May 12, 2023 07:08
Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@TheRealFalcon TheRealFalcon merged commit 7c52b8a into canonical:main May 12, 2023
@zykovd zykovd deleted the fix-key-error-iproute-pformat branch May 12, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants