Quick commit

This commit is contained in:
Andi Li 2020-07-28 17:17:19 +00:00
parent 854645d7c3
commit a4498846b1
3 changed files with 18 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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]
}