Skip to content

Commit b84815f

Browse files
committed
Adapt boot images test cases to the new skew functionality
1 parent 6ab5da8 commit b84815f

3 files changed

Lines changed: 41 additions & 31 deletions

File tree

test/extended-priv/mco_bootimages.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
e2e "k8s.io/kubernetes/test/e2e/framework"
1616
)
1717

18-
const mapiBaseErrorMessageTemplate = `1 Degraded MAPI MachineSets | 0 Degraded ControlPlaneMachineSets | 0 Degraded CAPI MachineSets | 0 CAPI MachineDeployments | Error(s):` +
18+
const mapiBaseErrorMessageTemplate = `1 Degraded MAPI MachineSets | 0 Degraded ControlPlaneMachineSets | 0 Degraded CAPI MachineSets | 0 Degraded CAPI MachineDeployments | Error(s):` +
1919
` error syncing MAPI MachineSet %s: failed to reconcile machineset %s, err:`
2020

2121
var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longduration][Serial][Disruptive] MCO Bootimages", func() {
@@ -44,6 +44,20 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
4444
wMcp = NewMachineConfigPool(oc.AsAdmin(), MachineConfigPoolWorker)
4545
machineConfiguration = GetMachineConfiguration(oc.AsAdmin())
4646
PreChecks(oc)
47+
48+
// Disable skew to avoid collisions
49+
exutil.By("Disabling skew functionality")
50+
initialMachineConfiguration := machineConfiguration.GetSpecOrFail()
51+
o.Expect(machineConfiguration.SetNoneSkew()).To(o.Succeed(), "Error disabing the skew functionality")
52+
o.Eventually(machineConfiguration.IsGenerationUpToDate, "2m", "10s").Should(o.BeTrue(), "MachineConfiguration observedGeneration did not catch up to generation")
53+
54+
g.DeferCleanup(func() {
55+
exutil.By("Restoring initial MachineConfiguration spec")
56+
o.Expect(machineConfiguration.SetSpec(initialMachineConfiguration)).To(o.Succeed(), "Error restoring initial MachineConfiguration spec")
57+
logger.Infof("OK!\n")
58+
})
59+
logger.Infof("OK!\n")
60+
4761
})
4862

