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

Interfaces_file - improvements #3328

Merged
merged 13 commits into from
Sep 19, 2021
Merged

Interfaces_file - improvements #3328

merged 13 commits into from
Sep 19, 2021

Conversation

russoz
Copy link
Collaborator

@russoz russoz commented Sep 3, 2021

SUMMARY

General improvements, simplifications and pythonification of the code.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/modules/system/interfaces_file.py
tests/unit/plugins/modules/system/interfaces_file/test_interfaces_file.py

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added affects_2.10 bug This issue/PR relates to a bug community_review module module needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_maintainer needs_triage plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging system tests tests unit tests/unit labels Sep 4, 2021
@felixfontein felixfontein added backport-3 check-before-release PR will be looked at again shortly before release and merged if possible. labels Sep 5, 2021
@russoz
Copy link
Collaborator Author

russoz commented Sep 7, 2021

@felixfontein I have not opened it yet, but I bet it is the sanity import moaning about coverage ;-)

UPDATE: Bingo!!!!

@felixfontein
Copy link
Collaborator

@russoz tests now all pass :)

@ansibullbot ansibullbot removed the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI label Sep 13, 2021
@russoz
Copy link
Collaborator Author

russoz commented Sep 18, 2021

@felixfontein @hryamzik just added an integration test for this scenario Felix described - it failed on the old code and worked on the new one ;-)

@ansibullbot ansibullbot added integration tests/integration needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI and removed stale_ci CI is older than 7 days, rerun before merging needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI labels Sep 18, 2021
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

LGTM as far as I can judge.

@hryamzik
Copy link
Contributor

LGTM

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Sep 19, 2021
@felixfontein felixfontein merged commit 7aae8d5 into ansible-collections:main Sep 19, 2021
@patchback
Copy link

patchback bot commented Sep 19, 2021

Backport to stable-3: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-3/7aae8d5386e0ddb944f171b1847e3e16e981d635/pr-3328

Backported as #3396

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Sep 19, 2021
* pythonific!! no camel cases, bitte

* simplified iface attributes parsing

* some improvements, passing tests

* simplified set_interface_option()

* further simplifications

* remove unreachable stmt

* pythonified a file open

* added changelog fragment

* adjustment per PR

* PR: fixed the auto- case

* PR: added testcase and chglog frag for the misleading change report

* extra line removed

* integration is not destructive

(cherry picked from commit 7aae8d5)
@felixfontein
Copy link
Collaborator

@russoz thanks for this improvement!
@hryamzik thanks for reviewing!

felixfontein pushed a commit that referenced this pull request Sep 19, 2021
* pythonific!! no camel cases, bitte

* simplified iface attributes parsing

* some improvements, passing tests

* simplified set_interface_option()

* further simplifications

* remove unreachable stmt

* pythonified a file open

* added changelog fragment

* adjustment per PR

* PR: fixed the auto- case

* PR: added testcase and chglog frag for the misleading change report

* extra line removed

* integration is not destructive

(cherry picked from commit 7aae8d5)

Co-authored-by: Alexei Znamensky <[email protected]>
@russoz russoz deleted the interfaces_file-improvement branch September 20, 2021 13:11
@pgassmann
Copy link

Regression: The new version repeatedly adds new lines for up/down option. The previous version (ansible 3.0) only added the option if it was not yet present.

- name: floating_ip_interface_up_ip 2a01:a:b:c::1/64 dev eth0
  interfaces_file:
    option: up
    iface: eth0
    dest: '/etc/network/interfaces.d/50-cloud-init.cfg'
    value: 'ip addr add 2a01:a:b:c::1/64 dev eth0'
    state: present

result: ansible-playbook --diff --check -vvv

TASK [floating_ip : floating_ip_interface_down_ip 2a01:a:b:c::1/64 dev eth0] ***************************************************
task path: /../roles/floating_ip/tasks/floating_ip.yml:12
changed: [mail01p.example.org] => changed=true 
  dest: /etc/network/interfaces.d/50-cloud-init.cfg
  gid: 0
  group: root
  ifaces:
    eth0:
      address: 2a01:d:e:f::1/64
      address_family: inet6
      down:
      - ip addr del 88.1.2.332 dev eth0
      - ip addr del 49.1.2.3/32 dev eth0
      - ip addr del 2a01:a:b:c::1/64 dev eth0
      - ip addr del 2a01:a:b:c::1/64 dev eth0
      gateway: fe80::1
      method: static
      post-up: []
      pre-up: []
      up:
      - ip addr add 88.1.2.332 dev eth0
      - ip addr add 49.1.2.3/32 dev eth0
      - ip addr add 2a01:a:b:c::1/64 dev eth0
    lo:
      address_family: inet
      down: []
      method: loopback
      post-up: []
      pre-up: []
      up: []
  invocation:
    module_args:
      address_family: null
      attributes: null
      backup: false
      dest: /etc/network/interfaces.d/50-cloud-init.cfg
      group: null
      iface: eth0
      mode: null
      option: down
      owner: null
      selevel: null
      serole: null
      setype: null
      seuser: null
      state: present
      unsafe_writes: false
      value: ip addr del 2a01:a:b:c::1/64 dev eth0
  mode: '0644'
  owner: root
  size: 823
  state: file
  uid: 0

resulting interface file after multiple runs:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
    dns-nameservers 213.133.99.99 213.133.98.98 213.133.100.100

# control-alias eth0
iface eth0 inet6 static
    address 2a01:d:e:f::1/64
    gateway fe80::1
    up ip addr add 88.1.2.3/32 dev eth0
    down ip addr del 88.1.2.3/32 dev eth0
    # ipv6
    up ip addr add 2a01:a:b:c::1/64 dev eth0
    up ip addr add 49.12.115.122/32 dev eth0
    up ip addr add 88.1.2.3/32 dev eth0
    up ip addr add 2a01:a:b:c::1/64 dev eth0
    up ip addr add 88.1.2.3/32 dev eth0
    up ip addr add 2a01:a:b:c::1/64 dev eth0
    up ip addr add 88.1.2.3/32 dev eth0
    up ip addr add 2a01:a:b:c::1/64 dev eth0
    down ip addr del 2a01:a:b:c::1/64 dev eth0
    down ip addr del 49.12.115.122/32 dev eth0
    down ip addr del 88.1.2.3/32 dev eth0
    down ip addr del 2a01:a:b:c::1/64 dev eth0
    down ip addr del 88.1.2.3/32 dev eth0
    down ip addr del 2a01:a:b:c::1/64 dev eth0
    down ip addr del 88.1.2.3/32 dev eth0
    down ip addr del 2a01:a:b:c::1/64 dev eth0

@felixfontein
Copy link
Collaborator

@russoz ^

@hryamzik
Copy link
Contributor

We also need a test case for this!

@pgassmann
Copy link

pgassmann commented Dec 2, 2021

@felixfontein @russoz should I create a separate Ticket for that case?

It would be optimal if the update would remove duplicates. At least state: absent should remove all items at once. (didn't test that)

@russoz
Copy link
Collaborator Author

russoz commented Dec 2, 2021

@pgassmann yes please, that would be great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug community_review integration tests/integration module module plugins plugin (any type) system tests tests unit tests/unit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants