Skip to content

Commit

Permalink
Merge pull request #18056 from vrothberg/this-that
Browse files Browse the repository at this point in the history
test/e2e/systemd_activate_test.go: simplify test
  • Loading branch information
openshift-merge-robot authored Apr 12, 2023
2 parents 1ad45d4 + f67d640 commit d45ad05
Showing 1 changed file with 19 additions and 38 deletions.
57 changes: 19 additions & 38 deletions test/e2e/systemd_activate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
"github.com/opencontainers/selinux/go-selinux"
)

var _ = Describe("Systemd activate", func() {
Expand All @@ -27,6 +26,8 @@ var _ = Describe("Systemd activate", func() {
var activate string

BeforeEach(func() {
SkipIfRemote("Testing stopped service requires both podman and podman-remote binaries")

tempDir, err = testUtils.CreateTempDirInTempDir()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand All @@ -36,8 +37,6 @@ var _ = Describe("Systemd activate", func() {
podmanTest = PodmanTestCreate(tempDir)
podmanTest.Setup()

SkipIfRemote("Testing stopped service requires both podman and podman-remote binaries")

activate, err = exec.LookPath("systemd-socket-activate")
if err != nil {
activate = "/usr/bin/systemd-socket-activate"
Expand Down Expand Up @@ -65,60 +64,42 @@ var _ = Describe("Systemd activate", func() {
Expect(err).ToNot(HaveOccurred())
addr := net.JoinHostPort(host, strconv.Itoa(port))

// Make a temporary root directory
tmpRootDir := filepath.Join(tempDir, "server_root")
err = os.Mkdir(tmpRootDir, 0755)
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpRootDir)

// When SELinux is enabled, a storage root directory should be
// labeled with a specific value
if selinux.GetEnabled() {
rootDir := "/var/lib/containers"
label := "container_var_lib_t"
if isRootless() {
rootDir = filepath.Join(os.Getenv("HOME"), ".local/share/containers")
label = "data_home_t"
}

args := []string{"--reference", rootDir, tmpRootDir}
// If rootDir doesn't exist, use "chcon -t" to label tmpRootDir
// instead of "chcon --reference"
if _, err := os.Stat(rootDir); err != nil {
args = []string{"-t", label, tmpRootDir}
}

chcon := testUtils.SystemExec("chcon", args)
Expect(chcon).Should(Exit(0))
}
podmanOptions := podmanTest.makeOptions(nil, false, false)

activateSession := testUtils.StartSystemExec(activate, []string{
systemdArgs := []string{
"-E", "http_proxy", "-E", "https_proxy", "-E", "no_proxy",
"-E", "HTTP_PROXY", "-E", "HTTPS_PROXY", "-E", "NO_PROXY",
"-E", "XDG_RUNTIME_DIR",
"--listen", addr,
podmanTest.PodmanBinary,
"--root", tmpRootDir,
"system", "service",
"--time=0",
})
podmanTest.PodmanBinary}
systemdArgs = append(systemdArgs, podmanOptions...)
systemdArgs = append(systemdArgs, "system", "service", "--time=0")

activateSession := testUtils.StartSystemExec(activate, systemdArgs)
Expect(activateSession.Exited).ShouldNot(Receive(), "Failed to start podman service")
defer activateSession.Signal(syscall.SIGTERM)

// Curried functions for specialized podman calls
// Create custom functions for running podman and
// podman-remote. This test is a rare exception where both
// binaries need to be run in parallel. Usually, the remote
// and non-remote details are hidden. Yet we use the
// `podmanOptions` above to make sure all settings (root,
// runroot, events, tmpdir, etc.) are used as in other e2e
// tests.
podmanRemote := func(args ...string) *testUtils.PodmanSession {
args = append([]string{"--url", "tcp://" + addr}, args...)
return testUtils.SystemExec(podmanTest.RemotePodmanBinary, args)
}

podman := func(args ...string) *testUtils.PodmanSession {
args = append([]string{"--root", tmpRootDir}, args...)
args = append(podmanOptions, args...)
return testUtils.SystemExec(podmanTest.PodmanBinary, args)
}

containerName := "top_" + testUtils.RandomString(8)
apiSession := podmanRemote(
"create", "--tty", "--name", containerName, "--entrypoint", "top",
"quay.io/libpod/alpine_labels:latest",
ALPINE,
)
Expect(apiSession).Should(Exit(0))
defer podman("rm", "-f", containerName)
Expand Down

0 comments on commit d45ad05

Please sign in to comment.