github.com/containers/podman/v5@v5.1.0-rc1/test/system/125-import.bats (about)

     1  #!/usr/bin/env bats   -*- bats -*-
     2  #
     3  # tests for podman import
     4  #
     5  
     6  load helpers
     7  
     8  @test "podman import" {
     9      local archive=$PODMAN_TMPDIR/archive.tar
    10      local random_content=$(random_string 12)
    11      # Generate a random name and tag (must be lower-case)
    12      local random_name=x0$(random_string 12 | tr A-Z a-z)
    13      local random_tag=t0$(random_string 7 | tr A-Z a-z)
    14      local fqin=localhost/$random_name:$random_tag
    15  
    16      run_podman run --name import $IMAGE sh -c "echo ${random_content} > /random.txt"
    17      run_podman export import -o $archive
    18      run_podman rm -t 0 -f import
    19  
    20      # Simple import
    21      run_podman import -q $archive
    22      iid="$output"
    23      run_podman run --rm $iid cat /random.txt
    24      is "$output" "$random_content" "simple import"
    25      run_podman rmi -f $iid
    26  
    27      # Simple import via stdin
    28      run_podman import -q - < <(cat $archive)
    29      iid="$output"
    30      run_podman run --rm $iid cat /random.txt
    31      is "$output" "$random_content" "simple import via stdin"
    32      run_podman rmi -f $iid
    33  
    34      # Tagged import
    35      run_podman import -q $archive $fqin
    36      run_podman run --rm $fqin cat /random.txt
    37      is "$output" "$random_content" "tagged import"
    38      run_podman rmi -f $fqin
    39  
    40      # Tagged import via stdin
    41      run_podman import -q - $fqin < <(cat $archive)
    42      run_podman run --rm $fqin cat /random.txt
    43      is "$output" "$random_content" "tagged import via stdin"
    44      run_podman rmi -f $fqin
    45  }
    46  
    47  # Integration tag to catch future breakage in tar, e.g. #19407
    48  # bats test_tags=distro-integration
    49  @test "podman export, alter tarball, re-import" {
    50      # FIXME: #21373 - tar < 1.35 is broken.
    51      # Remove this skip once all VMs are updated to 1.35.2 or above
    52      # (.2, because of #19407)
    53      tar_version=$(tar --version | head -1 | awk '{print $NF}' | tr -d .)
    54      if [[ $tar_version -lt 135 ]]; then
    55          skip "test requires tar >= 1.35 (you have: $tar_version)"
    56      fi
    57  
    58      # Create a test file following test
    59      mkdir $PODMAN_TMPDIR/tmp
    60      touch $PODMAN_TMPDIR/testfile1
    61      echo "modified tar file" >> $PODMAN_TMPDIR/tmp/testfile2
    62  
    63      # Create Dockerfile for test
    64      dockerfile=$PODMAN_TMPDIR/Dockerfile
    65  
    66      cat >$dockerfile <<EOF
    67  FROM $IMAGE
    68  ADD testfile1 /tmp
    69  WORKDIR /tmp
    70  EOF
    71  
    72      b_img=before_change_img
    73      b_cnt=before_change_cnt
    74      a_img=after_change_img
    75      a_cnt=after_change_cnt
    76  
    77      # Build from Dockerfile FROM non-existing local image
    78      run_podman build -t $b_img $PODMAN_TMPDIR
    79      run_podman create --name $b_cnt $b_img
    80  
    81      # Export built container as tarball
    82      run_podman export -o $PODMAN_TMPDIR/$b_cnt.tar $b_cnt
    83      run_podman rm -t 0 -f $b_cnt
    84  
    85      # Modify tarball contents
    86      echo "$_LOG_PROMPT tar --delete -f (tmpdir)/$b_cnt.tar tmp/testfile1"
    87      tar --delete -f $PODMAN_TMPDIR/$b_cnt.tar tmp/testfile1
    88      echo "$_LOG_PROMPT tar -C (tmpdir) -rf (tmpdir)/$b_cnt.tar tmp/testfile2"
    89      tar -C $PODMAN_TMPDIR -rf $PODMAN_TMPDIR/$b_cnt.tar tmp/testfile2
    90  
    91      # Import tarball and Tag imported image
    92      run_podman import -q $PODMAN_TMPDIR/$b_cnt.tar \
    93          --change "CMD sh -c \
    94          \"trap 'exit 33' 2;
    95          while true; do sleep 0.05;done\"" $a_img
    96  
    97      # Run imported image to confirm tarball modification, block on non-special signal
    98      run_podman run --name $a_cnt -d $a_img
    99  
   100      # Confirm testfile1 is deleted from tarball
   101      run_podman 1 exec $a_cnt cat /tmp/testfile1
   102      is "$output" ".*can't open '/tmp/testfile1': No such file or directory"
   103  
   104      # Confirm testfile2 is added to tarball
   105      run_podman exec $a_cnt cat /tmp/testfile2
   106      is "$output" "modified tar file" "modify tarball content"
   107  
   108      # Kill can send non-TERM/KILL signal to container to exit
   109      run_podman kill --signal 2 $a_cnt
   110      run_podman wait $a_cnt
   111  
   112      # Confirm exit within timeout
   113      run_podman ps -a --filter name=$a_cnt --format '{{.Status}}'
   114      is "$output" "Exited (33) .*" "Exit by non-TERM/KILL"
   115  
   116      run_podman rm -t 0 -f $a_cnt
   117      run_podman rmi $b_img $a_img
   118  
   119  }