From a54429cf877e899eb1516e3ee71ae9c6eedd7c5a Mon Sep 17 00:00:00 2001 From: Danila Kiver Date: Thu, 4 Jul 2019 03:58:37 +0300 Subject: Use conmon pidfile in generated systemd unit as PIDFile. By default, podman points PIDFile in generated unit file to non-existent location. As a result, the unit file, generated by podman, is broken: an attempt to start this unit without prior modification results in a crash, because systemd can not find the pidfile of service's main process. Fix the value of "PIDFile" and add a system test for this case. Signed-off-by: Danila Kiver --- test/system/250-generate-systemd.bats | 42 +++++++++++++++++++++++++++++++++++ test/system/helpers.bash | 11 +++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/system/250-generate-systemd.bats (limited to 'test/system') diff --git a/test/system/250-generate-systemd.bats b/test/system/250-generate-systemd.bats new file mode 100644 index 000000000..87ad69774 --- /dev/null +++ b/test/system/250-generate-systemd.bats @@ -0,0 +1,42 @@ +#!/usr/bin/env bats -*- bats -*- +# +# Tests generated configurations for systemd. +# + +load helpers + +# Be extra paranoid in naming to avoid collisions. +SERVICE_NAME="podman_test_$(random_string)" +UNIT_DIR="$HOME/.config/systemd/user" +UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service" + +function setup() { + basic_setup + mkdir -p "$UNIT_DIR" +} + +function teardown() { + rm -f "$UNIT_FILE" + systemctl --user stop "$SERVICE_NAME" + basic_teardown +} + +@test "podman generate - systemd - basic" { + skip_if_not_systemd + skip_if_remote + + run_podman create $IMAGE echo "I'm alive!" + cid="$output" + + run_podman generate systemd $cid > "$UNIT_FILE" + + run systemctl --user start "$SERVICE_NAME" + if [ $status -ne 0 ]; then + die "The systemd service $SERVICE_NAME did not start correctly!" + fi + + run_podman logs $cid + is "$output" "I'm alive!" "Container output" +} + +# vim: filetype=sh diff --git a/test/system/helpers.bash b/test/system/helpers.bash index 29ef19ecc..1db80f111 100644 --- a/test/system/helpers.bash +++ b/test/system/helpers.bash @@ -236,6 +236,17 @@ function skip_if_remote() { skip "${1:-test does not work with podman-remote}" } +######################### +# skip_if_not_systemd # ...with an optional message +######################### +function skip_if_not_systemd() { + if systemctl --user >/dev/null 2>&1; then + return + fi + + skip "${1:-no systemd or daemon does not respond}" +} + ######### # die # Abort with helpful message ######### -- cgit v1.2.3-54-g00ecf From c490754ff769f3327fb165fad87baf515210fbac Mon Sep 17 00:00:00 2001 From: Danila Kiver Date: Sat, 6 Jul 2019 01:35:46 +0300 Subject: Add debug information to "generate systemd" test. Signed-off-by: Danila Kiver --- test/system/250-generate-systemd.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/system') diff --git a/test/system/250-generate-systemd.bats b/test/system/250-generate-systemd.bats index 87ad69774..20a73c726 100644 --- a/test/system/250-generate-systemd.bats +++ b/test/system/250-generate-systemd.bats @@ -32,7 +32,7 @@ function teardown() { run systemctl --user start "$SERVICE_NAME" if [ $status -ne 0 ]; then - die "The systemd service $SERVICE_NAME did not start correctly!" + die "The systemd service $SERVICE_NAME did not start correctly, output: $output" fi run_podman logs $cid -- cgit v1.2.3-54-g00ecf From 1f435bf92cc5e828cb36e658d695070473a41f96 Mon Sep 17 00:00:00 2001 From: Danila Kiver Date: Sat, 6 Jul 2019 17:41:29 +0300 Subject: Reload systemd daemon on creation of units location dir in tests. Systemd manager drops non-existent directories from the units search path during initialization, thus, creation of UNIT_DIR, if it did not exist before, requres reloading the daemon. Signed-off-by: Danila Kiver --- test/system/250-generate-systemd.bats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/system') diff --git a/test/system/250-generate-systemd.bats b/test/system/250-generate-systemd.bats index 20a73c726..a8eb3b0a6 100644 --- a/test/system/250-generate-systemd.bats +++ b/test/system/250-generate-systemd.bats @@ -12,7 +12,11 @@ UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service" function setup() { basic_setup - mkdir -p "$UNIT_DIR" + + if [ ! -d "$UNIT_DIR" ]; then + mkdir -p "$UNIT_DIR" + systemctl --user daemon-reload + fi } function teardown() { -- cgit v1.2.3-54-g00ecf From 8fde4194b6a21bc54d83260990e839da9e1fe1e8 Mon Sep 17 00:00:00 2001 From: Danila Kiver Date: Sat, 6 Jul 2019 20:45:26 +0300 Subject: Move skipping systemd tests to early setup. There is no meaning of performing setup/teardown for these tests when we even can not work with systemd. Signed-off-by: Danila Kiver --- test/system/250-generate-systemd.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/system') diff --git a/test/system/250-generate-systemd.bats b/test/system/250-generate-systemd.bats index a8eb3b0a6..80199af5f 100644 --- a/test/system/250-generate-systemd.bats +++ b/test/system/250-generate-systemd.bats @@ -11,6 +11,9 @@ UNIT_DIR="$HOME/.config/systemd/user" UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service" function setup() { + skip_if_not_systemd + skip_if_remote + basic_setup if [ ! -d "$UNIT_DIR" ]; then @@ -26,9 +29,6 @@ function teardown() { } @test "podman generate - systemd - basic" { - skip_if_not_systemd - skip_if_remote - run_podman create $IMAGE echo "I'm alive!" cid="$output" -- cgit v1.2.3-54-g00ecf