-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
code review #2
Conversation
src/osbuild-manifests/aws_tag.py
Outdated
# "snapshot": "snap-0c1ca4850fcd5e573" | ||
# }]} | ||
amis = data['amis'] | ||
for ami in amis: |
There was a problem hiding this comment.
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
.
src/osbuild-manifests/aws_tag.py
Outdated
if tagExists: | ||
print(f"{resourceId} already tagged with FedoraUser=coreos tag") | ||
else: | ||
addTag(resourceId, region) | ||
print(f"FedoraUser=coreos tag successfully added to {resourceId}") |
There was a problem hiding this comment.
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:
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}") |
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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
}
]
}
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 |
There was a problem hiding this comment.
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
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' |
There was a problem hiding this comment.
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.
efcfd1b
to
2144e8f
Compare
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 |
There was a problem hiding this comment.
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
break | |
continue | |
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' |
There was a problem hiding this comment.
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:
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' | |
src/osbuild-manifests/aws_tag.py
Outdated
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 |
There was a problem hiding this comment.
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)
src/osbuild-manifests/aws_tag.py
Outdated
except subprocess.CalledProcessError as e: | ||
return(e.output) |
There was a problem hiding this comment.
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
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? |
2144e8f
to
26f4307
Compare
src/osbuild-manifests/aws_tag.py
Outdated
|
||
|
||
def getBuildsForStream(stream): | ||
buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all' |
There was a problem hiding this comment.
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
buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all' | |
buildFetchCmd = 'cosa buildfetch --stream='+ stream + ' --arch=all' | |
26f4307
to
c2ba0a9
Compare
c2ba0a9
to
179bfd6
Compare
src/osbuild-manifests/aws_tag.py
Outdated
if dry_run: | ||
print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}") | ||
return | ||
else: | ||
addTag(resourceId, region, dry_run) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
179bfd6
to
fd814ca
Compare
fd814ca
to
4f37b1f
Compare
No description provided.