github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/upgrade/test-upgrade.bats (about) 1 # -*- bats -*- 2 3 load helpers 4 5 # Create a var-lib-containers dir for this podman. We need to bind-mount 6 # this into the container, and use --root and --runroot and --tmpdir 7 # options both in the container podman and out here: that's the only 8 # way to share image and container storage. 9 if [ -z "${PODMAN_UPGRADE_WORKDIR}" ]; then 10 # Much as I'd love a descriptive name like "podman-upgrade-tests.XXXXX", 11 # keep it short ("pu") because of the 100-character path length limit 12 # for UNIX sockets (needed by conmon) 13 export PODMAN_UPGRADE_WORKDIR=$(mktemp -d --tmpdir=${BATS_TMPDIR:-${TMPDIR:-/tmp}} pu.XXXXXX) 14 15 touch $PODMAN_UPGRADE_WORKDIR/status 16 fi 17 18 # Generate a set of random strings used for content verification 19 if [ -z "${RANDOM_STRING_1}" ]; then 20 export RANDOM_STRING_1=$(random_string 15) 21 export LABEL_CREATED=$(random_string 16) 22 export LABEL_FAILED=$(random_string 17) 23 export LABEL_RUNNING=$(random_string 18) 24 export HOST_PORT=$(random_free_port) 25 fi 26 27 # Version string of the podman we're actually testing, e.g. '3.0.0-dev-d1a26013' 28 PODMAN_VERSION=$($PODMAN version |awk '/^Version:/ { V=$2 } /^Git Commit:/ { G=$3 } END { print V "-" substr(G,0,8) }') 29 30 setup() { 31 skip_if_rootless 32 33 # The podman-in-podman image (old podman) 34 if [[ -z "$PODMAN_UPGRADE_FROM" ]]; then 35 echo "# \$PODMAN_UPGRADE_FROM is undefined (should be e.g. v1.9.0)" >&3 36 false 37 fi 38 39 if [ "$(< $PODMAN_UPGRADE_WORKDIR/status)" = "failed" ]; then 40 # FIXME: exit instead? 41 echo "*** setup failed - no point in running tests" 42 false 43 fi 44 45 # cgroup-manager=systemd does not work inside a container 46 export _PODMAN_TEST_OPTS="--cgroup-manager=cgroupfs --root=$PODMAN_UPGRADE_WORKDIR/root --runroot=$PODMAN_UPGRADE_WORKDIR/runroot --tmpdir=$PODMAN_UPGRADE_WORKDIR/tmp" 47 } 48 49 ############################################################################### 50 # BEGIN setup 51 52 @test "initial setup: start $PODMAN_UPGRADE_FROM containers" { 53 echo failed >| $PODMAN_UPGRADE_WORKDIR/status 54 55 OLD_PODMAN=quay.io/podman/stable:$PODMAN_UPGRADE_FROM 56 $PODMAN pull $OLD_PODMAN 57 58 # Shortcut name, because we're referencing it a lot 59 pmroot=$PODMAN_UPGRADE_WORKDIR 60 61 # WWW content to share 62 mkdir -p $pmroot/var/www 63 echo $RANDOM_STRING_1 >$pmroot/var/www/index.txt 64 65 # podman tmpdir 66 mkdir -p $pmroot/tmp 67 68 # 69 # Script to run >>OLD<< podman commands. 70 # 71 # These commands will be run inside a podman container. The "podman" 72 # command in this script will be the desired old-podman version. 73 # 74 pmscript=$pmroot/setup 75 cat >| $pmscript <<EOF 76 #!/bin/bash 77 78 # events-backend=journald does not work inside a container 79 opts="--events-backend=file $_PODMAN_TEST_OPTS" 80 81 set -ex 82 83 # Try try again, because network flakiness makes this a point of failure 84 podman \$opts pull $IMAGE \ 85 || (sleep 10; podman \$opts pull $IMAGE) \ 86 || (sleep 30; podman \$opts pull $IMAGE) 87 88 89 podman \$opts create --name mycreatedcontainer --label mylabel=$LABEL_CREATED \ 90 $IMAGE false 91 92 podman \$opts run --name mydonecontainer $IMAGE echo ++$RANDOM_STRING_1++ 93 94 podman \$opts run --name myfailedcontainer --label mylabel=$LABEL_FAILED \ 95 $IMAGE sh -c 'exit 17' || true 96 97 podman \$opts run -d --name myrunningcontainer --label mylabel=$LABEL_RUNNING \ 98 --network bridge \ 99 -p $HOST_PORT:80 \ 100 -v $pmroot/var/www:/var/www \ 101 -w /var/www \ 102 $IMAGE /bin/busybox-extras httpd -f -p 80 103 104 podman \$opts pod create --name mypod 105 106 podman \$opts network create mynetwork 107 108 echo READY 109 while :;do 110 if [ -e /stop ]; then 111 echo STOPPING 112 podman \$opts stop -t 0 myrunningcontainer || true 113 podman \$opts rm -f myrunningcontainer || true 114 exit 0 115 fi 116 sleep 0.5 117 done 118 EOF 119 chmod 555 $pmscript 120 121 # Clean up vestiges of previous run 122 $PODMAN rm -f podman_parent || true 123 124 125 local netname=testnet-$(random_string 10) 126 $PODMAN network create $netname 127 128 # Not entirely a NOP! This is just so we get the /run/... mount points created on a CI VM 129 # --mac-address is needed to create /run/cni, --network is needed to create /run/containers for dnsname 130 $PODMAN run --rm --mac-address 78:28:a6:8d:24:8a --network $netname $OLD_PODMAN true 131 $PODMAN network rm -f $netname 132 133 134 # 135 # Use new-podman to run the above script under old-podman. 136 # 137 # DO NOT USE run_podman HERE! That would use $_PODMAN_TEST_OPTS 138 # and would write into our shared test dir, which would then 139 # pollute it for use by old-podman. We must keep that pristine 140 # so old-podman is the first to write to it. 141 # 142 # mount /etc/containers/storage.conf to use the same storage settings as on the host 143 # mount /dev/shm because the container locks are stored there 144 # mount /var/lib/cni, /run/cni and /etc/cni/net.d for cni networking 145 # mount /run/containers for the dnsname plugin 146 # 147 $PODMAN run -d --name podman_parent --pid=host \ 148 --privileged \ 149 --net=host \ 150 --cgroupns=host \ 151 --pid=host \ 152 -v /etc/containers/storage.conf:/etc/containers/storage.conf \ 153 -v /dev/fuse:/dev/fuse \ 154 -v /run/crun:/run/crun \ 155 -v /run/netns:/run/netns:rshared \ 156 -v /run/containers:/run/containers \ 157 -v /run/cni:/run/cni \ 158 -v /var/lib/cni:/var/lib/cni \ 159 -v /etc/cni/net.d:/etc/cni/net.d \ 160 -v /dev/shm:/dev/shm \ 161 -v $pmroot:$pmroot \ 162 $OLD_PODMAN $pmroot/setup 163 164 _PODMAN_TEST_OPTS= wait_for_ready podman_parent 165 166 echo OK >| $PODMAN_UPGRADE_WORKDIR/status 167 } 168 169 # END setup 170 ############################################################################### 171 # BEGIN actual tests 172 173 # This is a NOP; used only so the version string will show up in logs 174 @test "upgrade: $PODMAN_UPGRADE_FROM -> $PODMAN_VERSION" { 175 : 176 } 177 178 @test "images" { 179 run_podman images -a --format '{{.Names}}' 180 is "$output" "\[$IMAGE\]" "podman images" 181 } 182 183 @test "ps : one container running" { 184 run_podman ps --format '{{.Image}}--{{.Names}}' 185 is "$output" "$IMAGE--myrunningcontainer" "ps: one container running" 186 } 187 188 @test "ps -a : shows all containers" { 189 # IMPORTANT: we can't use --sort=created, because that requires #8427 190 # on the *creating* podman end. 191 run_podman ps -a \ 192 --format '{{.Names}}--{{.Status}}--{{.Ports}}--{{.Labels.mylabel}}' \ 193 --sort=names 194 is "${lines[0]}" ".*-infra--Created----<no value>" "infra container" 195 is "${lines[1]}" "mycreatedcontainer--Created----$LABEL_CREATED" "created" 196 is "${lines[2]}" "mydonecontainer--Exited (0).*----<no value>" "done" 197 is "${lines[3]}" "myfailedcontainer--Exited (17) .*----$LABEL_FAILED" "fail" 198 is "${lines[4]}" "myrunningcontainer--Up .*--0.0.0.0:$HOST_PORT->80/tcp--$LABEL_RUNNING" "running" 199 200 # For debugging: dump containers and IDs 201 if [[ -n "$PODMAN_UPGRADE_TEST_DEBUG" ]]; then 202 run_podman ps -a 203 for l in "${lines[@]}"; do 204 echo "# $l" >&3 205 done 206 fi 207 } 208 209 210 @test "inspect - all container status" { 211 tests=" 212 running | running | 0 213 created | configured | 0 214 done | exited | 0 215 failed | exited | 17 216 " 217 while read cname state exitstatus; do 218 run_podman inspect --format '{{.State.Status}}--{{.State.ExitCode}}' my${cname}container 219 is "$output" "$state--$exitstatus" "status of my${cname}container" 220 done < <(parse_table "$tests") 221 } 222 223 @test "network - curl" { 224 run curl --max-time 3 -s 127.0.0.1:$HOST_PORT/index.txt 225 is "$output" "$RANDOM_STRING_1" "curl on running container" 226 } 227 228 # IMPORTANT: connect should happen before restart, we want to check 229 # if we can connect on an existing running container 230 @test "network - connect" { 231 skip_if_version_older 2.2.0 232 run_podman network connect mynetwork myrunningcontainer 233 run_podman network disconnect podman myrunningcontainer 234 run curl --max-time 3 -s 127.0.0.1:$HOST_PORT/index.txt 235 is "$output" "$RANDOM_STRING_1" "curl on container with second network connected" 236 } 237 238 @test "network - restart" { 239 # restart the container and check if we can still use the port 240 run_podman stop -t0 myrunningcontainer 241 run_podman start myrunningcontainer 242 run curl --max-time 3 -s 127.0.0.1:$HOST_PORT/index.txt 243 is "$output" "$RANDOM_STRING_1" "curl on restarted container" 244 } 245 246 247 @test "logs" { 248 run_podman logs mydonecontainer 249 is "$output" "++$RANDOM_STRING_1++" "podman logs on stopped container" 250 } 251 252 @test "exec" { 253 run_podman exec myrunningcontainer cat /var/www/index.txt 254 is "$output" "$RANDOM_STRING_1" "exec into myrunningcontainer" 255 } 256 257 @test "load" { 258 # FIXME, is this really necessary? 259 skip "TBI. Not sure if there's any point to this." 260 } 261 262 @test "mount" { 263 skip "TBI" 264 } 265 266 @test "pods" { 267 run_podman pod inspect mypod 268 is "$output" ".*mypod.*" 269 270 run_podman pod start mypod 271 is "$output" "[0-9a-f]\\{64\\}" "podman pod start" 272 273 run_podman pod ps 274 is "$output" ".*mypod.*" "podman pod ps shows name" 275 is "$output" ".*Running.*" "podman pod ps shows running state" 276 277 run_podman pod stop mypod 278 is "$output" "[0-9a-f]\\{64\\}" "podman pod stop" 279 280 run_podman pod rm mypod 281 # FIXME: CI runs show this (non fatal) error: 282 # Error updating pod <ID> conmon cgroup PID limit: open /sys/fs/cgroup/libpod_parent/<ID>/conmon/pids.max: no such file or directory 283 # Investigate how to fix this (likely a race condition) 284 # Let's ignore the logrus messages for now 285 is "$output" ".*[0-9a-f]\\{64\\}" "podman pod rm" 286 } 287 288 # FIXME: commit? kill? network? pause? restart? top? volumes? What else? 289 290 291 @test "start" { 292 run_podman start -a mydonecontainer 293 is "$output" "++$RANDOM_STRING_1++" "start on already-run container" 294 } 295 296 @test "rm a stopped container" { 297 run_podman rm myfailedcontainer 298 is "$output" "[0-9a-f]\\{64\\}" "podman rm myfailedcontainer" 299 300 run_podman rm mydonecontainer 301 is "$output" "[0-9a-f]\\{64\\}" "podman rm mydonecontainer" 302 } 303 304 305 @test "stop and rm" { 306 run_podman stop myrunningcontainer 307 run_podman rm myrunningcontainer 308 } 309 310 @test "clean up parent" { 311 if [[ -n "$PODMAN_UPGRADE_TEST_DEBUG" ]]; then 312 skip "workdir is $PODMAN_UPGRADE_WORKDIR" 313 fi 314 315 # We're done with shared environment. By clearing this, we can now 316 # use run_podman for actions on the podman_parent container 317 unset _PODMAN_TEST_OPTS 318 319 # (Useful for debugging the 'rm -f' step below, which, when it fails, only 320 # gives a container ID. This 'ps' confirms that the CID is podman_parent) 321 run_podman ps -a 322 323 # Stop the container gracefully 324 run_podman exec podman_parent touch /stop 325 run_podman wait podman_parent 326 327 run_podman logs podman_parent 328 run_podman rm -f podman_parent 329 330 run_podman network rm -f mynetwork 331 332 umount $PODMAN_UPGRADE_WORKDIR/root/overlay || true 333 334 rm -rf $PODMAN_UPGRADE_WORKDIR 335 } 336 337 # FIXME: now clean up