From 59c49c022cf2aedd0728e19c355c1f46158fa4b4 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Wed, 8 Feb 2017 13:28:00 -0600 Subject: [PATCH] Properly bubble up connection errors Workaround https://github.com/gophercloud/gophercloud/issues/247 until a fix is merged upstream --- glide.lock | 7 +++-- glide.yaml | 3 +- magnum/account_test.go | 65 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 magnum/account_test.go diff --git a/glide.lock b/glide.lock index 33e88f8..af57907 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 21808762abe2c2931a10471c6824047d3b3944fa2964ef87fd94b67a0c4bea11 -updated: 2017-02-06T10:34:03.651359382-06:00 +hash: 5fa0d1131570ebcb88e2771c4b5f83a77585dd15ab25e6da5dcc03da17355651 +updated: 2017-02-07T10:34:03.651359382-06:00 imports: - name: github.com/davecgh/go-spew version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 @@ -16,7 +16,8 @@ imports: repo: https://github.com/getcarina/libcarina.git vcs: git - name: github.com/gophercloud/gophercloud - version: b267f2372f44b2479bb598d4e333804b667b80e5 + version: 40d34bc60a8c44769fd3de9eda6a9c918512c667 + repo: https://github.com/carolynvs/gophercloud.git vcs: git subpackages: - openstack diff --git a/glide.yaml b/glide.yaml index ab9783c..f0a07c2 100644 --- a/glide.yaml +++ b/glide.yaml @@ -13,7 +13,8 @@ import: repo: https://github.com/getcarina/libcarina.git vcs: git - package: github.com/gophercloud/gophercloud - version: magnum + version: preserve-token-conn-error + repo: https://github.com/carolynvs/gophercloud.git vcs: git subpackages: - openstack diff --git a/magnum/account_test.go b/magnum/account_test.go new file mode 100644 index 0000000..aed658a --- /dev/null +++ b/magnum/account_test.go @@ -0,0 +1,65 @@ +package magnum + +import ( + "fmt" + "net/http" + "net/http/httptest" + "testing" + + "github.com/getcarina/carina/common" + "github.com/stretchr/testify/assert" +) + +const identityAPIVersion = "/v3/" + +type handler func(w http.ResponseWriter, r *http.Request) + +func identityHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + switch r.RequestURI { + case identityAPIVersion + "/tokens": + fmt.Fprintln(w, `{"access":{"serviceCatalog":[{"endpoints":[{"tenantId":"963451","publicURL":"https:\/\/example.com:9511","region":"RegionOne"}],"name":"cloudContainer","type":"container-infra"}],"user":{"name":"fake-user","id":"fake-userid"},"token":{"expires":"3000-01-01T12:00:00Z","id":"fake-token","tenant":{"name":"fake-tenantname","id":"fake-tenantid"}}}}`) + default: + w.WriteHeader(404) + fmt.Fprintln(w, "unexpected request: "+r.RequestURI) + } +} + +func createMockCarina(h handler) (*httptest.Server, *httptest.Server) { + return httptest.NewServer(http.HandlerFunc(h)), httptest.NewServer(http.HandlerFunc(identityHandler)) +} + +func createMagnumService(identityServer *httptest.Server, carinaServer *httptest.Server) *Magnum { + acct := &Account{ + AuthEndpoint: identityServer.URL + identityAPIVersion, + EndpointOverride: carinaServer.URL, + UserName: "fake-user", + Password: "fake-password", + Domain: "Default", + Project: "Default", + Region: "RegionOne", + } + + return &Magnum{Account: acct} +} + +func TestGopherCloudIdentityV3ErrorHandlingWorkaround(t *testing.T) { + common.Log.RegisterTestLogger(t) + + acct := &Account{ + AuthEndpoint: "bork://example.com" + identityAPIVersion, + UserName: "fake-user", + Password: "fake-password", + Domain: "Default", + Project: "Default", + Region: "RegionOne", + } + + svc := &Magnum{Account: acct} + + _, err := svc.ListClusters() + + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "unsupported protocol scheme") +} \ No newline at end of file