Skip to content

Commit

Permalink
Wait before check the first time vm status
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentBaer authored and Vincent Baer committed Nov 25, 2022
1 parent bf40de0 commit dea0097
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cloud/services/compute/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func (s *Service) CheckVmState(clockInsideLoop time.Duration, clockLoop time.Dur
currentTimeout := clock_time.Now().Add(time.Second * clockLoop)
var getVmState = false
for !getVmState {
time.Sleep(clockInsideLoop * time.Second)
vm, err := s.GetVm(vmId)
if err != nil {
return err
Expand All @@ -251,7 +252,6 @@ func (s *Service) CheckVmState(clockInsideLoop time.Duration, clockLoop time.Dur
if *vmState == state {
break
}
time.Sleep(clockInsideLoop * time.Second)

if clock_time.Now().After(currentTimeout) {
return errors.New("Vm still not running")
Expand Down
2 changes: 1 addition & 1 deletion controllers/oscmachine_vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS
}

vmID = vm.GetVmId()
err = vmSvc.CheckVmState(5, 120, "running", vmID)
err = vmSvc.CheckVmState(20, 120, "running", vmID)
if err != nil {
return reconcile.Result{}, fmt.Errorf("%w Can not get vm %s running for OscMachine %s/%s", err, vmID, machineScope.GetNamespace(), machineScope.GetName())
}
Expand Down
13 changes: 9 additions & 4 deletions controllers/oscmachine_vm_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,7 @@ func TestReconcileVm(t *testing.T) {
deviceName := vtc.machineSpec.Node.Vm.DeviceName
vmSpec := vtc.machineSpec.Node.Vm
var clockInsideLoop time.Duration = 5
var firstClockInsideLoop time.Duration = 20
var clockLoop time.Duration = 60
var firstClockLoop time.Duration = 120
loadBalancerName := vtc.machineSpec.Node.Vm.LoadBalancerName
Expand Down Expand Up @@ -2059,7 +2060,7 @@ func TestReconcileVm(t *testing.T) {

mockOscVmInterface.
EXPECT().
CheckVmState(gomock.Eq(clockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
CheckVmState(gomock.Eq(firstClockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
Return(vtc.expCheckVmStateBootErr)

if vtc.machineSpec.Node.Vm.VolumeName != "" {
Expand Down Expand Up @@ -2393,6 +2394,7 @@ func TestReconcileVmLink(t *testing.T) {
volumeDeviceName := vtc.machineSpec.Node.Vm.VolumeDeviceName

var clockInsideLoop time.Duration = 5
var firstClockInsideLoop time.Duration = 20
var clockLoop time.Duration = 60
var firstClockLoop time.Duration = 120
if vtc.expCreateVmFound {
Expand All @@ -2410,9 +2412,10 @@ func TestReconcileVmLink(t *testing.T) {
if vtc.expCheckVmStateBootFound {
mockOscVmInterface.
EXPECT().
CheckVmState(gomock.Eq(clockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
CheckVmState(gomock.Eq(firstClockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
Return(vtc.expCheckVmStateBootErr)
}

if vtc.expCheckVolumeStateAvailableFound {
mockOscVolumeInterface.
EXPECT().
Expand Down Expand Up @@ -2589,6 +2592,7 @@ func TestReconcileVmLinkPubicIp(t *testing.T) {

vmSpec := vtc.machineSpec.Node.Vm
var clockInsideLoop time.Duration = 5
var firstClockInsideLoop time.Duration = 20
var clockLoop time.Duration = 60
var firstClockLoop time.Duration = 120

Expand Down Expand Up @@ -2618,7 +2622,7 @@ func TestReconcileVmLinkPubicIp(t *testing.T) {

mockOscVmInterface.
EXPECT().
CheckVmState(gomock.Eq(clockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
CheckVmState(gomock.Eq(firstClockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
Return(vtc.expCheckVmStateBootErr)

if vtc.machineSpec.Node.Vm.VolumeName != "" {
Expand Down Expand Up @@ -2764,6 +2768,7 @@ func TestReconcileVmSecurityGroup(t *testing.T) {
deviceName := vtc.machineSpec.Node.Vm.DeviceName
vmSpec := vtc.machineSpec.Node.Vm
var clockInsideLoop time.Duration = 5
var firstClockInsideLoop time.Duration = 20
var clockLoop time.Duration = 60
var firstClockLoop time.Duration = 120
loadBalancerName := vtc.machineSpec.Node.Vm.LoadBalancerName
Expand Down Expand Up @@ -2795,7 +2800,7 @@ func TestReconcileVmSecurityGroup(t *testing.T) {

mockOscVmInterface.
EXPECT().
CheckVmState(gomock.Eq(clockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
CheckVmState(gomock.Eq(firstClockInsideLoop), gomock.Eq(firstClockLoop), gomock.Eq(vmState), gomock.Eq(vmId)).
Return(vtc.expCheckVmStateBootErr)
if vtc.machineSpec.Node.Vm.VolumeName != "" {

Expand Down

0 comments on commit dea0097

Please sign in to comment.