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 Sep 2, 2020
1 parent f4ef7e5 commit 8f07cb1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
28 changes: 14 additions & 14 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 All @@ -572,9 +572,8 @@ 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 @@ -586,12 +585,13 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
},
}, isMultiZone),
IsWindows: isWindowsCluster,
UseCMD: true,
}

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 "echo hello world>> C:\\mnt\\test-1\\data.txt& FOR /L %N IN () DO timeout 3600"
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
3 changes: 2 additions & 1 deletion test/e2e/testsuites/specs.go
Expand Up @@ -32,6 +32,7 @@ type PodDetails struct {
Cmd string
Volumes []VolumeDetails
IsWindows bool
UseCMD bool
}

type VolumeDetails struct {
Expand Down Expand Up @@ -178,7 +179,7 @@ func (pod *PodDetails) SetupStatefulset(client clientset.Interface, namespace *v
}
tpvc.requestedPersistentVolumeClaim = generateStatefulSetPVC(tpvc.namespace.Name, storageClassName, tpvc.claimSize, tpvc.volumeMode, tpvc.dataSource)
ginkgo.By("setting up the statefulset")
tStatefulset := NewTestStatefulset(client, namespace, pod.Cmd, tpvc.requestedPersistentVolumeClaim, "pvc", fmt.Sprintf("%s%d", volume.VolumeMount.MountPathGenerate, 1), volume.VolumeMount.ReadOnly, pod.IsWindows)
tStatefulset := NewTestStatefulset(client, namespace, pod.Cmd, tpvc.requestedPersistentVolumeClaim, "pvc", fmt.Sprintf("%s%d", volume.VolumeMount.MountPathGenerate, 1), volume.VolumeMount.ReadOnly, pod.IsWindows, pod.UseCMD)

cleanupFuncs = append(cleanupFuncs, tStatefulset.Cleanup)
return tStatefulset, cleanupFuncs
Expand Down
14 changes: 10 additions & 4 deletions test/e2e/testsuites/testsuites.go
Expand Up @@ -535,7 +535,7 @@ type TestStatefulset struct {
podName string
}

func NewTestStatefulset(c clientset.Interface, ns *v1.Namespace, command string, pvc *v1.PersistentVolumeClaim, volumeName, mountPath string, readOnly, isWindows bool) *TestStatefulset {
func NewTestStatefulset(c clientset.Interface, ns *v1.Namespace, command string, pvc *v1.PersistentVolumeClaim, volumeName, mountPath string, readOnly, isWindows, useCMD bool) *TestStatefulset {
generateName := "azuredisk-volume-tester-"
selectorValue := fmt.Sprintf("%s%d", generateName, rand.Int())
replicas := int32(1)
Expand Down Expand Up @@ -585,9 +585,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 useCMD {
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 8f07cb1

Please sign in to comment.