@@ -38,6 +38,151 @@ import (
3838 "github.com/openstack-k8s-operators/nova-operator/controllers"
3939)
4040
41+ var _ = Describe ("Nova controller - notifications" , func () {
42+
43+ When ("Nova CR instance is created" , func () {
44+ BeforeEach (func () {
45+ DeferCleanup (
46+ k8sClient .Delete , ctx , CreateNovaSecret (novaNames .NovaName .Namespace , SecretName ))
47+ DeferCleanup (
48+ k8sClient .Delete , ctx , CreateNovaMessageBusSecret (cell0 ))
49+ DeferCleanup (
50+ mariadb .DeleteDBService ,
51+ mariadb .CreateDBService (
52+ novaNames .NovaName .Namespace ,
53+ "openstack" ,
54+ corev1.ServiceSpec {
55+ Ports : []corev1.ServicePort {{Port : 3306 }},
56+ },
57+ ),
58+ )
59+ memcachedSpec := infra .GetDefaultMemcachedSpec ()
60+
61+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (novaNames .NovaName .Namespace , MemcachedInstance , memcachedSpec ))
62+ infra .SimulateMemcachedReady (novaNames .MemcachedNamespace )
63+
64+ DeferCleanup (keystone .DeleteKeystoneAPI , keystone .CreateKeystoneAPI (novaNames .NovaName .Namespace ))
65+
66+ DeferCleanup (th .DeleteInstance , CreateNovaWithCell0 (novaNames .NovaName ))
67+
68+ keystone .SimulateKeystoneServiceReady (novaNames .KeystoneServiceName )
69+ mariadb .SimulateMariaDBDatabaseCompleted (novaNames .APIMariaDBDatabaseName )
70+ mariadb .SimulateMariaDBAccountCompleted (novaNames .APIMariaDBDatabaseAccount )
71+ mariadb .SimulateMariaDBDatabaseCompleted (cell0 .MariaDBDatabaseName )
72+ mariadb .SimulateMariaDBAccountCompleted (cell0 .MariaDBAccountName )
73+ infra .SimulateTransportURLReady (cell0 .TransportURLName )
74+ SimulateReadyOfNovaTopServices ()
75+ })
76+ It ("notification transport url is not set" , func () {
77+
78+ // assert that a the top level internal internal secret is created
79+ // with the proper data
80+ internalTopLevelSecret := th .GetSecret (novaNames .InternalTopLevelSecretName )
81+ // verify if nova secret has notification-transport-url
82+ Expect (internalTopLevelSecret .Data ).To (HaveKey ("notification_transport_url" ))
83+ Expect (internalTopLevelSecret .Data ).To (
84+ HaveKeyWithValue ("notification_transport_url" , []byte ("" )))
85+
86+ assertNotHaveNotificationTransportURL := func (configData string ) {
87+
88+ Expect (configData ).ToNot (
89+ ContainSubstring ("[notifications]" ))
90+
91+ Expect (configData ).To (
92+ ContainSubstring ("[oslo_messaging_notifications]\n driver = noop" ))
93+
94+ }
95+
96+ // verify if confs are updated with notification-transport-url under oslo_messaging_notifications
97+ // assert in nova-api conf
98+ configDataMap := th .GetSecret (novaNames .APIConfigDataName )
99+ Expect (configDataMap .Data ).Should (HaveKey ("01-nova.conf" ))
100+ configData := string (configDataMap .Data ["01-nova.conf" ])
101+ assertNotHaveNotificationTransportURL (configData )
102+
103+ // assert in sch conf
104+ configDataMap = th .GetSecret (novaNames .SchedulerConfigDataName )
105+ Expect (configDataMap .Data ).Should (HaveKey ("01-nova.conf" ))
106+ configData = string (configDataMap .Data ["01-nova.conf" ])
107+ assertNotHaveNotificationTransportURL (configData )
108+
109+ // assert in cell0-conductor conf
110+ configDataMap = th .GetSecret (cell0 .ConductorConfigDataName )
111+ Expect (configDataMap .Data ).Should (HaveKey ("01-nova.conf" ))
112+ configData = string (configDataMap .Data ["01-nova.conf" ])
113+ assertNotHaveNotificationTransportURL (configData )
114+
115+ })
116+
117+ It ("notification transport url is set with new rabbit" , func () {
118+
119+ // add new-rabbit in Nova CR
120+ notificationsBus := GetNotificationsBusNames (novaNames .NovaName )
121+ DeferCleanup (k8sClient .Delete , ctx , CreateNotificiationTransportURLSecret (notificationsBus ))
122+
123+ Eventually (func (g Gomega ) {
124+ nova := GetNova (novaNames .NovaName )
125+ nova .Spec .NotificationsBusInstance = & notificationsBus .BusName
126+ g .Expect (k8sClient .Update (ctx , nova )).Should (Succeed ())
127+ }, timeout , interval ).Should (Succeed ())
128+
129+ // as new-rabbit already exists in cluster, infra operator will create transporturl for it
130+ // simulating same
131+ infra .SimulateTransportURLReady (notificationsBus .TransportURLName )
132+ transportURLName := infra .GetTransportURL (notificationsBus .TransportURLName )
133+ Expect (transportURLName .Spec .RabbitmqClusterName ).To (Equal (notificationsBus .BusName ))
134+
135+ th .ExpectCondition (
136+ novaNames .NovaName ,
137+ ConditionGetterFunc (NovaConditionGetter ),
138+ novav1 .NovaNotificationMQReadyCondition ,
139+ corev1 .ConditionTrue ,
140+ )
141+
142+ // the nova secret(i.e top level secret) should have notification_transport_url value set
143+ internalTopLevelSecret := th .GetSecret (novaNames .InternalTopLevelSecretName )
144+ Expect (internalTopLevelSecret .Data ).To (HaveKey ("notification_transport_url" ))
145+ Expect (internalTopLevelSecret .Data ["notification_transport_url" ]).ShouldNot (BeEmpty ())
146+
147+ assertHaveNotificationTransportURL := func (configData string ) {
148+
149+ expectedConf1 := "[notifications]\n notify_on_state_change = vm_and_task_state\n notification_format=both"
150+
151+ expectedConf2 := fmt .Sprintf (
152+ "[oslo_messaging_notifications]\n transport_url = rabbit://%s/fake\n driver = messagingv2" ,
153+ notificationsBus .TransportURLName .Name )
154+
155+ Expect (configData ).To (
156+ ContainSubstring (expectedConf1 ))
157+
158+ Expect (configData ).To (
159+ ContainSubstring (expectedConf2 ))
160+
161+ }
162+
163+ // assert in nova-api conf
164+ configDataMap := th .GetSecret (novaNames .APIConfigDataName )
165+ Expect (configDataMap .Data ).Should (HaveKey ("01-nova.conf" ))
166+ configData := string (configDataMap .Data ["01-nova.conf" ])
167+ assertHaveNotificationTransportURL (configData )
168+
169+ // assert in sch conf
170+ configDataMap = th .GetSecret (novaNames .SchedulerConfigDataName )
171+ Expect (configDataMap .Data ).Should (HaveKey ("01-nova.conf" ))
172+ configData = string (configDataMap .Data ["01-nova.conf" ])
173+ assertHaveNotificationTransportURL (configData )
174+
175+ // assert in cell0-conductor conf
176+ configDataMap = th .GetSecret (cell0 .ConductorConfigDataName )
177+ Expect (configDataMap .Data ).Should (HaveKey ("01-nova.conf" ))
178+ configData = string (configDataMap .Data ["01-nova.conf" ])
179+ assertHaveNotificationTransportURL (configData )
180+
181+ })
182+ })
183+
184+ })
185+
41186var _ = Describe ("Nova controller" , func () {
42187 When ("Nova CR instance is created without a proper secret" , func () {
43188 BeforeEach (func () {
0 commit comments