Skip to content

Commit c073a6b

Browse files
committed
Adds tests for notification bus
1 parent c14c644 commit c073a6b

3 files changed

Lines changed: 149 additions & 16 deletions

File tree

test/functional/base_test.go

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import (
2121

2222
. "github.com/onsi/gomega" //revive:disable:dot-imports
2323

24+
"maps"
25+
2426
batchv1 "k8s.io/api/batch/v1"
2527
corev1 "k8s.io/api/core/v1"
2628
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
2729
"k8s.io/apimachinery/pkg/types"
2830
"k8s.io/utils/ptr"
29-
"maps"
3031
"sigs.k8s.io/controller-runtime/pkg/client"
3132

3233
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
@@ -164,6 +165,30 @@ func CreateNovaWithCell0(name types.NamespacedName) client.Object {
164165
return th.CreateUnstructured(rawNova)
165166
}
166167

168+
func CreateNovaWithNotificationBus(
169+
name types.NamespacedName,
170+
notificationsBus NotificationsBusNames) client.Object {
171+
172+
rawNova := map[string]interface{}{
173+
"apiVersion": "nova.openstack.org/v1beta1",
174+
"kind": "Nova",
175+
"metadata": map[string]interface{}{
176+
"name": name.Name,
177+
"namespace": name.Namespace,
178+
},
179+
"spec": map[string]interface{}{
180+
"secret": SecretName,
181+
"apiDatabaseAccount": novaNames.APIMariaDBDatabaseAccount.Name,
182+
// I think we don't need cell0.transport-url here
183+
// but its in CR.
184+
"apiMessageBusInstance": cell0.TransportURLName.Name,
185+
"notificationsBusInstance": notificationsBus.TransportURLName.Name,
186+
},
187+
}
188+
189+
return th.CreateUnstructured(rawNova)
190+
}
191+
167192
func GetNova(name types.NamespacedName) *novav1.Nova {
168193
instance := &novav1.Nova{}
169194
Eventually(func(g Gomega) {
@@ -228,6 +253,20 @@ func CreateNovaMessageBusSecret(cell CellNames) *corev1.Secret {
228253
return s
229254
}
230255

256+
func CreateNovaNotificationBusSecret(notificationsBus NotificationsBusNames) *corev1.Secret {
257+
logger.Info("", "rabbit-notification", notificationsBus)
258+
s := th.CreateSecret(
259+
types.NamespacedName{
260+
Namespace: novaNames.NovaName.Namespace,
261+
Name: fmt.Sprintf("%s-secret", notificationsBus.TransportURLName.Name)},
262+
map[string][]byte{
263+
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", novaNames.notificationsBusName)),
264+
},
265+
)
266+
logger.Info("Secret created", "name", s.Name)
267+
return s
268+
}
269+
231270
func GetDefaultNovaCellSpec(cell CellNames) map[string]interface{} {
232271
return map[string]interface{}{
233272
"cellName": cell.CellName,
@@ -485,6 +524,47 @@ func GetCellNames(novaName types.NamespacedName, cell string) CellNames {
485524
return c
486525
}
487526

527+
type NotificationsBusNames struct {
528+
notificationsBusName string
529+
notificationsBusCRName types.NamespacedName
530+
TransportURLName types.NamespacedName
531+
532+
// MariaDBDatabaseName types.NamespacedName
533+
// MariaDBAccountName types.NamespacedName
534+
// APIDatabaseAccountName types.NamespacedName
535+
// ConductorName types.NamespacedName
536+
// DBSyncJobName types.NamespacedName
537+
// ConductorConfigDataName types.NamespacedName
538+
// ConductorScriptDataName types.NamespacedName
539+
// ConductorStatefulSetName types.NamespacedName
540+
// CellMappingJobName types.NamespacedName
541+
// CellDeleteJobName types.NamespacedName
542+
// MetadataName types.NamespacedName
543+
// MetadataStatefulSetName types.NamespacedName
544+
// MetadataConfigDataName types.NamespacedName
545+
// MetadataNeutronConfigDataName types.NamespacedName
546+
// NoVNCProxyName types.NamespacedName
547+
// NoVNCProxyStatefulSetName types.NamespacedName
548+
// CellNoVNCProxyNameConfigDataName types.NamespacedName
549+
// InternalCellSecretName types.NamespacedName
550+
// InternalAPINetworkNADName types.NamespacedName
551+
// ComputeConfigSecretName types.NamespacedName
552+
// NovaComputeName types.NamespacedName
553+
// NovaComputeStatefulSetName types.NamespacedName
554+
// NovaComputeConfigDataName types.NamespacedName
555+
// HostDiscoveryJobName types.NamespacedName
556+
// DBPurgeCronJobName types.NamespacedName
557+
}
558+
559+
func GetNotificationsBusNames(novaName types.NamespacedName) NotificationsBusNames {
560+
busName := "rabbitmq-broadcaster"
561+
return NotificationsBusNames{
562+
notificationsBusName: busName,
563+
notificationsBusCRName: types.NamespacedName{Namespace: novaName.Namespace, Name: busName},
564+
TransportURLName: types.NamespacedName{Namespace: novaName.Namespace, Name: busName},
565+
}
566+
}
567+
488568
type NovaNames struct {
489569
Namespace string
490570
NovaName types.NamespacedName
@@ -519,6 +599,7 @@ type NovaNames struct {
519599
MemcachedNamespace types.NamespacedName
520600
Cells map[string]CellNames
521601
NovaTopologies []types.NamespacedName
602+
notificationsBusName types.NamespacedName
522603
}
523604

524605
func GetNovaNames(novaName types.NamespacedName, cellNames []string) NovaNames {

test/functional/nova_controller_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,57 @@ import (
3838
"github.com/openstack-k8s-operators/nova-operator/controllers"
3939
)
4040

41+
var _ = Describe("Nova controller - notifications broadcaster", func() {
42+
43+
When("Nova CR instance is created", func() {
44+
BeforeEach(func() {
45+
notificationsBus := GetNotificationsBusNames(novaNames.NovaName)
46+
47+
DeferCleanup(
48+
k8sClient.Delete, ctx, CreateNovaSecret(novaNames.NovaName.Namespace, SecretName))
49+
50+
DeferCleanup(
51+
k8sClient.Delete, ctx, CreateNovaNotificationBusSecret(notificationsBus))
52+
DeferCleanup(
53+
mariadb.DeleteDBService,
54+
mariadb.CreateDBService(
55+
novaNames.NovaName.Namespace,
56+
"openstack",
57+
corev1.ServiceSpec{
58+
Ports: []corev1.ServicePort{{Port: 3306}},
59+
},
60+
),
61+
)
62+
memcachedSpec := GetDefaultMemcachedSpec()
63+
64+
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(novaNames.NovaName.Namespace, MemcachedInstance, memcachedSpec))
65+
infra.SimulateMemcachedReady(novaNames.MemcachedNamespace)
66+
67+
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(novaNames.NovaName.Namespace))
68+
69+
DeferCleanup(th.DeleteInstance, CreateNovaWithNotificationBus(novaNames.NovaName, notificationsBus))
70+
71+
})
72+
73+
It("should create notificationsBusInstance secret with transport url", func() {
74+
75+
nova := GetNova(novaNames.NovaName)
76+
77+
Expect(nova.Spec.NotificationsBusInstance).ToNot(BeNil())
78+
Expect(*nova.Spec.NotificationsBusInstance).To(Equal("rabbitmq-broadcaster"))
79+
80+
secretName := types.NamespacedName{
81+
Namespace: novaNames.NovaName.Namespace,
82+
Name: fmt.Sprintf("%s-secret", *nova.Spec.NotificationsBusInstance),
83+
}
84+
secret := th.GetSecret(secretName)
85+
Expect(secret).NotTo(BeNil())
86+
Expect(secret.Data).To(HaveKey("transport_url"))
87+
logger.Info("", "rabbit-url", secret.Data["transport_url"])
88+
})
89+
})
90+
})
91+
4192
var _ = Describe("Nova controller", func() {
4293
When("Nova CR instance is created without a proper secret", func() {
4394
BeforeEach(func() {

test/functional/suite_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,22 @@ import (
7070
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
7171

7272
var (
73-
cfg *rest.Config
74-
k8sClient client.Client
75-
testEnv *envtest.Environment
76-
ctx context.Context
77-
cancel context.CancelFunc
78-
logger logr.Logger
79-
th *common_test.TestHelper
80-
keystone *keystone_test.TestHelper
81-
mariadb *mariadb_test.TestHelper
82-
infra *infra_test.TestHelper
83-
novaNames NovaNames
84-
cell0 CellNames
85-
cell1 CellNames
86-
cell2 CellNames
87-
cell3 CellNames
73+
cfg *rest.Config
74+
k8sClient client.Client
75+
testEnv *envtest.Environment
76+
ctx context.Context
77+
cancel context.CancelFunc
78+
logger logr.Logger
79+
th *common_test.TestHelper
80+
keystone *keystone_test.TestHelper
81+
mariadb *mariadb_test.TestHelper
82+
infra *infra_test.TestHelper
83+
novaNames NovaNames
84+
cell0 CellNames
85+
cell1 CellNames
86+
cell2 CellNames
87+
cell3 CellNames
88+
notificationsBus NotificationsBusNames
8889
)
8990

9091
func TestAPIs(t *testing.T) {

0 commit comments

Comments
 (0)