Skip to content

Commit eea68de

Browse files
ocpbugs-57524: improve stability of MCN slow tests
1 parent c68dfc0 commit eea68de

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

test/extended/machine_config/helpers.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,28 @@ func CheckMCNConditionStatus(mcn *mcfgv1.MachineConfigNode, conditionType mcfgv1
735735
return conditionStatus == status
736736
}
737737

738-
// `getMCNConditionStatus` returns the status of the desired condition type for MCN, or an empty string if the condition does not exist
739-
func getMCNConditionStatus(mcn *mcfgv1.MachineConfigNode, conditionType mcfgv1.StateProgress) metav1.ConditionStatus {
738+
// `GetMCNCondition` returns the queried condition or nil if the condition does not exist
739+
func GetMCNCondition(mcn *mcfgv1.MachineConfigNode, conditionType mcfgv1.StateProgress) *metav1.Condition {
740740
// Loop through conditions and return the status of the desired condition type
741741
conditions := mcn.Status.Conditions
742742
for _, condition := range conditions {
743743
if condition.Type == string(conditionType) {
744-
framework.Logf("MCN '%s' %s condition status is %s", mcn.Name, conditionType, condition.Status)
745-
return condition.Status
744+
return &condition
746745
}
747746
}
748-
return ""
747+
return nil
748+
}
749+
750+
// `getMCNConditionStatus` returns the status of the desired condition type for MCN, or an empty string if the condition does not exist
751+
func getMCNConditionStatus(mcn *mcfgv1.MachineConfigNode, conditionType mcfgv1.StateProgress) metav1.ConditionStatus {
752+
// Loop through conditions and return the status of the desired condition type
753+
condition := GetMCNCondition(mcn, conditionType)
754+
if condition == nil {
755+
return ""
756+
}
757+
758+
framework.Logf("MCN '%s' %s condition status is %s", mcn.Name, conditionType, condition.Status)
759+
return condition.Status
749760
}
750761

751762
// `ConfirmUpdatedMCNStatus` confirms that an MCN is in a fully updated state, which requires:
@@ -994,7 +1005,7 @@ func GetNodeInMachine(oc *exutil.CLI, machineName string) (corev1.Node, error) {
9941005
return *node, nil
9951006
}
9961007

997-
// `GetNewReadyNodeInMachine` waits up to 2 minutes for the newly provisioned node in a desired machine node to be ready
1008+
// `GetNewReadyNodeInMachine` waits up to 4 minutes for the newly provisioned node in a desired machine node to be ready
9981009
func GetNewReadyNodeInMachine(oc *exutil.CLI, machineName string) (corev1.Node, error) {
9991010
desiredNode := corev1.Node{}
10001011
err := fmt.Errorf("no ready node in Machine: %s", machineName)
@@ -1013,7 +1024,7 @@ func GetNewReadyNodeInMachine(oc *exutil.CLI, machineName string) (corev1.Node,
10131024
}
10141025

10151026
return false
1016-
}, 2*time.Minute, 3*time.Second).Should(o.BeTrue())
1027+
}, 4*time.Minute, 5*time.Second).Should(o.BeTrue(), fmt.Sprintf("Node in machine %v never became ready.", machineName))
10171028
return desiredNode, err
10181029
}
10191030

test/extended/machine_config/machine_config_node.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ func ValidateMCNConditionOnNodeDegrade(oc *exutil.CLI, fixture string, isSno boo
371371
mcName = "91-master-testfile-invalid"
372372
}
373373

