mirror of
https://github.com/containers/podman.git
synced 2025-06-26 12:56:45 +08:00
test/e2e/systemd_activate_test.go: simplify test
While debugging #17904 we found the test to be missing the common podman flags. Add them to the podman invocations and remove some clutter. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
@ -17,7 +17,6 @@ import (
|
|||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Systemd activate", func() {
|
var _ = Describe("Systemd activate", func() {
|
||||||
@ -27,6 +26,8 @@ var _ = Describe("Systemd activate", func() {
|
|||||||
var activate string
|
var activate string
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
|
SkipIfRemote("Testing stopped service requires both podman and podman-remote binaries")
|
||||||
|
|
||||||
tempDir, err = testUtils.CreateTempDirInTempDir()
|
tempDir, err = testUtils.CreateTempDirInTempDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
@ -36,8 +37,6 @@ var _ = Describe("Systemd activate", func() {
|
|||||||
podmanTest = PodmanTestCreate(tempDir)
|
podmanTest = PodmanTestCreate(tempDir)
|
||||||
podmanTest.Setup()
|
podmanTest.Setup()
|
||||||
|
|
||||||
SkipIfRemote("Testing stopped service requires both podman and podman-remote binaries")
|
|
||||||
|
|
||||||
activate, err = exec.LookPath("systemd-socket-activate")
|
activate, err = exec.LookPath("systemd-socket-activate")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
activate = "/usr/bin/systemd-socket-activate"
|
activate = "/usr/bin/systemd-socket-activate"
|
||||||
@ -65,60 +64,42 @@ var _ = Describe("Systemd activate", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
addr := net.JoinHostPort(host, strconv.Itoa(port))
|
addr := net.JoinHostPort(host, strconv.Itoa(port))
|
||||||
|
|
||||||
// Make a temporary root directory
|
podmanOptions := podmanTest.makeOptions(nil, false, false)
|
||||||
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
|
systemdArgs := []string{
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
|
|
||||||
activateSession := testUtils.StartSystemExec(activate, []string{
|
|
||||||
"-E", "http_proxy", "-E", "https_proxy", "-E", "no_proxy",
|
"-E", "http_proxy", "-E", "https_proxy", "-E", "no_proxy",
|
||||||
"-E", "HTTP_PROXY", "-E", "HTTPS_PROXY", "-E", "NO_PROXY",
|
"-E", "HTTP_PROXY", "-E", "HTTPS_PROXY", "-E", "NO_PROXY",
|
||||||
|
"-E", "XDG_RUNTIME_DIR",
|
||||||
"--listen", addr,
|
"--listen", addr,
|
||||||
podmanTest.PodmanBinary,
|
podmanTest.PodmanBinary}
|
||||||
"--root", tmpRootDir,
|
systemdArgs = append(systemdArgs, podmanOptions...)
|
||||||
"system", "service",
|
systemdArgs = append(systemdArgs, "system", "service", "--time=0")
|
||||||
"--time=0",
|
|
||||||
})
|
activateSession := testUtils.StartSystemExec(activate, systemdArgs)
|
||||||
Expect(activateSession.Exited).ShouldNot(Receive(), "Failed to start podman service")
|
Expect(activateSession.Exited).ShouldNot(Receive(), "Failed to start podman service")
|
||||||
defer activateSession.Signal(syscall.SIGTERM)
|
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 {
|
podmanRemote := func(args ...string) *testUtils.PodmanSession {
|
||||||
args = append([]string{"--url", "tcp://" + addr}, args...)
|
args = append([]string{"--url", "tcp://" + addr}, args...)
|
||||||
return testUtils.SystemExec(podmanTest.RemotePodmanBinary, args)
|
return testUtils.SystemExec(podmanTest.RemotePodmanBinary, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
podman := func(args ...string) *testUtils.PodmanSession {
|
podman := func(args ...string) *testUtils.PodmanSession {
|
||||||
args = append([]string{"--root", tmpRootDir}, args...)
|
args = append(podmanOptions, args...)
|
||||||
return testUtils.SystemExec(podmanTest.PodmanBinary, args)
|
return testUtils.SystemExec(podmanTest.PodmanBinary, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
containerName := "top_" + testUtils.RandomString(8)
|
containerName := "top_" + testUtils.RandomString(8)
|
||||||
apiSession := podmanRemote(
|
apiSession := podmanRemote(
|
||||||
"create", "--tty", "--name", containerName, "--entrypoint", "top",
|
"create", "--tty", "--name", containerName, "--entrypoint", "top",
|
||||||
"quay.io/libpod/alpine_labels:latest",
|
ALPINE,
|
||||||
)
|
)
|
||||||
Expect(apiSession).Should(Exit(0))
|
Expect(apiSession).Should(Exit(0))
|
||||||
defer podman("rm", "-f", containerName)
|
defer podman("rm", "-f", containerName)
|
||||||
|
Reference in New Issue
Block a user