From ece0c7e5d31a6ae97274a7db80dbabb7564fdc72 Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Thu, 29 Jul 2021 08:18:58 +0300 Subject: Support template unit files in podman generate systemd Signed-off-by: Boaz Shuster --- test/system/250-systemd.bats | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test') diff --git a/test/system/250-systemd.bats b/test/system/250-systemd.bats index 98241c309..d4fb7ab08 100644 --- a/test/system/250-systemd.bats +++ b/test/system/250-systemd.bats @@ -201,4 +201,33 @@ LISTEN_FDNAMES=listen_fdnames" "LISTEN Environment passed: $context" check_listen_env "$stdenv" "podman start" } +@test "podman generate - systemd template" { + cname=$(random_string) + run_podman run -dt --name $cname $IMAGE top + + run_podman generate systemd --template -n $cname + is "$output" ".*%I.*" "%I indentifiers in template" + is "$output" ".*%i.*" "%i indentifiers in template" +} + +@test "podman generate - systemd template no support for pod" { + cname=$(random_string) + podname=$(random_string) + run_podman pod create --name $podname + run_podman run --pod $podname -dt --name $cname $IMAGE top + + run_podman 125 generate systemd --new --template -n $podname + is "$output" ".*--template is not supported for pods.*" "Error message contains 'not supported'" + + run_podman rm -f $cname + run_podman pod rm -f $podname +} + +@test "podman generate - systemd template only used on --new" { + cname=$(random_string) + run_podman create --name $cname $IMAGE top + run_podman 125 generate systemd --new=false --template -n $cname + is "$output" ".*--template cannot be set" "Error message should be '--template requires --new'" +} + # vim: filetype=sh -- cgit v1.2.3-54-g00ecf From 7494876000daa3f2a58d07f89561fd3ea447819a Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Thu, 28 Oct 2021 13:31:54 +0300 Subject: Use systemctl in local system test Signed-off-by: Boaz Shuster --- test/system/250-systemd.bats | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/system/250-systemd.bats b/test/system/250-systemd.bats index d4fb7ab08..28e28b30c 100644 --- a/test/system/250-systemd.bats +++ b/test/system/250-systemd.bats @@ -9,6 +9,7 @@ load helpers.systemd SERVICE_NAME="podman_test_$(random_string)" UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service" +TEMPLATE_FILE_PREFIX="$UNIT_DIR/$SERVICE_NAME" function setup() { skip_if_remote "systemd tests are meaningless over remote" @@ -206,8 +207,37 @@ LISTEN_FDNAMES=listen_fdnames" "LISTEN Environment passed: $context" run_podman run -dt --name $cname $IMAGE top run_podman generate systemd --template -n $cname - is "$output" ".*%I.*" "%I indentifiers in template" - is "$output" ".*%i.*" "%i indentifiers in template" + echo "$output" > "$TEMPLATE_FILE_PREFIX@.service" + run_podman rm -f $cname + + systemctl daemon-reload + + INSTANCE="$SERVICE_NAME@1.service" + run systemctl start "$INSTANCE" + if [ $status -ne 0 ]; then + die "Error starting systemd unit $INSTANCE, output: $output" + fi + + run systemctl status "$INSTANCE" + if [ $status -ne 0 ]; then + die "Non-zero status of systemd unit $INSTANCE, output: $output" + fi + + run systemctl stop "$INSTANCE" + if [ $status -ne 0 ]; then + die "Error stopping systemd unit $INSTANCE, output: $output" + fi + + if [[ -z "$status" ]]; then + run systemctl is-active "$INSTANCE" + if [ $status -ne 0 ]; then + die "Error checking stauts of systemd unit $INSTANCE, output: $output" + fi + is "$output" "$status" "$INSTANCE not in expected state" + fi + + rm -f "$TEMPLATE_FILE_PREFIX@.service" + systemctl daemon-reload } @test "podman generate - systemd template no support for pod" { -- cgit v1.2.3-54-g00ecf From 6ee3b33d3825177033763e51f756209102e0a309 Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Mon, 8 Nov 2021 16:56:06 +0200 Subject: change from run to create in 250-systemd.bats Signed-off-by: Boaz Shuster --- pkg/systemd/generate/containers.go | 4 ++++ test/system/250-systemd.bats | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index c0a49c614..a4b18ec88 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -394,6 +394,10 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst info.IdentifySpecifier = true runIx := -1 nameIx := -1 + // Add systemd identify specifier next to the name value + // to set a name to the container according to the parameters passed to systemd. + // In case no --name set for that container, use ServiceName specified + // in the containerInfo struct. for argIx, arg := range startCommand { if arg == "run" { runIx = argIx diff --git a/test/system/250-systemd.bats b/test/system/250-systemd.bats index 28e28b30c..1c778a5e3 100644 --- a/test/system/250-systemd.bats +++ b/test/system/250-systemd.bats @@ -204,7 +204,7 @@ LISTEN_FDNAMES=listen_fdnames" "LISTEN Environment passed: $context" @test "podman generate - systemd template" { cname=$(random_string) - run_podman run -dt --name $cname $IMAGE top + run_podman create --name $cname $IMAGE top run_podman generate systemd --template -n $cname echo "$output" > "$TEMPLATE_FILE_PREFIX@.service" -- cgit v1.2.3-54-g00ecf