374+
var degradedNodeMCN *mcfgv1.MachineConfigNode
374375
// Cleanup MC and fix node degradation on failure or test completion
375376
defer func() {
376377
// Delete the applied MC
@@ -380,6 +381,13 @@ func ValidateMCNConditionOnNodeDegrade(oc *exutil.CLI, fixture string, isSno boo
380381
// Recover the degraded MCP
381382
recoverErr := RecoverFromDegraded(oc, poolName)
382383
o.Expect(recoverErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not recover MCP '%v' from degraded state.", poolName))
384+
385+
// If the test reached checking the MCN ensure the NodeDegraded condition is properly restored
386+
if degradedNodeMCN != nil {
387+
conditionMet, err := WaitForMCNConditionStatus(clientSet, degradedNodeMCN.Name, mcfgv1.MachineConfigNodeNodeDegraded, metav1.ConditionFalse, 30*time.Second, 1*time.Second)
388+
o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("Error occured while waiting for NodeDegraded=False: %v", err))
389+
o.Expect(conditionMet).To(o.BeTrue(), "Error, could not detect NodeDegraded=False.")
390+
}
383391
}()
384392

385393
// Apply invalid MC
@@ -398,11 +406,27 @@ func ValidateMCNConditionOnNodeDegrade(oc *exutil.CLI, fixture string, isSno boo
398406
o.Expect(degradedNodeErr).NotTo(o.HaveOccurred(), "Could not get degraded node.")
399407

400408
// Validate MCN of degraded node
401-
degradedNodeMCN, degradedErr := clientSet.MachineconfigurationV1().MachineConfigNodes().Get(context.TODO(), degradedNode.Name, metav1.GetOptions{})
409+
// get and log MCN conditions for debugging purposes
410+
degradedNodeMCN, degradedErr = clientSet.MachineconfigurationV1().MachineConfigNodes().Get(context.TODO(), degradedNode.Name, metav1.GetOptions{})
402411
o.Expect(degradedErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error getting MCN of degraded node '%v'.", degradedNode.Name))
403-
framework.Logf("Validating that `AppliedFilesAndOS` and `UpdateExecuted` conditions in '%v' MCN have a status of 'Unknown'.", degradedNodeMCN.Name)
404-
o.Expect(CheckMCNConditionStatus(degradedNodeMCN, mcfgv1.MachineConfigNodeUpdateFilesAndOS, metav1.ConditionUnknown)).Should(o.BeTrue(), "Condition 'AppliedFilesAndOS' does not have the expected status of 'Unknown'.")
405-
o.Expect(CheckMCNConditionStatus(degradedNodeMCN, mcfgv1.MachineConfigNodeUpdateExecuted, metav1.ConditionUnknown)).Should(o.BeTrue(), "Condition 'UpdateExecuted' does not have the expected status of 'Unknown'.")
412+
nodeDegradedCondition := GetMCNCondition(degradedNodeMCN, mcfgv1.MachineConfigNodeNodeDegraded)
413+
o.Expect(nodeDegradedCondition).NotTo(o.BeNil(), "Condition 'NodeDegraded' does not exist.")
414+
framework.Logf("`NodeDegraded` condition status is `%v` with the message `%v`", nodeDegradedCondition.Status, nodeDegradedCondition.Message)
415+
filesAndOSCondition := GetMCNCondition(degradedNodeMCN, mcfgv1.MachineConfigNodeUpdateFilesAndOS)
416+
o.Expect(filesAndOSCondition).NotTo(o.BeNil(), "Condition 'AppliedFilesAndOS' does not exist.")
417+
framework.Logf("`AppliedFilesAndOS` condition status is `%v` with the message `%v`", filesAndOSCondition.Status, filesAndOSCondition.Message)
418+
executedCondition := GetMCNCondition(degradedNodeMCN, mcfgv1.MachineConfigNodeUpdateExecuted)
419+
o.Expect(executedCondition).NotTo(o.BeNil(), "Condition 'UpdateExecuted' does not exist.")
420+
framework.Logf("`UpdateExecuted` condition status is `%v` with the message `%v`", executedCondition.Status, executedCondition.Message)
421+
// validate the conditions are as expected
422+
framework.Logf("Validating that `NodeDegraded` condition in '%v' MCN has a status of 'True'.", degradedNodeMCN.Name)
423+
o.Expect(nodeDegradedCondition.Status).Should(o.Equal(metav1.ConditionTrue), "Condition 'NodeDegraded' does not have the expected status of 'True'.")
424+
o.Expect(nodeDegradedCondition.Message).Should(o.ContainSubstring(fmt.Sprintf("Node %s upgrade failure.", degradedNodeMCN.Name)), "Condition 'NodeDegraded' does not have the expected message.")
425+
o.Expect(nodeDegradedCondition.Message).Should(o.ContainSubstring("/home/core: file exists"), "Condition 'NodeDegraded' does not have the expected message details.")
426+
framework.Logf("Validating that `UpdateExecuted` condition in '%v' MCN has a status of 'Unknown'.", degradedNodeMCN.Name)
427+
o.Expect(executedCondition.Status).Should(o.Equal(metav1.ConditionUnknown), "Condition 'UpdateExecuted' does not have the expected status of 'Unknown'.")
428+
framework.Logf("Validating that `AppliedFilesAndOS` condition in '%v' MCN has a status of 'Unknown'.", degradedNodeMCN.Name)
429+
o.Expect(filesAndOSCondition.Status).Should(o.Equal(metav1.ConditionUnknown), "Condition 'AppliedFilesAndOS' does not have the expected status of 'Unknown'.")
406430
}
407431

408432
// `ValidateMCNProperties` checks that MCNs with correct properties are created on node creation

0 commit comments

Comments
 (0)