Skip to content

Commit 6fc2864

Browse files
committed
Add functional tests for region and external keystone API
- Add test to verify region field is set in status when specified - Add test for external keystone API functionality including: * Region field being set in status * API endpoints being correctly set from override spec * No deployment being created for external keystone API * Conditions being set correctly - Fix timing issue in webhook test by adding Eventually wrapper All 70 functional tests now pass.
1 parent ebc9e38 commit 6fc2864

File tree

2 files changed

+121
-6
lines changed

2 files changed

+121
-6
lines changed

test/functional/keystoneapi_controller_test.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ import (
3737
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3838
mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers"
3939
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
40+
appsv1 "k8s.io/api/apps/v1"
4041
corev1 "k8s.io/api/core/v1"
42+
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
4143
"k8s.io/apimachinery/pkg/types"
4244
"k8s.io/utils/ptr"
4345
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -2349,4 +2351,115 @@ OIDCRedirectURI "{{ .KeystoneEndpointPublic }}/v3/auth/OS-FEDERATION/websso/open
23492351
})
23502352
})
23512353

2354+
When("A KeystoneAPI is created with region specified", func() {
2355+
BeforeEach(func() {
2356+
spec := GetDefaultKeystoneAPISpec()
2357+
spec["region"] = "test-region"
2358+
DeferCleanup(
2359+
k8sClient.Delete, ctx, CreateKeystoneMessageBusSecret(namespace, "rabbitmq-secret"))
2360+
DeferCleanup(th.DeleteInstance, CreateKeystoneAPI(keystoneAPIName, spec))
2361+
DeferCleanup(
2362+
k8sClient.Delete, ctx, CreateKeystoneAPISecret(namespace, SecretName))
2363+
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, "memcached", memcachedSpec))
2364+
DeferCleanup(
2365+
mariadb.DeleteDBService,
2366+
mariadb.CreateDBService(
2367+
namespace,
2368+
GetKeystoneAPI(keystoneAPIName).Spec.DatabaseInstance,
2369+
corev1.ServiceSpec{
2370+
Ports: []corev1.ServicePort{{Port: 3306}},
2371+
},
2372+
),
2373+
)
2374+
mariadb.SimulateMariaDBAccountCompleted(keystoneAccountName)
2375+
mariadb.SimulateMariaDBDatabaseCompleted(keystoneDatabaseName)
2376+
infra.SimulateTransportURLReady(types.NamespacedName{
2377+
Name: fmt.Sprintf("%s-keystone-transport", keystoneAPIName.Name),
2378+
Namespace: namespace,
2379+
})
2380+
infra.SimulateMemcachedReady(types.NamespacedName{
2381+
Name: "memcached",
2382+
Namespace: namespace,
2383+
})
2384+
th.SimulateJobSuccess(dbSyncJobName)
2385+
th.SimulateJobSuccess(bootstrapJobName)
2386+
th.SimulateDeploymentReplicaReady(deploymentName)
2387+
})
2388+
2389+
It("should set region in status", func() {
2390+
Eventually(func(g Gomega) {
2391+
instance := keystone.GetKeystoneAPI(keystoneAPIName)
2392+
g.Expect(instance).NotTo(BeNil())
2393+
g.Expect(instance.Status.Region).To(Equal("test-region"))
2394+
g.Expect(instance.Spec.Region).To(Equal("test-region"))
2395+
}, timeout, interval).Should(Succeed())
2396+
2397+
th.ExpectCondition(
2398+
keystoneAPIName,
2399+
ConditionGetterFunc(KeystoneConditionGetter),
2400+
condition.ReadyCondition,
2401+
corev1.ConditionTrue,
2402+
)
2403+
})
2404+
})
2405+
2406+
When("A KeystoneAPI is created with externalKeystoneAPI enabled", func() {
2407+
BeforeEach(func() {
2408+
spec := GetDefaultKeystoneAPISpec()
2409+
spec["externalKeystoneAPI"] = true
2410+
spec["region"] = "external-region"
2411+
spec["override"] = map[string]any{
2412+
"service": map[string]any{
2413+
"public": map[string]any{
2414+
"endpointURL": "https://external-keystone.example.com:5000",
2415+
},
2416+
"internal": map[string]any{
2417+
"endpointURL": "https://internal-keystone.example.com:5000",
2418+
},
2419+
},
2420+
}
2421+
DeferCleanup(
2422+
k8sClient.Delete, ctx, CreateKeystoneAPISecret(namespace, SecretName))
2423+
DeferCleanup(th.DeleteInstance, CreateKeystoneAPI(keystoneAPIName, spec))
2424+
})
2425+
2426+
It("should set region and endpoints in status without deploying resources", func() {
2427+
Eventually(func(g Gomega) {
2428+
instance := keystone.GetKeystoneAPI(keystoneAPIName)
2429+
g.Expect(instance).NotTo(BeNil())
2430+
g.Expect(instance.Spec.ExternalKeystoneAPI).To(BeTrue())
2431+
g.Expect(instance.Status.Region).To(Equal("external-region"))
2432+
g.Expect(instance.Status.APIEndpoints).To(HaveKeyWithValue("public", "https://external-keystone.example.com:5000"))
2433+
g.Expect(instance.Status.APIEndpoints).To(HaveKeyWithValue("internal", "https://internal-keystone.example.com:5000"))
2434+
g.Expect(instance.Status.ReadyCount).To(Equal(int32(0)))
2435+
}, timeout, interval).Should(Succeed())
2436+
2437+
// Verify conditions are set for external keystone
2438+
th.ExpectCondition(
2439+
keystoneAPIName,
2440+
ConditionGetterFunc(KeystoneConditionGetter),
2441+
condition.DBReadyCondition,
2442+
corev1.ConditionTrue,
2443+
)
2444+
th.ExpectCondition(
2445+
keystoneAPIName,
2446+
ConditionGetterFunc(KeystoneConditionGetter),
2447+
condition.DeploymentReadyCondition,
2448+
corev1.ConditionTrue,
2449+
)
2450+
th.ExpectCondition(
2451+
keystoneAPIName,
2452+
ConditionGetterFunc(KeystoneConditionGetter),
2453+
condition.ReadyCondition,
2454+
corev1.ConditionTrue,
2455+
)
2456+
2457+
// Verify no deployment is created
2458+
Eventually(func() bool {
2459+
err := k8sClient.Get(ctx, deploymentName, &appsv1.Deployment{})
2460+
return k8s_errors.IsNotFound(err)
2461+
}, timeout, interval).Should(BeTrue())
2462+
})
2463+
})
2464+
23522465
})

test/functional/keystoneapi_webhook_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,14 @@ var _ = Describe("KeystoneAPI Webhook", func() {
171171
th.SimulateJobSuccess(bootstrapJobName)
172172
th.SimulateDeploymentReplicaReady(deploymentName)
173173

174-
th.ExpectCondition(
175-
keystoneAPIName,
176-
ConditionGetterFunc(KeystoneConditionGetter),
177-
condition.ReadyCondition,
178-
corev1.ConditionTrue,
179-
)
174+
Eventually(func(g Gomega) {
175+
th.ExpectCondition(
176+
keystoneAPIName,
177+
ConditionGetterFunc(KeystoneConditionGetter),
178+
condition.ReadyCondition,
179+
corev1.ConditionTrue,
180+
)
181+
}, timeout, interval).Should(Succeed())
180182
})
181183

182184
It("rejects update with wrong service override endpoint type", func() {

0 commit comments

Comments
 (0)