-
Notifications
You must be signed in to change notification settings - Fork 908
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
net/network_manager: do not set "may-fail" to False for both ipv4 and ipv6 #4622
Conversation
d813fad
to
aeea3d1
Compare
d1dff82
to
560dede
Compare
Please note that since we don't want to introduce new commits that put cloud-init in a broken state, so this will be squash merged if/when ready. |
That is precisely why I arranged the commits in such a way that first the fix is applied and then the revert of the revert of the original commit so that once we re-apply the original commit, at no stage cloud-init is broken. |
Okay I see now what you are trying to do. However, I still don't think we want git history to look the way that you've proposed this. Reasons:
I think I'm fine with keeping these commits separate if the commit message gets fixed, since "do the right thing for NetworkManager in all cases of dhcp4+dhcp6" is a fundamentally different thing than "change the default configuration to include dhcp6". |
560dede
to
dff7239
Compare
Ok I have tried to update the commit message to something that is more appropriate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. This works, but I requested some minor changes inline.
Here's a patch containing what I suggested:
diff --git a/cloudinit/net/network_manager.py b/cloudinit/net/network_manager.py
index 589ab7368..237b440c8 100644
--- a/cloudinit/net/network_manager.py
+++ b/cloudinit/net/network_manager.py
@@ -98,24 +98,16 @@ class NMConnection:
if self._config_option_is_set(section, option):
self.config[section][option] = value
- def _set_mayfail_true_if_both_false_dhcp(self):
+ def _set_mayfail_true_if_both_dhcp(self):
"""
- If for both ipv4 and ipv6, 'may-fail' is set to be False,
- set it to True for both of them.
+ If for both ipv4 and ipv6, method is 'dhcp' or 'auto', set
+ 'may-fail' to 'true'.
"""
for family in ["ipv4", "ipv6"]:
- if not self._config_option_is_set(family, "may-fail"):
- # if either ipv4 or ipv6 sections are not set/configured,
- # do not do anything.
- return
- if self._get_config_option(family, "may-fail") == "true":
- # if for either ipv4 or ipv6, 'may-fail' is 'true', do
- # not do anything.
- return
- if (
- self._get_config_option(family, "method") != "auto"
- and self._get_config_option(family, "method") != "dhcp"
- ):
+ if self._get_config_option(family, "method") not in [
+ "dhcp",
+ "auto",
+ ]:
# if both v4 and v6 are not dhcp, do not do anything.
return
@@ -130,7 +122,6 @@ class NMConnection:
Ensures there's appropriate [ipv4]/[ipv6] for given family
appropriate for given configuration type
"""
-
method_map = {
"static": "manual",
"static6": "manual",
@@ -170,14 +161,6 @@ class NMConnection:
self.config[family]["method"] = method
self._set_default(family, "may-fail", "false")
- # we do not want to set may-fail to false for both ipv4 and ipv6 dhcp
- # at the at the same time. This will make the network configuration
- # work only when both ipv4 and ipv6 dhcp succeeds. This may not be
- # what we want. If we have configured both ipv4 and ipv6 dhcp, any one
- # succeeding should be enough. Therefore, if "may-fail" is set to
- # False for both ipv4 and ipv6 dhcp, set them both to True.
- self._set_mayfail_true_if_both_false_dhcp()
-
def _add_numbered(self, section, key_prefix, value):
"""
Adds a numbered property, such as address<n> or route<n>, ensuring
@@ -333,6 +316,14 @@ class NMConnection:
if family == "ipv4" and "mtu" in subnet:
ipv4_mtu = subnet["mtu"]
+ # we do not want to set may-fail to false for both ipv4 and ipv6 dhcp
+ # at the at the same time. This will make the network configuration
+ # work only when both ipv4 and ipv6 dhcp succeeds. This may not be
+ # what we want. If we have configured both ipv4 and ipv6 dhcp, any one
+ # succeeding should be enough. Therefore, if "may-fail" is set to
+ # False for both ipv4 and ipv6 dhcp, set them both to True.
+ self._set_mayfail_true_if_both_dhcp()
+
if ipv4_mtu is None:
ipv4_mtu = device_mtu
if not ipv4_mtu == device_mtu:
Let me know if that works for you.
dff7239
to
0cd31f7
Compare
I have sent an updated rework. Kept most of the changes except that I do check for "may-fail". |
623b578
to
dbc156c
Compare
… ipv6 dhcp If "may-fail" is set to False in the Network Manager keyfile for both ipv4 and ipv6 for dhcp configuration, it essentially means both ipv4 and ipv6 network initialization using dhcp must succeed for the overall network configuration to succeed. This means, for environments where only ipv4 or ipv6 is available but not both and we need to configure both ipv4 and ipv6 dhcp, the overall network configuration will fail. This is not what we want. When both ipv4 and ipv6 dhcp are configured, it is enough for the overall configuration to succeed if any one succeeds. Therefore, set "may-fail" to True for both ipv4 and ipv6 if and only if both ipv4 and ipv6 are configured as dhcp in the Network Manager keyfile and "may-fail" is set to False for both. If both ipv4 and ipv6 are configured in the keyfile and if for any of them "may-fail" is already set to True,then do nothing. All other cases remain same as before. Please see discussions in PR canonical#4474. Co-authored-by: James Falcon <james.falcon@canonical.com> Signed-off-by: Ani Sinha <anisinha@redhat.com>
dbc156c
to
aa8e7b7
Compare
set it to True for both of them. | ||
""" | ||
for family in ["ipv4", "ipv6"]: | ||
if self._get_config_option(family, "may-fail") != "false": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this check is currently not required. But I still want to have this explicitly spelled out.
This will make sure on Azure we can use both dhcp4 and dhcp6 when IMDS is not used. This is useful in situations where only ipv6 network is available and there is no dhcp4 running. This change is mostly a reversal of commit 29ed5f5 and therefore, re-application of the commit 518047a with some small changes. The issue that caused the reversal of 518047a is fixed by the earlier commit: cab0eaf ("net/network_manager: do not set "may-fail" to False for both ipv4 and ipv6 dhcp") Fixes canonicalGH-4439 Signed-off-by: Ani Sinha <anisinha@redhat.com>
aa8e7b7
to
0153924
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ani-sinha , this looks good to me.
@holmanb , since you proposed the idea, do you mind reviewing as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, @ani-sinha.
Thanks for your work on this.
Please see discussions in #4474 .
The second patch unreverts the revert TheRealFalcon@21e6dfb .
The first change tries to the fix the issue due to which the above reversal was made.