From 63b5a7ac966ac73ebe5682f8b7dad6846bf1929a Mon Sep 17 00:00:00 2001 From: Yug Date: Wed, 30 Sep 2020 12:08:09 +0530 Subject: [PATCH] ci: add function to validate checksum calculateSha512sum() returns the md5sum of a file inside a pod. Signed-off-by: Yug --- e2e/pod.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/e2e/pod.go b/e2e/pod.go index c4a7e4b38..b8cfd4b1b 100644 --- a/e2e/pod.go +++ b/e2e/pod.go @@ -210,3 +210,19 @@ func deletePodWithLabel(label, ns string, skipNotFound bool) error { } return err } + +// calculateSHA512sum returns the sha512sum of a file inside a pod. +func calculateSHA512sum(f *framework.Framework, app *v1.Pod, filePath string, opt *metav1.ListOptions) (string, error) { + cmd := fmt.Sprintf("sha512sum %s", filePath) + sha512sumOut, stdErr, err := execCommandInPod(f, cmd, app.Namespace, opt) + if err != nil { + return "", err + } + if stdErr != "" { + return "", fmt.Errorf("error: sha512sum could not be calculated %v", stdErr) + } + // extract checksum from sha512sum output. + checkSum := strings.Split(sha512sumOut, "")[0] + e2elog.Logf("Calculated checksum %s", checkSum) + return checkSum, nil +}