From b6b25c80dec45eb98200d510a2c14d92d777a140 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 17 Aug 2022 10:38:25 +0200 Subject: [PATCH] e2e storage: add CreateFile to pod IO operations This complements the other operations and will be used by some future tests. --- test/e2e/storage/drivers/proxy/io.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/e2e/storage/drivers/proxy/io.go b/test/e2e/storage/drivers/proxy/io.go index 74fb6e1fa48..296ed882b11 100644 --- a/test/e2e/storage/drivers/proxy/io.go +++ b/test/e2e/storage/drivers/proxy/io.go @@ -18,6 +18,7 @@ package proxy import ( "fmt" + "io" "k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/storage/drivers/csi-test/mock/service" @@ -37,7 +38,7 @@ func (p PodDirIO) DirExists(path string) (bool, error) { "sh", "-c", fmt.Sprintf("if ! [ -e '%s' ]; then echo notexist; elif [ -d '%s' ]; then echo dir; else echo nodir; fi", path, path), - }) + }, nil) if err != nil { return false, fmt.Errorf("error executing dir test commands: stderr=%q, %v", stderr, err) } @@ -54,27 +55,36 @@ func (p PodDirIO) DirExists(path string) (bool, error) { } func (p PodDirIO) Mkdir(path string) error { - _, stderr, err := p.execute([]string{"mkdir", path}) + _, stderr, err := p.execute([]string{"mkdir", path}, nil) if err != nil { return fmt.Errorf("mkdir %q: stderr=%q, %v", path, stderr, err) } return nil } +func (p PodDirIO) CreateFile(path string, content io.Reader) error { + _, stderr, err := p.execute([]string{"dd", "of=" + path}, content) + if err != nil { + return fmt.Errorf("dd of=%s: stderr=%q, %v", path, stderr, err) + } + return nil +} + func (p PodDirIO) RemoveAll(path string) error { - _, stderr, err := p.execute([]string{"rm", "-rf", path}) + _, stderr, err := p.execute([]string{"rm", "-rf", path}, nil) if err != nil { return fmt.Errorf("rm -rf %q: stderr=%q, %v", path, stderr, err) } return nil } -func (p PodDirIO) execute(command []string) (string, string, error) { +func (p PodDirIO) execute(command []string, stdin io.Reader) (string, string, error) { return p.F.ExecWithOptions(framework.ExecOptions{ Command: command, Namespace: p.Namespace, PodName: p.PodName, ContainerName: p.ContainerName, + Stdin: stdin, CaptureStdout: true, CaptureStderr: true, Quiet: true,