diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-07 22:21:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-07 22:21:36 +0200 |
commit | 74dc9a45e3f85b4fc55a2d1cb2786885eb4489f5 (patch) | |
tree | f27f5b26b4076fe8dd2dad3afde8407640c77807 /test/e2e/libpod_suite_remoteclient_test.go | |
parent | 2e40bdebfd245ff04e86b1ea42f663087d97fccf (diff) | |
parent | bc7b1ca03da88473c10e59197becd812cf341663 (diff) | |
download | podman-74dc9a45e3f85b4fc55a2d1cb2786885eb4489f5.tar.gz podman-74dc9a45e3f85b4fc55a2d1cb2786885eb4489f5.tar.bz2 podman-74dc9a45e3f85b4fc55a2d1cb2786885eb4489f5.zip |
Merge pull request #2977 from baude/makeitrain
enable integration tests for remote-client
Diffstat (limited to 'test/e2e/libpod_suite_remoteclient_test.go')
-rw-r--r-- | test/e2e/libpod_suite_remoteclient_test.go | 74 |
1 files changed, 66 insertions, 8 deletions
diff --git a/test/e2e/libpod_suite_remoteclient_test.go b/test/e2e/libpod_suite_remoteclient_test.go index 1e477fe2f..05c355711 100644 --- a/test/e2e/libpod_suite_remoteclient_test.go +++ b/test/e2e/libpod_suite_remoteclient_test.go @@ -3,13 +3,17 @@ package integration import ( + "bytes" "fmt" "github.com/containers/libpod/pkg/rootless" "io/ioutil" "os" "os/exec" "path/filepath" + "strconv" "strings" + "syscall" + "time" "github.com/onsi/ginkgo" ) @@ -50,33 +54,76 @@ func PodmanTestCreate(tempDir string) *PodmanTestIntegration { return pti } +func (p *PodmanTestIntegration) ResetVarlinkAddress() { + os.Unsetenv("PODMAN_VARLINK_ADDRESS") +} + +func (p *PodmanTestIntegration) SetVarlinkAddress(addr string) { + os.Setenv("PODMAN_VARLINK_ADDRESS", addr) +} + func (p *PodmanTestIntegration) StartVarlink() { if os.Geteuid() == 0 { os.MkdirAll("/run/podman", 0755) } varlinkEndpoint := p.VarlinkEndpoint - if addr := os.Getenv("PODMAN_VARLINK_ADDRESS"); addr != "" { - varlinkEndpoint = addr - } + p.SetVarlinkAddress(p.VarlinkEndpoint) args := []string{"varlink", "--timeout", "0", varlinkEndpoint} podmanOptions := getVarlinkOptions(p, args) command := exec.Command(p.PodmanBinary, podmanOptions...) fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " ")) command.Start() + command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + p.VarlinkCommand = command p.VarlinkSession = command.Process } func (p *PodmanTestIntegration) StopVarlink() { + var out bytes.Buffer + var pids []int varlinkSession := p.VarlinkSession - varlinkSession.Kill() - varlinkSession.Wait() if !rootless.IsRootless() { - socket := strings.Split(p.VarlinkEndpoint, ":")[1] - if err := os.Remove(socket); err != nil { - fmt.Println(err) + if err := varlinkSession.Kill(); err != nil { + fmt.Fprintf(os.Stderr, "error on varlink stop-kill %q", err) } + if _, err := varlinkSession.Wait(); err != nil { + fmt.Fprintf(os.Stderr, "error on varlink stop-wait %q", err) + } + + } else { + p.ResetVarlinkAddress() + parentPid := fmt.Sprintf("%d", p.VarlinkSession.Pid) + pgrep := exec.Command("pgrep", "-P", parentPid) + fmt.Printf("running: pgrep %s\n", parentPid) + pgrep.Stdout = &out + err := pgrep.Run() + if err != nil { + fmt.Fprint(os.Stderr, "unable to find varlink pid") + } + + for _, s := range strings.Split(out.String(), "\n") { + if len(s) == 0 { + continue + } + p, err := strconv.Atoi(s) + if err != nil { + fmt.Fprintf(os.Stderr, "unable to convert %s to int", s) + } + if p != 0 { + pids = append(pids, p) + } + } + + pids = append(pids, p.VarlinkSession.Pid) + for _, pid := range pids { + syscall.Kill(pid, syscall.SIGKILL) + } + } + socket := strings.Split(p.VarlinkEndpoint, ":")[1] + if err := os.Remove(socket); err != nil { + fmt.Println(err) } } @@ -110,3 +157,14 @@ func (p *PodmanTestIntegration) RestoreArtifact(image string) error { command.Wait() return nil } + +func (p *PodmanTestIntegration) DelayForVarlink() { + for i := 0; i < 5; i++ { + session := p.Podman([]string{"info"}) + session.WaitWithDefaultTimeout() + if session.ExitCode() == 0 || i == 4 { + break + } + time.Sleep(1 * time.Second) + } +} |