Skip to content

Commit

Permalink
Generalize tests to check for specific resources in backup
Browse files Browse the repository at this point in the history
Instead of expecting a specific number of objects backed up
we should check if the objects we care about were backed up,
the check can also catch bugs that we could have missed in case
the number didnt change but for some reason our desired object
wasnt backed up.

Signed-off-by: Shelly Kagan <[email protected]>
  • Loading branch information
ShellyKa13 committed Feb 1, 2024
1 parent 3bc1ff3 commit f726738
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 151 deletions.
36 changes: 36 additions & 0 deletions tests/framework/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,42 @@ func WaitForBackupPhase(ctx context.Context, backupName string, backupNamespace
return nil
}

func DescribeBackup(ctx context.Context, backupName string) (map[string]interface{}, error) {
var result map[string]interface{}
checkCMD := exec.CommandContext(ctx, veleroCLI, "backup", "describe", "--details", "-o", "json", backupName)

stdoutPipe, err := checkCMD.StdoutPipe()
if err != nil {
return result, err
}

jsonBuf := make([]byte, 16*1024)
err = checkCMD.Start()
if err != nil {
return result, err
}

bytesRead, err := io.ReadFull(stdoutPipe, jsonBuf)
if err != nil && err != io.ErrUnexpectedEOF {
return result, err
}
if bytesRead == len(jsonBuf) {
return result, errors.New("json returned bigger than max allowed")
}

jsonBuf = jsonBuf[0:bytesRead]
err = checkCMD.Wait()
if err != nil {
return result, err
}
json.Unmarshal(jsonBuf, &result)
if err != nil {
return result, err
}

return result, nil
}

func CreateSnapshotLocation(ctx context.Context, locationName, provider, region string, backupNamespace string) error {
args := []string{
"snapshot-location", "create", locationName,
Expand Down
14 changes: 14 additions & 0 deletions tests/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
backupNamespaceEnv = "KVP_BACKUP_NS"
regionEnv = "KVP_REGION"
storageClassEnv = "KVP_STORAGE_CLASS"
minioProxyURLEnv = "KVP_MINIO_PROXY_URL"

defaultRegionName = "minio"
defaultBackupNamespace = "velero"
Expand All @@ -53,6 +54,7 @@ type Framework struct {
BackupNamespace string
StorageClass string
Region string
MinioProxyURL string
// Namespace provides a namespace for each test generated/unique ns per test
Namespace *v1.Namespace
namespacesToDelete []*v1.Namespace
Expand Down Expand Up @@ -117,6 +119,17 @@ func getStorageClassFromEnv() string {
return storageClass
}

func getMinioProxyURLFromEnv() string {
minioProxyURL := os.Getenv(minioProxyURLEnv)
if minioProxyURL == "" {
fmt.Fprintf(os.Stderr, "defaulting to minio port 9000\n")
return ""
}

fmt.Fprintf(ginkgo.GinkgoWriter, "MinioProxyURL [%s]\n", minioProxyURL)
return minioProxyURL
}

func getMaxFailsFromEnv() int {
maxFailsEnv := os.Getenv("REPORTER_MAX_FAILS")
if maxFailsEnv == "" {
Expand Down Expand Up @@ -148,6 +161,7 @@ func NewFramework() *Framework {
BackupNamespace: getBackupNamespaceFromEnv(),
Region: getRegionFromEnv(),
StorageClass: getStorageClassFromEnv(),
MinioProxyURL: getMinioProxyURLFromEnv(),
Clients: ClientsInstance,
reporter: reporter,
}
Expand Down
Loading

0 comments on commit f726738

Please sign in to comment.