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

nm: Fix the incorrect change indication when apply the same config twice #396

Merged
merged 2 commits into from Jul 5, 2021

Conversation

cathay4t
Copy link
Collaborator

@cathay4t cathay4t commented Jun 24, 2021

Patch 1

When applying the same network connections twice, the second apply still
shows changed: true.

The root cause:

  • When user never asked about ethtool configuration, network-role
    will generate an all-default NM.SettingEthtool and pass it to
    NetworkManager daemon. But NetworkManager discard it when saving to
    ifcfg plugin as ifcfg plugin will not keep empty ethtool option.

  • During second apply, the NM.SimpleConnection.compare will return
    False indicating configuration changed because of on-disk connection
    has no ethtool setting while pending connection does.

To fix it, we just remove the all-default NM.SettingEthtool.

Patch 2

Fix the incorrect change indication for dns option

When applying with dhcp4: "no" or auto6: "no", we get incorrect
change indication even when network connection was not changed.

The root cause is the NM.SettingIPConfig.clear_dns_options(True) will
create an empty list which will be discard by ifcfg plugin.
The follow up NM.Connection.compare() will show configuration changed
as dns option entry missing.

Fixed by remove dns option completely before appending.

@coveralls
Copy link

coveralls commented Jun 24, 2021

Pull Request Test Coverage Report for Build 1000358175

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 409 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.03%) to 40.178%

Files with Coverage Reduction New Missed Lines %
/home/runner/work/network/network/library/network_connections.py 409 21.29%
Totals Coverage Status
Change from base Build 991459915: -0.03%
Covered Lines: 1039
Relevant Lines: 2586

💛 - Coveralls

thom311
thom311 previously approved these changes Jun 24, 2021
@thom311
Copy link
Contributor

thom311 commented Jun 24, 2021

fix in NM here: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/905

(the workaround here is of course still necessary)

@liangwen12year liangwen12year self-requested a review June 24, 2021 16:59
liangwen12year
liangwen12year previously approved these changes Jun 24, 2021
Copy link
Collaborator

@liangwen12year liangwen12year left a comment

Choose a reason for hiding this comment

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

LGTM, nice patch.

@liangwen12year liangwen12year enabled auto-merge (rebase) June 24, 2021 20:14
@tyll
Copy link
Member

tyll commented Jun 25, 2021

It would be great to have a test for this that applies a certain profile twice that triggered this error and asserts that the module does not report "changed" for the second time the profile is applied. What do you think?

@cathay4t cathay4t force-pushed the fix_changed branch 2 times, most recently from 4feeac3 to adf68bd Compare June 29, 2021 06:52
Comment on lines +32 to +43
network_connections:
- name: "{{ interface }}"
state: up
type: ethernet
ip:
dhcp4: "no"
auto6: "no"
Copy link
Member

Choose a reason for hiding this comment

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

This variable can be set in line 5 for the playbook then it does not need to be repeated and it would ensure that the profiles are always the same.

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 had trouble on this. Could you provide an example?

Copy link
Contributor

Choose a reason for hiding this comment

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

This variable

Which variable?

I had trouble on this.

What did you try, and what was the result?

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 tried to place the network_connections at the host level variable, and then remove that from import_role task. Not work.
Even with this in import_role task will not work:

    - block:
        - import_role:
            name: linux-system-roles.network
          vars:
            - network_connections: " {{ network_connections }} "
          register: __network_connections_result

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what the problem is - here is an example playbook calling a role with a variable defined at the host level - https://gist.github.com/richm/e9d338d8b39254b84b90fd2bf0b0b0a1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. The code is working now.

@cathay4t cathay4t force-pushed the fix_changed branch 3 times, most recently from 4a8a093 to b2e1a8d Compare June 29, 2021 15:16
@cathay4t cathay4t dismissed stale reviews from liangwen12year and thom311 June 29, 2021 15:19

new patch added.

@cathay4t
Copy link
Collaborator Author

@liangwen12year @thom311 I have included another patch fixing the DNS option change indication problem. Please review it again.

@cathay4t cathay4t force-pushed the fix_changed branch 2 times, most recently from 5ab784d to 1cb331e Compare July 1, 2021 08:33
@cathay4t
Copy link
Collaborator Author

cathay4t commented Jul 1, 2021

@tyll @richm Patch updated to use vars to mitigate the duplication in test code.

@cathay4t cathay4t force-pushed the fix_changed branch 3 times, most recently from d041e89 to 4e65cc4 Compare July 1, 2021 12:04
library/network_connections.py Outdated Show resolved Hide resolved
Copy link
Member

@tyll tyll left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@tyll tyll left a comment

Choose a reason for hiding this comment

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

👍

@tyll tyll enabled auto-merge (rebase) July 1, 2021 16:19
@tyll
Copy link
Member

tyll commented Jul 1, 2021

[citest bad]

1 similar comment
@tyll
Copy link
Member

tyll commented Jul 1, 2021

[citest bad]

When applying the same network connections twice, the second apply still
shows `changed: true`.

The root cause:
 * When user never asked about ethtool configuration, network-role
   will generate an all-default `NM.SettingEthtool` and pass it to
   NetworkManager daemon. But NetworkManager discard it when saving to
   ifcfg plugin as ifcfg plugin will not keep empty ethtool option.

 * During second apply, the `NM.SimpleConnection.compare` will return
   False indicating configuration changed because of on-disk connection
   has no ethtool setting while pending connection does.

To fix it, we just remove the all-default `NM.SettingEthtool`.

Signed-off-by: Gris Ge <fge@redhat.com>
When applying with `dhcp4: "no"` or `auto6: "no"`, we get incorrect
change indication even when network connection was not changed.

The root cause is the `NM.SettingIPConfig.clear_dns_options(True)` will
create an empty list which will be discard by ifcfg plugin.
The follow up `NM.Connection.compare()` will show configuration changed
as dns option entry missing.

Fixed by remove dns option completely before appending.

Signed-off-by: Gris Ge <fge@redhat.com>
@cathay4t
Copy link
Collaborator Author

cathay4t commented Jul 5, 2021

[citest bad]

@cathay4t cathay4t disabled auto-merge July 5, 2021 12:15
@cathay4t
Copy link
Collaborator Author

cathay4t commented Jul 5, 2021

The CI failure is unrelated. Force merging.

@cathay4t cathay4t merged commit 245ff58 into linux-system-roles:main Jul 5, 2021
@cathay4t cathay4t deleted the fix_changed branch July 5, 2021 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants