Skip to content

Commit

Permalink
fix: use CMD command to avoid the encoding issue
Browse files Browse the repository at this point in the history
Signed-off-by: ZeroMagic <jiliu8@microsoft.com>
  • Loading branch information
ZeroMagic committed Aug 30, 2020
1 parent f4ef7e5 commit a705137
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
26 changes: 13 additions & 13 deletions test/e2e/dynamic_provisioning_test.go
Expand Up @@ -99,7 +99,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
ginkgo.It("should create a volume on demand with mount options [kubernetes.io/azure-disk] [disk.csi.azure.com] [Windows]", func() {
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
ClaimSize: "10Gi",
Expand Down Expand Up @@ -184,7 +184,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
ginkgo.It("should create a volume on demand and mount it as readOnly in a pod [kubernetes.io/azure-disk] [disk.csi.azure.com] [Windows]", func() {
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("touch /mnt/test-1/data"),
Cmd: convertToPowershellorCmdCommandIfNecessary("touch /mnt/test-1/data"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
FSType: "ext4",
Expand All @@ -210,7 +210,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
ginkgo.It("should create multiple PV objects, bind to PVCs and attach all to different pods on the same node [kubernetes.io/azure-disk] [disk.csi.azure.com] [Windows]", func() {
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Cmd: convertToPowershellorCmdCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
FSType: "ext3",
Expand All @@ -224,7 +224,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
IsWindows: isWindowsCluster,
},
{
Cmd: convertToPowershellCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Cmd: convertToPowershellorCmdCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
FSType: "ext4",
Expand All @@ -238,7 +238,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
IsWindows: isWindowsCluster,
},
{
Cmd: convertToPowershellCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Cmd: convertToPowershellorCmdCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
FSType: "xfs",
Expand All @@ -265,7 +265,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
skipIfTestingInWindowsCluster()

pod := testsuites.PodDetails{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' >> /mnt/test-1/data && while true; do sleep 3600; done"),
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' >> /mnt/test-1/data && while true; do sleep 3600; done"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
FSType: "ext3",
Expand All @@ -282,7 +282,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
podCheckCmd := []string{"cat", "/mnt/test-1/data"}
expectedString := "hello world\n"
if isWindowsCluster {
podCheckCmd = []string{"powershell.exe", "-Command", "Get-Content C:\\mnt\\test-1\\data.txt"}
podCheckCmd = []string{"cmd", "/c", "type C:\\mnt\\test-1\\data.txt"}
expectedString = "hello world\r\n"
}
test := testsuites.DynamicallyProvisionedDeletePodTest{
Expand Down Expand Up @@ -366,7 +366,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
ginkgo.It("should create multiple PV objects, bind to PVCs and attach all to a single pod [kubernetes.io/azure-disk] [disk.csi.azure.com] [Windows]", func() {
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && echo 'hello world' > /mnt/test-2/data && echo 'hello world' > /mnt/test-3/data && grep 'hello world' /mnt/test-1/data && grep 'hello world' /mnt/test-2/data && grep 'hello world' /mnt/test-3/data"),
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && echo 'hello world' > /mnt/test-2/data && echo 'hello world' > /mnt/test-3/data && grep 'hello world' /mnt/test-1/data && grep 'hello world' /mnt/test-2/data && grep 'hello world' /mnt/test-3/data"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
FSType: "ext3",
Expand Down Expand Up @@ -484,7 +484,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {

pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: t.normalizeVolumes(volumes, isMultiZone),
IsWindows: isWindowsCluster,
},
Expand Down Expand Up @@ -516,7 +516,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
skipIfUsingInTreeVolumePlugin()
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Cmd: convertToPowershellorCmdCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
ClaimSize: "10Gi",
Expand Down Expand Up @@ -546,7 +546,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
ginkgo.It("should detach disk after pod deleted [disk.csi.azure.com] [Windows]", func() {
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Cmd: convertToPowershellorCmdCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
ClaimSize: "10Gi",
Expand Down Expand Up @@ -574,7 +574,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
ginkgo.It("should create a statefulset object, write and read to it, delete the pod and write and read to it again [kubernetes.io/azure-disk] [disk.csi.azure.com] [Windows]", func() {

pod := testsuites.PodDetails{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' >> /mnt/test-1/data && while true; do sleep 3600; done"),
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' >> /mnt/test-1/data && while true; do sleep 3600; done"),
Volumes: t.normalizeVolumes([]testsuites.VolumeDetails{
{
FSType: "ext3",
Expand All @@ -591,7 +591,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
podCheckCmd := []string{"cat", "/mnt/test-1/data"}
expectedString := "hello world\n"
if isWindowsCluster {
podCheckCmd = []string{"powershell.exe", "-Command", "Get-Content C:\\mnt\\test-1\\data.txt"}
podCheckCmd = []string{"cmd", "/c", "type C:\\mnt\\test-1\\data.txt"}
expectedString = "hello world\r\n"
}
test := testsuites.DynamicallyProvisionedStatefulSetTest{
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/pre_provisioning_test.go
Expand Up @@ -81,7 +81,7 @@ var _ = ginkgo.Describe("Pre-Provisioned", func() {
diskSize := fmt.Sprintf("%dGi", defaultDiskSize)
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: []testsuites.VolumeDetails{
{
VolumeID: volumeID,
Expand Down Expand Up @@ -189,7 +189,7 @@ var _ = ginkgo.Describe("Pre-Provisioned", func() {
pods := []testsuites.PodDetails{}
for i := 1; i <= 5; i++ {
pod := testsuites.PodDetails{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: []testsuites.VolumeDetails{
{
VolumeID: volumeID,
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/suite_test.go
Expand Up @@ -206,7 +206,7 @@ func skipIfUsingInTreeVolumePlugin() {
}
}

func convertToPowershellCommandIfNecessary(command string) string {
func convertToPowershellorCmdCommandIfNecessary(command string) string {
if !isWindowsCluster {
return command
}
Expand All @@ -219,7 +219,7 @@ func convertToPowershellCommandIfNecessary(command string) string {
case "while true; do echo $(date -u) >> /mnt/test-1/data; sleep 3600; done":
return "while (1) { Add-Content -Encoding Ascii C:\\mnt\\test-1\\data.txt $(Get-Date -Format u); sleep 3600 }"
case "echo 'hello world' >> /mnt/test-1/data && while true; do sleep 3600; done":
return "Add-Content -Encoding Ascii C:\\mnt\\test-1\\data.txt 'hello world'; while (1) { sleep 3600 }"
return "FOR /L %N IN () DO @echo hello >> C:\\mnt\\test-1\\data.txt"
case "echo 'hello world' > /mnt/test-1/data && echo 'hello world' > /mnt/test-2/data && echo 'hello world' > /mnt/test-3/data && grep 'hello world' /mnt/test-1/data && grep 'hello world' /mnt/test-2/data && grep 'hello world' /mnt/test-3/data":
return "echo 'hello world' | Out-File -FilePath C:\\mnt\\test-1\\data.txt; Get-Content C:\\mnt\\test-1\\data.txt | findstr 'hello world'; echo 'hello world' | Out-File -FilePath C:\\mnt\\test-2\\data.txt; Get-Content C:\\mnt\\test-2\\data.txt | findstr 'hello world'; echo 'hello world' | Out-File -FilePath C:\\mnt\\test-3\\data.txt; Get-Content C:\\mnt\\test-3\\data.txt | findstr 'hello world'"
}
Expand Down
13 changes: 10 additions & 3 deletions test/e2e/testsuites/testsuites.go
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"k8s.io/klog"
"math/rand"
"strings"
"time"

"sigs.k8s.io/azuredisk-csi-driver/pkg/azuredisk"
Expand Down Expand Up @@ -585,9 +586,15 @@ func NewTestStatefulset(c clientset.Interface, ns *v1.Namespace, command string,
testStatefulset.statefulset.Spec.Template.Spec.NodeSelector = map[string]string{
"kubernetes.io/os": "windows",
}
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Image = "e2eteam/busybox:1.29"
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Command = []string{"powershell.exe"}
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Args = []string{"-Command", command}
if strings.Contains(command, "DO @") {
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Image = "e2eteam/busybox:1.29"
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Command = []string{"cmd"}
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Args = []string{"/c", command}
} else {
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Image = "e2eteam/busybox:1.29"
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Command = []string{"powershell.exe"}
testStatefulset.statefulset.Spec.Template.Spec.Containers[0].Args = []string{"-Command", command}
}
}

return testStatefulset
Expand Down

0 comments on commit a705137

Please sign in to comment.