Fix the clean ami script to remove the amis based on date #8146
No reviewers
Labels
No labels
after freeze
automation
backlog
blocked
change-ack
change-nak
change-noreleng
changes
Closed As
Can't Fix
Closed As
Duplicate
Closed As
Fixed
Closed As
Fixed with Explanation
Closed As
Get back later
Closed As
Grooming
Closed As
Insufficient data
Closed As
Invalid
Closed As
It's all good
Closed As
taiga
Closed As
upstream
day-to-day
dev
docs
easyfix
epel
f26
f27
f28
f29
f30
f31
f32
f33
f34
f35
f36
f37
f38
f39
f40
f41
f42
f43
f44
f45
fedora
groomed
high-gain
high-trouble
in-progress
in-review
investigation
legal
low-gain
low-trouble
mass rebuild
medium-gain
medium-trouble
meeting
mini-initiative
new_artifact
ops
pdc_retirement
rawhide
RCA
review
script
sidetarget
sprint-0
sprint-1
sprint-2
sprint-3
sprint-4
sprint-5
unfrozen
waiting on external
Backlog Status
Needs Review
Backlog Status
Ready
chore
documentation
points
01
points
02
points
03
points
05
points
08
points
13
Priority
High
Priority
Low
Priority
Medium
Sprint Status
Blocked
Sprint Status
Done
Sprint Status
In Progress
Sprint Status
Review
Sprint Status
To Do
Technical Debt
Work Item
Bug
Work Item
Epic
Work Item
Spike
Work Item
Task
Work Item
User Story
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
releng/tickets!8146
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-clean-ami-script"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This fixes #8126.
Additional changes made to the script:
--daysparam.Signed-off-by: Sayan Chowdhury sayan.chowdhury2012@gmail.com
days=10 is hardcoded here - is that right? I think it should be
days=dayscan we re-order these two (change perms first and then delete) and then add a nice comment about what is going on?
It took me a while to figure out what is going on and I'm still not sure it's entirely right (or maybe I misunderstand).
For each AMI:
(2*$days < item < $days)-> DELETE($days < item < TODAY)-> CHANGE PERMISSIONSIs that right?
Here, 10 is the number of days the AMIs will stay with the changed perms.
This help message needs more clarity. I don't quite get exactly what value you want me to give it for days.
we need a comment at the beginning of this if/else that explains how we are determining which AMIs are OK to delete.
actually maybe better to just explain all of the logic before any of the if statements in this function.
Do we have more regions now?
rebased onto e8bb003aa24db1ec202545ad378be1553e7eb7a4
We have nightly AMIs in two additional regions:
ca-central-1
eu-west-2
rebased onto 41b8936aaf72746038704b7b51542ef5367044b8
Done.
Looks good to me, one minor change may required:
we might want to make NIGHTLY lowercase at
pagure.io/fork/sayanchowdhury/releng@0ce51d0036/f/scripts/clean-amis.py (_95), since result of fedfind is somewhat like this for rawhide and F30 nightly:Also, this won't delete any of Fedora updates and updates testing AMIs, since for both cases compose_info.label starts with Update-*
for delete, its $days-10 < item < TODAY-10 -> DELETE
Yeah,
NIGHTLYis the variable. The value of it isnightly.Yes, This is to prevent from deleting the 2WA Host released AMIs. I could not find a way to distinguish from the other AMIs.
ah yes, missed it.
Compose ID of updates are usually Fedora-$releases-updates-$composedate and for updates-testing, it is Fedora-$releases-updates-testing-$composedate .
We do 2WA release from updates compose, so maybe we can filter out at compose ID level to remove AMIs from updates-testing?
@dustymabe WDYT
@sayanchowdhury One question for my clarity, does using topic org.fedoraproject.prod.fedimg.image.upload gets us to fetch AMIs for all desired regions we want AMIs to make private or delete or we should move to
org.fedoraproject.prod.fedimg.image.publishtopic where we have AMI IDs for all regions available?We can do this. But still updates composes would stay.
Let's define a new variable at the top of the script (
WAIT_PERIOD=10)i'm not sure if we should use
dayshere at all. we basically want any AMIs that have had launch permissions removed for more than 10 days right? I almost wonder if we should be using fedmsg at all and not pure ec2 commands for this.we should be able to remove updates-testing AMIs IMHO. Can we use any other identifying information?
looks like @sinnykumari already said this above :) - sorry @sinnykumari
If I upload an AMI today and this gets run today does that AMI get its launch permissions removed?
rebased onto 6a46caca939ed6620d2ed022b5b4bcbb097093a7
rebased onto 731affa16d9b413f1539a475d23b9180a2df87bc
rebased onto d41e4dabfbd4734f828decae3e3dadffbdaed7d7
@dustymabe I fixed the issue that you pointed out. Now AMIs $((today-5)-$days) < item < $(today-5) will be deleted.
Since the AMIs will be deleted after 10 days, so the $(today-15)-days < item < today -15
The benefit of using this doesn't seem to be worth it to me. We define more twice and we call it twice and all but one argument is static. Let's just call get_page() instead rather than making readers lookup what
functools.partialdoes?add comment above this.
why should we include AMIs that have the date in them? What does it mean if they do have the date in them?
What does this mean? Add comment
these should be useful for the dry-run case, no?
Here are some slight modifications that would make this more useful I think:
note the comment about possibly using tags set on the AMIs to determine when
the launch permissions were removed.
any updates for today for me to review?
1 new commit added
Tmp commitrebased onto 95aca465273674f9b47c12160c620a317fe02d72
rebased onto 28179f2189a3dd32b5b2cfefa9a12d476f413139
rebased onto 2d0a536a680e1899acccad7a2e22bd8ac22d4efc
rebased onto 68aafd7315ccbfa5f51215b1a5a6db26b6bafa06
rebased onto 9beff8aacd778409a724b1845be4cb24a815668f
Specify the number of days worth of AMI fedmsg information to fetch from datagrepper.
probably need to raise an exception here?
I don't understand the 2nd if statement here and below for deletewaitperiod.
need description error message here
Need to fix function description and arg descrition here
This is a tag key/value pair we are defining here right? I would do something like
Key=LaunchPermissionRevokedandValue=todaystimestamp.this seems limiting - we will only delete images that were deleted on that day. We want to delete all the ones with permissions revoked before that day. I'm thinking we should get all images with this tag (key) and then filter the list of AMIs based on the timestamp (value).
"on or before that day" or "before that day"
This is when you want to delete same day images.
I don't know if I support deleting same day images but I guess it makes sense for development. The user should be able to pass
--permswaitperiod 0, right? We should not need a special if statement for this."on or before that day" works for me if it does for you. but in general "off by one" shouldn't matter too much here.
since it's 0, the if condition evaluated to false and the default value of 10 is set. And yes it's needed for development purpose.
+1
I see. In that case we should change things up a bit. Let's set the defaults for these values in argparse calls above and then just use
args.daysargs.permswaitperiodandargs.deletewaitperiodeverywhere - WDYT?Sounds good to me
1 new commit added
Temp commit before squashjust checking - not sure what
ami['Tags']returns but i would think this should betag.keys()and not tag.values.. Do you have an example of whattags=ami['Tags']returns?i would make the function args here generic.. ie timestamp1, timestamp2 and add a description:
eturns true if timestamp1 is greater than or equal to timestamp2maybe rename the function to
_timestamp_greater()the readability of the later code benefits from thisthis shouldn't happen. I would at least print out a warning message with information
[{'Key': 'LaunchPermissionRevoked', 'Value': '27022019'}]
List of dictionaries
1 new commit added
Another temp commitadd a comment before this if statement - something like
maybe we should change the function to be titled
is_timestamp_older()3 new commits added
Another temp commitTemp commit before squashFix the clean ami script to remove the amis based on date1 new commit added
Temp commiti may have given you a bug - not sure if the string can span two lines here. maybe test it and see.
LGTM - other than the one comment.
@sinnykumari - can you review this in the morning?
1 new commit added
Format the script with blackrebased onto 9abfb34f4f2539febcb09ee4f608caae73f7e11f
Yeah I had fixed that in the next commit.
rebased onto ba567ec22576d6304a0d6f028f2fbe7cb942ef43
Note that by this method we will be able to fetch TwoWeek compose id only for recent ones (from the time we added multi-arch support in twoweek.complete fedmsg topic). If we are interested to deleting most of the older composes, then we will have to add another condition to get composeID, sample json is https://apps.fedoraproject.org/datagrepper/id?id=2018-01994496-c703-49d6-8ffc-e99afd07c406&is_raw=true&size=extra-large
This idea came to my mind today as well, nice to see that this is already taken care of!
Added one concern above, other than that LGTM.
rebased onto 1d716c707effae0a0542a397eec5e74ab1a5beb6
2 new commits added
Format the script with blackFix the clean ami script to remove the amis based on dateLGTM, have re-looked only into the modified content which I believe would be the "older-format fedmsg messages" section
need to set default value here
need to set default value here right?
can you verify that changing this from
'-(\d{8}).'to"-(\d{8})."doesn't cause any problems?1 new commit added
fixup! Fix the clean ami script to remove the amis based on dateWhy is this seperated? Cant it be joined in the for loop below?
Use elif since same arch wont be repeated and less checks 😄
Same as above
these changes LGTM - can you address mohan's comments?
Same as the one that I asked above, why separated, rather than being the for loop below?
I have no idea on how delete amis and change ami permissions work, but other than that and the above comments I made, its LGTM.
No because the first query returns the number of pages. which is utilized in the next loop
1 new commit added
fixup! Fix the clean ami script to remove the amis based on dateLGTM. Let's squash and merge and then can you:
rebased onto
44e1c85878Pull-Request has been merged by mohanboddu