image-tests: don't use random names for CI artifacts

When using random names for artifacts like AWS snapshots, or Azure
images, it becomes hard to clean them up in case of CI failure. See this
issue for more details:
https://github.com/osbuild/osbuild-composer/issues/942

This PR introduces predictable names so that we can easily determine
which artifact belongs to which PR and therefore we can decide to wipe
all resources that are not needed any more.
This commit is contained in:
Martin Sehnoutka 2020-09-08 13:59:14 +02:00 committed by Ondřej Budai
parent e80110a12c
commit 509964bede
5 changed files with 27 additions and 26 deletions

View file

@ -178,7 +178,7 @@ func DeleteEC2Image(e *ec2.EC2, imageDesc *imageDescription) error {
// WithBootedImageInEC2 runs the function f in the context of booted
// image in AWS EC2
func WithBootedImageInEC2(e *ec2.EC2, imageDesc *imageDescription, publicKey string, f func(address string) error) (retErr error) {
func WithBootedImageInEC2(e *ec2.EC2, securityGroupName string, imageDesc *imageDescription, publicKey string, f func(address string) error) (retErr error) {
// generate user data with given public key
userData, err := CreateUserData(publicKey)
if err != nil {
@ -187,12 +187,6 @@ func WithBootedImageInEC2(e *ec2.EC2, imageDesc *imageDescription, publicKey str
// Security group must be now generated, because by default
// all traffic to EC2 instance is filtered.
securityGroupName, err := GenerateRandomString("osbuild-image-tests-security-group-")
if err != nil {
return fmt.Errorf("cannot generate a random name for the image: %#v", err)
}
// Firstly create a security group
securityGroup, err := e.CreateSecurityGroup(&ec2.CreateSecurityGroupInput{
GroupName: aws.String(securityGroupName),

View file

@ -7,8 +7,6 @@ import (
"os"
"syscall"
"time"
"github.com/google/uuid"
)
// durationMin returns the smaller of two given durations
@ -52,14 +50,3 @@ func killProcessCleanly(process *os.Process, timeout time.Duration) error {
return process.Kill()
}
// GenerateRandomString generates a new random string with specified prefix.
// The random part is based on UUID.
func GenerateRandomString(prefix string) (string, error) {
id, err := uuid.NewRandom()
if err != nil {
return "", err
}
return prefix + id.String(), nil
}