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: add cleanup for VPC #105

Merged
merged 1 commit into from
Feb 11, 2021
Merged

ec2: add cleanup for VPC #105

merged 1 commit into from
Feb 11, 2021

Conversation

asmorodskyi
Copy link
Collaborator

No description provided.

@asmorodskyi asmorodskyi added the wip Work in progress label Dec 22, 2020
@codecov
Copy link

codecov bot commented Dec 22, 2020

Codecov Report

Merging #105 (7fc74bc) into master (e531df5) will increase coverage by 2.62%.
The diff coverage is 95.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #105      +/-   ##
==========================================
+ Coverage   78.79%   81.42%   +2.62%     
==========================================
  Files          27       27              
  Lines        2028     2315     +287     
==========================================
+ Hits         1598     1885     +287     
  Misses        430      430              
Impacted Files Coverage Δ
tests/generators.py 96.55% <75.00%> (-3.45%) ⬇️
ocw/lib/EC2.py 76.15% <90.19%> (+9.93%) ⬆️
ocw/lib/emailnotify.py 52.72% <91.66%> (+25.27%) ⬆️
tests/test_ec2.py 98.16% <98.01%> (+1.08%) ⬆️
ocw/lib/provider.py 98.48% <100.00%> (ø)
ocw/lib/vault.py 100.00% <100.00%> (ø)
tests/test_pcwconfig.py 100.00% <100.00%> (ø)
webui/settings.py 91.66% <100.00%> (+0.49%) ⬆️

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 e531df5...7fc74bc. Read the comment docs.

Copy link
Collaborator

@grisu48 grisu48 left a comment

Choose a reason for hiding this comment

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

Minor comments, LGTM!

ocw/lib/EC2.py Outdated Show resolved Hide resolved
ocw/lib/EC2.py Outdated Show resolved Hide resolved
ocw/lib/EC2.py Show resolved Hide resolved
tests/test_ec2.py Outdated Show resolved Hide resolved
@asmorodskyi asmorodskyi removed the wip Work in progress label Feb 4, 2021
@asmorodskyi
Copy link
Collaborator Author

@okurz

Copy link
Collaborator

@cfconrad cfconrad left a comment

Choose a reason for hiding this comment

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

Some nit comments

ocw/lib/EC2.py Outdated
self.cleanup_uploader_vpcs()

def delete_vpc(self, region, vpcId):
if PCWConfig.getBoolean('cleanup/vpc_only_notify', self._namespace):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think, most of the variables in the configuration use - as separator. And maybe cleanup/no-vpc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agree with separator change . but I find cleanup/no-vpc less informative . why you don't like cleanup/vpc-notify-only ?

Copy link
Collaborator

@cfconrad cfconrad Feb 5, 2021

Choose a reason for hiding this comment

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

I just saw that you also have cleanup/vpc_cleanup and then no-vpc doesn't say anything...
But I'm not sure about it. as you have some kind of tree in these options. Cause vpc_only_notify doesn't work if vpc_cleanup=false.

Maybe we can change the code in that manner, that we have as default

cleanup/vpc-cleanup=True   # Find and delete left over VPC's
cleanup/vpc-notifiy=True      #  Find and notify for left over VPC's

and you can set one or the other and get the expected result.

Another thing is, that we talk only about ec2-vpc's. But at least GCE has VPC as well. Don't know if you wanna reflect that somehow, or we just say "vpc-cleanup where ever it is implemented"

ocw/lib/EC2.py Outdated
self.log_info('{} in {} looks like uploader leftover. (OwnerId={}).', vpc['VpcId'], region,
vpc['OwnerId'])
if not self.delete_vpc(region, vpc['VpcId']) and not self.dry_run:
send_mail('VPC deletion locked by running VMs',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

your comment makes me realize that this approach with delete_vpc returns False in several unrelated cases was bad decision . will redo this part.

@@ -259,8 +259,16 @@ def has(setting: str) -> bool:
return False

@staticmethod
def getBoolean(config_path: str, default=False) -> bool:
value = ConfigFile().get(config_path, default)
def getBoolean(config_path: str, namespace: str = None, default=False) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder, why we do not change get_feature_property() so it handle bool types as well.

And then drop this getBoolean().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

after spending another half-day on this PR I realized that this is enough :) while generally agree with you I would like to move this into separate PR . I create issue to not forget about this #108

Copy link
Collaborator

@grisu48 grisu48 left a comment

Choose a reason for hiding this comment

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

Still LGTM! 🚀 I like the new functions, which makes it a bit more maintainable IMHO. Good work Anton! 🙂

Comment on lines +237 to +239
except Exception as e:
self.log_err("{} on VPC deletion. {}", type(e).__name__, traceback.format_exc())
send_mail('{} on VPC deletion in [{}]'.format(type(e).__name__, self._namespace), traceback.format_exc())
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a rather bad style. In general one should not catch "Exception" itself except for very rare cases. And also as the "try" covers the complete body of the method I wonder why you even handle the exception on this level and not on caller level

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

deleting VPC is quite complex thing which includes several step each one can fail in several different way ( network issues , vault/password problems , various exceptions from AWS API ) idea is that any issues with deleting one VPC should not interrupt process of deleting others .
I am aware about the fact that catching everything is bad practice , but I don't think it is applicable here . Keep in mind that even if I will remove try/catch here same function will be called again in 1 hour https://github.com/SUSE/pcw/blob/master/ocw/lib/cleanup.py#L45 so from some perspective everything is wrapped in try/catch Exception anyway :).

Copy link
Member

Choose a reason for hiding this comment

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

well, ok, your decision :)

Copy link
Collaborator

@cfconrad cfconrad left a comment

Choose a reason for hiding this comment

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

LGTM

@asmorodskyi asmorodskyi merged commit a4b1e08 into SUSE:master Feb 11, 2021
@asmorodskyi asmorodskyi deleted the vpc branch July 21, 2022 11:38
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.

4 participants