Browse code

Merge pull request #18349 from mrfuxi/cli-specific-errors-in-api

Remove CLI specific information for API error messages. Issue #17147

Vincent Demeester authored on 2015/12/07 00:02:40
Showing 3 changed files
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"strings"
7 7
 
8 8
 	"github.com/docker/docker/pkg/integration/checker"
9
+	"github.com/docker/docker/runconfig"
9 10
 	"github.com/go-check/check"
10 11
 )
11 12
 
... ...
@@ -202,7 +203,7 @@ func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
202 202
 	// Running container linking to a container with --net host should have failed
203 203
 	c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
204 204
 	// Running container linking to a container with --net host should have failed
205
-	c.Assert(out, checker.Contains, "--net=host can't be used with links. This would result in undefined behavior")
205
+	c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error())
206 206
 }
207 207
 
208 208
 func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
... ...
@@ -3384,17 +3384,17 @@ func (s *DockerSuite) TestRunContainerNetModeWithDnsMacHosts(c *check.C) {
3384 3384
 	}
3385 3385
 
3386 3386
 	out, _, err = dockerCmdWithError("run", "--dns", "1.2.3.4", "--net=container:parent", "busybox")
3387
-	if err == nil || !strings.Contains(out, "Conflicting options: --dns and the network mode") {
3387
+	if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkAndDNS.Error()) {
3388 3388
 		c.Fatalf("run --net=container with --dns should error out")
3389 3389
 	}
3390 3390
 
3391 3391
 	out, _, err = dockerCmdWithError("run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox")
3392
-	if err == nil || !strings.Contains(out, "--mac-address and the network mode") {
3392
+	if err == nil || !strings.Contains(out, runconfig.ErrConflictContainerNetworkAndMac.Error()) {
3393 3393
 		c.Fatalf("run --net=container with --mac-address should error out")
3394 3394
 	}
3395 3395
 
3396 3396
 	out, _, err = dockerCmdWithError("run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox")
3397
-	if err == nil || !strings.Contains(out, "--add-host and the network mode") {
3397
+	if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkHosts.Error()) {
3398 3398
 		c.Fatalf("run --net=container with --add-host should error out")
3399 3399
 	}
3400 3400
 }
... ...
@@ -3405,17 +3405,17 @@ func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) {
3405 3405
 	dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
3406 3406
 
3407 3407
 	out, _, err := dockerCmdWithError("run", "-p", "5000:5000", "--net=container:parent", "busybox")
3408
-	if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
3408
+	if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkPublishPorts.Error()) {
3409 3409
 		c.Fatalf("run --net=container with -p should error out")
3410 3410
 	}
3411 3411
 
3412 3412
 	out, _, err = dockerCmdWithError("run", "-P", "--net=container:parent", "busybox")
3413
-	if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
3413
+	if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkPublishPorts.Error()) {
3414 3414
 		c.Fatalf("run --net=container with -P should error out")
3415 3415
 	}
3416 3416
 
3417 3417
 	out, _, err = dockerCmdWithError("run", "--expose", "5000", "--net=container:parent", "busybox")
3418
-	if err == nil || !strings.Contains(out, "Conflicting options: --expose and the network mode (--net)") {
3418
+	if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkExposePorts.Error()) {
3419 3419
 		c.Fatalf("run --net=container with --expose should error out")
3420 3420
 	}
3421 3421
 }
... ...
@@ -18,29 +18,29 @@ import (
18 18
 
19 19
 var (
20 20
 	// ErrConflictContainerNetworkAndLinks conflict between --net=container and links
21
-	ErrConflictContainerNetworkAndLinks = fmt.Errorf("Conflicting options: --net=container can't be used with links. This would result in undefined behavior")
21
+	ErrConflictContainerNetworkAndLinks = fmt.Errorf("Conflicting options: container type network can't be used with links. This would result in undefined behavior")
22 22
 	// ErrConflictUserDefinedNetworkAndLinks conflict between --net=<NETWORK> and links
23
-	ErrConflictUserDefinedNetworkAndLinks = fmt.Errorf("Conflicting options: --net=<NETWORK> can't be used with links. This would result in undefined behavior")
23
+	ErrConflictUserDefinedNetworkAndLinks = fmt.Errorf("Conflicting options: networking can't be used with links. This would result in undefined behavior")
24 24
 	// ErrConflictSharedNetwork conflict between private and other networks
25 25
 	ErrConflictSharedNetwork = fmt.Errorf("Container sharing network namespace with another container or host cannot be connected to any other network")
26 26
 	// ErrConflictHostNetwork conflict from being disconnected from host network or connected to host network.
27 27
 	ErrConflictHostNetwork = fmt.Errorf("Container cannot be disconnected from host network or connected to host network")
28 28
 	// ErrConflictNoNetwork conflict between private and other networks
29
-	ErrConflictNoNetwork = fmt.Errorf("Container cannot be connected to multiple networks with one of the networks in --none mode")
29
+	ErrConflictNoNetwork = fmt.Errorf("Container cannot be connected to multiple networks with one of the networks in private (none) mode")
30 30
 	// ErrConflictNetworkAndDNS conflict between --dns and the network mode
31
-	ErrConflictNetworkAndDNS = fmt.Errorf("Conflicting options: --dns and the network mode (--net)")
31
+	ErrConflictNetworkAndDNS = fmt.Errorf("Conflicting options: dns and the network mode")
32 32
 	// ErrConflictNetworkHostname conflict between the hostname and the network mode
33
-	ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: -h and the network mode (--net)")
33
+	ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: hostname and the network mode")
34 34
 	// ErrConflictHostNetworkAndLinks conflict between --net=host and links
35
-	ErrConflictHostNetworkAndLinks = fmt.Errorf("Conflicting options: --net=host can't be used with links. This would result in undefined behavior")
35
+	ErrConflictHostNetworkAndLinks = fmt.Errorf("Conflicting options: host type networking can't be used with links. This would result in undefined behavior")
36 36
 	// ErrConflictContainerNetworkAndMac conflict between the mac address and the network mode
37
-	ErrConflictContainerNetworkAndMac = fmt.Errorf("Conflicting options: --mac-address and the network mode (--net)")
37
+	ErrConflictContainerNetworkAndMac = fmt.Errorf("Conflicting options: mac-address and the network mode")
38 38
 	// ErrConflictNetworkHosts conflict between add-host and the network mode
39
-	ErrConflictNetworkHosts = fmt.Errorf("Conflicting options: --add-host and the network mode (--net)")
40
-	// ErrConflictNetworkPublishPorts conflict between the pulbish options and the network mode
41
-	ErrConflictNetworkPublishPorts = fmt.Errorf("Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)")
39
+	ErrConflictNetworkHosts = fmt.Errorf("Conflicting options: custom host-to-IP mapping and the network mode")
40
+	// ErrConflictNetworkPublishPorts conflict between the publish options and the network mode
41
+	ErrConflictNetworkPublishPorts = fmt.Errorf("Conflicting options: port publishing and the container type network mode")
42 42
 	// ErrConflictNetworkExposePorts conflict between the expose option and the network mode
43
-	ErrConflictNetworkExposePorts = fmt.Errorf("Conflicting options: --expose and the network mode (--net)")
43
+	ErrConflictNetworkExposePorts = fmt.Errorf("Conflicting options: port exposing and the container type network mode")
44 44
 )
45 45
 
46 46
 // Parse parses the specified args for the specified command and generates a Config,