Skip to content

Commit

Permalink
Improve functional tests to support single mode API
Browse files Browse the repository at this point in the history
This commit improves the existing functional tests to reflect the new
changes introduced by the previous patches.
In particular the glance_controller_test:

1. handles the creation of a single API (split vs single)
2. checks if a CronJob exists when the main CR is created
3. checks if a PVC associated to imageCacheSize exists

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Oct 24, 2023
1 parent 1547ba8 commit 7219776
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 67 deletions.
17 changes: 13 additions & 4 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

glancev1 "github.com/openstack-k8s-operators/glance-operator/api/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
batchv1 "k8s.io/api/batch/v1"
)

func GetGlance(name types.NamespacedName) *glancev1.Glance {
Expand Down Expand Up @@ -154,10 +155,9 @@ func CreateGlanceSecret(namespace string, name string) *corev1.Secret {

func GetDefaultGlanceSpec() map[string]interface{} {
return map[string]interface{}{
"databaseInstance": "openstack",
"secret": SecretName,
"glanceAPIInternal": GetDefaultGlanceAPITemplate(GlanceAPITypeInternal),
"glanceAPIExternal": GetDefaultGlanceAPITemplate(GlanceAPITypeExternal),
"databaseInstance": "openstack",
"secret": SecretName,
"glanceAPI": GetDefaultGlanceAPITemplate(GlanceAPITypeSingle),
}
}

Expand Down Expand Up @@ -212,3 +212,12 @@ func AssertPVCExist(name types.NamespacedName) {
g.Expect(k8s_errors.IsNotFound(err)).To(BeFalse())
}, th.Timeout, th.Interval).Should(Succeed())
}