4963
g.It("[PolarionID:81403][OTP] In BootImages Machineset should update by default", g.Label("Platform:aws", "Platform:gcp"), func() {
@@ -75,7 +89,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
7589

7690
// For none - mode i.e opt-out MachineSet are not updated with original value if we try to set with any fake value
7791
exutil.By("Opt-out boot images update")
78-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
7992
o.Expect(
8093
machineConfiguration.SetNoneManagedBootImagesConfig(MachineSetResource),
8194
).To(o.Succeed(), "Error configuring None managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -127,7 +140,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
127140
logger.Infof("OK!\n")
128141

129142
exutil.By("Opt-in boot images update")
130-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
131143
o.Expect(
132144
machineConfiguration.SetAllManagedBootImagesConfig(MachineSetResource),
133145
).To(o.Succeed(), "Error configuring ALL managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -229,7 +241,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
229241

230242
exutil.By("Opt-in boot images update")
231243

232-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
233244
o.Expect(
234245
machineConfiguration.SetPartialManagedBootImagesConfig(MachineSetResource, labelName, labelValue),
235246
).To(o.Succeed(), "Error configuring Partial managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -329,7 +340,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
329340
)
330341
exutil.By("Opt-in boot images update")
331342

332-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
333343
o.Expect(
334344
machineConfiguration.SetPartialManagedBootImagesConfig(MachineSetResource, labelName, labelValue),
335345
).To(o.Succeed(), "Error configuring Partial managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -475,7 +485,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
475485
logger.Infof("OK!\n")
476486

477487
exutil.By("To patch the Partial Mode in machineConfiguration")
478-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
479488
o.Expect(
480489
machineConfiguration.SetPartialManagedBootImagesConfig(MachineSetResource, "", ""),
481490
).To(o.Succeed(), "Error configuring Partial managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -484,7 +493,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
484493
logger.Infof("OK\n")
485494

486495
exutil.By("To patch the All Mode in machieConfiguration")
487-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
488496
o.Expect(
489497
machineConfiguration.SetAllManagedBootImagesConfig(MachineSetResource),
490498
).To(o.Succeed(), "Error configuring All managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -493,7 +501,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
493501
logger.Infof("OK\n")
494502

495503
exutil.By("Opt-out boot images update")
496-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
497504
o.Expect(machineConfiguration.SetNoneManagedBootImagesConfig(MachineSetResource)).To(o.Succeed(), "Error configuring None managedBootImages in the 'cluster' MachineConfiguration resource")
498505
logger.Infof("OK!\n")
499506
checkManagedBootImagesStatus(machineConfiguration, "None")
@@ -517,7 +524,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
517524

518525
exutil.By("Opt-in boot images update")
519526

520-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
521527
o.Expect(
522528
machineConfiguration.SetPartialManagedBootImagesConfig(MachineSetResource, labelName, labelValue),
523529
).To(o.Succeed(), "Error configuring Partial managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -606,7 +612,6 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati
606612
)
607613

608614
exutil.By("Opt-in boot images update")
609-
defer machineConfiguration.SetSpec(machineConfiguration.GetSpecOrFail())
610615
o.Expect(
611616
machineConfiguration.SetPartialManagedBootImagesConfig(MachineSetResource, labelName, labelValue),
612617
).To(o.Succeed(), "Error configuring Partial managedBootImages in the 'cluster' MachineConfiguration resource")
@@ -806,19 +811,17 @@ func GetRHCOSVersionFromConfigMap(oc *exutil.CLI) string {
806811
func testUserDataUpdateFailure(oc *exutil.CLI, clonedMSName, clonedSecretName, expectedFailedMessageRegexp string, userDataModifyFunc func(userData string) (string, error)) {
807812

808813
var (
809-
machineConfiguration = GetMachineConfiguration(oc.AsAdmin())
810-
machineSet = NewMachineSetList(oc.AsAdmin(), MachineAPINamespace).GetAllOrFail()[0]
811-
fakeImageName = getBackdatedBootImage(oc.AsAdmin())
812-
labelName = "test"
813-
labelValue = "update"
814-
secondLabelValue = "update2"
815-
machineClusterOperator = NewResource(oc.AsAdmin(), "ClusterOperator", "machine-config")
816-
initialMachineConfigSpec = machineConfiguration.GetSpecOrFail()
817-
clonedSecret *Secret
814+
machineConfiguration = GetMachineConfiguration(oc.AsAdmin())
815+
machineSet = NewMachineSetList(oc.AsAdmin(), MachineAPINamespace).GetAllOrFail()[0]
816+
fakeImageName = getBackdatedBootImage(oc.AsAdmin())
817+
labelName = "test"
818+
labelValue = "update"
819+
secondLabelValue = "update2"
820+
machineClusterOperator = NewResource(oc.AsAdmin(), "ClusterOperator", "machine-config")
821+
clonedSecret *Secret
818822
)
819823

820824
exutil.By("Opt-in boot images update")
821-
defer machineConfiguration.SetSpec(initialMachineConfigSpec)
822825
o.Expect(
823826
machineConfiguration.SetPartialManagedBootImagesConfig(MachineSetResource, labelName, labelValue),
824827
).To(o.Succeed(), "Error configuring Partial managedBootImages in the 'cluster' MachineConfiguration resource")

test/extended-priv/mco_controlplanemachineset.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,7 @@ func testMachineConfigurationStatusUpdate(mc *MachineConfiguration, patchConfig
415415
o.Expect(mc.SetNoneSkew()).To(o.Succeed(), "Error disabling skew enforcement on %s", mc)
416416

417417
// Wait for the controller to observe and process the spec change
418-
o.Eventually(func() (bool, error) {
419-
generation, err := mc.Get(`{.metadata.generation}`)
420-
if err != nil {
421-
return false, err
422-
}
423-
observedGeneration, err := mc.Get(`{.status.observedGeneration}`)
424-
if err != nil {
425-
return false, err
426-
}
427-
return generation == observedGeneration, nil
428-
}, "2m", "10s").Should(o.BeTrue(), "MachineConfiguration observedGeneration did not catch up to generation")
418+
o.Eventually(mc.IsGenerationUpToDate, "2m", "10s").Should(o.BeTrue(), "MachineConfiguration observedGeneration did not catch up to generation")
429419

430420
originalStatus, err := mc.GetManagedBootImagesStatus()
431421
o.Expect(err).NotTo(o.HaveOccurred(), "Error getting original status from %s", mc)

test/extended-priv/resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type ResourceInterface interface {
5050
GetLabel(label string) (string, error)
5151
Describe() (string, error)
5252
ExportToFile(fileName string) error
53+
IsGenerationUpToDate() (bool, error)
5354
PrettyString() string
5455
GetOC() *exutil.CLI
5556
GetCleanJSON() (string, error)
@@ -434,6 +435,22 @@ func (r *Resource) ExportToFile(fileName string) error {
434435
return err
435436
}
436437

438+
// IsGenerationUpToDate returns true if the resource has a generation value and this value is up to date
439+
// If the resource has no generation the function will return an error
440+
func (r Resource) IsGenerationUpToDate() (bool, error) {
441+
generation, err := r.Get(`{.metadata.generation}`)
442+
if err != nil {
443+
return false, err
444+
}
445+
446+
observedGeneration, err := r.Get(`{.status.observedGeneration}`)
447+
if err != nil {
448+
return false, err
449+
}
450+
451+
return generation == observedGeneration, nil
452+
}
453+
437454
// NewMCOTemplate creates a new template using the MCO fixture directory as the base path of the template file
438455
func NewMCOTemplate(oc *exutil.CLI, fileName string) *Template {
439456
return &Template{oc: oc, templateFile: generateTemplateAbsolutePath(fileName)}

0 commit comments

Comments
 (0)