Allow post-start load of busybox to remove restarts

The restarts in the authz plugin test suite seems to be causing
flakiness in CI, and can be avoided by separating the daemon start and
busybox image load.

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)
This commit is contained in:
Phil Estes 2016-02-18 22:00:45 -08:00
parent 074561b0ec
commit fe015c5ce0
2 changed files with 27 additions and 27 deletions

View file

@ -193,13 +193,10 @@ func (s *DockerAuthzSuite) TearDownSuite(c *check.C) {
func (s *DockerAuthzSuite) TestAuthZPluginAllowRequest(c *check.C) {
// start the daemon and load busybox, --net=none build fails otherwise
// cause it needs to pull busybox
c.Assert(s.d.StartWithBusybox(), check.IsNil)
// restart the daemon and enable the plugin, otherwise busybox loading
// is blocked by the plugin itself
c.Assert(s.d.Restart("--authorization-plugin="+testAuthZPlugin), check.IsNil)
c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin), check.IsNil)
s.ctrl.reqRes.Allow = true
s.ctrl.resRes.Allow = true
c.Assert(s.d.LoadBusybox(), check.IsNil)
// Ensure command successful
out, err := s.d.Cmd("run", "-d", "busybox", "top")
@ -254,12 +251,10 @@ func (s *DockerAuthzSuite) TestAuthZPluginAllowEventStream(c *check.C) {
testRequires(c, DaemonIsLinux)
// start the daemon and load busybox to avoid pulling busybox from Docker Hub
c.Assert(s.d.StartWithBusybox(), check.IsNil)
// restart the daemon and enable the authorization plugin, otherwise busybox loading
// is blocked by the plugin itself
c.Assert(s.d.Restart("--authorization-plugin="+testAuthZPlugin), check.IsNil)
c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin), check.IsNil)
s.ctrl.reqRes.Allow = true
s.ctrl.resRes.Allow = true
c.Assert(s.d.LoadBusybox(), check.IsNil)
startTime := strconv.FormatInt(daemonTime(c).Unix(), 10)
// Add another command to to enable event pipelining

View file

@ -321,24 +321,7 @@ func (d *Daemon) StartWithBusybox(arg ...string) error {
if err := d.Start(arg...); err != nil {
return err
}
bb := filepath.Join(d.folder, "busybox.tar")
if _, err := os.Stat(bb); err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("unexpected error on busybox.tar stat: %v", err)
}
// saving busybox image from main daemon
if err := exec.Command(dockerBinary, "save", "--output", bb, "busybox:latest").Run(); err != nil {
return fmt.Errorf("could not save busybox image: %v", err)
}
}
// loading busybox image to this daemon
if out, err := d.Cmd("load", "--input", bb); err != nil {
return fmt.Errorf("could not load busybox image: %s", out)
}
if err := os.Remove(bb); err != nil {
d.c.Logf("could not remove %s: %v", bb, err)
}
return nil
return d.LoadBusybox()
}
// Stop will send a SIGINT every second and wait for the daemon to stop.
@ -413,6 +396,28 @@ func (d *Daemon) Restart(arg ...string) error {
return d.Start(arg...)
}
// LoadBusybox will load the stored busybox into a newly started daemon
func (d *Daemon) LoadBusybox() error {
bb := filepath.Join(d.folder, "busybox.tar")
if _, err := os.Stat(bb); err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("unexpected error on busybox.tar stat: %v", err)
}
// saving busybox image from main daemon
if err := exec.Command(dockerBinary, "save", "--output", bb, "busybox:latest").Run(); err != nil {
return fmt.Errorf("could not save busybox image: %v", err)
}
}
// loading busybox image to this daemon
if out, err := d.Cmd("load", "--input", bb); err != nil {
return fmt.Errorf("could not load busybox image: %s", out)
}
if err := os.Remove(bb); err != nil {
d.c.Logf("could not remove %s: %v", bb, err)
}
return nil
}
func (d *Daemon) queryRootDir() (string, error) {
// update daemon root by asking /info endpoint (to support user
// namespaced daemon with root remapped uid.gid directory)