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

ec2_eni: Fix idempotency when security_groups is specified #337

Merged
merged 5 commits into from
Jul 8, 2021
Merged

ec2_eni: Fix idempotency when security_groups is specified #337

merged 5 commits into from
Jul 8, 2021

Conversation

ichekaldin
Copy link
Contributor

@ichekaldin ichekaldin commented Apr 23, 2021

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

@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
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
Copy link
Member

goneri commented Apr 23, 2021

recheck

1 similar comment
@goneri
Copy link
Member

goneri commented Apr 23, 2021

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
Copy link
Contributor Author

ichekaldin commented Apr 25, 2021

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
Copy link
Contributor

tremble commented Apr 26, 2021

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
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
Copy link
Collaborator

jillr commented Apr 29, 2021

@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
Contributor Author

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

@jillr
Copy link
Collaborator

jillr commented May 14, 2021

recheck

@goneri
Copy link
Member

goneri commented May 14, 2021

recheck

@ichekaldin
Copy link
Contributor Author

@jillr @goneri Is something blocking this PR?

Copy link
Collaborator

@jillr jillr left a comment

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
Copy link
Collaborator

jillr commented Jun 18, 2021

recheck

@jillr jillr added gate and removed gate labels Jun 18, 2021
@jillr
Copy link
Collaborator

jillr commented Jun 18, 2021

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
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
Copy link
Contributor

tremble commented Jul 5, 2021

@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
Copy link
Contributor

tremble commented Jul 5, 2021

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

@ichekaldin
Copy link
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
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