Skip to content

Commit b1eb6cc

Browse files
Merge pull request #5587 from sergiordlr/migrate_private_test_ocp_87023
MCO-1182: migrate private test case OCP-87023
2 parents 40b06f0 + 317c38a commit b1eb6cc

2 files changed

Lines changed: 138 additions & 1 deletion

File tree

test/extended-priv/machineconfiguration.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package extended
22

33
import (
4+
"strings"
5+
46
exutil "github.com/openshift/machine-config-operator/test/extended-priv/util"
57
logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext"
68
)
@@ -48,3 +50,35 @@ func (mc MachineConfiguration) SetPartialManagedBootImagesConfig(resource, label
4850
func (mc MachineConfiguration) SetNoneManagedBootImagesConfig(resource string) error {
4951
return mc.Patch("merge", `{"spec":{"managedBootImages":{"machineManagers":[{"resource": "`+resource+`","apiGroup": "machine.openshift.io","selection": {"mode": "None"}}]}}}`)
5052
}
53+
54+
// EnableIrreconcilableValidationOverrides enables irreconcilableValidationOverrides for storage
55+
func (mc MachineConfiguration) EnableIrreconcilableValidationOverrides() error {
56+
return mc.Patch("merge", `{"spec":{"irreconcilableValidationOverrides":{"storage":["Disks","Raid","FileSystems"]}}}`)
57+
}
58+
59+
// GetManagedBootImagesStatus returns the entire .status.managedBootImagesStatus field
60+
func (mc MachineConfiguration) GetManagedBootImagesStatus() (string, error) {
61+
return mc.Get(`{.status.managedBootImagesStatus}`)
62+
}
63+
64+
// GetManagedBootImagesStatusForResource returns the status for a specific resource type
65+
func (mc MachineConfiguration) GetManagedBootImagesStatusForResource(resource string) (string, error) {
66+
return mc.Get(`{.status.managedBootImagesStatus.machineManagers[?(@.resource=="` + resource + `")]}`)
67+
}
68+
69+
// GetManagedBootImagesModeForResource returns the selection mode for a specific resource type
70+
func (mc MachineConfiguration) GetManagedBootImagesModeForResource(resource string) (string, error) {
71+
return mc.Get(`{.status.managedBootImagesStatus.machineManagers[?(@.resource=="` + resource + `")].selection.mode}`)
72+
}
73+
74+
// GetAllManagedBootImagesResources returns all resource types configured in the status as a slice
75+
func (mc MachineConfiguration) GetAllManagedBootImagesResources() ([]string, error) {
76+
result, err := mc.Get(`{.status.managedBootImagesStatus.machineManagers[*].resource}`)
77+
if err != nil {
78+
return nil, err
79+
}
80+
if result == "" {
81+
return []string{}, nil
82+
}
83+
return strings.Fields(result), nil
84+
}

test/extended-priv/mco_controlplanemachineset.go

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
o "github.com/onsi/gomega"
88
exutil "github.com/openshift/machine-config-operator/test/extended-priv/util"
99
logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext"
10+
"github.com/tidwall/gjson"
1011
)
1112

12-
var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/disruptive][Serial][Disruptive][OCPFeatureGate:ManagedBootImagesCPMS] MCO ControlPlaneMachineSet", func() {
13+
var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/disruptive][Serial][Disruptive][OCPFeatureGate:ManagedBootImagesCPMS] MCO ControlPlaneMachineSet", g.Label("Platform:gce", "Platform:aws", "Platform:azure"), func() {
1314
defer g.GinkgoRecover()
1415

