Skip to content

Commit

Permalink
Add extraMounts functional tests
Browse files Browse the repository at this point in the history
This change adds a functional test for the Glance extraMounts. It
ensures we're able to validate the abstraction of 'corev1.VolumeSource'
struct introduced in lib-common/storage module.

Jira: https://issues.redhat.com/browse/OSPRH-11210

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Dec 3, 2024
1 parent 52beb44 commit 41930fc
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,37 @@ func GetDummyBackend() string {
dummyBackend := "enabled_backends=backend1:rbd"
return fmt.Sprintf("%s\n%s", section, dummyBackend)
}

// GetExtraMounts - Utility function that simulates extraMounts pointing
// to a Ceph secret
func GetExtraMounts() []map[string]interface{} {
return []map[string]interface{}{
{
"name": glanceTest.Instance.Name,
"region": "az0",
"extraVol": []map[string]interface{}{
{
"extraVolType": GlanceCephExtraMountsSecretName,
"propagation": []string{
"GlanceAPI",
},
"volumes": []map[string]interface{}{
{
"name": GlanceCephExtraMountsSecretName,
"secret": map[string]interface{}{
"secretName": GlanceCephExtraMountsSecretName,
},
},
},
"mounts": []map[string]interface{}{
{
"name": GlanceCephExtraMountsSecretName,
"mountPath": GlanceCephExtraMountsPath,
"readOnly": true,
},
},
},
},
},
}
}
64 changes: 64 additions & 0 deletions test/functional/glance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
ptr "k8s.io/utils/ptr"
Expand Down Expand Up @@ -591,6 +592,69 @@ var _ = Describe("Glance controller", func() {
})
})

When("Glance CR instance is built with ExtraMounts", func() {
BeforeEach(func() {
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, glanceTest.MemcachedInstance, memcachedSpec))
infra.SimulateMemcachedReady(glanceTest.GlanceMemcached)

rawSpec := map[string]interface{}{
"storage": map[string]interface{}{
"storageRequest": glanceTest.GlancePVCSize,
},
"storageRequest": glanceTest.GlancePVCSize,
"secret": SecretName,
"databaseInstance": glanceTest.GlanceDatabaseName.Name,
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
"customServiceConfig": GlanceDummyBackend,
"extraMounts": GetExtraMounts(),
}
DeferCleanup(th.DeleteInstance, CreateGlance(glanceTest.Instance, rawSpec))
DeferCleanup(
mariadb.DeleteDBService,
mariadb.CreateDBService(
glanceTest.Instance.Namespace,
GetGlance(glanceName).Spec.DatabaseInstance,
corev1.ServiceSpec{
Ports: []corev1.ServicePort{{Port: 3306}},
},
),
)
mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName)
mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount)
th.SimulateJobSuccess(glanceTest.GlanceDBSync)
keystoneAPI := keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPI)
keystone.SimulateKeystoneServiceReady(glanceTest.KeystoneService)
})
It("Check the extraMounts of the resulting StatefulSets", func() {
th.SimulateStatefulSetReplicaReady(glanceTest.GlanceInternalStatefulSet)
th.SimulateStatefulSetReplicaReady(glanceTest.GlanceExternalStatefulSet)
// Retrieve the generated resources and the two internal/external
// instances that are split behind the scenes
ssInternal := th.GetStatefulSet(glanceTest.GlanceInternalStatefulSet)
ssExternal := th.GetStatefulSet(glanceTest.GlanceExternalStatefulSet)

for _, ss := range []*appsv1.StatefulSet{ssInternal, ssExternal} {
// Check the resulting deployment fields
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(5))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))
// Get the glance-api container
container := ss.Spec.Template.Spec.Containers[2]
// Fail if glance-api doesn't have the right number of VolumeMounts
// entries
Expect(container.VolumeMounts).To(HaveLen(7))
// Inspect VolumeMounts and make sure we have the Ceph MountPath
// provided through extraMounts
for _, vm := range container.VolumeMounts {
if vm.Name == "ceph" {
Expect(vm.MountPath).To(
ContainSubstring(GlanceCephExtraMountsPath))
}
}
}
})
})

// Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests
// that exercise standard account create / update patterns that should be
// common to all controllers that ensure MariaDBAccount CRs.
Expand Down
4 changes: 4 additions & 0 deletions test/functional/glance_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const (
MemcachedInstance = "memcached"
// AccountName - name of the MariaDBAccount CR
AccountName = glance.DatabaseName
// GlanceCephExtraMountsPath -
GlanceCephExtraMountsPath = "/etc/ceph"
// GlanceCephExtraMountsSecretName -
GlanceCephExtraMountsSecretName = "ceph"
)

// GlanceTestData is the data structure used to provide input data to envTest
Expand Down

0 comments on commit 41930fc

Please sign in to comment.