Skip to content

ec2_eni: Fix idempotency when security_groups is specified - #337

Merged
ansible-zuul[bot] merged 5 commits into
ansible-collections:mainfrom
ichekaldin:ec2_eni/fix_idempotency_security_groups
Jul 8, 2021
Merged

ec2_eni: Fix idempotency when security_groups is specified#337
ansible-zuul[bot] merged 5 commits into
ansible-collections:mainfrom
ichekaldin:ec2_eni/fix_idempotency_security_groups

Conversation

@ichekaldin

@ichekaldin ichekaldin commented Apr 23, 2021

Copy link
Copy Markdown
Contributor
SUMMARY

If security_groups attribute is specified - module always returns Changed = True.

Fixes #255.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_eni

ADDITIONAL INFORMATION

Example:

- amazon.aws.ec2_eni:
    name: my-eni
    security_groups:
      - my-sg
    subnet_id: subnet-123456

Will always return Changed = True.

If `security_groups` attribute is specified - module always returns
`Changed` = `True`.

Example:

```
- amazon.aws.ec2_eni:
    name: my-eni
    security_groups:
      - my-sg
    subnet_id: subnet-123456
```

Will always return `Changed` = `True`.

This PR fixes that.
@ichekaldin ichekaldin changed the title Fix idempotency when security_groups is specified ec2_eni: Fix idempotency when security_groups is specified Apr 23, 2021
@ansibullbot

Copy link
Copy Markdown

@ansibullbot ansibullbot added bug This issue/PR relates to a bug community_review module module needs_triage new_contributor Help guide this first time contributor plugins plugin (any type) small_patch Hopefully easy to review labels Apr 23, 2021
@ichekaldin

Copy link
Copy Markdown
Contributor Author

Strange. Integration tests fail with the following error:

ERROR! couldn't resolve module/action 'ec2_instance'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/home/zuul/.ansible/collections/ansible_collections/amazon/aws/tests/integration/targets/ec2_eni/tasks/main.yaml': line 71, column 5, but may be elsewhere in the file depending on the exact syntax problem.

The line in question is:

  - name: Create 2 instances to test attaching and detaching network interfaces
    ec2_instance:

It has nothing to do with the changes I made. Has this integration test worked previously?

@goneri

goneri commented Apr 23, 2021

Copy link
Copy Markdown
Member

recheck

1 similar comment
@goneri

goneri commented Apr 23, 2021

Copy link
Copy Markdown
Member

recheck

@ansibullbot ansibullbot added integration tests/integration tests tests labels Apr 25, 2021
@ansibullbot ansibullbot removed the small_patch Hopefully easy to review label Apr 25, 2021
@ichekaldin

ichekaldin commented Apr 25, 2021

Copy link
Copy Markdown
Contributor Author

The test fails with the following error:

TASK [ec2_eni : Assert that ec2_eni_info returns all the values we expect] *****
task path: /home/zuul/.ansible/collections/ansible_collections/amazon/aws/tests/integration/targets/ec2_eni/tasks/test_eni_basic_creation.yaml:24
[WARNING]: an unexpected error occurred during Jinja2 environment setup: unable
to locate collection ansible.netcommon
exception during Jinja2 environment setup: Traceback (most recent call last):
  File "/tmp/ansible-test-bntq2_0j/ansible/utils/collection_loader/_collection_finder.py", line 1058, in _get_collection_metadata
    collection_pkg = import_module('ansible_collections.' + collection_name)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'ansible_collections.ansible.netcommon'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/ansible-test-bntq2_0j/ansible/template/__init__.py", line 485, in __getitem__
    ts = _get_collection_metadata(acr.collection)
  File "/tmp/ansible-test-bntq2_0j/ansible/utils/collection_loader/_collection_finder.py", line 1060, in _get_collection_metadata
    raise ValueError('unable to locate collection {0}'.format(collection_name))
ValueError: unable to locate collection ansible.netcommon
fatal: [testhost]: FAILED! => {
    "msg": "The conditional check '_interface_0.private_ip_address | ansible.netcommon.ipaddr' failed. The error was: template error while templating string: unable to locate collection ansible.netcommon. String: {% if _interface_0.private_ip_address | ansible.netcommon.ipaddr %} True {% else %} False {% endif %}"
}

I think I hit a wall in trying to fix it.

I'm inclined to remove lines in 60 and 155 in tests/integration/targets/ec2_eni/tasks/test_eni_basic_creation.yaml:

      - _interface_0.private_ip_address | ansible.netcommon.ipaddr

