Skip to content

Commit 4ae0be0

Browse files
lmicciniopenshift-merge-bot[bot]
authored andcommitted
Optimize tests to reduce cpu/mem usage
1 parent f0d56cd commit 4ae0be0

File tree

5 files changed

+107
-98
lines changed

5 files changed

+107
-98
lines changed

test/functional/base_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,15 @@ func CreateNovaWithNCellsAndEnsureReady(cellNumber int, novaNames *NovaNames) {
10631063
DeferCleanup(keystone.DeleteKeystoneAPI, novaNames.KeystoneAPIName)
10641064

10651065
// Set region on KeystoneAPI to ensure GetRegion() returns a value
1066+
keystoneAPI := keystone.GetKeystoneAPI(novaNames.KeystoneAPIName)
1067+
keystoneAPI.Spec.Region = "regionOne"
1068+
Expect(k8sClient.Update(ctx, keystoneAPI)).To(Succeed())
1069+
1070+
// Update status separately after spec is applied
10661071
Eventually(func(g Gomega) {
1067-
keystoneAPI := keystone.GetKeystoneAPI(novaNames.KeystoneAPIName)
1068-
keystoneAPI.Spec.Region = "regionOne"
1069-
g.Expect(k8sClient.Update(ctx, keystoneAPI)).To(Succeed())
1070-
keystoneAPI.Status.Region = "regionOne"
1071-
g.Expect(k8sClient.Status().Update(ctx, keystoneAPI)).To(Succeed())
1072+
ks := keystone.GetKeystoneAPI(novaNames.KeystoneAPIName)
1073+
ks.Status.Region = "regionOne"
1074+
g.Expect(k8sClient.Status().Update(ctx, ks)).To(Succeed())
10721075
}, timeout, interval).Should(Succeed())
10731076

10741077
memcachedSpec := infra.GetDefaultMemcachedSpec()

test/functional/nova_controller_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,10 +1516,8 @@ var _ = Describe("Nova controller", func() {
15161516
infra.SimulateMemcachedReady(novaNames.MemcachedNamespace)
15171517
keystoneAPIName := keystone.CreateKeystoneAPI(novaNames.NovaName.Namespace)
15181518
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
1519-
keystoneAPI := keystone.GetKeystoneAPI(keystoneAPIName)
1520-
Eventually(func(g Gomega) {
1521-
g.Expect(k8sClient.Status().Update(ctx, keystoneAPI.DeepCopy())).Should(Succeed())
1522-
}, timeout, interval).Should(Succeed())
1519+
// Note: Status update removed as it was updating with stale object and not setting any fields.
1520+
// The SimulateKeystoneServiceReady call below handles necessary setup.
15231521
keystone.SimulateKeystoneServiceReady(novaNames.KeystoneServiceName)
15241522
})
15251523
It("propagates topology to the Nova components except cell1 that has an override", func() {
@@ -1940,12 +1938,16 @@ var _ = Describe("Nova controller - region defaults", func() {
19401938
})
19411939

19421940
It("defaults the region to regionOne", func() {
1941+
// Clear region on KeystoneAPI spec first
1942+
keystoneAPI := keystone.GetKeystoneAPI(novaNames.KeystoneAPIName)
1943+
keystoneAPI.Spec.Region = ""
1944+
Expect(k8sClient.Update(ctx, keystoneAPI)).To(Succeed())
1945+
1946+
// Update status separately after spec is applied
19431947
Eventually(func(g Gomega) {
1944-
keystoneAPI := keystone.GetKeystoneAPI(novaNames.KeystoneAPIName)
1945-
keystoneAPI.Spec.Region = ""
1946-
g.Expect(k8sClient.Update(ctx, keystoneAPI)).To(Succeed())
1947-
keystoneAPI.Status.Region = ""
1948-
g.Expect(k8sClient.Status().Update(ctx, keystoneAPI)).To(Succeed())
1948+
ks := keystone.GetKeystoneAPI(novaNames.KeystoneAPIName)
1949+
ks.Status.Region = ""
1950+
g.Expect(k8sClient.Status().Update(ctx, ks)).To(Succeed())
19491951
}, timeout, interval).Should(Succeed())
19501952

19511953
Eventually(func(g Gomega) {

test/functional/nova_multicell_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,8 @@ var _ = Describe("Nova multi cell", func() {
889889
infra.SimulateMemcachedReady(novaNames.MemcachedNamespace)
890890
keystoneAPIName := keystone.CreateKeystoneAPI(novaNames.NovaName.Namespace)
891891
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
892-
keystoneAPI := keystone.GetKeystoneAPI(keystoneAPIName)
893-
Eventually(func(g Gomega) {
894-
g.Expect(k8sClient.Status().Update(ctx, keystoneAPI.DeepCopy())).Should(Succeed())
895-
}, timeout, interval).Should(Succeed())
892+
// Note: Status update removed as it was updating with stale object and not setting any fields.
893+
// The SimulateKeystoneServiceReady call below handles necessary setup.
896894
keystone.SimulateKeystoneServiceReady(novaNames.KeystoneServiceName)
897895
})
898896
It("cell0 becomes ready without metadata and the rest of nova is deployed", func() {

test/functional/nova_scheduler_test.go

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -285,51 +285,54 @@ var _ = Describe("NovaScheduler controller", func() {
285285
)
286286

287287
// Wait for config to be regenerated with region
288+
var configData string
288289
Eventually(func(g Gomega) {
289290
configDataMap := th.GetSecret(novaNames.SchedulerConfigDataName)
290291
g.Expect(configDataMap).ShouldNot(BeNil())
291292
g.Expect(configDataMap.Data).Should(HaveKey("01-nova.conf"))
292-
configData := string(configDataMap.Data["01-nova.conf"])
293-
294-
// Parse the INI file to properly access sections
295-
cfg, err := ini.Load([]byte(configData))
296-
g.Expect(err).ShouldNot(HaveOccurred(), "Should be able to parse config as INI")
297-
298-
// Verify region_name in [keystone_authtoken]
299-
section := cfg.Section("keystone_authtoken")
300-
g.Expect(section).ShouldNot(BeNil(), "Should find [keystone_authtoken] section")
301-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
302-
303-
// Verify region_name in [placement]
304-
section = cfg.Section("placement")
305-
g.Expect(section).ShouldNot(BeNil(), "Should find [placement] section")
306-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
307-
308-
// Verify region_name in [glance]
309-
section = cfg.Section("glance")
310-
g.Expect(section).ShouldNot(BeNil(), "Should find [glance] section")
311-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
312-
313-
// Verify region_name in [neutron]
314-
section = cfg.Section("neutron")
315-
g.Expect(section).ShouldNot(BeNil(), "Should find [neutron] section")
316-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
317-
318-
// Verify os_region_name in [cinder]
319-
section = cfg.Section("cinder")
320-
g.Expect(section).ShouldNot(BeNil(), "Should find [cinder] section")
321-
g.Expect(section.Key("os_region_name").String()).Should(Equal(testRegion))
322-
323-
// Verify barbican_region_name in [barbican]
324-
section = cfg.Section("barbican")
325-
g.Expect(section).ShouldNot(BeNil(), "Should find [barbican] section")
326-
g.Expect(section.Key("barbican_region_name").String()).Should(Equal(testRegion))
327-
328-
// Verify endpoint_region_name in [oslo_limit]
329-
section = cfg.Section("oslo_limit")
330-
g.Expect(section).ShouldNot(BeNil(), "Should find [oslo_limit] section")
331-
g.Expect(section.Key("endpoint_region_name").String()).Should(Equal(testRegion))
293+
configData = string(configDataMap.Data["01-nova.conf"])
294+
// Quick check that config contains the expected region before parsing
295+
g.Expect(configData).To(ContainSubstring(testRegion))
332296
}, timeout, interval).Should(Succeed())
297+
298+
// Parse the INI file once after Eventually succeeds (avoids repeated parsing)
299+
cfg, err := ini.Load([]byte(configData))
300+
Expect(err).ShouldNot(HaveOccurred(), "Should be able to parse config as INI")
301+
302+
// Verify region_name in [keystone_authtoken]
303+
section := cfg.Section("keystone_authtoken")
304+
Expect(section).ShouldNot(BeNil(), "Should find [keystone_authtoken] section")
305+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
306+
307+
// Verify region_name in [placement]
308+
section = cfg.Section("placement")
309+
Expect(section).ShouldNot(BeNil(), "Should find [placement] section")
310+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
311+
312+
// Verify region_name in [glance]
313+
section = cfg.Section("glance")
314+
Expect(section).ShouldNot(BeNil(), "Should find [glance] section")
315+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
316+
317+
// Verify region_name in [neutron]
318+
section = cfg.Section("neutron")
319+
Expect(section).ShouldNot(BeNil(), "Should find [neutron] section")
320+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
321+
322+
// Verify os_region_name in [cinder]
323+
section = cfg.Section("cinder")
324+
Expect(section).ShouldNot(BeNil(), "Should find [cinder] section")
325+
Expect(section.Key("os_region_name").String()).Should(Equal(testRegion))
326+
327+
// Verify barbican_region_name in [barbican]
328+
section = cfg.Section("barbican")
329+
Expect(section).ShouldNot(BeNil(), "Should find [barbican] section")
330+
Expect(section.Key("barbican_region_name").String()).Should(Equal(testRegion))
331+
332+
// Verify endpoint_region_name in [oslo_limit]
333+
section = cfg.Section("oslo_limit")
334+
Expect(section).ShouldNot(BeNil(), "Should find [oslo_limit] section")
335+
Expect(section.Key("endpoint_region_name").String()).Should(Equal(testRegion))
333336
})
334337

335338
It("stored the input hash in the Status", func() {

test/functional/novaapi_controller_test.go

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -307,51 +307,54 @@ endpoint_service_type = compute`))
307307
)
308308

309309
// Wait for config to be regenerated with region
310+
var configData string
310311
Eventually(func(g Gomega) {
311312
configDataMap := th.GetSecret(novaNames.APIConfigDataName)
312313
g.Expect(configDataMap).ShouldNot(BeNil())
313314
g.Expect(configDataMap.Data).Should(HaveKey("01-nova.conf"))
314-
configData := string(configDataMap.Data["01-nova.conf"])
315-
316-
// Parse the INI file to properly access sections
317-
cfg, err := ini.Load([]byte(configData))
318-
g.Expect(err).ShouldNot(HaveOccurred(), "Should be able to parse config as INI")
319-
320-
// Verify region_name in [keystone_authtoken]
321-
section := cfg.Section("keystone_authtoken")
322-
g.Expect(section).ShouldNot(BeNil(), "Should find [keystone_authtoken] section")
323-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
324-
325-
// Verify region_name in [placement]
326-
section = cfg.Section("placement")
327-
g.Expect(section).ShouldNot(BeNil(), "Should find [placement] section")
328-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
329-
330-
// Verify region_name in [glance]
331-
section = cfg.Section("glance")
332-
g.Expect(section).ShouldNot(BeNil(), "Should find [glance] section")
333-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
334-
335-
// Verify region_name in [neutron]
336-
section = cfg.Section("neutron")
337-
g.Expect(section).ShouldNot(BeNil(), "Should find [neutron] section")
338-
g.Expect(section.Key("region_name").String()).Should(Equal(testRegion))
339-
340-
// Verify os_region_name in [cinder]
341-
section = cfg.Section("cinder")
342-
g.Expect(section).ShouldNot(BeNil(), "Should find [cinder] section")
343-
g.Expect(section.Key("os_region_name").String()).Should(Equal(testRegion))
344-
345-
// Verify barbican_region_name in [barbican]
346-
section = cfg.Section("barbican")
347-
g.Expect(section).ShouldNot(BeNil(), "Should find [barbican] section")
348-
g.Expect(section.Key("barbican_region_name").String()).Should(Equal(testRegion))
349-
350-
// Verify endpoint_region_name in [oslo_limit]
351-
section = cfg.Section("oslo_limit")
352-
g.Expect(section).ShouldNot(BeNil(), "Should find [oslo_limit] section")
353-
g.Expect(section.Key("endpoint_region_name").String()).Should(Equal(testRegion))
315+
configData = string(configDataMap.Data["01-nova.conf"])
316+
// Quick check that config contains the expected region before parsing
317+
g.Expect(configData).To(ContainSubstring(testRegion))
354318
}, timeout, interval).Should(Succeed())
319+
320+
// Parse the INI file once after Eventually succeeds (avoids repeated parsing)
321+
cfg, err := ini.Load([]byte(configData))
322+
Expect(err).ShouldNot(HaveOccurred(), "Should be able to parse config as INI")
323+
324+
// Verify region_name in [keystone_authtoken]
325+
section := cfg.Section("keystone_authtoken")
326+
Expect(section).ShouldNot(BeNil(), "Should find [keystone_authtoken] section")
327+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
328+
329+
// Verify region_name in [placement]
330+
section = cfg.Section("placement")
331+
Expect(section).ShouldNot(BeNil(), "Should find [placement] section")
332+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
333+
334+
// Verify region_name in [glance]
335+
section = cfg.Section("glance")
336+
Expect(section).ShouldNot(BeNil(), "Should find [glance] section")
337+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
338+
339+
// Verify region_name in [neutron]
340+
section = cfg.Section("neutron")
341+
Expect(section).ShouldNot(BeNil(), "Should find [neutron] section")
342+
Expect(section.Key("region_name").String()).Should(Equal(testRegion))
343+
344+
// Verify os_region_name in [cinder]
345+
section = cfg.Section("cinder")
346+
Expect(section).ShouldNot(BeNil(), "Should find [cinder] section")
347+
Expect(section.Key("os_region_name").String()).Should(Equal(testRegion))
348+
349+
// Verify barbican_region_name in [barbican]
350+
section = cfg.Section("barbican")
351+
Expect(section).ShouldNot(BeNil(), "Should find [barbican] section")
352+
Expect(section.Key("barbican_region_name").String()).Should(Equal(testRegion))
353+
354+
// Verify endpoint_region_name in [oslo_limit]
355+
section = cfg.Section("oslo_limit")
356+
Expect(section).ShouldNot(BeNil(), "Should find [oslo_limit] section")
357+
Expect(section.Key("endpoint_region_name").String()).Should(Equal(testRegion))
355358
})
356359

357360
It("stored the input hash in the Status", func() {

0 commit comments

Comments
 (0)