github.com/containers/podman/v5@v5.1.0-rc1/test/system/120-load.bats (about) 1 #!/usr/bin/env bats -*- bats -*- 2 # 3 # tests for podman load 4 # 5 6 load helpers 7 load helpers.network 8 9 function teardown() { 10 # Destroy all images, to make sure we don't leave garbage behind. 11 # 12 # The tests in here do funky things with image store, including 13 # reloading the default $IMAGE in a way that appears normal but 14 # is not actually the same as what is normally pulled, e.g., 15 # annotations and image digests may be different. See 16 # https://github.com/containers/podman/discussions/17911 17 run_podman rmi -a -f 18 19 basic_teardown 20 } 21 22 # Custom helpers for this test only. These just save us having to duplicate 23 # the same thing four times (two tests, each with -i and stdin). 24 # 25 # initialize, read image ID and name 26 get_iid_and_name() { 27 run_podman images -a --format '{{.ID}} {{.Repository}}:{{.Tag}}' 28 read iid img_name <<<"$output" 29 30 archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar 31 } 32 33 # Simple verification of image ID and name 34 verify_iid_and_name() { 35 run_podman images -a --format '{{.ID}} {{.Repository}}:{{.Tag}}' 36 read new_iid new_img_name < <(echo "$output") 37 38 # Verify 39 is "$new_iid" "$iid" "Image ID of loaded image == original" 40 is "$new_img_name" "$1" "Name & tag of restored image" 41 } 42 43 @test "podman load invalid file" { 44 # Regression test for #9672 to make sure invalid input yields errors. 45 invalid=$PODMAN_TMPDIR/invalid 46 echo "I am an invalid file and should cause a podman-load error" > $invalid 47 run_podman 125 load -i $invalid 48 # podman and podman-remote emit different messages; this is a common string 49 is "$output" ".*payload does not match any of the supported image formats:.*" \ 50 "load -i INVALID fails with expected diagnostic" 51 } 52 53 @test "podman save to pipe and load" { 54 # Generate a random name and tag (must be lower-case) 55 local random_name=x0$(random_string 12 | tr A-Z a-z) 56 local random_tag=t0$(random_string 7 | tr A-Z a-z) 57 local fqin=localhost/$random_name:$random_tag 58 run_podman tag $IMAGE $fqin 59 60 # Believe it or not, 'podman load' would barf if any path element 61 # included a capital letter 62 archive=$PODMAN_TMPDIR/MySubDirWithCaps/MyImage-$(random_string 8).tar 63 mkdir -p $(dirname $archive) 64 65 # We can't use run_podman because that uses the BATS 'run' function 66 # which redirects stdout and stderr. Here we need to guarantee 67 # that podman's stdout is a pipe, not any other form of redirection 68 $PODMAN save --format oci-archive $fqin | cat >$archive 69 assert "$?" -eq 0 "Command failed: podman save ... | cat" 70 71 # Make sure we can reload it 72 run_podman rmi $fqin 73 run_podman load -i $archive 74 75 # FIXME: cannot compare IID, see #7371, so we check only the tag 76 run_podman images $fqin --format '{{.Repository}}:{{.Tag}}' 77 is "${lines[0]}" "$fqin" "image preserves name across save/load" 78 79 # Clean up 80 run_podman rmi $fqin 81 } 82 83 @test "podman image scp transfer" { 84 skip_if_remote "only applicable under local podman" 85 86 # See https://github.com/containers/podman/pull/21300 for details 87 if [[ "$CI_DESIRED_DATABASE" = "boltdb" ]]; then 88 skip "impossible due to pitfalls in our SSH implementation" 89 fi 90 91 # See https://github.com/containers/podman/pull/21431 92 if [[ -n "$PODMAN_IGNORE_CGROUPSV1_WARNING" ]]; then 93 skip "impossible to test due to pitfalls in our SSH implementation" 94 fi 95 96 # The testing is the same whether we're root or rootless; all that 97 # differs is the destination (not-me) username. 98 if is_rootless; then 99 # Simple: push to root. 100 whoami=$(id -un) 101 notme=root 102 _sudo() { command sudo -n "$@"; } 103 else 104 # Harder: our CI infrastructure needs to define this & set up the acct 105 whoami=root 106 notme=${PODMAN_ROOTLESS_USER} 107 if [[ -z "$notme" ]]; then 108 skip "To run this test, set PODMAN_ROOTLESS_USER to a safe username" 109 fi 110 _sudo() { command sudo -n -u "$notme" "$@"; } 111 fi 112 113 # If we can't sudo, we can't test. 114 _sudo true || skip "cannot sudo to $notme" 115 116 # Preserve digest of original image; we will compare against it later 117 run_podman image inspect --format '{{.RepoDigests}}' $IMAGE 118 src_digests=$output 119 120 # image name that is not likely to exist in the destination 121 newname=foo.bar/nonesuch/c_$(random_string 10 | tr A-Z a-z):mytag 122 run_podman tag $IMAGE $newname 123 124 # Copy it there. 125 run_podman image scp $newname ${notme}@localhost:: 126 is "$output" "Copying blob .*Copying config.*Writing manifest" 127 128 # confirm that image was copied. FIXME: also try $PODMAN image inspect? 129 _sudo $PODMAN image exists $newname 130 131 # Copy it back, this time using -q 132 run_podman untag $IMAGE $newname 133 run_podman image scp -q ${notme}@localhost::$newname 134 135 expect="Loaded image: $newname" 136 is "$output" "$expect" "-q silences output" 137 138 # Confirm that we have it, and that its digest matches our original 139 run_podman image inspect --format '{{.Digest}}' $newname 140 assert "$output" =~ "$src_digests" "Digest of re-fetched image is in list of original image digests" 141 142 # test tagging capability 143 run_podman untag $IMAGE $newname 144 run_podman image scp ${notme}@localhost::$newname foobar:123 145 146 run_podman image inspect --format '{{.Digest}}' foobar:123 147 assert "$output" =~ "$src_digest" "Digest of re-fetched image is in list of original image digests" 148 149 # remove root img for transfer back with another name 150 _sudo $PODMAN image rm $newname 151 152 # get foobar's ID, for an ID transfer test 153 run_podman image inspect --format '{{.ID}}' foobar:123 154 run_podman image scp $output ${notme}@localhost::foobartwo 155 156 _sudo $PODMAN image exists foobartwo 157 158 # Clean up 159 _sudo $PODMAN image rm foobartwo 160 run_podman untag $IMAGE $newname 161 162 # Negative test for nonexistent image. 163 # FIXME: error message is 2 lines, the 2nd being "exit status 125". 164 # FIXME: is that fixable, or do we have to live with it? 165 nope="nope.nope/nonesuch:notag" 166 run_podman 125 image scp ${notme}@localhost::$nope 167 is "$output" "Error: $nope: image not known.*" "Pulling nonexistent image" 168 169 run_podman 125 image scp $nope ${notme}@localhost:: 170 is "$output" "Error: $nope: image not known.*" "Pushing nonexistent image" 171 172 run_podman rmi foobar:123 173 } 174 175 176 @test "podman load - by image ID" { 177 # FIXME: how to build a simple archive instead? 178 get_iid_and_name 179 180 # Save image by ID, and remove it. 181 run_podman save $iid -o $archive 182 run_podman rmi $iid 183 184 # Load using -i; IID should be preserved, but name is not. 185 run_podman load -i $archive 186 verify_iid_and_name "<none>:<none>" 187 188 # Same as above, using stdin 189 run_podman rmi $iid 190 run_podman load < $archive 191 verify_iid_and_name "<none>:<none>" 192 193 # Same as above, using stdin but with `podman image load` 194 run_podman rmi $iid 195 run_podman image load < $archive 196 verify_iid_and_name "<none>:<none>" 197 } 198 199 @test "podman load - by image name" { 200 get_iid_and_name 201 run_podman save $img_name -o $archive 202 run_podman rmi $iid 203 204 # Load using -i; this time the image should be tagged. 205 run_podman load -i $archive 206 verify_iid_and_name $img_name 207 run_podman rmi $iid 208 209 # Also make sure that `image load` behaves the same. 210 run_podman image load -i $archive 211 verify_iid_and_name $img_name 212 run_podman rmi $iid 213 214 # Same as above, using stdin 215 run_podman load < $archive 216 verify_iid_and_name $img_name 217 } 218 219 @test "podman load - from URL" { 220 get_iid_and_name 221 run_podman save $img_name -o $archive 222 run_podman rmi $iid 223 224 HOST_PORT=$(random_free_port) 225 SERVER=http://127.0.0.1:$HOST_PORT 226 227 # Bind-mount the archive to a container running httpd 228 run_podman run -d --name myweb -p "$HOST_PORT:80" \ 229 -v $archive:/var/www/image.tar:Z \ 230 -w /var/www \ 231 $IMAGE /bin/busybox-extras httpd -f -p 80 232 233 run_podman load -i $SERVER/image.tar 234 verify_iid_and_name $img_name 235 236 run_podman rm -f -t0 myweb 237 } 238 239 @test "podman load - redirect corrupt payload" { 240 run_podman 125 load <<< "Danger, Will Robinson!! This is a corrupt tarball!" 241 is "$output" \ 242 ".*payload does not match any of the supported image formats:.*" \ 243 "Diagnostic from 'podman load' unknown/corrupt payload" 244 } 245 246 @test "podman load - multi-image archive" { 247 # img1 & 2 should be images that are not locally present; they must also 248 # be usable on the host arch. The nonlocal image (:000000xx) is kept 249 # up-to-date for all RHEL/Fedora arches; the other image we use is 250 # the one tagged ':multiimage', which as of 2021-07-15 is :20210610 251 # but that tag will grow stale over time. If/when this test fails, 252 # your first approach should be to manually update :multiimage to 253 # point to a more recent testimage. (Use the quay.io GUI, it's waaay 254 # easier than pulling/pushing the correct manifest.) 255 img1=${PODMAN_NONLOCAL_IMAGE_FQN} 256 img2="$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME:multiimage" 257 archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar 258 259 _prefetch $img1 260 _prefetch $img2 261 262 run_podman save -m -o $archive $img1 $img2 263 run_podman rmi -f $img1 $img2 264 run_podman load -i $archive 265 266 run_podman image exists $img1 267 run_podman image exists $img2 268 run_podman rmi -f $img1 $img2 269 } 270 271 @test "podman load - multi-image archive with redirect" { 272 # (see comments in test above re: img1 & 2) 273 img1=${PODMAN_NONLOCAL_IMAGE_FQN} 274 img2="$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME:multiimage" 275 archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar 276 277 _prefetch $img1 278 _prefetch $img2 279 280 # We can't use run_podman because that uses the BATS 'run' function 281 # which redirects stdout and stderr. Here we need to guarantee 282 # that podman's stdout is a pipe, not any other form of redirection 283 $PODMAN save -m $img1 $img2 | cat >$archive 284 assert "$?" -eq 0 "Command failed: podman save ... | cat" 285 286 run_podman rmi -f $img1 $img2 287 run_podman load -i $archive 288 289 run_podman image exists $img1 290 run_podman image exists $img2 291 run_podman rmi -f $img1 $img2 292 } 293 294 @test "podman save --oci-accept-uncompressed-layers" { 295 archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar 296 untar=$PODMAN_TMPDIR/myuntar-$(random_string 8) 297 mkdir -p $untar 298 299 # Create a tarball, unpack it and make sure the layers are uncompressed. 300 run_podman save -o $archive --format oci-archive --uncompressed $IMAGE 301 tar -C $untar -xvf $archive 302 run file $untar/blobs/sha256/* 303 is "$output" ".*POSIX tar archive" "layers are uncompressed" 304 } 305 306 # vim: filetype=sh