@@ -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