Skip to content

Commit

Permalink
Improve envTest including PVC asserts
Browse files Browse the repository at this point in the history
It's a good idea assert that a local pvc is created and exists when the
main Glance CR is applied. This patch adds the related assert functions
and check that a local PVC exists when Glance is created. Given that we
are not enabling image-cache in the 'DefaultGlanceSpec', an additional
assert that checks that a '-cache' pvc has not been provisioned during
the creation phase.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Oct 9, 2023
1 parent 3ed85f8 commit 2a8d708
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
18 changes: 18 additions & 0 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,21 @@ func GlanceAPIExists(name types.NamespacedName) {
g.Expect(k8s_errors.IsNotFound(err)).To(BeFalse())
}, timeout, interval).Should(Succeed())
}

// AssertPVCDoesNotExist ensures the local PVC resource does not exist in a k8s cluster.
func AssertPVCDoesNotExist(name types.NamespacedName) {
instance := &corev1.PersistentVolumeClaim{}
Eventually(func(g Gomega) {
err := th.K8sClient.Get(th.Ctx, name, instance)
g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue())
}, th.Timeout, th.Interval).Should(Succeed())
}

// AssertPVCExist ensures the local PVC resource exist in a k8s cluster.
func AssertPVCExist(name types.NamespacedName) {
instance := &corev1.PersistentVolumeClaim{}
Eventually(func(g Gomega) {
err := th.K8sClient.Get(th.Ctx, name, instance)
g.Expect(k8s_errors.IsNotFound(err)).To(BeFalse())
}, th.Timeout, th.Interval).Should(Succeed())
}
18 changes: 10 additions & 8 deletions test/functional/glance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var _ = Describe("Glance controller", func() {
BeforeEach(func() {
DeferCleanup(th.DeleteInstance, CreateDefaultGlance(glanceName))
})

It("initializes the status fields", func() {
Eventually(func(g Gomega) {
glance := GetGlance(glanceName)
Expand All @@ -44,7 +43,6 @@ var _ = Describe("Glance controller", func() {
g.Expect(glance.Status.GlanceAPIInternalReadyCount).To(Equal(int32(0)))
}, timeout, interval).Should(Succeed())
})

It("reports InputReady False as secret is not found", func() {
th.ExpectConditionWithDetails(
glanceName,
Expand All @@ -55,7 +53,6 @@ var _ = Describe("Glance controller", func() {
"Input data resources missing",
)
})

It("initializes Spec fields", func() {
Glance := GetGlance(glanceTest.Instance)
Expect(Glance.Spec.DatabaseInstance).Should(Equal("openstack"))
Expand All @@ -67,21 +64,18 @@ var _ = Describe("Glance controller", func() {
Expect(Glance.Spec.Quotas.ImageCountTotal).To(Equal(int(0)))
Expect(Glance.Spec.Quotas.ImageStageTotal).To(Equal(int(0)))
})

It("should have a finalizer", func() {
// the reconciler loop adds the finalizer so we have to wait for
// it to run
Eventually(func() []string {
return GetGlance(glanceTest.Instance).Finalizers
}, timeout, interval).Should(ContainElement("Glance"))
})

It("should not create a config map", func() {
Eventually(func() []corev1.ConfigMap {
return th.ListConfigMaps(glanceTest.GlanceConfigMapData.Name).Items
}, timeout, interval).Should(BeEmpty())
})

It("creates service account, role and rolebindig", func() {
th.ExpectCondition(
glanceName,
Expand Down Expand Up @@ -113,13 +107,15 @@ var _ = Describe("Glance controller", func() {
Expect(binding.Subjects).To(HaveLen(1))
Expect(binding.Subjects[0].Name).To(Equal(sa.Name))
})

It("defaults the containerImages", func() {
glance := GetGlance(glanceName)
Expect(glance.Spec.ContainerImage).To(Equal(glancev1.GlanceAPIContainerImage))
Expect(glance.Spec.GlanceAPIInternal.ContainerImage).To(Equal(glancev1.GlanceAPIContainerImage))
Expect(glance.Spec.GlanceAPIExternal.ContainerImage).To(Equal(glancev1.GlanceAPIContainerImage))
})
It("should not have a pvc yet", func() {
AssertPVCDoesNotExist(glanceTest.Instance)
})
})
When("Glance DB is created", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -153,7 +149,6 @@ var _ = Describe("Glance controller", func() {
corev1.ConditionFalse,
)
})

It("Should fail if db-sync job fails when DB is Created", func() {
mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance)
th.SimulateJobFailure(glanceTest.GlanceDBSync)
Expand Down Expand Up @@ -245,6 +240,10 @@ var _ = Describe("Glance controller", func() {
keystone.SimulateKeystoneServiceReady(glanceTest.Instance)
keystone.SimulateKeystoneEndpointReady(glanceTest.GlanceInternalRoute)
})
It("should have a local pvc", func() {
AssertPVCExist(glanceTest.Instance)
AssertPVCDoesNotExist(glanceTest.GlanceCache)
})
It("Creates glanceAPI", func() {
GlanceAPIExists(glanceTest.GlanceInternal)
GlanceAPIExists(glanceTest.GlanceExternal)
Expand All @@ -253,6 +252,9 @@ var _ = Describe("Glance controller", func() {
th.AssertServiceExists(glanceTest.GlancePublicRoute)
th.AssertServiceExists(glanceTest.GlanceInternalRoute)
})
It("should not have a cache pvc (no imageCacheSize provided)", func() {
AssertPVCDoesNotExist(glanceTest.GlanceCache)
})
})
When("Glance CR is deleted", func() {
BeforeEach(func() {
Expand Down
5 changes: 5 additions & 0 deletions test/functional/glance_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type GlanceTestData struct {
GlanceInternalAPI types.NamespacedName
GlanceExternalAPI types.NamespacedName
InternalAPINAD types.NamespacedName
GlanceCache types.NamespacedName
}

// GetGlanceTestData is a function that initialize the GlanceTestData
Expand Down Expand Up @@ -127,6 +128,10 @@ func GetGlanceTestData(glanceName types.NamespacedName) GlanceTestData {
"imageCountUpload": 100,
"imageCountTotal": 100,
},
GlanceCache: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-cache", glanceName.Name),
},
InternalAPINAD: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: "internalapi",
Expand Down

0 comments on commit 2a8d708

Please sign in to comment.