Skip to content

Fix sysconfig render when set-name is missing#1327

Merged
TheRealFalcon merged 1 commit into
canonical:mainfrom
akutz:fix/lp-1855945
Mar 15, 2022
Merged

Fix sysconfig render when set-name is missing#1327
TheRealFalcon merged 1 commit into
canonical:mainfrom
akutz:fix/lp-1855945

Conversation

@akutz
Copy link
Copy Markdown
Contributor

@akutz akutz commented Mar 11, 2022

Proposed Commit Message

Fix sysconfig render when set-name is missing

This patch addresses an issue where the absence of set-name
in a network configuration potentially results in an unintended
network configuration.

LP: #1855945

Additional Context

NA

Test Steps

make clean_pyc && PYTHONPATH="$(pwd)" python3 -m \
  pytest -v --log-level=DEBUG \
  -k test_iface_name_from_device_with_matching_mac_address \
  tests/unittests/test_net.py

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

@akutz akutz force-pushed the fix/lp-1855945 branch 11 times, most recently from b04cd67 to 5a218bb Compare March 11, 2022 21:43
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 this fix. Overall LGTM.

The for loop is juuuust starting to get long enough that I'd consider putting the code you added into its own method/function, but I think it's ok as-is too. I'll leave it up to you if you want to change it.

Re: the circular import, I'm not a huge fan of the proposed solution as it adds more indirection and imports an underscore prefixed name.

Given that your current solution is already a workaround, I think a simpler (though maybe slightly hackier) workaround is to move the get_interfaces_by_mac import from the top of network_state.py to the top of the handle_ethernets method where you added it.

Long term, I think that most of the functions at the bottom of network_state.py (is_ipv6_addr through mask_and_ipv5_to_bcast_addr) probably make more sense in cloudinit/net/__init__.py. That's obviously a bigger refactor though, and not one we should do in this PR.

There are a number of test failures due to the moved function, but I think if we just move the import they should be fine.

Comment thread cloudinit/net/network_state.py
@akutz
Copy link
Copy Markdown
Contributor Author

akutz commented Mar 15, 2022

Thanks for this fix. Overall LGTM.

The for loop is juuuust starting to get long enough that I'd consider putting the code you added into its own method/function, but I think it's ok as-is too. I'll leave it up to you if you want to change it.

Re: the circular import, I'm not a huge fan of the proposed solution as it adds more indirection and imports an underscore prefixed name.

Yeah, neither was I, but I also am not so actively involved with the project that I felt comfortable to refactor things too heavily.

Given that your current solution is already a workaround, I think a simpler (though maybe slightly hackier) workaround is to move the get_interfaces_by_mac import from the top of network_state.py to the top of the handle_ethernets method where you added it.

I thought about that, but get_interfaces_by_mac is a wrapper for other functions. Oh, are you suggesting relocating the actual import statement, not the method itself?

Long term, I think that most of the functions at the bottom of network_state.py (is_ipv6_addr through mask_and_ipv5_to_bcast_addr) probably make more sense in cloudinit/net/__init__.py. That's obviously a bigger refactor though, and not one we should do in this PR.

Indeed. See my previous comment about refactoring.

There are a number of test failures due to the moved function, but I think if we just move the import they should be fine.

I cannot figure out why as I added a shim to the original location. Why does moving the import fix things? Oh, because of the global symbol being changed?

akutz added a commit to akutz/cloud-init that referenced this pull request Mar 15, 2022
This patch refactors several network, helper functions out of the
network_state.py file and into cloudinit.net. This is in relation
to LP #1855945 and github.com/canonical/pull/1327. The
aforementioned issue requires some refactoring to avoid circular
imports, but it was not proper to do that refactoring in *that*
pull request. Thus this PR is specific to the refactoring and can
be evaluated on its own merits.
@akutz
Copy link
Copy Markdown
Contributor Author

akutz commented Mar 15, 2022

I pushed #1336 to handle the refactored network functions. Once approved, I can rebase this PR on that one.

akutz added a commit to akutz/cloud-init that referenced this pull request Mar 15, 2022
This patch refactors several network, helper functions out of the
network_state.py file and into cloudinit.net. This is in relation
to LP #1855945 and github.com/canonical/pull/1327. The
aforementioned issue requires some refactoring to avoid circular
imports, but it was not proper to do that refactoring in *that*
pull request. Thus this PR is specific to the refactoring and can
be evaluated on its own merits.
@TheRealFalcon
Copy link
Copy Markdown
Contributor

Oh, are you suggesting relocating the actual import statement, not the method itself?

Yes, but since you did the refactor instead (thanks for that!), not needed.

akutz added a commit to akutz/cloud-init that referenced this pull request Mar 15, 2022
This patch refactors several network, helper functions out of the
network_state.py file and into cloudinit.net. This is in relation
to LP #1855945 and github.com/canonical/pull/1327. The
aforementioned issue requires some refactoring to avoid circular
imports, but it was not proper to do that refactoring in *that*
pull request. Thus this PR is specific to the refactoring and can
be evaluated on its own merits.
TheRealFalcon pushed a commit that referenced this pull request Mar 15, 2022
This patch refactors several network, helper functions out of the
network_state.py file and into cloudinit.net. This is in relation
to LP #1855945 and github.com//pull/1327. The
aforementioned issue requires some refactoring to avoid circular
imports, but it was not proper to do that refactoring in *that*
pull request. Thus this PR is specific to the refactoring and can
be evaluated on its own merits.
This patch addresses https://bugs.launchpad.net/cloud-init/+bug/1855945,
where the absence of set-name in a network configuration potentially
results in an unintended network configuration.

Please note a function from cloudinit.net.networkstate was relocated
under cloudinit.net due to a circular dependency introduced by the
former calling get_interfaces_by_mac in the latter. A stub function
has been created to preserve backward compatibility.
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 @akutz . Assuming CI passes, I'll merge this soon.

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