Operations on paths that are not resources must end with /

According to OCCI specification, operations on paths that are not
resource instances or location paths, the path must end with "/". We
need to add the rule manually, since otherwise routes will strip out all
the slashes when generating the resources rules.
This commit is contained in:
Alvaro Lopez Garcia 2015-04-17 14:17:31 +02:00
parent b52984db6c
commit a44c086d55
3 changed files with 59 additions and 39 deletions

View File

@ -93,36 +93,39 @@ class TestComputeController(test_middleware.TestMiddleware):
tenant = fakes.tenants["bar"]
app = self.get_app()
req = self._build_req("/compute", tenant["id"], method="GET")
for url in ("/compute/", "/compute"):
req = self._build_req(url, tenant["id"], method="GET")
m = mock.MagicMock()
m.user.project_id = tenant["id"]
req.environ["keystone.token_auth"] = m
m = mock.MagicMock()
m.user.project_id = tenant["id"]
req.environ["keystone.token_auth"] = m
resp = req.get_response(app)
resp = req.get_response(app)
expected_result = ""
self.assertDefaults(resp)
self.assertExpectedResult(expected_result, resp)
self.assertEqual(204, resp.status_code)
expected_result = ""
self.assertDefaults(resp)
self.assertExpectedResult(expected_result, resp)
self.assertEqual(204, resp.status_code)
def test_list_vms(self):
tenant = fakes.tenants["foo"]
app = self.get_app()
req = self._build_req("/compute", tenant["id"], method="GET")
for url in ("/compute/", "/compute"):
req = self._build_req(url, tenant["id"], method="GET")
resp = req.get_response(app)
resp = req.get_response(app)
self.assertEqual(200, resp.status_code)
expected = []
for s in fakes.servers[tenant["id"]]:
expected.append(
("X-OCCI-Location", utils.join_url(self.application_url + "/",
"compute/%s" % s["id"]))
)
self.assertDefaults(resp)
self.assertExpectedResult(expected, resp)
self.assertEqual(200, resp.status_code)
expected = []
for s in fakes.servers[tenant["id"]]:
expected.append(
("X-OCCI-Location",
utils.join_url(self.application_url + "/",
"compute/%s" % s["id"]))
)
self.assertDefaults(resp)
self.assertExpectedResult(expected, resp)
def test_show_vm(self):
tenant = fakes.tenants["foo"]

View File

@ -79,35 +79,38 @@ class TestStorageController(test_middleware.TestMiddleware):
tenant = fakes.tenants["bar"]
app = self.get_app()
req = self._build_req("/storage", tenant["id"], method="GET")
for url in ("/storage/", "/storage"):
req = self._build_req(url, tenant["id"], method="GET")
m = mock.MagicMock()
m.user.project_id = tenant["id"]
req.environ["keystone.token_auth"] = m
m = mock.MagicMock()
m.user.project_id = tenant["id"]
req.environ["keystone.token_auth"] = m
resp = req.get_response(app)
resp = req.get_response(app)
expected_result = ""
self.assertContentType(resp)
self.assertExpectedResult(expected_result, resp)
self.assertEqual(204, resp.status_code)
expected_result = ""
self.assertContentType(resp)
self.assertExpectedResult(expected_result, resp)
self.assertEqual(204, resp.status_code)
def test_list_vols(self):
tenant = fakes.tenants["foo"]
app = self.get_app()
req = self._build_req("/storage", tenant["id"], method="GET")
for url in ("/storage/", "/storage"):
req = self._build_req(url, tenant["id"], method="GET")
resp = req.get_response(app)
resp = req.get_response(app)
self.assertEqual(200, resp.status_code)
expected = []
for s in fakes.volumes[tenant["id"]]:
expected.append(
("X-OCCI-Location", utils.join_url(self.application_url + "/",
"storage/%s" % s["id"]))
)
self.assertExpectedResult(expected, resp)
self.assertEqual(200, resp.status_code)
expected = []
for s in fakes.volumes[tenant["id"]]:
expected.append(
("X-OCCI-Location",
utils.join_url(self.application_url + "/",
"storage/%s" % s["id"]))
)
self.assertExpectedResult(expected, resp)
def test_show_vol(self):
tenant = fakes.tenants["foo"]

View File

@ -145,6 +145,13 @@ class OCCIMiddleware(object):
ooi.api.compute.Controller)
self.mapper.resource("server", "compute",
controller=self.resources["compute"])
# OCCI states that paths must end with a "/" when operating on pahts,
# that are not location pahts or resource instances, so we should add
# this rule manually
self.mapper.connect("compute", "/compute/",
controller=self.resources["compute"],
action="index",
conditions=dict(method=["GET"]))
self.mapper.connect("compute", "/compute/",
controller=self.resources["compute"],
action="delete_all",
@ -154,6 +161,13 @@ class OCCIMiddleware(object):
ooi.api.storage.Controller)
self.mapper.resource("volume", "storage",
controller=self.resources["storage"])
# OCCI states that paths must end with a "/" when operating on pahts,
# that are not location pahts or resource instances, so we should add
# this rule manually
self.mapper.connect("storage", "/storage/",
controller=self.resources["storage"],
action="index",
conditions=dict(method=["GET"]))
@webob.dec.wsgify(RequestClass=Request)
def __call__(self, req):