Browse code

LCOW: Log stderr on failures

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2018/03/09 02:53:27
Showing 3 changed files
... ...
@@ -2,6 +2,7 @@ package dockerfile // import "github.com/docker/docker/builder/dockerfile"
2 2
 
3 3
 import (
4 4
 	"os"
5
+	"runtime"
5 6
 	"testing"
6 7
 
7 8
 	"github.com/docker/docker/builder/remotecontext"
... ...
@@ -97,7 +98,9 @@ func initDispatchTestCases() []dispatchTestCase {
97 97
 }
98 98
 
99 99
 func TestDispatch(t *testing.T) {
100
-	skip.If(t, os.Getuid() != 0, "skipping test that requires root")
100
+	if runtime.GOOS != "windows" {
101
+		skip.If(t, os.Getuid() != 0, "skipping test that requires root")
102
+	}
101 103
 	testCases := initDispatchTestCases()
102 104
 
103 105
 	for _, testCase := range testCases {
... ...
@@ -47,6 +47,9 @@ func TestDockerfileOutsideTheBuildContext(t *testing.T) {
47 47
 	defer cleanup()
48 48
 
49 49
 	expectedError := "Forbidden path outside the build context: ../../Dockerfile ()"
50
+	if runtime.GOOS == "windows" {
51
+		expectedError = "failed to resolve scoped path ../../Dockerfile ()"
52
+	}
50 53
 
51 54
 	readAndCheckDockerfile(t, "DockerfileOutsideTheBuildContext", contextDir, "../../Dockerfile", expectedError)
52 55
 }
... ...
@@ -61,7 +64,9 @@ func TestNonExistingDockerfile(t *testing.T) {
61 61
 }
62 62
 
63 63
 func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) {
64
-	skip.If(t, os.Getuid() != 0, "skipping test that requires root")
64
+	if runtime.GOOS != "windows" {
65
+		skip.If(t, os.Getuid() != 0, "skipping test that requires root")
66
+	}
65 67
 	tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
66 68
 	assert.NilError(t, err)
67 69
 
... ...
@@ -80,7 +85,7 @@ func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath,
80 80
 		Source:  tarStream,
81 81
 	}
82 82
 	_, _, err = remotecontext.Detect(config)
83
-	assert.Check(t, is.Error(err, expectedError))
83
+	assert.Check(t, is.ErrorContains(err, expectedError))
84 84
 }
85 85
 
86 86
 func TestCopyRunConfig(t *testing.T) {
... ...
@@ -4,7 +4,6 @@ package lcow // import "github.com/docker/docker/daemon/graphdriver/lcow"
4 4
 
5 5
 import (
6 6
 	"bytes"
7
-	"errors"
8 7
 	"fmt"
9 8
 	"io"
10 9
 	"strings"
... ...
@@ -13,6 +12,7 @@ import (
13 13
 
14 14
 	"github.com/Microsoft/hcsshim"
15 15
 	"github.com/Microsoft/opengcs/client"
16
+	"github.com/pkg/errors"
16 17
 	"github.com/sirupsen/logrus"
17 18
 )
18 19
 
... ...
@@ -323,8 +323,9 @@ func (svm *serviceVM) createUnionMount(mountName string, mvds ...hcsshim.MappedV
323 323
 	}
324 324
 
325 325
 	logrus.Debugf("Doing the overlay mount with union directory=%s", mountName)
326
-	if err = svm.runProcess(fmt.Sprintf("mkdir -p %s", mountName), nil, nil, nil); err != nil {
327
-		return err
326
+	errOut := &bytes.Buffer{}
327
+	if err = svm.runProcess(fmt.Sprintf("mkdir -p %s", mountName), nil, nil, errOut); err != nil {
328
+		return errors.Wrapf(err, "mkdir -p %s failed (%s)", mountName, errOut.String())
328 329
 	}
329 330
 
330 331
 	var cmd string
... ...
@@ -340,8 +341,9 @@ func (svm *serviceVM) createUnionMount(mountName string, mvds ...hcsshim.MappedV
340 340
 		upper := fmt.Sprintf("%s/upper", svm.getShortContainerPath(&mvds[0]))
341 341
 		work := fmt.Sprintf("%s/work", svm.getShortContainerPath(&mvds[0]))
342 342
 
343
-		if err = svm.runProcess(fmt.Sprintf("mkdir -p %s %s", upper, work), nil, nil, nil); err != nil {
344
-			return err
343
+		errOut := &bytes.Buffer{}
344
+		if err = svm.runProcess(fmt.Sprintf("mkdir -p %s %s", upper, work), nil, nil, errOut); err != nil {
345
+			return errors.Wrapf(err, "mkdir -p %s failed (%s)", mountName, errOut.String())
345 346
 		}
346 347
 
347 348
 		cmd = fmt.Sprintf("mount -t overlay overlay -olowerdir=%s,upperdir=%s,workdir=%s %s",
... ...
@@ -352,8 +354,9 @@ func (svm *serviceVM) createUnionMount(mountName string, mvds ...hcsshim.MappedV
352 352
 	}
353 353
 
354 354
 	logrus.Debugf("createUnionMount: Executing mount=%s", cmd)
355
-	if err = svm.runProcess(cmd, nil, nil, nil); err != nil {
356
-		return err
355
+	errOut = &bytes.Buffer{}
356
+	if err = svm.runProcess(cmd, nil, nil, errOut); err != nil {
357
+		return errors.Wrapf(err, "%s failed (%s)", cmd, errOut.String())
357 358
 	}
358 359
 
359 360
 	svm.unionMounts[mountName] = 1