Skip to content

Commit 4e841c1

Browse files
add e2e test for MCP in MCN
1 parent 12ffd22 commit 4e841c1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/e2e-techpreview/mcn_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package e2e_techpreview_test
22

33
import (
44
"bytes"
5+
"context"
56
"os/exec"
67
"testing"
78

89
"github.com/openshift/machine-config-operator/test/framework"
910
"github.com/openshift/machine-config-operator/test/helpers"
1011
"github.com/stretchr/testify/require"
12+
13+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1114
)
1215

1316
func TestMCNScopeSadPath(t *testing.T) {
@@ -53,3 +56,37 @@ func TestMCNScopeHappyPath(t *testing.T) {
5356
// This oc command effectively use the service account of the nodeUnderTest's MCD pod, which should only be able to edit nodeUnderTest's MCN.
5457
helpers.ExecCmdOnNode(t, cs, nodeUnderTest, "chroot", "/rootfs", "oc", "patch", "machineconfignodes", nodeUnderTest.Name, "--type=merge", "-p", "{\"spec\":{\"configVersion\":{\"desired\":\"rendered-worker-test\"}}}")
5558
}
59+
60+
// `TestMCNPoolNameDefault` checks that the MCP name is correctly populated in a node's MCN object for default MCPs
61+
func TestMCNPoolNameDefault(t *testing.T) {
62+
63+
cs := framework.NewClientSet("")
64+
65+
// Grab a random node from each default pool
66+
workerNode := helpers.GetRandomNode(t, cs, "worker")
67+
masterNode := helpers.GetRandomNode(t, cs, "master")
68+
69+
// Test that MCN pool name value matches MCP association
70+
workerNodeMCN, workerErr := cs.MachineconfigurationV1alpha1Interface.MachineConfigNodes().Get(context.TODO(), workerNode.Name, metav1.GetOptions{})
71+
require.Equal(t, "worker", workerNodeMCN.Spec.Pool.Name)
72+
require.NoError(t, workerErr)
73+
masterNodeMCN, masterErr := cs.MachineconfigurationV1alpha1Interface.MachineConfigNodes().Get(context.TODO(), masterNode.Name, metav1.GetOptions{})
74+
require.Equal(t, "master", masterNodeMCN.Spec.Pool.Name)
75+
require.NoError(t, masterErr)
76+
}
77+
78+
// `TestMCNPoolNameDefault` checks that the MCP name is correctly populated in a node's MCN object for custom MCPs
79+
func TestMCNPoolNameCustom(t *testing.T) {
80+
81+
cs := framework.NewClientSet("")
82+
83+
// Create a custom MCP and assign a worker node to it
84+
customMCPName := "infra"
85+
customNode := helpers.GetRandomNode(t, cs, "worker")
86+
helpers.CreatePoolWithNode(t, cs, customMCPName, customNode)
87+
88+
// Test that MCN pool name value matches MCP association
89+
customNodeMCN, customErr := cs.MachineconfigurationV1alpha1Interface.MachineConfigNodes().Get(context.TODO(), customNode.Name, metav1.GetOptions{})
90+
require.Equal(t, customMCPName, customNodeMCN.Spec.Pool.Name)
91+
require.NoError(t, customErr)
92+
}

0 commit comments

Comments
 (0)