Browse code

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)

Phil Estes authored on 2016/02/19 15:00:45
Showing 2 changed files
... ...
@@ -193,13 +193,10 @@ func (s *DockerAuthzSuite) TearDownSuite(c *check.C) {
193 193
 func (s *DockerAuthzSuite) TestAuthZPluginAllowRequest(c *check.C) {
194 194
 	// start the daemon and load busybox, --net=none build fails otherwise
195 195
 	// cause it needs to pull busybox
196
-	c.Assert(s.d.StartWithBusybox(), check.IsNil)
197
-	// restart the daemon and enable the plugin, otherwise busybox loading
198
-	// is blocked by the plugin itself
199
-	c.Assert(s.d.Restart("--authorization-plugin="+testAuthZPlugin), check.IsNil)
200
-
196
+	c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin), check.IsNil)
201 197
 	s.ctrl.reqRes.Allow = true
202 198
 	s.ctrl.resRes.Allow = true
199
+	c.Assert(s.d.LoadBusybox(), check.IsNil)
203 200
 
204 201
 	// Ensure command successful
205 202
 	out, err := s.d.Cmd("run", "-d", "busybox", "top")
... ...
@@ -254,12 +251,10 @@ func (s *DockerAuthzSuite) TestAuthZPluginAllowEventStream(c *check.C) {
254 254
 	testRequires(c, DaemonIsLinux)
255 255
 
256 256
 	// start the daemon and load busybox to avoid pulling busybox from Docker Hub
257
-	c.Assert(s.d.StartWithBusybox(), check.IsNil)
258
-	// restart the daemon and enable the authorization plugin, otherwise busybox loading
259
-	// is blocked by the plugin itself
260
-	c.Assert(s.d.Restart("--authorization-plugin="+testAuthZPlugin), check.IsNil)
257
+	c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin), check.IsNil)
261 258
 	s.ctrl.reqRes.Allow = true
262 259
 	s.ctrl.resRes.Allow = true
260
+	c.Assert(s.d.LoadBusybox(), check.IsNil)
263 261
 
264 262
 	startTime := strconv.FormatInt(daemonTime(c).Unix(), 10)
265 263
 	// Add another command to to enable event pipelining
... ...
@@ -321,24 +321,7 @@ func (d *Daemon) StartWithBusybox(arg ...string) error {
321 321
 	if err := d.Start(arg...); err != nil {
322 322
 		return err
323 323
 	}
324
-	bb := filepath.Join(d.folder, "busybox.tar")
325
-	if _, err := os.Stat(bb); err != nil {
326
-		if !os.IsNotExist(err) {
327
-			return fmt.Errorf("unexpected error on busybox.tar stat: %v", err)
328
-		}
329
-		// saving busybox image from main daemon
330
-		if err := exec.Command(dockerBinary, "save", "--output", bb, "busybox:latest").Run(); err != nil {
331
-			return fmt.Errorf("could not save busybox image: %v", err)
332
-		}
333
-	}
334
-	// loading busybox image to this daemon
335
-	if out, err := d.Cmd("load", "--input", bb); err != nil {
336
-		return fmt.Errorf("could not load busybox image: %s", out)
337
-	}
338
-	if err := os.Remove(bb); err != nil {
339
-		d.c.Logf("could not remove %s: %v", bb, err)
340
-	}
341
-	return nil
324
+	return d.LoadBusybox()
342 325
 }
343 326
 
344 327
 // 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 {
413 413
 	return d.Start(arg...)
414 414
 }
415 415
 
416
+// LoadBusybox will load the stored busybox into a newly started daemon
417
+func (d *Daemon) LoadBusybox() error {
418
+	bb := filepath.Join(d.folder, "busybox.tar")
419
+	if _, err := os.Stat(bb); err != nil {
420
+		if !os.IsNotExist(err) {
421
+			return fmt.Errorf("unexpected error on busybox.tar stat: %v", err)
422
+		}
423
+		// saving busybox image from main daemon
424
+		if err := exec.Command(dockerBinary, "save", "--output", bb, "busybox:latest").Run(); err != nil {
425
+			return fmt.Errorf("could not save busybox image: %v", err)
426
+		}
427
+	}
428
+	// loading busybox image to this daemon
429
+	if out, err := d.Cmd("load", "--input", bb); err != nil {
430
+		return fmt.Errorf("could not load busybox image: %s", out)
431
+	}
432
+	if err := os.Remove(bb); err != nil {
433
+		d.c.Logf("could not remove %s: %v", bb, err)
434
+	}
435
+	return nil
436
+}
437
+
416 438
 func (d *Daemon) queryRootDir() (string, error) {
417 439
 	// update daemon root by asking /info endpoint (to support user
418 440
 	// namespaced daemon with root remapped uid.gid directory)