Skip to content

Commit fa5a7a5

Browse files
Merge pull request openstack-k8s-operators#476 from fmount/em_envtest
Add extraMounts functional tests
2 parents cbc7eaf + 67ff150 commit fa5a7a5

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

test/functional/base_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,37 @@ func CinderVolumeNotExists(name types.NamespacedName) {
296296
g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue())
297297
}, timeout, interval).Should(Succeed())
298298
}
299+
300+
// GetExtraMounts - Utility function that simulates extraMounts pointing
301+
// to a Ceph secret
302+
func GetExtraMounts() []map[string]interface{} {
303+
return []map[string]interface{}{
304+
{
305+
"name": cinderTest.Instance.Name,
306+
"region": "az0",
307+
"extraVol": []map[string]interface{}{
308+
{
309+
"extraVolType": CinderCephExtraMountsSecretName,
310+
"propagation": []string{
311+
"CinderVolume",
312+
},
313+
"volumes": []map[string]interface{}{
314+
{
315+
"name": CinderCephExtraMountsSecretName,
316+
"secret": map[string]interface{}{
317+
"secretName": CinderCephExtraMountsSecretName,
318+
},
319+
},
320+
},
321+
"mounts": []map[string]interface{}{
322+
{
323+
"name": CinderCephExtraMountsSecretName,
324+
"mountPath": CinderCephExtraMountsPath,
325+
"readOnly": true,
326+
},
327+
},
328+
},
329+
},
330+
},
331+
}
332+
}

test/functional/cinder_controller_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,68 @@ var _ = Describe("Cinder controller", func() {
863863

864864
})
865865

866+
When("Cinder CR instance is built with ExtraMounts", func() {
867+
BeforeEach(func() {
868+
rawSpec := map[string]interface{}{
869+
"secret": SecretName,
870+
"databaseInstance": "openstack",
871+
"rabbitMqClusterName": "rabbitmq",
872+
"extraMounts": GetExtraMounts(),
873+
"cinderAPI": map[string]interface{}{
874+
"containerImage": cinderv1.CinderAPIContainerImage,
875+
},
876+
"cinderScheduler": map[string]interface{}{
877+
"containerImage": cinderv1.CinderSchedulerContainerImage,
878+
},
879+
"cinderVolumes": map[string]interface{}{
880+
"volume1": map[string]interface{}{
881+
"containerImage": cinderv1.CinderVolumeContainerImage,
882+
},
883+
},
884+
}
885+
886+
DeferCleanup(th.DeleteInstance, CreateCinder(cinderTest.Instance, rawSpec))
887+
DeferCleanup(k8sClient.Delete, ctx, CreateCinderMessageBusSecret(cinderTest.Instance.Namespace, cinderTest.RabbitmqSecretName))
888+
DeferCleanup(
889+
mariadb.DeleteDBService,
890+
mariadb.CreateDBService(
891+
cinderTest.Instance.Namespace,
892+
GetCinder(cinderTest.Instance).Spec.DatabaseInstance,
893+
corev1.ServiceSpec{
894+
Ports: []corev1.ServicePort{{Port: 3306}},
895+
},
896+
),
897+
)
898+
infra.SimulateTransportURLReady(cinderTest.CinderTransportURL)
899+
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, cinderTest.MemcachedInstance, memcachedSpec))
900+
infra.SimulateMemcachedReady(cinderTest.CinderMemcached)
901+
keystoneAPIName := keystone.CreateKeystoneAPI(cinderTest.Instance.Namespace)
902+
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
903+
mariadb.SimulateMariaDBAccountCompleted(cinderTest.Database)
904+
mariadb.SimulateMariaDBDatabaseCompleted(cinderTest.Database)
905+
th.SimulateJobSuccess(cinderTest.CinderDBSync)
906+
keystone.SimulateKeystoneEndpointReady(cinderTest.CinderKeystoneEndpoint)
907+
})
908+
909+
It("Check the extraMounts of the resulting StatefulSets", func() {
910+
th.SimulateStatefulSetReplicaReady(cinderTest.CinderAPI)
911+
th.SimulateStatefulSetReplicaReady(cinderTest.CinderScheduler)
912+
// Retrieve the generated resources
913+
volume := cinderTest.CinderVolumes[0]
914+
th.SimulateStatefulSetReplicaReady(volume)
915+
ss := th.GetStatefulSet(volume)
916+
// Check the resulting deployment replicas
917+
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
918+
// Assert Volume exists in the StatefulSet
919+
th.AssertVolumeExists(CinderCephExtraMountsSecretName, ss.Spec.Template.Spec.Volumes)
920+
// Get the cinder-volume container
921+
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(2))
922+
container := ss.Spec.Template.Spec.Containers[1]
923+
// Inspect VolumeMounts and make sure we have the Ceph MountPath
924+
// provided through extraMounts
925+
th.AssertVolumeMountExists(CinderCephExtraMountsSecretName, "", container.VolumeMounts)
926+
})
927+
})
866928
// Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests
867929
// that exercise standard account create / update patterns that should be
868930
// common to all controllers that ensure MariaDBAccount CRs.

test/functional/cinder_test_data.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const (
3333
InternalCertSecretName = "internal-tls-certs"
3434
//CABundleSecretName -
3535
CABundleSecretName = "combined-ca-bundle"
36+
// CinderCephExtraMountsPath -
37+
CinderCephExtraMountsPath = "/etc/ceph"
38+
// CinderCephExtraMountsSecretName -
39+
CinderCephExtraMountsSecretName = "ceph"
3640
)
3741

3842
// CinderTestData is the data structure used to provide input data to envTest

0 commit comments

Comments
 (0)