Fix default storage class tests

Name of the default storage class is not "default", it must be discovered
dynamically.
This commit is contained in:
Jan Safranek 2017-03-17 10:41:11 +01:00
parent 223c721d6e
commit 3b1d1c40b4

View File

@ -303,11 +303,12 @@ var _ = framework.KubeDescribe("Dynamic provisioning", func() {
// Modifying the default storage class can be disruptive to other tests that depend on it // Modifying the default storage class can be disruptive to other tests that depend on it
It("should be disabled by changing the default annotation[Slow] [Serial] [Disruptive] [Volume]", func() { It("should be disabled by changing the default annotation[Slow] [Serial] [Disruptive] [Volume]", func() {
framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere") framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere")
scName := getDefaultStorageClassName(c)
By("setting the is-default StorageClass annotation to false") By("setting the is-default StorageClass annotation to false")
verifyDefaultStorageClass(c, true) verifyDefaultStorageClass(c, scName, true)
defer updateDefaultStorageClass(c, "true") defer updateDefaultStorageClass(c, scName, "true")
updateDefaultStorageClass(c, "false") updateDefaultStorageClass(c, scName, "false")
By("creating a claim with default storageclass and expecting it to timeout") By("creating a claim with default storageclass and expecting it to timeout")
claim := newClaim(ns) claim := newClaim(ns)
@ -327,11 +328,12 @@ var _ = framework.KubeDescribe("Dynamic provisioning", func() {
// Modifying the default storage class can be disruptive to other tests that depend on it // Modifying the default storage class can be disruptive to other tests that depend on it
It("should be disabled by removing the default annotation[Slow] [Serial] [Disruptive] [Volume]", func() { It("should be disabled by removing the default annotation[Slow] [Serial] [Disruptive] [Volume]", func() {
framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere") framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere")
scName := getDefaultStorageClassName(c)
By("removing the is-default StorageClass annotation") By("removing the is-default StorageClass annotation")
verifyDefaultStorageClass(c, true) verifyDefaultStorageClass(c, scName, true)
defer updateDefaultStorageClass(c, "true") defer updateDefaultStorageClass(c, scName, "true")
updateDefaultStorageClass(c, "") updateDefaultStorageClass(c, scName, "")
By("creating a claim with default storageclass and expecting it to timeout") By("creating a claim with default storageclass and expecting it to timeout")
claim := newClaim(ns) claim := newClaim(ns)
@ -350,14 +352,35 @@ var _ = framework.KubeDescribe("Dynamic provisioning", func() {
}) })
}) })
func verifyDefaultStorageClass(c clientset.Interface, expectedDefault bool) { func getDefaultStorageClassName(c clientset.Interface) string {
sc, err := c.StorageV1().StorageClasses().Get("default", metav1.GetOptions{}) list, err := c.StorageV1().StorageClasses().List(metav1.ListOptions{})
if err != nil {
framework.Failf("Error listing storage classes: %v", err)
}
var scName string
for _, sc := range list.Items {
if storageutil.IsDefaultAnnotation(sc.ObjectMeta) {
if len(scName) != 0 {
framework.Failf("Multiple default storage classes found: %q and %q", scName, sc.Name)
}
scName = sc.Name
}
}
if len(scName) == 0 {
framework.Failf("No default storage class found")
}
framework.Logf("Default storage class: %q", scName)
return scName
}
func verifyDefaultStorageClass(c clientset.Interface, scName string, expectedDefault bool) {
sc, err := c.StorageV1().StorageClasses().Get(scName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(storageutil.IsDefaultAnnotation(sc.ObjectMeta)).To(Equal(expectedDefault)) Expect(storageutil.IsDefaultAnnotation(sc.ObjectMeta)).To(Equal(expectedDefault))
} }
func updateDefaultStorageClass(c clientset.Interface, defaultStr string) { func updateDefaultStorageClass(c clientset.Interface, scName string, defaultStr string) {
sc, err := c.StorageV1().StorageClasses().Get("default", metav1.GetOptions{}) sc, err := c.StorageV1().StorageClasses().Get(scName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
if defaultStr == "" { if defaultStr == "" {
@ -376,7 +399,7 @@ func updateDefaultStorageClass(c clientset.Interface, defaultStr string) {
if defaultStr == "true" { if defaultStr == "true" {
expectedDefault = true expectedDefault = true
} }
verifyDefaultStorageClass(c, expectedDefault) verifyDefaultStorageClass(c, scName, expectedDefault)
} }
func newClaim(ns string) *v1.PersistentVolumeClaim { func newClaim(ns string) *v1.PersistentVolumeClaim {