Rev 44: goose: make nova compatible with novaservice in http://bazaar.launchpad.net/+branch/goose
John Arbash Meinel
john at arbash-meinel.com
Thu Dec 20 11:09:35 UTC 2012
At http://bazaar.launchpad.net/+branch/goose
------------------------------------------------------------
revno: 44 [merge]
revision-id: john at arbash-meinel.com-20121220110920-4puxwnk1xgkwj6t0
parent: dimiter.naydenov at canonical.com-20121219175106-jrf5ap2q0fwr9qhg
parent: john at arbash-meinel.com-20121220063208-61rchcoqjy4xrr79
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: goose
timestamp: Thu 2012-12-20 11:09:20 +0000
message:
goose: make nova compatible with novaservice
Expose SetupHTTP, since that seems to be how the service is meant to be used.
Change the error classes to not use global state, but instead grab the values
from the new '*Nova' attribute. The static errors won't have one, but that
didn't break any tests. Either the testing is incomplete, or the point where
we rewrap any errors into an actual error is handling it correctly.
Change lbox.check so that we know 'go build ./...' is happy, so we will
be less likely to run into this in the future.
Note that none of the 'local_tests' actually used the nova double, so
having it 'working' is a bit of a misnomer. It just builds, it wasn't
being used anyway.
R=wallyworld
CC=
modified:
.lbox.check lbox.check-20121119075114-1yxgv2cch71gqwmy-1
nova/local_test.go local_test.go-20121211025007-7ef9zfjje8pofkrl-1
testservices/novaservice/service_http.go service_http.go-20121129120146-2t7i4bl19fqu3mnp-4
testservices/novaservice/service_http_test.go service_http_test.go-20121129120146-2t7i4bl19fqu3mnp-5
-------------- next part --------------
=== modified file '.lbox.check'
--- a/.lbox.check 2012-11-19 07:51:15 +0000
+++ b/.lbox.check 2012-12-20 06:29:40 +0000
@@ -8,6 +8,8 @@
echo "gofmt is sad:\n\n$BADFMT"
exit 1
fi
+go build ./...
+
VERSION=`go version | awk '{print $3}'`
if [ $VERSION == 'devel' ]; then
=== modified file 'nova/local_test.go'
--- a/nova/local_test.go 2012-12-11 04:09:12 +0000
+++ b/nova/local_test.go 2012-12-20 06:29:40 +0000
@@ -24,7 +24,7 @@
// The following attributes are for using testing doubles.
httpsuite.HTTPSuite
identityDouble http.Handler
- novaDouble http.Handler
+ novaDouble *novaservice.Nova
}
func (s *localLiveSuite) SetUpSuite(c *C) {
@@ -47,7 +47,9 @@
service := identityservice.Service{"nova", "compute", []identityservice.Endpoint{ep}}
s.identityDouble.(*identityservice.UserPass).AddService(service)
// Create a nova service at the registered endpoint.
- s.novaDouble = novaservice.New("localhost", baseURL+"/", token)
+ // TODO: identityservice.UserPass always uses tenantId="1", patch this
+ // when that changes.
+ s.novaDouble = novaservice.New("localhost", baseURL+"/", token, "1")
s.LiveTests.SetUpSuite(c)
}
@@ -58,7 +60,7 @@
func (s *localLiveSuite) SetUpTest(c *C) {
s.HTTPSuite.SetUpTest(c)
- s.Mux.Handle(baseURL+"/", s.novaDouble)
+ s.novaDouble.SetupHTTP(s.Mux)
s.Mux.Handle("/", s.identityDouble)
s.LiveTests.SetUpTest(c)
}
=== modified file 'testservices/novaservice/service_http.go'
--- a/testservices/novaservice/service_http.go 2012-12-19 17:50:12 +0000
+++ b/testservices/novaservice/service_http.go 2012-12-20 06:32:08 +0000
@@ -21,6 +21,7 @@
body string
contentType string
errorText string
+ nova *Nova
}
// verbatim real Nova responses (as errors).
@@ -38,6 +39,7 @@
`,
"text/plain; charset=UTF-8",
"unauthorized request",
+ nil,
}
errForbidden = &errorResponse{
http.StatusForbidden,
@@ -45,12 +47,14 @@
`flavormanage to be performed.", "code": 403}}`,
"application/json; charset=UTF-8",
"forbidden flavors request",
+ nil,
}
errBadRequest = &errorResponse{
http.StatusBadRequest,
`{"badRequest": {"message": "Malformed request url", "code": 400}}`,
"application/json; charset=UTF-8",
"bad request base path or URL",
+ nil,
}
errBadRequest2 = &errorResponse{
http.StatusBadRequest,
@@ -58,12 +62,14 @@
`request since it is either malformed or otherwise incorrect.", "code": 400}}`,
"application/json; charset=UTF-8",
"bad request URL",
+ nil,
}
errBadRequestSG = &errorResponse{
http.StatusBadRequest,
`{"badRequest": {"message": "Security group id should be integer", "code": 400}}`,
"application/json; charset=UTF-8",
"bad security group id type",
+ nil,
}
errNotFound = &errorResponse{
http.StatusNotFound,
@@ -75,24 +81,28 @@
`,
"text/plain; charset=UTF-8",
"resource not found",
+ nil,
}
errNotFoundJSON = &errorResponse{
http.StatusNotFound,
`{"itemNotFound": {"message": "The resource could not be found.", "code": 404}}`,
"application/json; charset=UTF-8",
"resource not found",
+ nil,
}
errNotFoundJSONSG = &errorResponse{
http.StatusNotFound,
`{"itemNotFound": {"message": "Security group $ID$ not found.", "code": 404}}`,
"application/json; charset=UTF-8",
"",
+ nil,
}
errNotFoundJSONSGR = &errorResponse{
http.StatusNotFound,
`{"itemNotFound": {"message": "Rule ($ID$) not found.", "code": 404}}`,
"application/json; charset=UTF-8",
"security rule not found",
+ nil,
}
errMultipleChoices = &errorResponse{
http.StatusMultipleChoices,
@@ -103,6 +113,7 @@
`[{"href": "$ENDPOINT$$URL$", "rel": "self"}]}]}`,
"application/json",
"multiple URL redirection choices",
+ nil,
}
errNoVersion = &errorResponse{
http.StatusOK,
@@ -110,6 +121,7 @@
`T11:33:21Z", "id": "v2.0", "links": [{"href": "$ENDPOINT$", "rel": "self"}]}]}`,
"application/json",
"no version specified in URL",
+ nil,
}
errVersionsLinks = &errorResponse{
http.StatusOK,
@@ -125,12 +137,14 @@
`"application/vnd.sun.wadl+xml", "rel": "describedby"}]}}`,
"application/json",
"version missing from URL",
+ nil,
}
errNotImplemented = &errorResponse{
http.StatusNotImplemented,
"501 Not Implemented",
"text/plain; charset=UTF-8",
"not implemented",
+ nil,
}
errNoGroupId = &errorResponse{
errorText: "no security group id given",
@@ -141,11 +155,6 @@
return e.errorText
}
-// endpoint returns the current testing server's endpoint URL.
-func endpoint() string {
- return hostname + versionPath + "/"
-}
-
// requestBody returns the body for the error response, replacing
// $ENDPOINT$, $URL$, $ID$, and $ERROR$ in e.body with the values from
// the request.
@@ -153,7 +162,9 @@
url := strings.TrimLeft(r.URL.Path, "/")
body := e.body
if body != "" {
- body = strings.Replace(body, "$ENDPOINT$", endpoint(), -1)
+ if e.nova != nil {
+ body = strings.Replace(body, "$ENDPOINT$", e.nova.endpoint(true, "/"), -1)
+ }
body = strings.Replace(body, "$URL$", url, -1)
body = strings.Replace(body, "$ERROR$", e.Error(), -1)
if slash := strings.LastIndex(url, "/"); slash != -1 {
@@ -206,6 +217,7 @@
`{"internalServerError":{"message":"$ERROR$",code:500}}`,
"application/json",
err.Error(),
+ h.n,
}
}
resp.ServeHTTP(w, r)
@@ -743,7 +755,7 @@
}
// setupHTTP attaches all the needed handlers to provide the HTTP API.
-func (n *Nova) setupHTTP(mux *http.ServeMux) {
+func (n *Nova) SetupHTTP(mux *http.ServeMux) {
handlers := map[string]http.Handler{
"/": n.handler((*Nova).handleRoot),
"/$v/": errBadRequest,
=== modified file 'testservices/novaservice/service_http_test.go'
--- a/testservices/novaservice/service_http_test.go 2012-12-19 16:48:12 +0000
+++ b/testservices/novaservice/service_http_test.go 2012-12-20 06:29:40 +0000
@@ -33,7 +33,7 @@
func (s *NovaHTTPSuite) SetUpTest(c *C) {
s.HTTPSuite.SetUpTest(c)
- s.service.setupHTTP(s.Mux)
+ s.service.SetupHTTP(s.Mux)
}
func (s *NovaHTTPSuite) TearDownTest(c *C) {
More information about the bazaar-commits
mailing list