github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/system/270-socket-activation.bats (about)

     1  #!/usr/bin/env bats   -*- bats -*-
     2  #
     3  # Tests podman system service under systemd socket activation
     4  #
     5  
     6  load helpers
     7  load helpers.systemd
     8  
     9  SERVICE_NAME="podman_test_$(random_string)"
    10  
    11  SERVICE_SOCK_ADDR="/run/podman/$SERVICE_NAME.sock"
    12  if is_rootless; then
    13      SERVICE_SOCK_ADDR="$XDG_RUNTIME_DIR/podman/$SERVICE_NAME.sock"
    14  fi
    15  
    16  SERVICE_FILE="$UNIT_DIR/$SERVICE_NAME.service"
    17  SOCKET_FILE="$UNIT_DIR/$SERVICE_NAME.socket"
    18  
    19  # URL to use for ping
    20  _PING=http://placeholder-hostname/libpod/_ping
    21  
    22  function setup() {
    23      skip_if_remote "systemd tests are meaningless over remote"
    24  
    25      basic_setup
    26  
    27      cat > $SERVICE_FILE <<EOF
    28  [Unit]
    29  Description=Podman API Service
    30  Requires=$SERVICE_NAME.socket
    31  After=$SERVICE_NAME.socket
    32  Documentation=man:podman-system-service(1)
    33  StartLimitIntervalSec=0
    34  
    35  [Service]
    36  Type=exec
    37  KillMode=process
    38  Environment=LOGGING="--log-level=info"
    39  ExecStart=$PODMAN $LOGGING system service -t 2
    40  EOF
    41      cat > $SOCKET_FILE <<EOF
    42  [Unit]
    43  Description=Podman API Socket
    44  Documentation=man:podman-system-service(1)
    45  
    46  [Socket]
    47  ListenStream=%t/podman/$SERVICE_NAME.sock
    48  SocketMode=0660
    49  
    50  [Install]
    51  WantedBy=sockets.target
    52  EOF
    53  
    54      # ensure pause die before each test runs
    55      if is_rootless; then
    56          local pause_pid_file="$XDG_RUNTIME_DIR/libpod/tmp/pause.pid"
    57          if [ -f $pause_pid_file ]; then
    58              kill -9 $(< $pause_pid_file) 2> /dev/null
    59              rm -f $pause_pid_file
    60          fi
    61      fi
    62      systemctl start "$SERVICE_NAME.socket"
    63  }
    64  
    65  function teardown() {
    66      systemctl stop "$SERVICE_NAME.socket"
    67      rm -f "$SERVICE_FILE" "$SOCKET_FILE"
    68      systemctl daemon-reload
    69      basic_teardown
    70  }
    71  
    72  @test "podman system service - socket activation - no container" {
    73      run curl -s --max-time 3 --unix-socket $SERVICE_SOCK_ADDR $_PING
    74      echo "curl output: $output"
    75      is "$status" "0" "curl exit status"
    76      is "$output" "OK" "podman service responds normally"
    77  }
    78  
    79  @test "podman system service - socket activation - existing container" {
    80      run_podman run -d $IMAGE sleep 90
    81      cid="$output"
    82  
    83      run curl -s --max-time 3 --unix-socket $SERVICE_SOCK_ADDR $_PING
    84      echo "curl output: $output"
    85      is "$status" "0" "curl exit status"
    86      is "$output" "OK" "podman service responds normally"
    87  
    88      run_podman rm -f $cid
    89  }
    90  
    91  @test "podman system service - socket activation - kill rootless pause" {
    92      if ! is_rootless; then
    93          skip "there is no pause process when running rootful"
    94      fi
    95      run_podman run -d $IMAGE sleep 90
    96      cid="$output"
    97  
    98      local pause_pid_file="$XDG_RUNTIME_DIR/libpod/tmp/pause.pid"
    99      if [ ! -f $pause_pid_file ]; then
   100          # This seems unlikely, but not impossible
   101          die "Pause pid file does not exist: $pause_pid_file"
   102      fi
   103  
   104      echo "kill -9 $(< pause_pid_file)"
   105      kill -9 $(< $pause_pid_file)
   106  
   107      run curl -s --max-time 3 --unix-socket $SERVICE_SOCK_ADDR $_PING
   108      echo "curl output: $output"
   109      is "$status" "0" "curl exit status"
   110      is "$output" "OK" "podman service responds normally"
   111  
   112      run_podman rm -f $cid
   113  }
   114  
   115  # vim: filetype=sh