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

ENI: DescribeNetworkInterfaces attachment.instance-id filter #3549

Merged
merged 7 commits into from
Nov 23, 2021

Conversation

Preskton
Copy link
Contributor

@Preskton Preskton commented Dec 14, 2020

Related issue: #3550

Description

Allows consumers to filter ENIs by the attachment.instance-id filter, if present. Today, attempting to filter by attachment.instance-id yields an Exception similar to:

moto.ec2.exceptions.FilterNotImplementedError: The filter 'attachment.instance-id' for DescribeNetworkInterfaces has not been implemented in Moto yet. Feel free to open an issue at https://github.com/spulec/moto/issues

TODO

  • Open an issue
  • Test this actually works
  • Unit tests
  • Lint, formatting, etc.
  • Better description

@Preskton Preskton changed the title ENI: attachment.instance-id filter ENI: attachment.instance-id filter -- WIP Dec 14, 2020
@coveralls
Copy link

coveralls commented Dec 14, 2020

Coverage Status

Coverage decreased (-0.1%) to 94.419% when pulling 4063467 on Preskton:eni_attachment_instance-id_filter into c9c30b8 on spulec:master.

@bblommers
Copy link
Collaborator

Thanks for the opening a PR @Preskton! Will convert it to a draft - let me know when you think it's ready for review.

@bblommers bblommers marked this pull request as draft December 15, 2020 07:52
@Preskton
Copy link
Contributor Author

@bblommers since this is my first contribution, I have a couple of quick questions:

Would you mind taking a quick peek at the change and let me know if a) the change is reasonable/directionally correct, and b) if the unit test appears in line with how other items are tested?

Second, when I run black, there are a handful of errors outside of my current change's scope. Should I change them as part of this PR?

@bblommers
Copy link
Collaborator

This looks like the right approach @Preskton, both in terms of the actual change and the testing.

Black shouldn't touch anything else, really, as it is already formatted in master.
Which version are you using?

@Preskton
Copy link
Contributor Author

Thanks for taking a peek, @bblommers. Turns out my py installs were absolutely wrecked. Cleaned them up and was able to get things going correctly.

I now have working tests - could you please provide feedback if this is an appropriate style? I was getting a little confused between if I should use client/resources or hit the backends directly.

Also, what guidance can you provide around clearing this warning? I'd like to knock it out before I merge.

tests/test_ec2/test_elastic_network_interfaces.py::test_elastic_network_interfaces_get_by_attachment_instance_id
  /code/Preskton/moto/moto/ec2/models.py:567: PendingDeprecationWarning: Could not find AMI with image-id:ami-d3adb33f, in the near future this will cause an error.
  Use ec2_backend.describe_images() to find suitable image for your test
    warnings.warn(

Thanks in advance!

@Preskton Preskton marked this pull request as ready for review December 15, 2020 19:11
@Preskton Preskton changed the title ENI: attachment.instance-id filter -- WIP ENI: attachment.instance-id filter Dec 15, 2020
@Preskton Preskton changed the title ENI: attachment.instance-id filter ENI: DescribeNetworkInterfaces attachment.instance-id filter Dec 15, 2020
@mock_ec2_deprecated
@mock_ec2
def test_elastic_network_interfaces_get_by_attachment_instance_id():
conn = boto.connect_vpc("the_key", "the_secret")
Copy link
Collaborator

@bblommers bblommers Dec 16, 2020

Choose a reason for hiding this comment

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

Creating the VPC can be done with the boto3-client as well.

@mock_ec2_deprecated makes it possible to mock boto, but were trying to phase out support for boto at some point. So new tests shouldn't have any @.._deprecated decorators.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have an example where we're using the new style and attaching an ENI? The only other ENI attach example I could find was using the deprecated style.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is be very similar using boto3. Haven't tested it out, but this should work:

eni1 = ec2_client.create_network_interface(SubnetId=..., Groups=[..])
ec2_client.attach_network_interface(DeviceIndex=1, InstanceId=..., NetworkInterfaceId=...)

)

create_instances_result = ec2_resource.create_instances(
ImageId="ami-d3adb33f", MinCount=1, MaxCount=1
Copy link
Collaborator

Choose a reason for hiding this comment

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

The warning pops up for quite a few tests - I think it's to do with the fact that this ImageId does not exist in our mocked world.
Don't worry this for now - we'll clean all those warnings up in one go (at some point..)

@codecov-commenter
Copy link

Codecov Report

Merging #3549 (e00b278) into master (74666c1) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3549      +/-   ##
==========================================
+ Coverage   95.21%   95.22%   +0.01%     
==========================================
  Files         535      535              
  Lines       59827    59844      +17     
==========================================
+ Hits        56963    56989      +26     
+ Misses       2864     2855       -9     
Flag Coverage Δ
servertests 47.63% <0.00%> (-0.01%) ⬇️
test_responses 32.39% <0.00%> (+<0.01%) ⬆️
unittests 95.13% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
moto/ec2/models.py 94.88% <100.00%> (+0.06%) ⬆️
moto/s3/models.py 94.98% <0.00%> (-0.01%) ⬇️
moto/s3/responses.py 95.73% <0.00%> (+0.02%) ⬆️
moto/awslambda/models.py 93.01% <0.00%> (+0.11%) ⬆️
moto/s3/exceptions.py 93.92% <0.00%> (+2.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74666c1...e00b278. Read the comment docs.

@bblommers bblommers linked an issue Nov 23, 2021 that may be closed by this pull request
@bblommers
Copy link
Collaborator

Hope you don't mind me touching this PR @Preskton - I just fixed up the test to get it ready

@bblommers bblommers merged commit d64fd52 into getmoto:master Nov 23, 2021
@bblommers bblommers added this to the 2.2.17 milestone Nov 23, 2021
@github-actions
Copy link
Contributor

This is now part of moto >= 2.2.17.dev13

sahilshah6196 pushed a commit to EBSCOIS/moto that referenced this pull request Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENI: Filter by attachment.instance-id
4 participants