github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/system/120-load.bats (about) 1 #!/usr/bin/env bats -*- bats -*- 2 # 3 # tests for podman load 4 # 5 6 load helpers 7 8 # Custom helpers for this test only. These just save us having to duplicate 9 # the same thing four times (two tests, each with -i and stdin). 10 # 11 # initialize, read image ID and name 12 get_iid_and_name() { 13 run_podman images -a --format '{{.ID}} {{.Repository}}:{{.Tag}}' 14 read iid img_name < <(echo "$output") 15 16 archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar 17 } 18 19 # Simple verification of image ID and name 20 verify_iid_and_name() { 21 run_podman images -a --format '{{.ID}} {{.Repository}}:{{.Tag}}' 22 read new_iid new_img_name < <(echo "$output") 23 24 # Verify 25 is "$new_iid" "$iid" "Image ID of loaded image == original" 26 is "$new_img_name" "$1" "Name & tag of restored image" 27 } 28 29 @test "podman load invalid file" { 30 # Regression test for #9672 to make sure invalid input yields errors. 31 invalid=$PODMAN_TMPDIR/invalid 32 echo "I am an invalid file and should cause a podman-load error" > $invalid 33 run_podman 125 load -i $invalid 34 # podman and podman-remote emit different messages; this is a common string 35 is "$output" ".*payload does not match any of the supported image formats .*" \ 36 "load -i INVALID fails with expected diagnostic" 37 } 38 39 @test "podman save to pipe and load" { 40 # Generate a random name and tag (must be lower-case) 41 local random_name=x0$(random_string 12 | tr A-Z a-z) 42 local random_tag=t0$(random_string 7 | tr A-Z a-z) 43 local fqin=localhost/$random_name:$random_tag 44 run_podman tag $IMAGE $fqin 45 46 # Believe it or not, 'podman load' would barf if any path element 47 # included a capital letter 48 archive=$PODMAN_TMPDIR/MySubDirWithCaps/MyImage-$(random_string 8).tar 49 mkdir -p $(dirname $archive) 50 51 # We can't use run_podman because that uses the BATS 'run' function 52 # which redirects stdout and stderr. Here we need to guarantee 53 # that podman's stdout is a pipe, not any other form of redirection 54 $PODMAN save --format oci-archive $fqin | cat >$archive 55 if [ "$status" -ne 0 ]; then 56 die "Command failed: podman save ... | cat" 57 fi 58 59 # Make sure we can reload it 60 run_podman rmi $fqin 61 run_podman load -i $archive 62 63 # FIXME: cannot compare IID, see #7371, so we check only the tag 64 run_podman images $fqin --format '{{.Repository}}:{{.Tag}}' 65 is "$output" "$fqin" "image preserves name across save/load" 66 67 # Load with a new tag 68 local new_name=x1$(random_string 14 | tr A-Z a-z) 69 local new_tag=t1$(random_string 6 | tr A-Z a-z) 70 run_podman rmi $fqin 71 72 run_podman load -i $archive 73 run_podman images --format '{{.Repository}}:{{.Tag}}' --sort tag 74 is "${lines[0]}" "$IMAGE" "image is preserved" 75 is "${lines[1]}" "$fqin" "image is reloaded with old fqin" 76 77 # Clean up 78 run_podman rmi $fqin 79 } 80 81 82 @test "podman load - by image ID" { 83 # FIXME: how to build a simple archive instead? 84 get_iid_and_name 85 86 # Save image by ID, and remove it. 87 run_podman save $iid -o $archive 88 run_podman rmi $iid 89 90 # Load using -i; IID should be preserved, but name is not. 91 run_podman load -i $archive 92 verify_iid_and_name "<none>:<none>" 93 94 # Same as above, using stdin 95 run_podman rmi $iid 96 run_podman load < $archive 97 verify_iid_and_name "<none>:<none>" 98 99 # Same as above, using stdin but with `podman image load` 100 run_podman rmi $iid 101 run_podman image load < $archive 102 verify_iid_and_name "<none>:<none>" 103 104 # Cleanup: since load-by-iid doesn't preserve name, re-tag it; 105 # otherwise our global teardown will rmi and re-pull our standard image. 106 run_podman tag $iid $img_name 107 } 108 109 @test "podman load - by image name" { 110 get_iid_and_name 111 run_podman save $img_name -o $archive 112 run_podman rmi $iid 113 114 # Load using -i; this time the image should be tagged. 115 run_podman load -i $archive 116 verify_iid_and_name $img_name 117 run_podman rmi $iid 118 119 # Also make sure that `image load` behaves the same. 120 run_podman image load -i $archive 121 verify_iid_and_name $img_name 122 run_podman rmi $iid 123 124 # Same as above, using stdin 125 run_podman load < $archive 126 verify_iid_and_name $img_name 127 } 128 129 @test "podman load - redirect corrupt payload" { 130 run_podman 125 load <<< "Danger, Will Robinson!! This is a corrupt tarball!" 131 is "$output" \ 132 ".*payload does not match any of the supported image formats .*" \ 133 "Diagnostic from 'podman load' unknown/corrupt payload" 134 } 135 136 @test "podman load - multi-image archive" { 137 # img1 & 2 should be images that are not locally present; they must also 138 # be usable on the host arch. The nonlocal image (:000000xx) is kept 139 # up-to-date for all RHEL/Fedora arches; the other image we use is 140 # the one tagged ':multiimage', which as of 2021-07-15 is :20210610 141 # but that tag will grow stale over time. If/when this test fails, 142 # your first approach should be to manually update :multiimage to 143 # point to a more recent testimage. (Use the quay.io GUI, it's waaay 144 # easier than pulling/pushing the correct manifest.) 145 img1=${PODMAN_NONLOCAL_IMAGE_FQN} 146 img2="$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME:multiimage" 147 archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar 148 149 run_podman pull $img1 150 run_podman pull $img2 151 152 run_podman save -m -o $archive $img1 $img2 153 run_podman rmi -f $img1 $img2 154 run_podman load -i $archive 155 156 run_podman image exists $img1 157 run_podman image exists $img2 158 run_podman rmi -f $img1 $img2 159 } 160 161 @test "podman load - multi-image archive with redirect" { 162 # (see comments in test above re: img1 & 2) 163 img1=${PODMAN_NONLOCAL_IMAGE_FQN} 164 img2="$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME:multiimage" 165 archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar 166 167 run_podman pull $img1 168 run_podman pull $img2 169 170 # We can't use run_podman because that uses the BATS 'run' function 171 # which redirects stdout and stderr. Here we need to guarantee 172 # that podman's stdout is a pipe, not any other form of redirection 173 $PODMAN save -m $img1 $img2 | cat >$archive 174 if [ "$status" -ne 0 ]; then 175 die "Command failed: podman save ... | cat" 176 fi 177 178 run_podman rmi -f $img1 $img2 179 run_podman load -i $archive 180 181 run_podman image exists $img1 182 run_podman image exists $img2 183 run_podman rmi -f $img1 $img2 184 } 185 186 # vim: filetype=sh