@@ -71,15 +71,39 @@ var _ = Describe("BIOSSettings Controller", func() {
7171 })
7272
7373 It ("should successfully patch its reference to referred server" , func (ctx SpecContext ) {
74- BIOSSetting := make (map [string ]string )
74+ // settings mocked at
75+ // metal-operator/bmc/redfish_local.go defaultMockedBIOSSetting
76+ BIOSSetting := make (map [string ]string ) // no setting to apply
7577
7678 By ("Ensuring that the server has Available state" )
7779 Eventually (Object (server )).Should (SatisfyAll (
7880 HaveField ("Status.State" , metalv1alpha1 .ServerStateAvailable ),
7981 ))
82+ By ("Creating a BIOSSetting V1" )
83+ biosSettingsV1 := & metalv1alpha1.BIOSSettings {
84+ ObjectMeta : metav1.ObjectMeta {
85+ Namespace : ns .Name ,
86+ GenerateName : "test-" ,
87+ },
88+ Spec : metalv1alpha1.BIOSSettingsSpec {
89+ BIOSSettings : metalv1alpha1.Settings {Version : "P70 v1.45 (12/06/2017)" , SettingsMap : BIOSSetting },
90+ ServerRef : & v1.LocalObjectReference {Name : server .Name },
91+ ServerMaintenancePolicy : metalv1alpha1 .ServerMaintenancePolicyEnforced ,
92+ },
93+ }
94+ Expect (k8sClient .Create (ctx , biosSettingsV1 )).To (Succeed ())
8095
81- By ("Creating a BIOSSetting" )
82- biosSettings := & metalv1alpha1.BIOSSettings {
96+ By ("Ensuring that the Server has the correct server bios setting ref" )
97+ Eventually (Object (server )).Should (SatisfyAll (
98+ HaveField ("Spec.BIOSSettingsRef" , & v1.LocalObjectReference {Name : biosSettingsV1 .Name }),
99+ ))
100+
101+ Eventually (Object (biosSettingsV1 )).Should (SatisfyAny (
102+ HaveField ("Status.State" , metalv1alpha1 .BIOSSettingsStateApplied ),
103+ ))
104+
105+ By ("Creating a BIOSSetting V2" )
106+ biosSettingsV2 := & metalv1alpha1.BIOSSettings {
83107 ObjectMeta : metav1.ObjectMeta {
84108 Namespace : ns .Name ,
85109 GenerateName : "test-" ,
@@ -90,26 +114,33 @@ var _ = Describe("BIOSSettings Controller", func() {
90114 ServerMaintenancePolicy : metalv1alpha1 .ServerMaintenancePolicyEnforced ,
91115 },
92116 }
93- Expect (k8sClient .Create (ctx , biosSettings )).To (Succeed ())
117+ Expect (k8sClient .Create (ctx , biosSettingsV2 )).To (Succeed ())
94118
95119 By ("Ensuring that the Server has the correct server bios setting ref" )
96120 Eventually (Object (server )).Should (SatisfyAll (
97- HaveField ("Spec.BIOSSettingsRef" , & v1.LocalObjectReference {Name : biosSettings .Name }),
121+ HaveField ("Spec.BIOSSettingsRef" , & v1.LocalObjectReference {Name : biosSettingsV2 .Name }),
98122 ))
99123
100- Eventually (Object (biosSettings )).Should (SatisfyAny (
124+ Eventually (Object (biosSettingsV2 )).Should (SatisfyAny (
101125 HaveField ("Status.State" , metalv1alpha1 .BIOSSettingsStateApplied ),
102126 ))
103- })
104127
105- It ( "should move to completed if no bios setting changes to referred server" , func ( ctx SpecContext ) {
106- BIOSSetting := make ( map [ string ] string )
128+ By ( "Deleting the BIOSSettings V1 (old)" )
129+ Expect ( k8sClient . Delete ( ctx , biosSettingsV1 )). To ( Succeed () )
107130
108- By ("Ensuring that the server has Available state " )
131+ By ("Ensuring that the Server has the correct server bios setting ref " )
109132 Eventually (Object (server )).Should (SatisfyAll (
110- HaveField ("Status.State " , metalv1alpha1 . ServerStateAvailable ),
133+ HaveField ("Spec.BIOSSettingsRef " , & v1. LocalObjectReference { Name : biosSettingsV2 . Name } ),
111134 ))
112135
136+ })
137+
138+ It ("should move to completed if no bios setting changes to referred server" , func (ctx SpecContext ) {
139+ // settings which does not reboot. mocked at
140+ // metal-operator/bmc/redfish_local.go defaultMockedBIOSSetting
141+ BIOSSetting := make (map [string ]string )
142+ BIOSSetting ["abc" ] = "bar"
143+
113144 By ("Creating a BIOSSetting" )
114145 biosSettings := & metalv1alpha1.BIOSSettings {
115146 ObjectMeta : metav1.ObjectMeta {
@@ -142,16 +173,18 @@ var _ = Describe("BIOSSettings Controller", func() {
142173 ))
143174 })
144175
145- It ("should update the setting if setting changes requested with no reboot neeeded " , func (ctx SpecContext ) {
176+ It ("should update the setting without maintenance if setting requested needs no server reboot " , func (ctx SpecContext ) {
146177 BiosSetting := make (map [string ]string )
147178 // settings which does not reboot. mocked at
148179 // metal-operator/bmc/redfish_local.go defaultMockedBIOSSetting
149- BiosSetting ["abc" ] = "blahblah "
180+ BiosSetting ["abc" ] = "bar-changed-no-reboot "
150181
151182 // force BIOSSettings to not request maintenance
183+ // note: cant be in Available state as it will power off automatically.
152184 By ("update the server pwoerstate to On state" )
153185 Eventually (UpdateStatus (server , func () {
154186 server .Status .PowerState = metalv1alpha1 .ServerOnPowerState
187+ server .Status .State = metalv1alpha1 .ServerStateReserved
155188 })).Should (Succeed ())
156189
157190 By ("Creating a BIOS settings" )
@@ -201,11 +234,11 @@ var _ = Describe("BIOSSettings Controller", func() {
201234 ))
202235 })
203236
204- It ("should request maintenance when changing power status of server, even if bios settings does not need it" , func (ctx SpecContext ) {
237+ It ("should request maintenance when changing power status of server, even if bios settings update does not need it" , func (ctx SpecContext ) {
205238 BiosSetting := make (map [string ]string )
206239 // settings which does not reboot. mocked at
207240 // metal-operator/bmc/redfish_local.go defaultMockedBIOSSetting
208- BiosSetting ["abc" ] = "blahblahreboottoturnserveron "
241+ BiosSetting ["abc" ] = "bar-changed-to-turn-server-on "
209242
210243 // this is needed to transition through the unit test step by step
211244 // else, unit test finishes the state very fast without being able to check the transition
@@ -327,6 +360,8 @@ var _ = Describe("BIOSSettings Controller", func() {
327360 })
328361
329362 It ("should create maintenance if setting update needs reboot" , func (ctx SpecContext ) {
363+ // settings which does need reboot. mocked at
364+ // metal-operator/bmc/redfish_local.go defaultMockedBIOSSetting
330365 BiosSetting := make (map [string ]string )
331366 BiosSetting ["fooreboot" ] = "144"
332367
@@ -436,4 +471,81 @@ var _ = Describe("BIOSSettings Controller", func() {
436471 Eventually (Get (serverMaintenance )).Should (Satisfy (apierrors .IsNotFound ))
437472 Consistently (Get (serverMaintenance )).Should (Satisfy (apierrors .IsNotFound ))
438473 })
474+
475+ It ("should wait for upgrade and reconcile when biosSettings version is correct" , func (ctx SpecContext ) {
476+ bmcSetting := make (map [string ]string )
477+ bmcSetting ["abc" ] = "bar-wait-on-version-upgrade"
478+
479+ // force BIOSSettings to not request maintenance
480+ // note: cant be in Available state as it will power off automatically.
481+ By ("update the server pwoerstate to On state" )
482+ Eventually (UpdateStatus (server , func () {
483+ server .Status .PowerState = metalv1alpha1 .ServerOnPowerState
484+ server .Status .State = metalv1alpha1 .ServerStateReserved
485+ })).Should (Succeed ())
486+
487+ By ("Creating a BMCSetting" )
488+ biosSettings := & metalv1alpha1.BIOSSettings {
489+ ObjectMeta : metav1.ObjectMeta {
490+ Namespace : ns .Name ,
491+ GenerateName : "test-bmc-upgrade" ,
492+ },
493+ Spec : metalv1alpha1.BIOSSettingsSpec {
494+ BIOSSettings : metalv1alpha1.Settings {Version : "2.45.455b66-rev4" , SettingsMap : bmcSetting },
495+ ServerRef : & v1.LocalObjectReference {Name : server .Name },
496+ ServerMaintenancePolicy : metalv1alpha1 .ServerMaintenancePolicyEnforced ,
497+ },
498+ }
499+ Expect (k8sClient .Create (ctx , biosSettings )).To (Succeed ())
500+
501+ By ("Ensuring that the BMC has the correct BMC settings ref" )
502+ Eventually (Object (server )).Should (SatisfyAll (
503+ HaveField ("Spec.BIOSSettingsRef" , Not (BeNil ())),
504+ HaveField ("Spec.BIOSSettingsRef.Name" , biosSettings .Name ),
505+ ))
506+
507+ By ("Ensuring that the biosSettings resource state is correct State inVersionUpgrade" )
508+ Eventually (Object (biosSettings )).Should (SatisfyAny (
509+ HaveField ("Status.State" , metalv1alpha1 .BIOSSettingsStateInProgress ),
510+ ))
511+
512+ By ("Ensuring that the serverMaintenance not ref." )
513+ Consistently (Object (biosSettings )).Should (SatisfyAll (
514+ HaveField ("Spec.ServerMaintenanceRef" , BeNil ()),
515+ ))
516+
517+ By ("Simulate the server biosSettings version update by matching the spec version" )
518+ Eventually (Update (biosSettings , func () {
519+ biosSettings .Spec .BIOSSettings .Version = "P79 v1.45 (12/06/2017)"
520+ })).Should (Succeed ())
521+
522+ By ("Ensuring that the biosSettings resource has setting updated, and moved the state" )
523+ Eventually (Object (biosSettings )).Should (SatisfyAny (
524+ HaveField ("Status.State" , metalv1alpha1 .BIOSSettingsStateInProgress ),
525+ HaveField ("Status.State" , metalv1alpha1 .BIOSSettingsStateApplied ),
526+ ))
527+ Eventually (Object (biosSettings )).Should (SatisfyAll (
528+ HaveField ("Status.State" , metalv1alpha1 .BIOSSettingsStateApplied ),
529+ ))
530+
531+ By ("Ensuring that the serverMaintenance not ref." )
532+ Consistently (Object (biosSettings )).Should (SatisfyAll (
533+ HaveField ("Spec.ServerMaintenanceRef" , BeNil ()),
534+ ))
535+
536+ By ("Deleting the BMCSetting resource" )
537+ Expect (k8sClient .Delete (ctx , biosSettings )).To (Succeed ())
538+
539+ By ("Ensuring that the biosSettings resource is removed" )
540+ Eventually (Get (biosSettings )).Should (Satisfy (apierrors .IsNotFound ))
541+ Consistently (Get (biosSettings )).Should (Satisfy (apierrors .IsNotFound ))
542+
543+ By ("Ensuring that the Server biosSettings ref is empty on BMC" )
544+ Eventually (Object (server )).Should (SatisfyAll (
545+ HaveField ("Spec.BIOSSettingsRef" , BeNil ()),
546+ ))
547+ Consistently (Object (server )).Should (SatisfyAll (
548+ HaveField ("Spec.BIOSSettingsRef" , BeNil ()),
549+ ))
550+ })
439551})
0 commit comments