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

refactor: remove dependency on netifaces #4634

Merged
merged 7 commits into from
Mar 5, 2024

Conversation

catmsred
Copy link
Collaborator

netifaces is no longer being maintained and is only used by the VMWare data source. As such this commit replaces the calls to netifaces with cloudinit's native netinfo.

Proposed Commit Message

refactor: remove dependency on netifaces

netifaces is no longer being maintained and is only used by the VMWare data source.  As such this commit replaces the calls to netifaces with cloudinit's native netinfo.

Additional Context

This is related to #953. I have tagged is as WIP at this time because I would like to do more testing on VMWare directly to ensure the updated code works in an environment without mocks.

Checklist

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

@catmsred catmsred force-pushed the feature/remove_netifaces branch from 3c605bc to 8955aae Compare November 28, 2023 15:48
@catmsred
Copy link
Collaborator Author

@akutz @PengpengSun This PR proposes replacing VMWare's dependence on netifaces (which is no longer being actively maintained) with cloud-init's netinfo. I know there was a previous thread that discussed this and there is an extensive comment at the top of cloudinit/sources/DataSourceVMware.py explaining VMWare's preference for netifaces. There were three main points listed as follows:

  • Netifaces is built in C and is more portable across multiple system and more deterministic than shell exec'ing local network commands and parsing their output. Is this still true with netifaces no longer being maintained?
  • Netifaces provides a stable way to determine the view of the host's network after DHCP has brought the network online. Can you provide more clarification on the specific testing you did that gave you inconsistent data with netinfo?
  • It is currently possible to execute this datasource on macOS (which many developers use today) to print the output of the get_host_info function. The commands executed by netdev_info are fully functional on my Mac environment; is this still a concern?

If you have some time could you validate that this PR works as you expect in a VMWare environment? I have updated the unit tests but obviously that uses mocks for networking set up and may not hit all the points that concerned you when you originally introduced netifaces into the code base.

Thanks!

@akutz
Copy link
Contributor

akutz commented Nov 29, 2023

Hi @catmsred,

I will take a look, thank you for working on this!

Copy link
Member

@holmanb holmanb 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 your effort on this @catmsred!

Dropping this dependency will help reduce cloud image size requirements due to cloud-init and standardize networking code paths across datasources. This gives us one less datasource variance to have to maintain and reason about.

I know that this is still WIP, but there are few more items that we will want to take care of as part of this change. I know that you're probably waiting on feedback from @akutz and probably testing feedback before doing more work on this.

You mentioned removing the comment at the top of cloudinit/sources/DataSourceVMware.py already when we chatted earlier today.

Here are some other pointers to required changes in case it helps:

main branch updates:

pyproject.toml
tox.ini
requirements.txt
tools/build-on-netbsd
tools/build-on-openbsd

ubuntu packaging: update debian/control in the following branches

  • ubuntu/devel
  • ubuntu/mantic
  • ubuntu/lunar
  • ubuntu/jammy
  • ubuntu/focal

I haven't dug into the code yet to review, but a brief pass over it didn't yield any initial concerns besides the failing ci job.

Thanks again, and good work!

@holmanb holmanb self-assigned this Nov 30, 2023
@catmsred catmsred force-pushed the feature/remove_netifaces branch from 8955aae to 5b3565e Compare November 30, 2023 19:37
Copy link

github-actions bot commented Jan 4, 2024

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 TheRealFalcon, 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 TheRealFalcon to reopen it.)

@github-actions github-actions bot added the stale-pr Pull request is stale; will be auto-closed soon label Jan 4, 2024
@holmanb holmanb removed the stale-pr Pull request is stale; will be auto-closed soon label Jan 5, 2024
Copy link

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 TheRealFalcon, 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 TheRealFalcon to reopen it.)

@github-actions github-actions bot added the stale-pr Pull request is stale; will be auto-closed soon label Jan 20, 2024
@holmanb holmanb removed the stale-pr Pull request is stale; will be auto-closed soon label Jan 22, 2024
@holmanb
Copy link
Member

holmanb commented Jan 22, 2024

@akutz Have you had a chance to look at this? I believe @catmsred is testing this currently and we'll be trying to land it soon.

@catmsred catmsred force-pushed the feature/remove_netifaces branch from c55c07a to 70c72a1 Compare January 31, 2024 15:46
@catmsred
Copy link
Collaborator Author

@akutz @PengpengSun I have been struggling to set up a VMWare testing environment to validate this proposal. Would either of you have a chance to review and test it? Thanks!

@PengpengSun
Copy link
Contributor

Hi @catmsred , Thanks for your fix, we will review and verify it on VMware platform.

LOG.debug(
"multiple ipv4 gateways: %s, %s", ipv4, route["gateway"]
)
ipv4 = route["gateway"]
Copy link
Contributor

@PengpengSun PengpengSun Feb 7, 2024

Choose a reason for hiding this comment

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

I think route["gateway"] should be a gateway address, so here ipv4 should be gw4. Furthermore, can we make sure this is a default gateway?

ipv4 = None
ipv6 = None
routes = netinfo.route_info()
for route in routes:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with netinfo.route_info(), but with my local check, it returns a dict but list, so is this loop working as expected?

LOG.debug(
"multiple ipv6 gateways: %s, %s", ipv6, route["gateway"]
)
ipv6 = route["gateway"]
Copy link
Contributor

