Merge pull request #7691 from qiuming-best/e2e-parallel-upload-download

Add E2E test for parallel files upload and download
This commit is contained in:
qiuming
2024-05-09 15:27:06 +08:00
committed by GitHub
5 changed files with 305 additions and 7 deletions
+24
View File
@@ -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)
+17 -7
View File
@@ -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 {