Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -33,6 +33,7 @@ import ( |
| 33 | 33 |
) |
| 34 | 34 |
|
| 35 | 35 |
type testingT interface {
|
| 36 |
+ require.TestingT |
|
| 36 | 37 |
logT |
| 37 | 38 |
Fatalf(string, ...interface{})
|
| 38 | 39 |
} |
| ... | ... |
@@ -329,9 +330,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
|
| 329 | 329 |
// then save the busybox image from the main daemon and load it into this Daemon instance. |
| 330 | 330 |
func (d *Daemon) StartWithBusybox(t testingT, arg ...string) {
|
| 331 | 331 |
d.Start(t, arg...) |
| 332 |
- if err := d.LoadBusybox(); err != nil {
|
|
| 333 |
- t.Fatalf("Error loading busybox image to current daemon: %s\n%v", d.id, err)
|
|
| 334 |
- } |
|
| 332 |
+ d.LoadBusybox(t) |
|
| 335 | 333 |
} |
| 336 | 334 |
|
| 337 | 335 |
// Kill will send a SIGKILL to the daemon |
| ... | ... |
@@ -493,27 +492,24 @@ func (d *Daemon) handleUserns() {
|
| 493 | 493 |
} |
| 494 | 494 |
} |
| 495 | 495 |
|
| 496 |
-// LoadBusybox will load the stored busybox into a newly started daemon |
|
| 497 |
-func (d *Daemon) LoadBusybox() error {
|
|
| 498 |
- bb := filepath.Join(d.Folder, "busybox.tar") |
|
| 499 |
- if _, err := os.Stat(bb); err != nil {
|
|
| 500 |
- if !os.IsNotExist(err) {
|
|
| 501 |
- return errors.Errorf("unexpected error on busybox.tar stat: %v", err)
|
|
| 502 |
- } |
|
| 503 |
- // saving busybox image from main daemon |
|
| 504 |
- if out, err := exec.Command(d.dockerBinary, "save", "--output", bb, "busybox:latest").CombinedOutput(); err != nil {
|
|
| 505 |
- imagesOut, _ := exec.Command(d.dockerBinary, "images", "--format", "{{ .Repository }}:{{ .Tag }}").CombinedOutput()
|
|
| 506 |
- return errors.Errorf("could not save busybox image: %s\n%s", string(out), strings.TrimSpace(string(imagesOut)))
|
|
| 507 |
- } |
|
| 508 |
- } |
|
| 509 |
- // loading busybox image to this daemon |
|
| 510 |
- if out, err := d.Cmd("load", "--input", bb); err != nil {
|
|
| 511 |
- return errors.Errorf("could not load busybox image: %s", out)
|
|
| 512 |
- } |
|
| 513 |
- if err := os.Remove(bb); err != nil {
|
|
| 514 |
- return err |
|
| 515 |
- } |
|
| 516 |
- return nil |
|
| 496 |
+// LoadBusybox image into the daemon |
|
| 497 |
+func (d *Daemon) LoadBusybox(t testingT) {
|
|
| 498 |
+ clientHost, err := client.NewEnvClient() |
|
| 499 |
+ require.NoError(t, err, "failed to create client") |
|
| 500 |
+ defer clientHost.Close() |
|
| 501 |
+ |
|
| 502 |
+ ctx := context.Background() |
|
| 503 |
+ reader, err := clientHost.ImageSave(ctx, []string{"busybox:latest"})
|
|
| 504 |
+ require.NoError(t, err, "failed to download busybox") |
|
| 505 |
+ defer reader.Close() |
|
| 506 |
+ |
|
| 507 |
+ client, err := d.NewClient() |
|
| 508 |
+ require.NoError(t, err, "failed to create client") |
|
| 509 |
+ defer client.Close() |
|
| 510 |
+ |
|
| 511 |
+ resp, err := client.ImageLoad(ctx, reader, true) |
|
| 512 |
+ require.NoError(t, err, "failed to load busybox") |
|
| 513 |
+ defer resp.Body.Close() |
|
| 517 | 514 |
} |
| 518 | 515 |
|
| 519 | 516 |
func (d *Daemon) queryRootDir() (string, error) {
|
| ... | ... |
@@ -53,7 +53,7 @@ func (s *DockerAuthzV2Suite) TestAuthZPluginAllowNonVolumeRequest(c *check.C) {
|
| 53 | 53 |
// start the daemon with the plugin and load busybox, --net=none build fails otherwise |
| 54 | 54 |
// because it needs to pull busybox |
| 55 | 55 |
s.d.Restart(c, "--authorization-plugin="+authzPluginNameWithTag) |
| 56 |
- c.Assert(s.d.LoadBusybox(), check.IsNil) |
|
| 56 |
+ s.d.LoadBusybox(c) |
|
| 57 | 57 |
|
| 58 | 58 |
// defer disabling the plugin |
| 59 | 59 |
defer func() {
|
| ... | ... |
@@ -83,7 +83,7 @@ func (s *DockerAuthzV2Suite) TestAuthZPluginDisable(c *check.C) {
|
| 83 | 83 |
// start the daemon with the plugin and load busybox, --net=none build fails otherwise |
| 84 | 84 |
// because it needs to pull busybox |
| 85 | 85 |
s.d.Restart(c, "--authorization-plugin="+authzPluginNameWithTag) |
| 86 |
- c.Assert(s.d.LoadBusybox(), check.IsNil) |
|
| 86 |
+ s.d.LoadBusybox(c) |
|
| 87 | 87 |
|
| 88 | 88 |
// defer removing the plugin |
| 89 | 89 |
defer func() {
|
| ... | ... |
@@ -209,7 +209,7 @@ func (s *DockerAuthzSuite) TestAuthZPluginAllowRequest(c *check.C) {
|
| 209 | 209 |
s.d.Start(c, "--authorization-plugin="+testAuthZPlugin) |
| 210 | 210 |
s.ctrl.reqRes.Allow = true |
| 211 | 211 |
s.ctrl.resRes.Allow = true |
| 212 |
- c.Assert(s.d.LoadBusybox(), check.IsNil) |
|
| 212 |
+ s.d.LoadBusybox(c) |
|
| 213 | 213 |
|
| 214 | 214 |
// Ensure command successful |
| 215 | 215 |
out, err := s.d.Cmd("run", "-d", "busybox", "top")
|
| ... | ... |
@@ -322,7 +322,7 @@ func (s *DockerAuthzSuite) TestAuthZPluginAllowEventStream(c *check.C) {
|
| 322 | 322 |
s.d.Start(c, "--authorization-plugin="+testAuthZPlugin) |
| 323 | 323 |
s.ctrl.reqRes.Allow = true |
| 324 | 324 |
s.ctrl.resRes.Allow = true |
| 325 |
- c.Assert(s.d.LoadBusybox(), check.IsNil) |
|
| 325 |
+ s.d.LoadBusybox(c) |
|
| 326 | 326 |
|
| 327 | 327 |
startTime := strconv.FormatInt(daemonTime(c).Unix(), 10) |
| 328 | 328 |
// Add another command to to enable event pipelining |
| ... | ... |
@@ -418,7 +418,7 @@ func (s *DockerAuthzSuite) TestAuthZPluginEnsureLoadImportWorking(c *check.C) {
|
| 418 | 418 |
s.d.Start(c, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin) |
| 419 | 419 |
s.ctrl.reqRes.Allow = true |
| 420 | 420 |
s.ctrl.resRes.Allow = true |
| 421 |
- c.Assert(s.d.LoadBusybox(), check.IsNil) |
|
| 421 |
+ s.d.LoadBusybox(c) |
|
| 422 | 422 |
|
| 423 | 423 |
tmp, err := ioutil.TempDir("", "test-authz-load-import")
|
| 424 | 424 |
c.Assert(err, check.IsNil) |
| ... | ... |
@@ -445,7 +445,7 @@ func (s *DockerAuthzSuite) TestAuthZPluginHeader(c *check.C) {
|
| 445 | 445 |
s.d.Start(c, "--debug", "--authorization-plugin="+testAuthZPlugin) |
| 446 | 446 |
s.ctrl.reqRes.Allow = true |
| 447 | 447 |
s.ctrl.resRes.Allow = true |
| 448 |
- c.Assert(s.d.LoadBusybox(), check.IsNil) |
|
| 448 |
+ s.d.LoadBusybox(c) |
|
| 449 | 449 |
|
| 450 | 450 |
daemonURL, err := url.Parse(s.d.Sock()) |
| 451 | 451 |
|