@PengpengSun PengpengSun Feb 7, 2024

Choose a reason for hiding this comment

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

ditto. Is this a gw6 or ipv6?

# If there is an IPv4 gateway and an IPv6 gateway, return immediately to
# avoid extra work
if ipv4 and ipv6:
return ipv4, ipv4
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is to get ipv4 and ipv6 addresses of default interface, so return gateway is not expected. And it should be return ipv4, ipv6

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I have misunderstood the goal of this function. Based on your comments, the correct process for this functions is (one flow but actually IPv4/IPv6 for each step):

  1. Identify default gateway
  2. Extract interface of default gateway
  3. Get IP address of interface
  4. Return IP address

I will update the code to reflect this flow unless you have further corrections to add. Thanks again for your input here!

@catmsred catmsred requested a review from PengpengSun February 8, 2024 02:46
ipv4_if = route["iface"]
for route in routes["ipv6"]:
if route["destination"] == "::/0":
ipv6 = route["iface"]
Copy link
Contributor

Choose a reason for hiding this comment

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

s/ipv6/ipv6_if/

for dev_name in netdev:
for addr in netdev[dev_name]["ipv6"]:
if addr["ip"] == ipv6 and len(netdev[dev_name]["ipv4"]) == 1:
ipv4 = netdev[dev_name]["ipv6"][0]["ip"]
Copy link
Contributor

Choose a reason for hiding this comment

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

s/"ipv6"/"ipv4"/

@catmsred catmsred force-pushed the feature/remove_netifaces branch from a1e43a8 to e49d376 Compare February 13, 2024 15:32
@akutz
Copy link
Contributor

akutz commented Feb 13, 2024

I have put time on my schedule to review this today and/or tomorrow.

@catmsred catmsred force-pushed the feature/remove_netifaces branch 2 times, most recently from 7ff9cd6 to f79e6c1 Compare February 13, 2024 15:45
netifaces is no longer being maintained and is only used by the VMWare data
source.  As such this commit replaces the calls to netifaces with cloudinit's
native netinfo.
This commit removes netifaces from the cloud-init dependency lists
Efforts to remove netifaces from cloud-init's dependency tree
resulted in substantial changes to this function.  This change
adds unit testing to verify that the updated code behaves as
intended.
@catmsred catmsred force-pushed the feature/remove_netifaces branch from 90543d8 to b139d0a Compare February 26, 2024 14:34
@catmsred catmsred changed the title [WIP] refactor: remove dependency on netifaces refactor: remove dependency on netifaces Feb 26, 2024
@catmsred
Copy link
Collaborator Author

@PengpengSun Thank you for the feedback -- I have moved this to a non-WIP status but please let me know if there's any additional testing you would like to do before approving!

Copy link
Contributor

@PengpengSun PengpengSun 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 fixing this.

catmsred added a commit to catmsred/cloud-init that referenced this pull request Mar 4, 2024
netifaces is being removed from tip of main in canonicalGH-4634.  This change also
removes it from the Ubuntu packaging.
@catmsred catmsred mentioned this pull request Mar 4, 2024
5 tasks
Copy link
Member

@holmanb holmanb 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 this work @catmsred!

Looks good to me.

@holmanb holmanb merged commit 2ba7fdf into canonical:main Mar 5, 2024
29 checks passed
catmsred added a commit to catmsred/cloud-init that referenced this pull request Mar 5, 2024
netifaces is being removed from tip of main in canonicalGH-4634.  This change also
removes it from the Ubuntu packaging.
catmsred added a commit to catmsred/cloud-init that referenced this pull request Mar 5, 2024
netifaces is being removed from tip of main in canonicalGH-4634.  This change also
removes it from the Ubuntu packaging.
catmsred added a commit to catmsred/cloud-init that referenced this pull request Mar 5, 2024
netifaces is being removed from tip of main in canonicalGH-4634.  This change also
removes it from the Ubuntu packaging.
@catmsred catmsred mentioned this pull request Mar 5, 2024
5 tasks
catmsred added a commit to catmsred/cloud-init that referenced this pull request Mar 5, 2024
netifaces is being removed from tip of main in canonicalGH-4634.  This change also
removes it from the Ubuntu packaging.
@catmsred catmsred mentioned this pull request Mar 5, 2024
5 tasks
catmsred added a commit to catmsred/cloud-init that referenced this pull request Mar 11, 2024
Upstream netifaces is no longer being maintained and is only
used by the VMWare data source.  As such this commit
replaces the calls to netifaces with cloudinit's native netinfo.
catmsred added a commit to catmsred/cloud-init that referenced this pull request Mar 11, 2024
netifaces is being removed from tip of main in canonicalGH-4634.  This change also
removes it from the Ubuntu packaging.
holmanb pushed a commit that referenced this pull request Mar 13, 2024
netifaces is being removed from tip of main in GH-4634.  This change also
removes it from the Ubuntu packaging.
holmanb pushed a commit that referenced this pull request Mar 13, 2024
netifaces is being removed from tip of main in GH-4634.  This change also
removes it from the Ubuntu packaging.
holmanb pushed a commit that referenced this pull request Mar 15, 2024
netifaces is being removed from tip of main in GH-4634.  This change also
removes it from the Ubuntu packaging.
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.

4 participants