From 813ed2f3a55b1f2db30d3a1d6aca6756129e184b Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Mon, 9 Dec 2024 13:38:40 +0100 Subject: [PATCH] Add extraMounts functional tests This change adds a functional test for the Manila 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 --- test/functional/base_test.go | 34 +++++++++++ test/functional/manila_controller_test.go | 74 +++++++++++++++++++++++ test/functional/manila_test_data.go | 4 ++ 3 files changed, 112 insertions(+) diff --git a/test/functional/base_test.go b/test/functional/base_test.go index abfba06f..d248f10c 100644 --- a/test/functional/base_test.go +++ b/test/functional/base_test.go @@ -336,3 +336,37 @@ func GetCronJob(name types.NamespacedName) *batchv1.CronJob { }, timeout, interval).Should(Succeed()) return cron } + +// GetExtraMounts - Utility function that simulates extraMounts pointing +// to a Ceph secret +func GetExtraMounts() []map[string]interface{} { + return []map[string]interface{}{ + { + "name": manilaTest.Instance.Name, + "region": "az0", + "extraVol": []map[string]interface{}{ + { + "extraVolType": ManilaCephExtraMountsSecretName, + "propagation": []string{ + "ManilaShare", + }, + "volumes": []map[string]interface{}{ + { + "name": ManilaCephExtraMountsSecretName, + "secret": map[string]interface{}{ + "secretName": ManilaCephExtraMountsSecretName, + }, + }, + }, + "mounts": []map[string]interface{}{ + { + "name": ManilaCephExtraMountsSecretName, + "mountPath": ManilaCephExtraMountsPath, + "readOnly": true, + }, + }, + }, + }, + }, + } +} diff --git a/test/functional/manila_controller_test.go b/test/functional/manila_controller_test.go index 8258bb60..9fee90c9 100644 --- a/test/functional/manila_controller_test.go +++ b/test/functional/manila_controller_test.go @@ -856,6 +856,80 @@ var _ = Describe("Manila controller", func() { }, timeout, interval).Should(Succeed()) }) }) + When("Manila CR instance is built with ExtraMounts", func() { + BeforeEach(func() { + rawSpec := map[string]interface{}{ + "secret": SecretName, + "databaseInstance": "openstack", + "rabbitMqClusterName": "rabbitmq", + "extraMounts": GetExtraMounts(), + "manilaAPI": map[string]interface{}{ + "containerImage": manilav1.ManilaAPIContainerImage, + }, + "manilaScheduler": map[string]interface{}{ + "containerImage": manilav1.ManilaSchedulerContainerImage, + }, + "manilaShares": map[string]interface{}{ + "share0": map[string]interface{}{ + "containerImage": manilav1.ManilaShareContainerImage, + }, + }, + } + DeferCleanup(th.DeleteInstance, CreateManila(manilaTest.Instance, rawSpec)) + DeferCleanup(k8sClient.Delete, ctx, CreateManilaMessageBusSecret(manilaTest.Instance.Namespace, manilaTest.RabbitmqSecretName)) + DeferCleanup( + mariadb.DeleteDBService, + mariadb.CreateDBService( + manilaTest.Instance.Namespace, + GetManila(manilaTest.Instance).Spec.DatabaseInstance, + corev1.ServiceSpec{ + Ports: []corev1.ServicePort{{Port: 3306}}, + }, + ), + ) + infra.SimulateTransportURLReady(manilaTest.ManilaTransportURL) + DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, manilaTest.MemcachedInstance, memcachedSpec)) + infra.SimulateMemcachedReady(manilaTest.ManilaMemcached) + keystoneAPIName := keystone.CreateKeystoneAPI(manilaTest.Instance.Namespace) + DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName) + keystoneAPI := keystone.GetKeystoneAPI(keystoneAPIName) + keystoneAPI.Status.APIEndpoints["internal"] = "http://keystone-internal-openstack.testing" + Eventually(func(g Gomega) { + g.Expect(k8sClient.Status().Update(ctx, keystoneAPI.DeepCopy())).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + mariadb.SimulateMariaDBDatabaseCompleted(manilaTest.ManilaDatabaseName) + mariadb.SimulateMariaDBAccountCompleted(manilaTest.ManilaDatabaseAccount) + th.SimulateJobSuccess(manilaTest.ManilaDBSync) + keystone.SimulateKeystoneServiceReady(manilaTest.Instance) + }) + It("Check the extraMounts of the resulting StatefulSets", func() { + th.SimulateStatefulSetReplicaReady(manilaTest.ManilaAPI) + th.SimulateStatefulSetReplicaReady(manilaTest.ManilaScheduler) + th.SimulateStatefulSetReplicaReady(manilaTest.ManilaShares[0]) + keystone.SimulateKeystoneEndpointReady(manilaTest.ManilaKeystoneEndpoint) + // Retrieve the generated resources + share := manilaTest.ManilaShares[0] + th.SimulateStatefulSetReplicaReady(share) + ss := th.GetStatefulSet(share) + // Check the resulting deployment fields + Expect(int(*ss.Spec.Replicas)).To(Equal(1)) + Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(7)) + Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(2)) + // Get the manila-share container + container := ss.Spec.Template.Spec.Containers[1] + // Fail if manila-share doesn't have the right number of + // VolumeMounts entries + Expect(container.VolumeMounts).To(HaveLen(9)) + // 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(ManilaCephExtraMountsPath)) + } + } + }) + }) // Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests // that exercise standard account create / update patterns that should be diff --git a/test/functional/manila_test_data.go b/test/functional/manila_test_data.go index 4fa402d1..e8596247 100644 --- a/test/functional/manila_test_data.go +++ b/test/functional/manila_test_data.go @@ -33,6 +33,10 @@ const ( InternalCertSecretName = "internal-tls-certs" //CABundleSecretName - CABundleSecretName = "combined-ca-bundle" + // ManilaCephExtraMountsPath - + ManilaCephExtraMountsPath = "/etc/ceph" + // ManilaCephExtraMountsSecretName - + ManilaCephExtraMountsSecretName = "ceph" ) // ManilaTestData is the data structure used to provide input data to envTest