Browse code

distribution: errors: do not retry if no credentials provided

Fix and add test for case c) in #21054

Signed-off-by: Antonio Murdaca <runcom@redhat.com>

Antonio Murdaca authored on 2016/03/13 02:01:01
Showing 2 changed files
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"github.com/docker/distribution/registry/api/errcode"
9 9
 	"github.com/docker/distribution/registry/api/v2"
10 10
 	"github.com/docker/distribution/registry/client"
11
+	"github.com/docker/distribution/registry/client/auth"
11 12
 	"github.com/docker/docker/distribution/xfer"
12 13
 )
13 14
 
... ...
@@ -90,6 +91,9 @@ func retryOnError(err error) error {
90 90
 			return xfer.DoNotRetry{Err: err}
91 91
 		}
92 92
 	case *url.Error:
93
+		if v.Err == auth.ErrNoBasicAuthCredentials {
94
+			return xfer.DoNotRetry{Err: v.Err}
95
+		}
93 96
 		return retryOnError(v.Err)
94 97
 	case *client.UnexpectedHTTPResponseError:
95 98
 		return xfer.DoNotRetry{Err: err}
... ...
@@ -526,3 +526,12 @@ func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegation(c *check.C) {
526 526
 	c.Assert(err, check.IsNil, check.Commentf("Unable to read targets/releases metadata"))
527 527
 	c.Assert(string(contents), checker.Contains, `"latest"`, check.Commentf(string(contents)))
528 528
 }
529
+
530
+func (s *DockerRegistryAuthSuite) TestPushNoCredentialsNoRetry(c *check.C) {
531
+	repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
532
+	dockerCmd(c, "tag", "busybox", repoName)
533
+	out, _, err := dockerCmdWithError("push", repoName)
534
+	c.Assert(err, check.NotNil, check.Commentf(out))
535
+	c.Assert(out, check.Not(checker.Contains), "Retrying")
536
+	c.Assert(out, checker.Contains, "no basic auth credentials")
537
+}