Browse code

fix TestExecWithUserAfterLiveRestore

When container's status is running, shell command may have not
executed end. So if we use 'docker exec -u test' to execute
command, it may fail since user 'test' have not be added yet.

Signed-off-by: Fengtu Wang <wangfengtu@huawei.com>

Fengtu Wang authored on 2017/04/06 17:33:49
Showing 1 changed files
... ...
@@ -2788,11 +2788,15 @@ func (s *DockerDaemonSuite) TestExecWithUserAfterLiveRestore(c *check.C) {
2788 2788
 	testRequires(c, DaemonIsLinux)
2789 2789
 	s.d.StartWithBusybox(c, "--live-restore")
2790 2790
 
2791
-	out, err := s.d.Cmd("run", "-d", "--name=top", "busybox", "sh", "-c", "addgroup -S test && adduser -S -G test test -D -s /bin/sh && top")
2791
+	out, err := s.d.Cmd("run", "-d", "--name=top", "busybox", "sh", "-c", "addgroup -S test && adduser -S -G test test -D -s /bin/sh && touch /adduser_end && top")
2792 2792
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
2793 2793
 
2794 2794
 	s.d.WaitRun("top")
2795 2795
 
2796
+	// Wait for shell command to be completed
2797
+	_, err = s.d.Cmd("exec", "top", "sh", "-c", `for i in $(seq 1 5); do if [ -e /adduser_end ]; then rm -f /adduser_end && break; else sleep 1 && false; fi; done`)
2798
+	c.Assert(err, check.IsNil, check.Commentf("Timeout waiting for shell command to be completed"))
2799
+
2796 2800
 	out1, err := s.d.Cmd("exec", "-u", "test", "top", "id")
2797 2801
 	// uid=100(test) gid=101(test) groups=101(test)
2798 2802
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out1))