From 9e7149743a1dc3bbc21acc46677b2e5e4281870f Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Wed, 9 Sep 2015 17:35:07 -0700 Subject: [PATCH] Make lookupSandboxID() reliable - it is supposed to be called after lookupContainerID() but the latter is not guaranteed to succeed and in case of connection error will return what was passed to it. So in order to be able to operate with both long and short container ids in case of lookupContainerID() failure, always search by `partial-container-id` Signed-off-by: Alessandro Boch --- client/client_test.go | 2 ++ client/service.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/client/client_test.go b/client/client_test.go index 3e22b6c..d7ad8a6 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -87,6 +87,8 @@ func setupMockHTTPCallback() { return nopCloser{bytes.NewBufferString("")}, dummyHTTPHdr, 400, fmt.Errorf("Bad Request") } else if strings.Contains(path, fmt.Sprintf("sandboxes?container-id=%s", mockContainerID)) { rsp = string(mockSbListJSON) + } else if strings.Contains(path, fmt.Sprintf("sandboxes?partial-container-id=%s", mockContainerID)) { + rsp = string(mockSbListJSON) } case "POST": var data []byte diff --git a/client/service.go b/client/service.go index 7fe82f6..3656497 100644 --- a/client/service.go +++ b/client/service.go @@ -115,7 +115,7 @@ func lookupContainerID(cli *NetworkCli, cnNameID string) (string, error) { } func lookupSandboxID(cli *NetworkCli, containerID string) (string, error) { - obj, _, err := readBody(cli.call("GET", fmt.Sprintf("/sandboxes?container-id=%s", containerID), nil, nil)) + obj, _, err := readBody(cli.call("GET", fmt.Sprintf("/sandboxes?partial-container-id=%s", containerID), nil, nil)) if err != nil { return "", err }