and

      - _interface_0.private_ip_address | ansible.netcommon.ipaddr

My thinking here is that the appropriate validation is done by the subsequent lines:

      - _interface_0.private_ip_address == ip_1

and

      - _interface_0.private_ip_address == ip_5

Would that be acceptable?

@tremble

tremble commented Apr 26, 2021

Copy link
Copy Markdown
Contributor

ansible.netcommon.ipaddr feels like something we should have available to us during testing, many of our modules return IP addresses, and being able to validate this seems like core testing functionality.

Originally we had

  • ansible.netcommon
  • community.general
  • community.aws

While I think it's reasonable to minimise our test dependencies, supported collections (like ansible.netcommon) feel like something we should have available to us.

@goneri thoughts?

@ichekaldin

Copy link
Copy Markdown
Contributor Author

I realize that everyone is probably busy after release 1.5.0, but still wanted to follow up on this. What's the best way to proceed?

@jillr

jillr commented Apr 29, 2021

Copy link
Copy Markdown
Contributor

@tremble @ichekaldin I have no objection to adding ansible.netcommon back to tests/requirements.yml. It looks like these tests was missed when we recently removed ansible.netcommon from the requirements after other, unrelated usages were removed. Collections in that file will be installed to the test environment when integration tests run.

@ichekaldin

Copy link
Copy Markdown
Contributor Author

@jillr @tremble What can we do to move this forward? Thanks!

@jillr

jillr commented May 14, 2021

Copy link
Copy Markdown
Contributor

recheck

@goneri

goneri commented May 14, 2021

Copy link
Copy Markdown
Member

recheck

@ichekaldin

Copy link
Copy Markdown
Contributor Author

@jillr @goneri Is something blocking this PR?

@jillr jillr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @ichekaldin apologies, just needed to be reviewed once the CI was passing.

@jillr

jillr commented Jun 18, 2021

Copy link
Copy Markdown
Contributor

recheck

@jillr jillr added gate and removed gate labels Jun 18, 2021
@jillr

jillr commented Jun 18, 2021

Copy link
Copy Markdown
Contributor

gate job isn't running because one of the zuul changes hasn't merged, we'll get that merged asap

ansible-zuul Bot pushed a commit to ansible/ansible-zuul-jobs that referenced this pull request Jun 24, 2021
AWS jobs depend on ansible.netcommon

See: ansible-collections/amazon.aws#337 (comment)
@ichekaldin

Copy link
Copy Markdown
Contributor Author

@jillr Looks like the zuul changes are merged. Could this be merged as well?

@tremble tremble removed the gate label Jul 5, 2021
@tremble

tremble commented Jul 5, 2021

Copy link
Copy Markdown
Contributor

@ichekaldin - Apologies for any spam, trying to kick the CI

@tremble tremble closed this Jul 5, 2021
@tremble tremble reopened this Jul 5, 2021
@tremble tremble added the gate label Jul 5, 2021
@tremble

tremble commented Jul 5, 2021

Copy link
Copy Markdown
Contributor

'check' was automatically cancelled because gate's now running - as long as gate passes it should merge.

@ichekaldin

Copy link
Copy Markdown
Contributor Author

@tremble looks like the gate test fails with this:

TASK [ec2_eni : Assert that ec2_eni_info returns all the values we expect] *****
task path: /home/zuul/.ansible/collections/ansible_collections/amazon/aws/tests/integration/targets/ec2_eni/tasks/test_eni_basic_creation.yaml:24
fatal: [testhost]: FAILED! => {
    "msg": "The conditional check '_interface_0.private_ip_address | ansible.netcommon.ipaddr' failed. The error was: The ipaddr filter requires python's netaddr be installed on the ansible controller"
}

@tremble tremble removed the gate label Jul 8, 2021
@tremble tremble closed this Jul 8, 2021
@tremble tremble reopened this Jul 8, 2021
@tremble tremble added the gate label Jul 8, 2021
@ansible-zuul
ansible-zuul Bot merged commit 922514a into ansible-collections:main Jul 8, 2021
@ichekaldin

Copy link
Copy Markdown
Contributor Author

@tremble Thank you!

@ichekaldin
ichekaldin deleted the ec2_eni/fix_idempotency_security_groups branch July 8, 2021 16:43
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 CI community_review integration tests/integration module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ec2_eni idempotence bug

5 participants