Instead of having the misconfigured token server test
fail after maxing out retries, only retry a few times
then return an error which will not retry.
Referenced by #19425
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"os/exec" |
| 11 | 11 |
"path/filepath" |
| 12 | 12 |
"strings" |
| 13 |
+ "sync" |
|
| 13 | 14 |
"time" |
| 14 | 15 |
|
| 15 | 16 |
"github.com/docker/distribution/reference" |
| ... | ... |
@@ -630,16 +631,26 @@ func (s *DockerSuite) TestPushToCentralRegistryUnauthorized(c *check.C) {
|
| 630 | 630 |
c.Assert(out, check.Not(checker.Contains), "Retrying") |
| 631 | 631 |
} |
| 632 | 632 |
|
| 633 |
-func getTestTokenService(status int, body string) *httptest.Server {
|
|
| 633 |
+func getTestTokenService(status int, body string, retries int) *httptest.Server {
|
|
| 634 |
+ var mu sync.Mutex |
|
| 634 | 635 |
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
| 635 |
- w.WriteHeader(status) |
|
| 636 |
- w.Header().Set("Content-Type", "application/json")
|
|
| 637 |
- w.Write([]byte(body)) |
|
| 636 |
+ mu.Lock() |
|
| 637 |
+ if retries > 0 {
|
|
| 638 |
+ w.WriteHeader(http.StatusServiceUnavailable) |
|
| 639 |
+ w.Header().Set("Content-Type", "application/json")
|
|
| 640 |
+ w.Write([]byte(`{"errors":[{"code":"UNAVAILABLE","message":"cannot create token at this time"}]}`))
|
|
| 641 |
+ retries-- |
|
| 642 |
+ } else {
|
|
| 643 |
+ w.WriteHeader(status) |
|
| 644 |
+ w.Header().Set("Content-Type", "application/json")
|
|
| 645 |
+ w.Write([]byte(body)) |
|
| 646 |
+ } |
|
| 647 |
+ mu.Unlock() |
|
| 638 | 648 |
})) |
| 639 | 649 |
} |
| 640 | 650 |
|
| 641 | 651 |
func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *check.C) {
|
| 642 |
- ts := getTestTokenService(http.StatusUnauthorized, `{"errors": [{"Code":"UNAUTHORIZED", "message": "a message", "detail": null}]}`)
|
|
| 652 |
+ ts := getTestTokenService(http.StatusUnauthorized, `{"errors": [{"Code":"UNAUTHORIZED", "message": "a message", "detail": null}]}`, 0)
|
|
| 643 | 653 |
defer ts.Close() |
| 644 | 654 |
s.setupRegistryWithTokenService(c, ts.URL) |
| 645 | 655 |
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
| ... | ... |
@@ -651,7 +662,7 @@ func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *che |
| 651 | 651 |
} |
| 652 | 652 |
|
| 653 | 653 |
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnauthorized(c *check.C) {
|
| 654 |
- ts := getTestTokenService(http.StatusUnauthorized, `{"error": "unauthorized"}`)
|
|
| 654 |
+ ts := getTestTokenService(http.StatusUnauthorized, `{"error": "unauthorized"}`, 0)
|
|
| 655 | 655 |
defer ts.Close() |
| 656 | 656 |
s.setupRegistryWithTokenService(c, ts.URL) |
| 657 | 657 |
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
| ... | ... |
@@ -664,7 +675,7 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse |
| 664 | 664 |
} |
| 665 | 665 |
|
| 666 | 666 |
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseError(c *check.C) {
|
| 667 |
- ts := getTestTokenService(http.StatusInternalServerError, `{"error": "unexpected"}`)
|
|
| 667 |
+ ts := getTestTokenService(http.StatusTooManyRequests, `{"errors": [{"code":"TOOMANYREQUESTS","message":"out of tokens"}]}`, 4)
|
|
| 668 | 668 |
defer ts.Close() |
| 669 | 669 |
s.setupRegistryWithTokenService(c, ts.URL) |
| 670 | 670 |
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
| ... | ... |
@@ -672,12 +683,13 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse |
| 672 | 672 |
out, _, err := dockerCmdWithError("push", repoName)
|
| 673 | 673 |
c.Assert(err, check.NotNil, check.Commentf(out)) |
| 674 | 674 |
c.Assert(out, checker.Contains, "Retrying") |
| 675 |
+ c.Assert(out, checker.Not(checker.Contains), "Retrying in 15") |
|
| 675 | 676 |
split := strings.Split(out, "\n") |
| 676 |
- c.Assert(split[len(split)-2], check.Equals, "received unexpected HTTP status: 500 Internal Server Error") |
|
| 677 |
+ c.Assert(split[len(split)-2], check.Equals, "toomanyrequests: out of tokens") |
|
| 677 | 678 |
} |
| 678 | 679 |
|
| 679 | 680 |
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnparsable(c *check.C) {
|
| 680 |
- ts := getTestTokenService(http.StatusForbidden, `no way`) |
|
| 681 |
+ ts := getTestTokenService(http.StatusForbidden, `no way`, 0) |
|
| 681 | 682 |
defer ts.Close() |
| 682 | 683 |
s.setupRegistryWithTokenService(c, ts.URL) |
| 683 | 684 |
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
| ... | ... |
@@ -690,7 +702,7 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse |
| 690 | 690 |
} |
| 691 | 691 |
|
| 692 | 692 |
func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseNoToken(c *check.C) {
|
| 693 |
- ts := getTestTokenService(http.StatusOK, `{"something": "wrong"}`)
|
|
| 693 |
+ ts := getTestTokenService(http.StatusOK, `{"something": "wrong"}`, 0)
|
|
| 694 | 694 |
defer ts.Close() |
| 695 | 695 |
s.setupRegistryWithTokenService(c, ts.URL) |
| 696 | 696 |
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|