Skip to content

Commit

Permalink
test: add function to delete AWS bucket key
Browse files Browse the repository at this point in the history
Delete the key from bucket that contains the raw disk image.

Signed-off-by: Wainer dos Santos Moschetta <[email protected]>
  • Loading branch information
wainersm committed Jan 31, 2025
1 parent bbf181c commit 2d1413a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cloud-api-adaptor/test/provisioner/aws/provision_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ func (a *AWSProvisioner) DeleteVPC(ctx context.Context, cfg *envconf.Config) err
a.Image.deregisterImage()

Check failure on line 259 in src/cloud-api-adaptor/test/provisioner/aws/provision_common.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `a.Image.deregisterImage` is not checked (errcheck)
}

if a.Bucket.Key != "" {
log.Infof("Delete key %s from bucket: %s", a.Bucket.Key, a.Bucket.Name)
a.Bucket.deleteKey()

Check failure on line 264 in src/cloud-api-adaptor/test/provisioner/aws/provision_common.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `a.Bucket.deleteKey` is not checked (errcheck)
}

return nil
}

Expand Down Expand Up @@ -964,6 +969,17 @@ func (b *S3Bucket) uploadLargeFileWithCli(filepath string) error {
return nil
}

func (b *S3Bucket) deleteKey() error {
if _, err := b.Client.DeleteObject(context.TODO(), &s3.DeleteObjectInput{
Bucket: aws.String(b.Name),
Key: aws.String(b.Key),
}); err != nil {
return err
}

return nil
}

// ConvertQcow2ToRaw Converts an qcow2 image to raw. Requires `qemu-img` installed.
func ConvertQcow2ToRaw(qcow2 string, raw string) error {
cmd := exec.Command("qemu-img", "convert", "-O", "raw", qcow2, raw)
Expand Down

0 comments on commit 2d1413a

Please sign in to comment.