From 9b8b378782b8df655212b29c80daa1ed290a5a7c Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Thu, 12 May 2022 07:52:41 -0700 Subject: [PATCH] tests Windows: Fixes test failures related to COMPUTERNAMEs being truncated Windows ComputerNames cannot exceed 15 characters. This causes a few tests to fail when the node names exceed that limit. Additionally, the checks should be case insensitive. --- test/e2e/windows/host_process.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/e2e/windows/host_process.go b/test/e2e/windows/host_process.go index 70587cf6a14..beed9f7a1e2 100644 --- a/test/e2e/windows/host_process.go +++ b/test/e2e/windows/host_process.go @@ -64,8 +64,11 @@ const ( Write-Output $c throw "Contents of /etc/secret/foo.txt are not as expected" } - if ($env:NODE_NAME_TEST -ne $env:COMPUTERNAME) { - throw "NODE_NAME_TEST env var ($env:NODE_NAME_TEST) does not equal COMPUTERNAME ($env:COMPUTERNAME)" + # Windows ComputerNames cannot exceed 15 characters, which means that the $env:COMPUTERNAME + # can only be a substring of $env:NODE_NAME_TEST. We compare it with the hostname instead. + # The following comparison is case insensitive. + if ($env:NODE_NAME_TEST -ine "$(hostname)") { + throw "NODE_NAME_TEST env var ($env:NODE_NAME_TEST) does not equal hostname" } Write-Output "SUCCESS"` ) @@ -95,6 +98,8 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi ginkgo.By("scheduling a pod with a container that verifies %COMPUTERNAME% matches selected node name") image := imageutils.GetConfig(imageutils.BusyBox) podName := "host-process-test-pod" + // We're passing this to powershell.exe -Command. Inside, we must use apostrophes for strings. + command := fmt.Sprintf(`& {if ('%s' -ine "$(hostname)") { exit -1 }}`, targetNode.Name) pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: podName, @@ -111,7 +116,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi { Image: image.GetE2EImage(), Name: "computer-name-test", - Command: []string{"cmd.exe", "/K", "IF", "NOT", "%COMPUTERNAME%", "==", targetNode.Name, "(", "exit", "-1", ")"}, + Command: []string{"powershell.exe", "-Command", command}, }, }, RestartPolicy: v1.RestartPolicyNever,