Skip to content

Commit fc895f1

Browse files
Merge pull request #665 from fmount/ev_envtest
Add extraMounts functional tests
2 parents 33b0fc2 + 41930fc commit fc895f1

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

test/functional/base_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,37 @@ func GetDummyBackend() string {
311311
dummyBackend := "enabled_backends=backend1:rbd"
312312
return fmt.Sprintf("%s\n%s", section, dummyBackend)
313313
}
314+
315+
// GetExtraMounts - Utility function that simulates extraMounts pointing
316+
// to a Ceph secret
317+
func GetExtraMounts() []map[string]interface{} {
318+
return []map[string]interface{}{
319+
{
320+
"name": glanceTest.Instance.Name,
321+
"region": "az0",
322+
"extraVol": []map[string]interface{}{
323+
{
324+
"extraVolType": GlanceCephExtraMountsSecretName,
325+
"propagation": []string{
326+
"GlanceAPI",
327+
},
328+
"volumes": []map[string]interface{}{
329+
{
330+
"name": GlanceCephExtraMountsSecretName,
331+
"secret": map[string]interface{}{
332+
"secretName": GlanceCephExtraMountsSecretName,
333+
},
334+
},
335+
},
336+
"mounts": []map[string]interface{}{
337+
{
338+
"name": GlanceCephExtraMountsSecretName,
339+
"mountPath": GlanceCephExtraMountsPath,
340+
"readOnly": true,
341+
},
342+
},
343+
},
344+
},
345+
},
346+
}
347+
}

test/functional/glance_controller_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3232
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
3333
mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers"
34+
appsv1 "k8s.io/api/apps/v1"
3435
corev1 "k8s.io/api/core/v1"
3536
"k8s.io/apimachinery/pkg/types"
3637
ptr "k8s.io/utils/ptr"
@@ -591,6 +592,69 @@ var _ = Describe("Glance controller", func() {
591592
})
592593
})
593594

595+
When("Glance CR instance is built with ExtraMounts", func() {
596+
BeforeEach(func() {
597+
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, glanceTest.MemcachedInstance, memcachedSpec))
598+
infra.SimulateMemcachedReady(glanceTest.GlanceMemcached)
599+
600+
rawSpec := map[string]interface{}{
601+
"storage": map[string]interface{}{
602+
"storageRequest": glanceTest.GlancePVCSize,
603+
},
604+
"storageRequest": glanceTest.GlancePVCSize,
605+
"secret": SecretName,
606+
"databaseInstance": glanceTest.GlanceDatabaseName.Name,
607+
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
608+
"customServiceConfig": GlanceDummyBackend,
609+
"extraMounts": GetExtraMounts(),
610+
}
611+
DeferCleanup(th.DeleteInstance, CreateGlance(glanceTest.Instance, rawSpec))
612+
DeferCleanup(
613+
mariadb.DeleteDBService,
614+
mariadb.CreateDBService(
615+
glanceTest.Instance.Namespace,
616+
GetGlance(glanceName).Spec.DatabaseInstance,
617+
corev1.ServiceSpec{
618+
Ports: []corev1.ServicePort{{Port: 3306}},
619+
},
620+
),
621+
)
622+
mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName)
623+
mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount)
624+
th.SimulateJobSuccess(glanceTest.GlanceDBSync)
625+
keystoneAPI := keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)
626+
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPI)
627+
keystone.SimulateKeystoneServiceReady(glanceTest.KeystoneService)
628+
})
629+
It("Check the extraMounts of the resulting StatefulSets", func() {
630+
th.SimulateStatefulSetReplicaReady(glanceTest.GlanceInternalStatefulSet)
631+
th.SimulateStatefulSetReplicaReady(glanceTest.GlanceExternalStatefulSet)
632+
// Retrieve the generated resources and the two internal/external
633+
// instances that are split behind the scenes
634+
ssInternal := th.GetStatefulSet(glanceTest.GlanceInternalStatefulSet)
635+
ssExternal := th.GetStatefulSet(glanceTest.GlanceExternalStatefulSet)
636+
637+
for _, ss := range []*appsv1.StatefulSet{ssInternal, ssExternal} {
638+
// Check the resulting deployment fields
639+
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(5))
640+
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))
641+
// Get the glance-api container
642+
container := ss.Spec.Template.Spec.Containers[2]
643+
// Fail if glance-api doesn't have the right number of VolumeMounts
644+
// entries
645+
Expect(container.VolumeMounts).To(HaveLen(7))
646+
// Inspect VolumeMounts and make sure we have the Ceph MountPath
647+
// provided through extraMounts
648+
for _, vm := range container.VolumeMounts {
649+
if vm.Name == "ceph" {
650+
Expect(vm.MountPath).To(
651+
ContainSubstring(GlanceCephExtraMountsPath))
652+
}
653+
}
654+
}
655+
})
656+
})
657+
594658
// Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests
595659
// that exercise standard account create / update patterns that should be
596660
// common to all controllers that ensure MariaDBAccount CRs.

test/functional/glance_test_data.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const (
4545
MemcachedInstance = "memcached"
4646
// AccountName - name of the MariaDBAccount CR
4747
AccountName = glance.DatabaseName
48+
// GlanceCephExtraMountsPath -
49+
GlanceCephExtraMountsPath = "/etc/ceph"
50+
// GlanceCephExtraMountsSecretName -
51+
GlanceCephExtraMountsSecretName = "ceph"
4852
)
4953

5054
// GlanceTestData is the data structure used to provide input data to envTest

0 commit comments

Comments
 (0)