1516
var (
@@ -364,4 +365,106 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/disruptive
364365
"The user-data secret was unexpectedly updated when owner reference was present")
365366
logger.Infof("OK!\n")
366367
})
368+
369+
// AI-assisted: This test case validates that MachineConfiguration status correctly reflects spec changes
370+
g.It("[PolarionID:87023][OTP] MachineConfiguration status correctly reflects spec changes [apigroup:machineconfiguration.openshift.io]", func() {
371+
372+
var (
373+
testConfigs = []struct {
374+
description string
375+
patchConfig string
376+
}{
377+
{
378+
description: "Test Partial mode for MachineSet resource",
379+
patchConfig: `{"spec":{"managedBootImages":{"machineManagers":[{"resource":"machinesets","apiGroup":"machine.openshift.io","selection":{"mode":"Partial","partial":{"machineResourceSelector":{"matchLabels":{"test-label":"test-value"}}}}}]}}}`,
380+
},
381+
{
382+
description: "Test None mode for MachineSet resource",
383+
patchConfig: `{"spec":{"managedBootImages":{"machineManagers":[{"resource":"machinesets","apiGroup":"machine.openshift.io","selection":{"mode":"None"}}]}}}`,
384+
},
385+
{
386+
description: "Test All mode for MachineSet resource",
387+
patchConfig: `{"spec":{"managedBootImages":{"machineManagers":[{"resource":"machinesets","apiGroup":"machine.openshift.io","selection":{"mode":"All"}}]}}}`,
388+
},
389+
{
390+
description: "Test None mode for ControlPlaneMachineSet resource",
391+
patchConfig: `{"spec":{"managedBootImages":{"machineManagers":[{"resource":"controlplanemachinesets","apiGroup":"machine.openshift.io","selection":{"mode":"None"}}]}}}`,
392+
},
393+
{
394+
description: "Test All mode for ControlPlaneMachineSet resource",
395+
patchConfig: `{"spec":{"managedBootImages":{"machineManagers":[{"resource":"controlplanemachinesets","apiGroup":"machine.openshift.io","selection":{"mode":"All"}}]}}}`,
396+
},
397+
}
398+
)
399+
400+
for _, tc := range testConfigs {
401+
logger.Infof(tc.description)
402+
testMachineConfigurationStatusUpdate(machineConfiguration, tc.patchConfig)
403+
}
404+
})
367405
})
406+
407+
// testMachineConfigurationStatusUpdate validates that MachineConfiguration status updates correctly
408+
func testMachineConfigurationStatusUpdate(mc *MachineConfiguration, patchConfig string) {
409+
exutil.By("Capture original MachineConfiguration status")
410+
411+
originalSpec := mc.GetSpecOrFail()
412+
defer mc.SetSpec(originalSpec)
413+
originalStatus, err := mc.GetManagedBootImagesStatus()
414+
o.Expect(err).NotTo(o.HaveOccurred(), "Error getting original status from %s", mc)
415+
logger.Infof("Original status: %s", originalStatus)
416+
417+
// Capture the status for each resource before applying the config
418+
resourcesBefore, err := mc.GetAllManagedBootImagesResources()
419+
o.Expect(err).NotTo(o.HaveOccurred(), "Error getting all resources from status")
420+
421+
originalResourceStatus := make(map[string]string)
422+
for _, res := range resourcesBefore {
423+
if res != "" {
424+
status, err := mc.GetManagedBootImagesStatusForResource(res)
425+
o.Expect(err).NotTo(o.HaveOccurred(), "Error getting status for resource %s", res)
426+
originalResourceStatus[res] = status
427+
logger.Infof("Captured original status for resource %s", res)
428+
}
429+
}
430+
logger.Infof("OK!\n")
431+
432+
exutil.By("Extract resource and expected status config from the patch config")
433+
expectedStatusConfig := gjson.Get(patchConfig, "spec.managedBootImages.machineManagers.0").String()
434+
o.Expect(expectedStatusConfig).NotTo(o.BeEmpty(), "Failed to extract expected status config from patchConfig")
435+
436+
resource := gjson.Get(patchConfig, "spec.managedBootImages.machineManagers.0.resource").String()
437+
o.Expect(resource).NotTo(o.BeEmpty(), "Failed to extract resource from patchConfig")
438+
439+
logger.Infof("Resource: %s", resource)
440+
logger.Infof("Expected status config: %s", expectedStatusConfig)
441+
logger.Infof("OK!\n")
442+
443+
exutil.By("Apply the new configuration")
444+
o.Expect(mc.Patch("merge", patchConfig)).To(o.Succeed(), "Error applying configuration to %s", mc)
445+
logger.Infof("OK!\n")
446+
447+
exutil.By("Check that the configured resource is correctly reported in the status")
448+
o.Eventually(mc.GetManagedBootImagesStatusForResource, "5m", "10s").WithArguments(resource).Should(o.MatchJSON(expectedStatusConfig),
449+
"Resource %s status does not match the expected configuration. Expected: %s", resource, expectedStatusConfig)
450+
logger.Infof("OK!\n")
451+
452+
exutil.By("Check that other managedBootImagesStatus configurations remain the same as before")
453+
for res, originalStatusValue := range originalResourceStatus {
454+
if res != resource {
455+
o.Eventually(mc.GetManagedBootImagesStatusForResource, "5m", "10s").WithArguments(res).Should(o.MatchJSON(originalStatusValue),
456+
"Resource %s status changed unexpectedly. Expected: %s", res, originalStatusValue)
457+
logger.Infof("Resource %s status unchanged", res)
458+
}
459+
}
460+
logger.Infof("OK!\n")
461+
462+
exutil.By("Remove the applied configuration and restore original spec")
463+
o.Expect(mc.SetSpec(originalSpec)).To(o.Succeed(), "Error restoring original spec in %s", mc)
464+
logger.Infof("OK!\n")
465+
466+
exutil.By("Check that the original status values were restored")
467+
o.Eventually(mc.GetManagedBootImagesStatus, "5m", "10s").Should(o.MatchJSON(originalStatus),
468+
"Status was not restored to original value")
469+
logger.Infof("OK!\n")
470+
}

0 commit comments

Comments
 (0)