Skip to content

code review#2

Open
dustymabe wants to merge 4 commits intomasterfrom
dusty-gursewak
Open

code review#2
dustymabe wants to merge 4 commits intomasterfrom
dusty-gursewak

Conversation

@dustymabe
Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
# "snapshot": "snap-0c1ca4850fcd5e573"
# }]}
amis = data['amis']
for ami in amis:
Copy link
Copy Markdown
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 thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
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
Copy Markdown
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}")

Comment thread src/osbuild-manifests/aws_tag.py Outdated
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
Copy Markdown
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
Copy Markdown

@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"
        }
   ]
}

Comment thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
Comment thread src/osbuild-manifests/aws_tag.py Outdated
amis = data['amis']
else:
print(f"{build_id} does not have any AMIs for {arch} in meta.json")
return
Copy link
Copy Markdown
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

Comment thread src/osbuild-manifests/aws_tag.py Outdated
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
Copy Markdown
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.

Comment thread src/osbuild-manifests/aws_tag.py Outdated
amis = data['amis']
else:
print(f"{build_id} does not have any AMIs for {arch} in meta.json")
break
Copy link
Copy Markdown
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

Comment thread src/osbuild-manifests/aws_tag.py Outdated
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
Copy Markdown
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 thread src/osbuild-manifests/aws_tag.py Outdated
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
Copy Markdown
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 thread src/osbuild-manifests/aws_tag.py Outdated
Comment on lines +61 to +62
except subprocess.CalledProcessError as e:
return(e.output)
Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread src/osbuild-manifests/aws_tag.py Outdated


def getBuildsForStream(stream):
buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all'
Copy link
Copy Markdown
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 thread src/osbuild-manifests/aws_tag.py Outdated
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
Copy Markdown
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