mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-30 19:55:36 +00:00
Add E2E test for parallel files upload and download
Signed-off-by: Ming Qiu <ming.qiu@broadcom.com>
This commit is contained in:
@@ -299,6 +299,29 @@ func PrepareVolumeList(volumeNameList []string) (vols []*corev1.Volume) {
|
||||
return
|
||||
}
|
||||
|
||||
func CalFileHashInPod(ctx context.Context, namespace, podName, containerName, filePath string) (string, error) {
|
||||
arg := []string{"exec", "-n", namespace, "-c", containerName, podName,
|
||||
"--", "/bin/sh", "-c", fmt.Sprintf("sha256sum %s | awk '{ print $1 }'", filePath)}
|
||||
cmd := exec.CommandContext(ctx, "kubectl", arg...)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// Trim any leading or trailing whitespace characters from the output
|
||||
hash := string(output)
|
||||
hash = strings.TrimSpace(hash)
|
||||
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
func WriteRandomDataToFileInPod(ctx context.Context, namespace, podName, containerName, volume, filename string, fileSize int64) error {
|
||||
arg := []string{"exec", "-n", namespace, "-c", containerName, podName,
|
||||
"--", "/bin/sh", "-c", fmt.Sprintf("dd if=/dev/urandom of=/%s/%s bs=%d count=1", volume, filename, fileSize)}
|
||||
cmd := exec.CommandContext(ctx, "kubectl", arg...)
|
||||
fmt.Printf("Kubectl exec cmd =%v\n", cmd)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func CreateFileToPod(ctx context.Context, namespace, podName, containerName, volume, filename, content string) error {
|
||||
arg := []string{"exec", "-n", namespace, "-c", containerName, podName,
|
||||
"--", "/bin/sh", "-c", fmt.Sprintf("echo ns-%s pod-%s volume-%s > /%s/%s", namespace, podName, volume, volume, filename)}
|
||||
@@ -306,6 +329,7 @@ func CreateFileToPod(ctx context.Context, namespace, podName, containerName, vol
|
||||
fmt.Printf("Kubectl exec cmd =%v\n", cmd)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func FileExistInPV(ctx context.Context, namespace, podName, containerName, volume, filename string) (bool, error) {
|
||||
stdout, stderr, err := ReadFileFromPodVolume(ctx, namespace, podName, containerName, volume, filename)
|
||||
|
||||
|
||||
@@ -598,22 +598,32 @@ func IsVeleroReady(ctx context.Context, veleroCfg *VeleroConfig) (bool, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check BSL
|
||||
stdout, stderr, err = velerexec.RunCommand(exec.CommandContext(ctx, "kubectl", "get", "bsl", "default",
|
||||
// Check BSL with poll
|
||||
err = wait.PollUntilContextTimeout(ctx, PollInterval, time.Minute, true, func(ctx context.Context) (bool, error) {
|
||||
return checkBSL(ctx, veleroCfg) == nil, nil
|
||||
})
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to check the bsl")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func checkBSL(ctx context.Context, veleroCfg *VeleroConfig) error {
|
||||
namespace := veleroCfg.VeleroNamespace
|
||||
stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(ctx, "kubectl", "get", "bsl", "default",
|
||||
"-o", "json", "-n", namespace))
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to get bsl %s stdout=%s, stderr=%s", veleroCfg.BSLBucket, stdout, stderr)
|
||||
return errors.Wrapf(err, "failed to get bsl %s stdout=%s, stderr=%s", veleroCfg.BSLBucket, stdout, stderr)
|
||||
} else {
|
||||
bsl := &velerov1api.BackupStorageLocation{}
|
||||
if err = json.Unmarshal([]byte(stdout), bsl); err != nil {
|
||||
return false, errors.Wrapf(err, "failed to unmarshal the velero bsl")
|
||||
return errors.Wrapf(err, "failed to unmarshal the velero bsl")
|
||||
}
|
||||
if bsl.Status.Phase != velerov1api.BackupStorageLocationPhaseAvailable {
|
||||
return false, fmt.Errorf("current bsl %s is not available", veleroCfg.BSLBucket)
|
||||
return fmt.Errorf("current bsl %s is not available", veleroCfg.BSLBucket)
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrepareVelero(ctx context.Context, caseName string, veleroCfg VeleroConfig) error {
|
||||
|
||||
Reference in New Issue
Block a user