@@ -70,7 +70,7 @@ var _ = Describe("VirtualMachineConfiguration", func() {
7070 Expect (t .VM .Status .Resources .CPU .Cores ).To (Equal (initialCPUCores ))
7171 Expect (t .VM .Status .Resources .Memory .Size ).To (Equal (resource .MustParse (initialMemorySize )))
7272 Expect (t .VM .Status .Resources .CPU .CoreFraction ).To (Equal (initialCoreFraction ))
73- Expect (t .IsVDInVMStatus (t .VDBlank , t .VM )).To (BeFalse ())
73+ Expect (t .IsVDAttached (t .VDBlank , t .VM )).To (BeFalse ())
7474
7575 By ("Applying changes" )
7676 err = f .Clients .GenericClient ().Get (context .Background (), crclient .ObjectKeyFromObject (t .VM ), t .VM )
@@ -89,12 +89,14 @@ var _ = Describe("VirtualMachineConfiguration", func() {
8989 Expect (err ).NotTo (HaveOccurred ())
9090
9191 if restartApprovalMode == v1alpha2 .Manual {
92- time .Sleep (time .Second ) // Avoid race condition with need restart condition calculation
93- err = f .Clients .GenericClient ().Get (context .Background (), crclient .ObjectKeyFromObject (t .VM ), t .VM )
94- Expect (err ).NotTo (HaveOccurred ())
95- needRestart , _ := conditions .GetCondition (vmcondition .TypeAwaitingRestartToApplyConfiguration , t .VM .Status .Conditions )
96- Expect (needRestart .Status ).To (Equal (metav1 .ConditionTrue ))
97- Expect (t .VM .Status .RestartAwaitingChanges ).NotTo (BeNil ())
92+ // Avoid race condition with need restart condition calculation
93+ Eventually (func (g Gomega ) {
94+ err = f .Clients .GenericClient ().Get (context .Background (), crclient .ObjectKeyFromObject (t .VM ), t .VM )
95+ g .Expect (err ).NotTo (HaveOccurred ())
96+ needRestart , _ := conditions .GetCondition (vmcondition .TypeAwaitingRestartToApplyConfiguration , t .VM .Status .Conditions )
97+ g .Expect (needRestart .Status ).To (Equal (metav1 .ConditionTrue ))
98+ g .Expect (t .VM .Status .RestartAwaitingChanges ).NotTo (BeNil ())
99+ }).WithTimeout (3 * time .Second ).WithPolling (time .Second ).Should (Succeed ())
98100
99101 util .RebootVirtualMachineBySSH (f , t .VM )
100102 }
@@ -109,7 +111,7 @@ var _ = Describe("VirtualMachineConfiguration", func() {
109111 Expect (t .VM .Status .Resources .CPU .Cores ).To (Equal (changedCPUCores ))
110112 Expect (t .VM .Status .Resources .Memory .Size ).To (Equal (resource .MustParse (changedMemorySize )))
111113 Expect (t .VM .Status .Resources .CPU .CoreFraction ).To (Equal (changedCoreFraction ))
112- Expect (t .IsVDInVMStatus (t .VDBlank , t .VM )).To (BeTrue ())
114+ Expect (t .IsVDAttached (t .VDBlank , t .VM )).To (BeTrue ())
113115 },
114116 Entry ("when changes are applied manually" , v1alpha2 .Manual ),
115117 Entry ("when changes are applied automatically" , v1alpha2 .Automatic ),
@@ -163,9 +165,9 @@ func (c *configurationTest) GenerateConfigurationResources(restartApprovalMode v
163165 )
164166}
165167
166- func (c * configurationTest ) IsVDInVMStatus (vd * v1alpha2.VirtualDisk , vm * v1alpha2.VirtualMachine ) bool {
167- for _ , bda := range vm .Status .BlockDeviceRefs {
168- if bda .Kind == v1alpha2 .DiskDevice && bda .Name == vd .Name {
168+ func (c * configurationTest ) IsVDAttached (vd * v1alpha2.VirtualDisk , vm * v1alpha2.VirtualMachine ) bool {
169+ for _ , bd := range vm .Status .BlockDeviceRefs {
170+ if bd .Kind == v1alpha2 .DiskDevice && bd .Name == vd .Name && bd . Attached {
169171 return true
170172 }
171173 }
0 commit comments