diff options
author | baude <bbaude@redhat.com> | 2019-04-19 08:33:18 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-05-07 14:06:02 -0500 |
commit | bc7b1ca03da88473c10e59197becd812cf341663 (patch) | |
tree | 13d33a731ca50cd58b71ff7592770ae2afb9807d /test/e2e/libpod_suite_remoteclient_test.go | |
parent | 7b67c9601e1eab6c881ac44503c285c71b0a4a3a (diff) | |
download | podman-bc7b1ca03da88473c10e59197becd812cf341663.tar.gz podman-bc7b1ca03da88473c10e59197becd812cf341663.tar.bz2 podman-bc7b1ca03da88473c10e59197becd812cf341663.zip |
enable integration tests for remote-client
first pass at enabling a swath of integration tests for the
remote-client.
Signed-off-by: baude <bbaude@redhat.com>
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) + } +} |