github.com/containers/podman/v5@v5.1.0-rc1/test/system/251-system-service.bats (about)

     1  #!/usr/bin/env bats   -*- bats -*-
     2  #
     3  # Tests that require 'podman system service' but no other systemd aspects
     4  
     5  load helpers
     6  load helpers.systemd
     7  load helpers.network
     8  
     9  SERVICE_NAME="podman-service-$(random_string)"
    10  
    11  function teardown() {
    12      # Ignore exit status: this is just a backup stop in case tests failed
    13      run systemctl stop "$SERVICE_NAME"
    14  
    15      basic_teardown
    16  }
    17  
    18  @test "podman system service <bad_scheme_uri> returns error" {
    19      skip_if_remote "podman system service unavailable over remote"
    20      run_podman 125 system service localhost:9292
    21      is "$output" "Error: API Service endpoint scheme \"localhost\" is not supported. Try tcp://localhost:9292 or unix://localhost:9292"
    22  
    23      run_podman 125 system service myunix.sock
    24      is "$output" "Error: API Service endpoint scheme \"\" is not supported. Try tcp://myunix.sock or unix://myunix.sock"
    25  }
    26  
    27  @test "podman system service unix: without two slashes still works" {
    28      skip_if_remote "podman system service unavailable over remote"
    29      URL=unix:$PODMAN_TMPDIR/myunix.sock
    30  
    31      systemd-run --unit=$SERVICE_NAME $PODMAN system service $URL --time=0
    32      wait_for_file $PODMAN_TMPDIR/myunix.sock
    33  
    34      run_podman --host $URL info --format '{{.Host.RemoteSocket.Path}}'
    35      is "$output" "$URL" "RemoteSocket.Path using unix:"
    36  
    37      systemctl stop $SERVICE_NAME
    38      rm -f $PODMAN_TMPDIR/myunix.sock
    39  }
    40  
    41  @test "podman-system-service containers survive service stop" {
    42      skip_if_remote "podman system service unavailable over remote"
    43      local runtime=$(podman_runtime)
    44      if [[ "$runtime" != "crun" ]]; then
    45          skip "survival code only implemented in crun; you're using $runtime"
    46      fi
    47  
    48      port=$(random_free_port)
    49      URL=tcp://127.0.0.1:$port
    50  
    51      systemd-run --unit=$SERVICE_NAME $PODMAN system service $URL --time=0
    52      wait_for_port 127.0.0.1 $port
    53  
    54      # Start a long-running container.
    55      cname=keeps-running
    56      run_podman --url $URL run -d --name $cname $IMAGE top -d 2
    57  
    58      run_podman container inspect -l --format "{{.State.Running}}"
    59      is "$output" "true" "This should never fail"
    60  
    61      systemctl stop $SERVICE_NAME
    62  
    63      run_podman container inspect $cname --format "{{.State.Running}}"
    64      is "$output" "true" "Container is still running after podman server stops"
    65  
    66      run_podman rm -f -t 0 $cname
    67  }
    68  
    69  # This doesn't actually test podman system service, but we require it,
    70  # so least-awful choice is to run from this test file.
    71  @test "podman --host / -H options" {
    72      port=$(random_free_port)
    73      URL=tcp://127.0.0.1:$port
    74  
    75      # %%-remote makes this run real podman even when testing podman-remote
    76      systemd-run --unit=$SERVICE_NAME ${PODMAN%%-remote*} system service $URL --time=0
    77      wait_for_port 127.0.0.1 $port
    78  
    79      for opt in --host -H; do
    80          run_podman $opt $URL info --format '{{.Host.RemoteSocket.Path}}'
    81          is "$output" "$URL" "RemoteSocket.Path using $opt"
    82      done
    83  
    84      systemctl stop $SERVICE_NAME
    85  }
    86  
    87  # Regression test for https://github.com/containers/podman/issues/17749
    88  @test "podman-system-service --log-level=trace should be able to hijack" {
    89      skip_if_remote "podman system service unavailable over remote"
    90  
    91      port=$(random_free_port)
    92      URL=tcp://127.0.0.1:$port
    93  
    94      systemd-run --unit=$SERVICE_NAME $PODMAN --log-level=trace system service $URL --time=0
    95      wait_for_port 127.0.0.1 $port
    96  
    97      out=o-$(random_string)
    98      cname=c-$(random_string)
    99      run_podman --url $URL run --name $cname $IMAGE echo $out
   100      assert "$output" == "$out" "service is able to hijack and stream output back"
   101  
   102      run_podman --url $URL rm $cname
   103      systemctl stop $SERVICE_NAME
   104  }