Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a system test to modify and import an exported container #11426

Merged

Conversation

ttsuuubasa
Copy link
Contributor

Podman system test has a TODO list written in test/system/TODO.md.
This requesting test completed "Implied pull, build, export, modify, import, tag, run, kill" in the list.

The workflows written in TODO.md have multiple commands and therefore
the test file has been created apart from others as 800-scenario.bats.

800-scenario.bats has the workflow like the following,
and is different from the existing test 125-import.bats from the point of view of a purpose.
800-scenario.bats is more systematic than 125-import.bats
because it is not composed of a single command but user workflow oriented.

Please add this test 800-scenario.bats to the system tests.
Additionally, I would like to confirm that TODO.md is still valid.

(*) This test has the following WORKFLOW

  • Build from Dockerfile FROM non-existing local image
  • Export built container as tarball
  • Modify tarball contents by adding a file into tarball and deleting a file from tarball
  • Import tarball
  • Tag imported image
  • Run imported image to stop with SIGINT like not SIGTERM or SIGKILL
  • Kill can send non-TERM/KILL signal to container to exit
  • Confirm exit

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing!

The file should probably be called 800-import.bats since scenario seems a bit generic.

I just have a couple of nits. @edsantiago is the mastermind behind the system tests, PTAL :)


load helpers

alpine="quay.io/libpod/alpine"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already an internal variable $IMAGE which other tests are using. I suggest using that instead of $alpine to reduce the number of pulls and hence speed up the test a bit.

dockerfile=$PODMAN_TMPDIR/Dockerfile

cat >$dockerfile <<EOF
FROM $alpine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FROM $IMAGE

run_podman ps -a --filter name=$a_cnt --format '{{.Status}}'
is "$output" "Exited (33)" "Exit by non-TERM/KILL"

run_podman rmi -fa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing all images may be a bit too much. It would be nice if we could keep $IMAGE in the local storage.


alpine="quay.io/libpod/alpine"

@test "Implied pull, build, export, modify, import, tag, run, kill" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "podman import / export" ?


# Build from Dockerfile FROM non-existing local image
run_podman build -t $b_img $PODMAN_TMPDIR
run_podman run -d --name $b_cnt --stop-signal SIGKILL $b_img sleep 60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using podman create instead of run would be cheaper.


# Export built container as tarball
run_podman export -o $PODMAN_TMPDIR/$b_cnt.tar $b_cnt
run_podman rm -fa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing all containers seems a bit too much. Could we just remove $b_cnt?

iid=$output

# Tag imported image
run_podman tag $iid $a_img
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: podman import $PODMAN_TMPDIR/$b_cnt.tar ... $a_img would tag the imported image.


# Kill can send non-TERM/KILL signal to container to exit
run_podman kill --signal 2 $a_cnt
run_podman wait $a_cnt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going via podman logs works but I think that using podman exec may be easier. We could start a container, then do podman exec $ctr cat ... and check the output.

I'd expect it to be less work and easier to brain parse.

@ttsuuubasa
Copy link
Contributor Author

@vrothberg Thank you for your comment.
The test for "import" command has already existed as 125-import.bats.
Is it better to include this test to 125-import.bats?
I has modified the code based on your comment.

@vrothberg
Copy link
Member

Thank you, @fj-tsubasa!

Is it better to include this test to 125-import.bats?

I think so, yes. But I suggest to wait for @edsantiago's review first.

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually work with TMPDIR=/something-other-than-slash-tmp. Suggestion:

index c738d4433..29fd1c03c 100644
--- a/test/system/800-scenario.bats
+++ b/test/system/800-scenario.bats
@@ -9,8 +9,9 @@ load helpers
 @test "podman import / export" {

   # Create a test file following test
+    mkdir $PODMAN_TMPDIR/tmp
   touch $PODMAN_TMPDIR/testfile1
-  echo "modified tar file" >> $PODMAN_TMPDIR/testfile2
+  echo "modified tar file" >> $PODMAN_TMPDIR/tmp/testfile2

   # Create Dockerfile for test
   dockerfile=$PODMAN_TMPDIR/Dockerfile
@@ -36,7 +37,7 @@ EOF

   # Modify tarball contents
   tar --delete -f $PODMAN_TMPDIR/$b_cnt.tar tmp/testfile1
-  tar -rf $PODMAN_TMPDIR/$b_cnt.tar $PODMAN_TMPDIR/testfile2
+  tar -C $PODMAN_TMPDIR -rf $PODMAN_TMPDIR/$b_cnt.tar tmp/testfile2

   # Import tarball and Tag imported image
   run_podman import -q $PODMAN_TMPDIR/$b_cnt.tar \
@@ -48,11 +49,11 @@ EOF
   run_podman run --name $a_cnt -d $a_img

   # Confirm testfile1 is deleted from tarball
-  run_podman 1 exec $a_cnt cat $PODMAN_TMPDIR/testfile1 2>&1
-  is "$output" ".*can't open '$PODMAN_TMPDIR/testfile1': No such file or directory"
+  run_podman 1 exec $a_cnt cat /tmp/testfile1
+  is "$output" ".*can't open '/tmp/testfile1': No such file or directory"

   # Confirm testfile2 is added to tarball
-  run_podman exec $a_cnt cat $PODMAN_TMPDIR/testfile2
+  run_podman exec $a_cnt cat /tmp/testfile2
   is "$output" "modified tar file" "modify tarball content"

   # Kill can send non-TERM/KILL signal to container to exit

I agree with your suggestion to include this in 125-import, or at least somewhere in the 12x space (with a better name than "scenario").

I am OOTO on Tuesday and cannot follow up until late at night or Wednesday morning - sorry.

This is very nice work, thank you!

run_podman run --name $a_cnt -d $a_img

# Confirm testfile1 is deleted from tarball
run_podman 1 exec $a_cnt cat $PODMAN_TMPDIR/testfile1 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2>&1 here is unnecessary (and misleading)


@test "podman import / export" {

# Create a test file following test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with every other test script, would you mind using 4-space indentation?


load helpers

@test "podman import / export" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: @test "podman export, alter tarball, re-import" ?

@ttsuuubasa
Copy link
Contributor Author

@edsantiago Thank you for your comment !!
I has included my test 800-scenario.bats into 125-import.bats, and
I has modified the code based on your comment.

@edsantiago
Copy link
Member

LGTM but please squash your commits; that should fix the long-commit and trailing-whitespace errors.

This test has completed one of TODO items in test/system/TODO.md.
The item is "Implied pull, build, export, modify, import, tag, run, kill"

Signed-off-by: Tsubasa Watanabe <[email protected]>
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 9, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago, fj-tsubasa

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 9, 2021
@edsantiago
Copy link
Member

/lgtm

Thank you, @fj-tsubasa !

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2021
@openshift-merge-robot openshift-merge-robot merged commit 63f6656 into containers:main Sep 9, 2021
@ttsuuubasa ttsuuubasa deleted the system-test-scenario branch September 10, 2021 02:08
@ttsuuubasa
Copy link
Contributor Author

ttsuuubasa commented Sep 10, 2021

@edsantiago @vrothberg
Thank you for your acceptation and support for my first commit to OSS.
I think it is OK to delete the item of TODO.md "Implied pull, build, export, modify, import, tag, run, kill".

@vrothberg
Copy link
Member

An absolute pleasure, @fj-tsubasa. Thank you for contributing!

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants