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: Fix unhandled error for nonexistent security groups #7639

Merged
merged 2 commits into from
Apr 29, 2024

Conversation

viren-nadkarni
Copy link
Contributor

@viren-nadkarni viren-nadkarni commented Apr 29, 2024

This PR fixes an unhandled case where a non-existent security group when passed to RevokeSecurityGroupIngress and RevokeSecurityGroupEgress would raise an AttributeError.

  File "/home/viren/repo/moto-ext/moto/core/responses.py", line 270, in dispatch
    return cls()._dispatch(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/viren/repo/moto-ext/moto/core/responses.py", line 478, in _dispatch
    return self.call_action()
           ^^^^^^^^^^^^^^^^^^
  File "/home/viren/repo/moto-ext/moto/core/responses.py", line 575, in call_action
    response = method()
               ^^^^^^^^
  File "/home/viren/repo/moto-ext/moto/ec2/responses/security_groups.py", line 236, in revoke_security_group_ingress
    self.ec2_backend.revoke_security_group_ingress(**args)
  File "/home/viren/repo/moto-ext/moto/ec2/models/security_groups.py", line 824, in revoke_security_group_ingress
    group.group_id,
    ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'group_id'

The expected behaviour is as follows (tested against AWS)

$ aws ec2 revoke-security-group-ingress --group-name fasdf

An error occurred (InvalidGroup.NotFound) when calling the RevokeSecurityGroupIngress operation: The security group 'fasdf' does not exist in default VPC 'vpc-026b0bxxxxxx'

Supersedes #7428

Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 94.29%. Comparing base (9aef694) to head (db3e016).
Report is 216 commits behind head on master.

Files Patch % Lines
moto/ec2/models/security_groups.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7639      +/-   ##
==========================================
- Coverage   95.88%   94.29%   -1.60%     
==========================================
  Files         843     1082     +239     
  Lines       82578    92271    +9693     
==========================================
+ Hits        79178    87004    +7826     
- Misses       3400     5267    +1867     
Flag Coverage Δ
servertests 29.41% <0.00%> (-3.11%) ⬇️
unittests 94.26% <50.00%> (-1.59%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@viren-nadkarni viren-nadkarni marked this pull request as ready for review April 29, 2024 10:26
@bblommers bblommers added this to the 5.0.7 milestone Apr 29, 2024
Copy link
Collaborator

@bblommers bblommers left a comment

Choose a reason for hiding this comment

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

LGTM - thanks @viren-nadkarni!

@bblommers bblommers merged commit a39a38a into getmoto:master Apr 29, 2024
38 checks passed
Copy link
Contributor

This is now part of moto >= 5.0.7.dev3

@viren-nadkarni viren-nadkarni deleted the ec2-unhandled-exc-sg branch April 29, 2024 12:29
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.

None yet

2 participants