test/e2e: Add rollback test for kernelType
@@ -285,6 +285,11 @@ func TestKernelArguments(t *testing.T) {
func TestKernelType(t *testing.T) {
cs := framework.NewClientSet("")
+ // Get initial MachineConfig used by the worker pool so that we can rollback to it later on
+ mcp, err := cs.MachineConfigPools().Get("worker", metav1.GetOptions{})
+ require.Nil(t, err)
+ workerOldMC := mcp.Status.Configuration.Name
+
kernelType := &mcfgv1.MachineConfig{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("kerneltype-%s", uuid.NewUUID()),
@@ -296,7 +301,7 @@ func TestKernelType(t *testing.T) {
},
}
- _, err := cs.MachineConfigs().Create(kernelType)
+ _, err = cs.MachineConfigs().Create(kernelType)
require.Nil(t, err)
t.Logf("Created %s", kernelType.Name)
renderedConfig, err := waitForRenderedConfig(t, cs, "worker", kernelType.Name)
@@ -322,6 +327,39 @@ func TestKernelType(t *testing.T) {
}
t.Logf("Node %s has expected kernel", node.Name)
}
+
+ // Delete the applied kerneltype MachineConfig to make sure rollback works fine
+ if err := cs.MachineConfigs().Delete(kernelType.Name, &metav1.DeleteOptions{}); err != nil {
+ t.Error(err)
+ }
+
+ t.Logf("Deleted MachineConfig %s", kernelType.Name)
+
+ // Wait for the mcp to rollback to previous config
+ if err := waitForPoolComplete(t, cs, "worker", workerOldMC); err != nil {
+ t.Fatal(err)
+ }
+
+ // Re-fetch the worker nodes for updated annotations
+ nodes, err = getNodesByRole(cs, "worker")
+ require.Nil(t, err)
+ for _, node := range nodes {
+ assert.Equal(t, node.Annotations[constants.CurrentMachineConfigAnnotationKey], workerOldMC)
+ assert.Equal(t, node.Annotations[constants.MachineConfigDaemonStateAnnotationKey], constants.MachineConfigDaemonStateDone)
+ mcd, err := mcdForNode(cs, &node)
+ require.Nil(t, err)
+ mcdName := mcd.ObjectMeta.Name
+ // Worker node should now have default kernel
+ cmd, err := exec.Command("oc", "rsh", "-n", "openshift-machine-config-operator", mcdName,
+ "uname", "-a").CombinedOutput()
+ require.Nil(t, err)
+ kernelInfo := string(cmd)
+ if strings.Contains(kernelInfo, "PREEMPT RT") {
+ t.Fatalf("Node %s did not rollback successfully", node.Name)
+ }
+ t.Logf("Node %s has successfully rolled back", node.Name)
+ }
+
}
func getNodesByRole(cs *framework.ClientSet, role string) ([]corev1.Node, error) {
