github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/test_podman_pods.sh (about)

     1  #!/usr/bin/env bash
     2  # test_podman_pods.sh
     3  # A script to be run at the command line with Podman installed.
     4  # This should be run against a new kit to provide base level testing
     5  # on a freshly installed machine with no images or container in
     6  # play.  This currently needs to be run as root.
     7  #
     8  #
     9  # To run this command:
    10  #
    11  # /bin/bash -v test_podman_baseline.sh -e # Stop on error
    12  # /bin/bash -v test_podman_baseline.sh    # Continue on error
    13  #
    14  
    15  set -x
    16  
    17  # This scripts needs the jq json parser
    18  if [ -z $(command -v jq2) ]; then
    19      echo "This script requires the jq parser"
    20      exit 1
    21  fi
    22  
    23  # process input args
    24  stoponerror=0
    25  while getopts "den" opt; do
    26      case "$opt" in
    27      e) stoponerror=1
    28         ;;
    29      esac
    30  done
    31  
    32  
    33  if [ "$stoponerror" -eq 1 ]
    34  then
    35      echo "Script will stop on unexpected errors."
    36      set -e
    37      trap "Failed test ..." ERR
    38  fi
    39  
    40  
    41  ########
    42  # Create a named and unnamed pod
    43  ########
    44  podman pod create --name foobar
    45  podid=$(podman pod create)
    46  
    47  ########
    48  # Delete a named and unnamed pod
    49  ########
    50  podman pod rm foobar
    51  podman pod rm $podid
    52  
    53  ########
    54  # Create a named pod and run a container in it
    55  ########
    56  podman pod create --name foobar
    57  ctrid=$(podman run --pod foobar -dt docker.io/library/alpine:latest top)
    58  podman ps --no-trunc | grep $ctrid
    59  
    60  ########
    61  # Containers in a pod share network namespace
    62  ########
    63  podman run -dt --pod foobar docker.io/library/nginx:latest
    64  podman run -it --rm --pod foobar registry.fedoraproject.org/fedora-minimal:29 curl http://localhost
    65  
    66  ########
    67  # There should be 3 containers running now
    68  ########
    69  let numContainers=$(podman pod ps --format json | jq -r '.[0] .numberOfContainers')
    70  [ $numContainers -eq 3 ]
    71  
    72  ########
    73  # Pause a container in a pod
    74  ########
    75  podman pause $ctrid
    76  [ $(podman ps -a -f status=paused --format json | jq -r '.[0] .id') == $ctrid ]
    77  
    78  ########
    79  # Unpause a container in a pod
    80  ########
    81  podman unpause $ctrid
    82  podman ps  -q --no-trunc | grep $ctrid
    83  
    84  ########
    85  # Stop a pod and its containers
    86  ########
    87  podman pod stop foobar
    88  [ $(podman inspect $ctrid | jq -r '.[0] .State .Running') == "false" ]
    89  
    90  ########
    91  # Start a pod and its containers
    92  ########
    93  podman pod start foobar
    94  podman run -it --rm --pod foobar registry.fedoraproject.org/fedora-minimal:29 curl http://localhost
    95  
    96  ########
    97  # Pause a pod and its containers
    98  ########
    99  podman pod pause foobar
   100  [ $(podman pod ps --format json | jq -r '.[0] .status') == "Paused" ]
   101  
   102  ########
   103  # Unpause a pod and its containers
   104  ########
   105  podman pod unpause foobar
   106  podman run -it --rm --pod foobar registry.fedoraproject.org/fedora-minimal:29 curl http://localhost
   107  
   108  ########
   109  # Kill a pod and its containers
   110  ########
   111  podman pod kill foobar
   112  [ $(podman inspect $ctrid | jq -r '.[0] .State .Running') == "false" ]
   113  
   114  ########
   115  # Remove all pods and their containers
   116  ########
   117  podman pod rm -fa