From a4498846b1dede1118bb15712abb38764bd22e3e Mon Sep 17 00:00:00 2001 From: Andi Li Date: Tue, 28 Jul 2020 17:17:19 +0000 Subject: [PATCH] Quick commit --- test/e2e/storage/testsuites/base.go | 12 +++--------- test/e2e/storage/testsuites/snapshottable.go | 8 ++++++-- test/e2e/storage/utils/utils.go | 9 +++++++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/test/e2e/storage/testsuites/base.go b/test/e2e/storage/testsuites/base.go index 0a5c851b2b5..fbafa06d78d 100644 --- a/test/e2e/storage/testsuites/base.go +++ b/test/e2e/storage/testsuites/base.go @@ -18,7 +18,6 @@ package testsuites import ( "context" - "crypto/sha1" "flag" "fmt" "math" @@ -47,6 +46,7 @@ import ( e2evolume "k8s.io/kubernetes/test/e2e/framework/volume" "k8s.io/kubernetes/test/e2e/storage/podlogs" "k8s.io/kubernetes/test/e2e/storage/testpatterns" + "k8s.io/kubernetes/test/e2e/storage/utils" ) var ( @@ -616,18 +616,12 @@ func getPreProvisionedSnapshotContent(snapshotName, snapshotNamespace, snapshotH return snapshotContent } -func genShortHash(s string) string { - h := sha1.New() - h.Write([]byte(s)) - bs := h.Sum(nil) - return fmt.Sprintf("%x", bs)[:7] -} func getPreProvisionedSnapshotContentName(snapshotHandle string) string { - return fmt.Sprintf("pre-provisioned-snapcontent-%s", genShortHash(snapshotHandle)) + return fmt.Sprintf("pre-provisioned-snapcontent-%s", utils.GenShortHash(snapshotHandle)) } func getPreProvisionedSnapshotName(snapshotHandle string) string { - return fmt.Sprintf("pre-provisioned-snapshot-%s", genShortHash(snapshotHandle)) + return fmt.Sprintf("pre-provisioned-snapshot-%s", utils.GenShortHash(snapshotHandle)) } // StartPodLogs begins capturing log output and events from current diff --git a/test/e2e/storage/testsuites/snapshottable.go b/test/e2e/storage/testsuites/snapshottable.go index 6bc174ddf03..b21eb678d20 100644 --- a/test/e2e/storage/testsuites/snapshottable.go +++ b/test/e2e/storage/testsuites/snapshottable.go @@ -339,7 +339,7 @@ func DeleteAndWaitSnapshot(dc dynamic.Interface, ns string, snapshotName string, } ginkgo.By("checking the Snapshot has been deleted") - err = utils.WaitForNamespacedGVRDeletion(dc, SnapshotGVR, snapshotName, ns, poll, timeout) + err = utils.WaitForNamespacedGVRDeletion(dc, SnapshotGVR, ns, snapshotName, poll, timeout) return err } @@ -438,7 +438,11 @@ func CreateSnapshotResource(sDriver SnapshottableTestDriver, config *PerTestConf framework.Logf("Recording snapshot handle: %s", snapshotHandle) csiDriverName := r.Vsclass.Object["driver"].(string) - ginkgo.By("deleting the snapshot and snapshot content") // TODO: test what happens when I have two snapshot content that refer to the same content + // If the deletion policy is retain on vscontent: + // when vs is deleted vscontent will not be deleted + // when the vscontent is manually deleted then the underlying snapshot resource will not be deleted. + // We exploit this to create a snapshot resource from which we can create a preprovisioned snapshot + ginkgo.By("deleting the snapshot and snapshot content") err = dc.Resource(SnapshotGVR).Namespace(r.Vs.GetNamespace()).Delete(context.TODO(), r.Vs.GetName(), metav1.DeleteOptions{}) framework.ExpectNoError(err) diff --git a/test/e2e/storage/utils/utils.go b/test/e2e/storage/utils/utils.go index 7ee13f4f9ac..46efa31d4e5 100644 --- a/test/e2e/storage/utils/utils.go +++ b/test/e2e/storage/utils/utils.go @@ -18,6 +18,7 @@ package utils import ( "context" + "crypto/sha1" "crypto/sha256" "encoding/base64" "fmt" @@ -785,3 +786,11 @@ func WaitUntil(poll, timeout time.Duration, checkDone func() bool) bool { framework.Logf("WaitUntil failed after reaching the timeout %v", timeout) return false } + +// GenShortHash returns the first 7 hex characters of the sha1 hash of string s +func GenShortHash(s string) string { + h := sha1.New() + h.Write([]byte(s)) + bs := h.Sum(nil) + return fmt.Sprintf("%x", bs)[:7] +}