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

code review #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

code review #2

wants to merge 4 commits into from

Conversation

dustymabe
Copy link
Owner

No description provided.

# "snapshot": "snap-0c1ca4850fcd5e573"
# }]}
amis = data['amis']
for ami in amis:
Copy link
Owner Author

Choose a reason for hiding this comment

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

before we update the tag it would be nice to check to see if the tag exists on the AMI first.

this will combine nicely with a dry-run feature.. in the case the user passed in --dry-run then if the tags didn't exist on the AMI we could print a statement saying would add tags "FedoraGroup=coreos" to ami-XXX in region foobar.

Comment on lines 37 to 41
if tagExists:
print(f"{resourceId} already tagged with FedoraUser=coreos tag")
else:
addTag(resourceId, region)
print(f"FedoraUser=coreos tag successfully added to {resourceId}")
Copy link
Owner Author

Choose a reason for hiding this comment

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

I still think it would be nice to add a --dry-run option to this script and do something like:

Suggested change
if tagExists:
print(f"{resourceId} already tagged with FedoraUser=coreos tag")
else:
addTag(resourceId, region)
print(f"FedoraUser=coreos tag successfully added to {resourceId}")
if tagExists:
print(f"{resourceId} already tagged with FedoraUser=coreos tag")
return
if dryrun:
print(f"--dry-run specified. Would add FedoraUser=coreos tag to {resourceId}")
else:
addTag(resourceId, region)
print(f"FedoraUser=coreos tag successfully added to {resourceId}")

print(f"FedoraUser=coreos tag successfully added to {resourceId}")

def checkTag(resourceId):
checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} Name=value,Values=coreos'
Copy link
Owner Author

Choose a reason for hiding this comment

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

what does the Name=value,Values=coreos do here?

Also do we need to add --region to this command too?

Copy link
Collaborator

@gursewak1997 gursewak1997 Apr 22, 2024

Choose a reason for hiding this comment

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

We don't need --region when we are giving --resource-id as an arg.

And for Name=value,Values=coreos, that's the way to filter out data where Name is basically "key" and Values is well "value" from tags json data that's spit out from aws ec2 describe tags
An example of what I get from this ami is this:

{
    "Tags": [
        {
            "Key": "FedoraUser",
            "ResourceId": "ami-xyx12345",
            "ResourceType": "image",
            "Value": "coreos"
        }
   ]
}

amis = data['amis']
else:
print(f"{build_id} does not have any AMIs for {arch} in meta.json")
return
Copy link
Owner Author

Choose a reason for hiding this comment

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

we probably shouldn't return here but rather continue the loop because we want to continue to process later builds and other architectures

print(f"FedoraGroup=coreos tag successfully added to {resourceId}")
def checkTag(resourceId, region):
checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} Name=value,Values=coreos Name=key,Values=FedoraGroup --region {region} --output=json'
Copy link
Owner Author

Choose a reason for hiding this comment

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

Let's try with: Name=tag:FedoraGroup,Values=coreos, which is a bit easier to follow.

amis = data['amis']
else:
print(f"{build_id} does not have any AMIs for {arch} in meta.json")
break
Copy link
Owner Author

Choose a reason for hiding this comment

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

I think we need to continue and not break here? if we break then we won't check all architectures for a build ID

Suggested change
break
continue

return

def checkAndAddTag(resourceId, region, dry_run):
checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} --region {region} --output=json'
Copy link
Owner Author

Choose a reason for hiding this comment

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

optional: for clarity I would rename this:

Suggested change
checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} --region {region} --output=json'
describeTagsCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} --region {region} --output=json'

Comment on lines 53 to 60
else:
if dry_run:
print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}")
return
else:
addTag(resourceId, region)
print(f"FedoraGroup=coreos tag successfully added to {resourceId}")
return
Copy link
Owner Author

Choose a reason for hiding this comment

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

We should be able to move this logic into addTag() then this becomes easier to read:

else:
    addTag(resourceId, region, dry_run)

Comment on lines 61 to 62
except subprocess.CalledProcessError as e:
return(e.output)
Copy link
Owner Author

Choose a reason for hiding this comment

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

I think we should drop catching these exceptions

@dustymabe
Copy link
Owner Author

let's drop all try/catch blocks. We shouldn't be ignoring the exceptions I don't think. Is there any place where it makes sense for us to continue and ignore it?



def getBuildsForStream(stream):
buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all'
Copy link
Owner Author

Choose a reason for hiding this comment

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

maybe for consistency with other vars

Suggested change
buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all'
buildFetchCmd = 'cosa buildfetch --stream='+ stream + ' --arch=all'

Comment on lines 52 to 56
if dry_run:
print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}")
return
else:
addTag(resourceId, region, dry_run)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
if dry_run:
print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}")
return
else:
addTag(resourceId, region, dry_run)
addTag(resourceId, region, dry_run)

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.

2 participants