// AssertCronJobDoesNotExist ensures the CronJob resource does not exist in a k8s cluster.
func AssertCronJobDoesNotExist(name types.NamespacedName) {
instance := &batchv1.CronJob{}
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())
}
58 changes: 38 additions & 20 deletions test/functional/glance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ var _ = Describe("Glance controller", func() {
It("should not have a pvc yet", func() {
AssertPVCDoesNotExist(glanceTest.Instance)
})
It("dbPurge cronJob does not exist yet", func() {
AssertCronJobDoesNotExist(glanceTest.Instance)
})
})
When("Glance DB is created", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -216,7 +219,6 @@ var _ = Describe("Glance controller", func() {
It("has the expected container image defaults", func() {
glanceDefault := GetGlance(glanceTest.Instance)
Expect(glanceDefault.Spec.GlanceAPI.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT", glancev1.GlanceAPIContainerImage)))
//Expect(glanceDefault.Spec.GlanceAPIs.GlanceAPIInternal.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT", glancev1.GlanceAPIContainerImage)))
})
})
When("All the Resources are ready", func() {
Expand All @@ -239,15 +241,21 @@ var _ = Describe("Glance controller", func() {
keystone.SimulateKeystoneServiceReady(glanceTest.Instance)
keystone.SimulateKeystoneEndpointReady(glanceTest.GlancePublicRoute)
})
It("should have a local pvc", func() {
It("should have a local pvc but not for cache", func() {
AssertPVCExist(glanceTest.Instance)
AssertPVCDoesNotExist(glanceTest.GlanceCache)
})
It("Creates glanceAPI", func() {
// Default type is "split", make sure that behind the scenes two
// glanceAPI deployment are created
GlanceAPIExists(glanceTest.GlanceExternal)
GlanceAPIExists(glanceTest.GlanceInternal)
})
It("Assert Services are created", func() {
// Both glance-public and glance-internal svc are created regardless
// if we split behind the scenes
th.AssertServiceExists(glanceTest.GlancePublicSvc)
th.AssertServiceExists(glanceTest.GlanceInternalSvc)
})
It("should not have a cache pvc (no imageCacheSize provided)", func() {
AssertPVCDoesNotExist(glanceTest.GlanceCache)
Expand Down Expand Up @@ -282,26 +290,34 @@ var _ = Describe("Glance controller", func() {
BeforeEach(func() {
nad := th.CreateNetworkAttachmentDefinition(glanceTest.InternalAPINAD)
DeferCleanup(th.DeleteInstance, nad)
var externalEndpoints []interface{}
externalEndpoints = append(
externalEndpoints, map[string]interface{}{
"endpoint": "internal",
"ipAddressPool": "osp-internalapi",
"loadBalancerIPs": []string{"10.1.0.1", "10.1.0.2"},

serviceOverride := map[string]interface{}{}
serviceOverride["internal"] = map[string]interface{}{
"metadata": map[string]map[string]string{
"annotations": {
"metallb.universe.tf/address-pool": "osp-internalapi",
"metallb.universe.tf/allow-shared-ip": "osp-internalapi",
"metallb.universe.tf/loadBalancerIPs": "internal-lb-ip-1,internal-lb-ip-2",
},
"labels": {
"internal": "true",
"service": "glance",
},
},
)
"spec": map[string]interface{}{
"type": "LoadBalancer",
},
}
rawSpec := map[string]interface{}{
"storageRequest": glanceTest.GlancePVCSize,
"secret": SecretName,
"databaseInstance": "openstack",
"glanceAPIInternal": map[string]interface{}{
"containerImage": glancev1.GlanceAPIContainerImage,
"networkAttachments": []string{"internalapi"},
"externalEndpoints": externalEndpoints,
},
"glanceAPI": map[string]interface{}{
"containerImage": glancev1.GlanceAPIContainerImage,
"networkAttachments": []string{"internalapi"},
"override": map[string]interface{}{
"service": serviceOverride,
},
},
}
DeferCleanup(th.DeleteInstance, CreateGlance(glanceTest.Instance, rawSpec))
Expand All @@ -327,20 +343,22 @@ var _ = Describe("Glance controller", func() {
keystone.SimulateKeystoneServiceReady(glanceTest.Instance)
})
It("Check the resulting endpoints of the generated sub-CRs", func() {
/*th.SimulateDeploymentReadyWithPods(
th.SimulateDeploymentReadyWithPods(
glanceTest.GlanceInternalAPI,
map[string][]string{glanceName.Namespace + "/internalapi": {"10.0.0.1"}},
)*/
)
th.SimulateDeploymentReadyWithPods(
glanceTest.GlanceExternalAPI,
map[string][]string{glanceName.Namespace + "/internalapi": {"10.0.0.1"}},
)
// Retrieve the generated resources
// Retrieve the generated resources and the two internal/external
// instances that are split behind the scenes
glance := GetGlance(glanceTest.Instance)
//internalAPI := GetGlanceAPI(glanceTest.GlanceInternal)
internalAPI := GetGlanceAPI(glanceTest.GlanceInternal)
externalAPI := GetGlanceAPI(glanceTest.GlanceExternal)
// Check GlanceAPI NADs
//Expect(internalAPI.Spec.NetworkAttachments).To(Equal(glance.Spec.GlanceAPIs.GlanceAPIInternal.NetworkAttachments))
// Check GlanceAPI(s): we expect the two instances (internal/external)
// to have the same NADs as we mirror the deployment
Expect(internalAPI.Spec.NetworkAttachments).To(Equal(glance.Spec.GlanceAPI.NetworkAttachments))
Expect(externalAPI.Spec.NetworkAttachments).To(Equal(glance.Spec.GlanceAPI.NetworkAttachments))
})
})
Expand Down
21 changes: 19 additions & 2 deletions test/functional/glance_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
GlanceAPITypeInternal APIType = "internal"
//GlanceAPITypeExternal -
GlanceAPITypeExternal APIType = "external"
//GlanceAPITypeSingle -
GlanceAPITypeSingle APIType = "single"
)

// GlanceTestData is the data structure used to provide input data to envTest
Expand All @@ -39,6 +41,7 @@ type GlanceTestData struct {
GlancePort string
GlanceQuotas map[string]interface{}
Instance types.NamespacedName
GlanceSingle types.NamespacedName
GlanceInternal types.NamespacedName
GlanceExternal types.NamespacedName
GlanceRole types.NamespacedName
Expand All @@ -47,11 +50,13 @@ type GlanceTestData struct {
GlanceDBSync types.NamespacedName
GlancePublicRoute types.NamespacedName
GlancePublicSvc types.NamespacedName
GlanceInternalRoute types.NamespacedName
GlanceInternalSvc types.NamespacedName
GlanceService types.NamespacedName
GlanceConfigMapData types.NamespacedName
GlanceInternalConfigMapData types.NamespacedName
GlanceSingleConfigMapData types.NamespacedName
GlanceConfigMapScripts types.NamespacedName
GlanceSingleAPI types.NamespacedName
GlanceInternalAPI types.NamespacedName
GlanceExternalAPI types.NamespacedName
InternalAPINAD types.NamespacedName
Expand All @@ -70,6 +75,10 @@ func GetGlanceTestData(glanceName types.NamespacedName) GlanceTestData {
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-db-sync", glanceName.Name),
},
GlanceSingleAPI: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-single-api", glanceName.Name),
},
GlanceInternalAPI: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-internal-api", glanceName.Name),
Expand All @@ -78,6 +87,10 @@ func GetGlanceTestData(glanceName types.NamespacedName) GlanceTestData {
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-external-api", glanceName.Name),
},
GlanceSingle: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-single", glanceName.Name),
},
GlanceInternal: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-internal", glanceName.Name),
Expand Down Expand Up @@ -110,12 +123,16 @@ func GetGlanceTestData(glanceName types.NamespacedName) GlanceTestData {
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-%s", glanceName.Name, "internal-config-data"),
},
GlanceSingleConfigMapData: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-%s", glanceName.Name, "single-config-data"),
},
GlanceService: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: "image",
},
// Also used to identify GlanceKeystoneService
GlanceInternalRoute: types.NamespacedName{
GlanceInternalSvc: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-internal", glanceName.Name),
},
Expand Down
Loading

0 comments on commit 7219776

Please sign in to comment.