func (tc *testContext) waitForWindowsMachines(machineCount int, phase string, windowsLabel bool) (*mapi.MachineList, error) {
	if machineCount == 0 && phase != "" {
		return nil, errors.New("expected phase to be to be an empty string if machineCount is 0")
	}

	var machines *mapi.MachineList
	machineStateTimeLimit := time.Minute * 5
	startTime := time.Now()
	// Increasing the time limit due to https://bugzilla.redhat.com/show_bug.cgi?id=1936556
	if tc.CloudProvider.GetType() == config.VSpherePlatformType {
		// When deleting Machines, set the time limit to 10 minutes
		if machineCount == 0 {
			machineStateTimeLimit = time.Minute * 10
		} else {
			machineStateTimeLimit = time.Minute * 20
		}
	}

	listOptions := metav1.ListOptions{LabelSelector: clusterinfo.MachineE2ELabel + "=true"}
	if windowsLabel {
		listOptions.LabelSelector += "," + controllers.MachineOSLabel + "=Windows"
	} else {
		listOptions.LabelSelector += "," + controllers.MachineOSLabel + "!=Windows"
	}
	err := wait.Poll(retryInterval, machineStateTimeLimit, func() (done bool, err error) {
		machines, err = tc.client.Machine.Machines(clusterinfo.MachineAPINamespace).List(context.TODO(), listOptions)
		if err != nil {
			if apierrors.IsNotFound(err) {
				log.Printf("waiting for %d Windows Machines", machineCount)
				return false, nil
			}
			log.Printf("machine object listing failed: %v", err)
			return false, nil
		}
		if len(machines.Items) != machineCount {
			log.Printf("waiting for %d/%d Windows Machines", machineCount-len(machines.Items), machineCount)
			return false, nil
		}
		// A phase of "" skips the phase check
		if phase == "" {
			return true, nil
		}
		for _, machine := range machines.Items {
			if machine.Status.Phase == nil || *machine.Status.Phase != phase {
				return false, nil
			}
			// If waiting for a provisioned Machine, ensure the Machine is fully attached to the network and has an
			// assigned IPv4 address.
			if phase != "Provisioned" {
				continue
			}
			hasIPv4 := false
			for _, address := range machine.Status.Addresses {
				if address.Type != v1.NodeInternalIP {
					continue
				}
				if net.ParseIP(address.Address) != nil && net.ParseIP(address.Address).To4() != nil {
					hasIPv4 = true
					break
				}
			}
			if !hasIPv4 {
				return false, nil
			}
		}
		return true, nil
	})
	if phase == "" {
		phase = "deleted"
	}

	// Log the time elapsed while waiting for creation of the Machines
	var machineType string
	if windowsLabel {
		machineType = "with the Windows label"
	} else {
		machineType = "without the Windows label"
	}
	endTime := time.Now()
	log.Printf("%v time is required for %d Machines %s to reach phase %s", endTime.Sub(startTime),
		len(machines.Items), machineType, phase)
	return machines, err
}
// waitForWindowsMachines waits for a certain amount of Windows Machines to reach a certain phase
// if machineCount = 0, it implies we are only waiting for Machines to be deleted and the phase is
// ignored in this case. Returns the set of Machines that matched the provided windowsLabel criteria.
// TODO: Have this function take in a list of Windows Machines to wait for https://issues.redhat.com/browse/WINC-620
waitForWindowsMachines waits for a certain amount of Windows Machines to reach a certain phase
if machineCount = 0, it implies we are only waiting for Machines to be deleted and the phase is
ignored in this case. Returns the set of Machines that matched the provided windowsLabel criteria.
// waitForWindowsMachines waits for a certain amount of Windows Machines to reach a certain phase // if machineCount = 0 it implies we are only waiting for Machines to be deleted and the phase is // ignored in this case . Returns the set of Machines that matched the provided windowsLabel criteria . // TODO : Have this function take in a list of Windows Machines to wait for https : // issues . redhat . com / browse / WINC - 620
func (tc *testContext) waitForWindowsMachines(machineCount int, phase string, windowsLabel bool) (*mapi.MachineList, error) {
	if machineCount == 0 && phase != "" {
		return nil, errors.New("expected phase to be to be an empty string if machineCount is 0")
	}
	var machines *mapi.MachineList
	machineStateTimeLimit := time.Minute * 5
	startTime := time.Now()
	if tc.CloudProvider.GetType() == config.VSpherePlatformType {
		if machineCount == 0 {
			machineStateTimeLimit = time.Minute * 10
		} else {
			machineStateTimeLimit = time.Minute * 20
		}
	}
	listOptions := metav1.ListOptions{LabelSelector: clusterinfo.MachineE2ELabel + "=true"}
	if windowsLabel {
		listOptions.LabelSelector += "," + controllers.MachineOSLabel + "=Windows"
	} else {
		listOptions.LabelSelector += "," + controllers.MachineOSLabel + "!=Windows"
	}
	err := wait.Poll(retryInterval, machineStateTimeLimit, func() (done bool, err error) {
		machines, err = tc.client.Machine.Machines(clusterinfo.MachineAPINamespace).List(context.TODO(), listOptions)
		if err != nil {
			if apierrors.IsNotFound(err) {
				log.Printf("waiting for %d Windows Machines", machineCount)
				return false, nil
			}
			log.Printf("machine object listing failed: %v", err)
			return false, nil
		}
		if len(machines.Items) != machineCount {
			log.Printf("waiting for %d/%d Windows Machines", machineCount-len(machines.Items), machineCount)
			return false, nil
		}
		if phase == "" {
			return true, nil
		}
		for _, machine := range machines.Items {
			if machine.Status.Phase == nil || *machine.Status.Phase != phase {
				return false, nil
			}
			if phase != "Provisioned" {
				continue
			}
			hasIPv4 := false
			for _, address := range machine.Status.Addresses {
				if address.Type != v1.NodeInternalIP {
					continue
				}
				if net.ParseIP(address.Address) != nil && net.ParseIP(address.Address).To4() != nil {
					hasIPv4 = true
					break
				}
			}
			if !hasIPv4 {
				return false, nil
			}
		}
		return true, nil
	})
	if phase == "" {
		phase = "deleted"
	}
	var machineType string
	if windowsLabel {
		machineType = "with the Windows label"
	} else {
		machineType = "without the Windows label"
	}
	endTime := time.Now()
	log.Printf("%v time is required for %d Machines %s to reach phase %s", endTime.Sub(startTime),
		len(machines.Items), machineType, phase)
	return machines, err
}
func ( tc * testContext ) waitForWindowsMachines ( machineCount int , phase string , windowsLabel bool ) ( * mapi . MachineList , error ) { if machineCount == 0 && phase != " " { return nil , errors . New ( " " ) } var machines * mapi . MachineList machineStateTimeLimit := time . Minute * 5 startTime := time . Now ( ) if tc . CloudProvider . GetType ( ) == config . VSpherePlatformType { if machineCount == 0 { machineStateTimeLimit = time . Minute * 10 } else { machineStateTimeLimit = time . Minute * 20 } } listOptions := metav1 . ListOptions { LabelSelector : clusterinfo . MachineE2ELabel + " " } if windowsLabel { listOptions . LabelSelector += " " + controllers . MachineOSLabel + " " } else { listOptions . LabelSelector += " " + controllers . MachineOSLabel + " " } err := wait . Poll ( retryInterval , machineStateTimeLimit , func ( ) ( done bool , err error ) { machines , err = tc . client . Machine . Machines ( clusterinfo . MachineAPINamespace ) . List ( context . TODO ( ) , listOptions ) if err != nil { if apierrors . IsNotFound ( err ) { log . Printf ( " " , machineCount ) return false , nil } log . Printf ( " " , err ) return false , nil } if len ( machines . Items ) != machineCount { log . Printf ( " " , machineCount - len ( machines . Items ) , machineCount ) return false , nil } if phase == " " { return true , nil } for _ , machine := range machines . Items { if machine . Status . Phase == nil || * machine . Status . Phase != phase { return false , nil } if phase != " " { continue } hasIPv4 := false for _ , address := range machine . Status . Addresses { if address . Type != v1 . NodeInternalIP { continue } if net . ParseIP ( address . Address ) != nil && net . ParseIP ( address . Address ) . To4 ( ) != nil { hasIPv4 = true break } } if ! hasIPv4 { return false , nil } } return true , nil } ) if phase == " " { phase = " " } var machineType string if windowsLabel { machineType = " " } else { machineType = " " } endTime := time . Now ( ) log . Printf ( " " , endTime . Sub ( startTime ) , len ( machines . Items ) , machineType , phase ) return machines , err }
waitForWindowsMachines waits for a certain amount of Windows Machines to reach a certain phase
if machineCount = 0, it implies we are only waiting for Machines to be deleted and the phase is
ignored in this case.
waitForWindowsMachines waits for a certain amount of Windows Machines to reach a certain phase if machineCount = 0 it implies we are only waiting for Machines to be deleted and the phase is ignored in this case .
// Increasing the time limit due to https://bugzilla.redhat.com/show_bug.cgi?id=1936556 // When deleting Machines, set the time limit to 10 minutes // A phase of "" skips the phase check // If waiting for a provisioned Machine, ensure the Machine is fully attached to the network and has an // assigned IPv4 address. // Log the time elapsed while waiting for creation of the Machines