Skip to content

Commit

Permalink
Added tests for volume linked to compute.
Browse files Browse the repository at this point in the history
  • Loading branch information
enolfc committed Apr 9, 2015
1 parent a20e30a commit e273dbd
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 36 deletions.
64 changes: 43 additions & 21 deletions ooi/tests/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"foo": {"id": uuid.uuid4().hex,
"name": "foo"},
"bar": {"id": uuid.uuid4().hex,
"name": "bar"}
"name": "bar"},
"baz": {"id": uuid.uuid4().hex,
"name": "baz"},
}

flavors = {
Expand Down Expand Up @@ -61,6 +63,38 @@
}
}

volumes = {
tenants["foo"]["id"]: [
{
"id": uuid.uuid4().hex,
"displayName": "foo",
"size": 2,
"status": "in-use",
},
{
"id": uuid.uuid4().hex,
"displayName": "bar",
"size": 3,
"status": "in-use",
},
{
"id": uuid.uuid4().hex,
"displayName": "baz",
"size": 5,
"status": "in-use",
},
],
tenants["bar"]["id"]: [],
tenants["baz"]["id"]: [
{
"id": uuid.uuid4().hex,
"displayName": "volume",
"size": 5,
"status": "in-use",
},
],
}

servers = {
tenants["foo"]["id"]: [
{
Expand All @@ -86,30 +120,18 @@
},
],
tenants["bar"]["id"]: [],
}

volumes = {
tenants["foo"]["id"]: [
{
"id": uuid.uuid4().hex,
"displayName": "foo",
"size": 2,
"status": "in-use",
},
tenants["baz"]["id"]: [
{
"id": uuid.uuid4().hex,
"displayName": "bar",
"size": 3,
"status": "in-use",
},
{
"id": uuid.uuid4().hex,
"displayName": "baz",
"size": 5,
"status": "in-use",
"name": "withvolume",
"flavor": {"id": flavors[1]["id"]},
"image": {"id": images["bar"]["id"]},
"status": "ACTIVE",
"os-extended-volumes:volumes_attached": [
{"id": volumes[tenants["baz"]["id"]][0]["id"]}
]
},
],
tenants["bar"]["id"]: [],
}


Expand Down
18 changes: 18 additions & 0 deletions ooi/tests/middleware/test_compute_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ def test_create_vm(self):
self.assertExpectedResult(expected, resp)
self.assertContentType(resp)

def test_vm_links(self):
tenant = fakes.tenants["baz"]

app = self.get_app()

for server in fakes.servers[tenant["id"]]:
req = self._build_req("/compute/%s" % server["id"],
tenant["id"], method="GET")

resp = req.get_response(app)

vol_id = server["os-extended-volumes:volumes_attached"][0]["id"]
link_id = '_'.join([server["id"], vol_id])

self.assertContentType(resp)
self.assertResultIncludesLink(link_id, server["id"], vol_id, resp)
self.assertEqual(200, resp.status_code)


class ComputeControllerTextPlain(test_middleware.TestMiddlewareTextPlain,
TestComputeController):
Expand Down
26 changes: 26 additions & 0 deletions ooi/tests/middleware/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def assertExpectedResult(self, expected, result):
results = result.text.splitlines()
self.assertItemsEqual(expected, results)

def assertResultIncludesLink(self, link_id, source, target, result):
expected_attrs = set([
'occi.core.source="%s"' % source,
'occi.core.target="%s"' % target,
'occi.core.id="%s"' % link_id,
])
for lines in result.text.splitlines():
r = lines.split(":", 1)
if r[0] == "Link":
attrs = set([s.strip() for s in r[1].split(";")])
if expected_attrs.issubset(attrs):
return
self.fail("Failed to find %s in %s." % expected_attrs, result)

def _build_req(self, path, tenant_id, **kwargs):
if self.accept is not None:
kwargs["accept"] = self.accept
Expand Down Expand Up @@ -103,3 +117,15 @@ def assertExpectedResult(self, expected, result):

def test_correct_accept(self):
self.assertEqual("text/occi", self.accept)

def assertResultIncludesLink(self, link_id, source, target, result):
expected_attrs = set([
'occi.core.source="%s"' % source,
'occi.core.target="%s"' % target,
'occi.core.id="%s"' % link_id,
])
for val in result.headers.getall("Link"):
attrs = set([s.strip() for s in val.split(";")])
if expected_attrs.issubset(attrs):
return
self.fail("Failed to find %s in %s." % expected_attrs, result)
40 changes: 25 additions & 15 deletions ooi/tests/middleware/test_storage_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from ooi.tests import fakes
from ooi.tests.middleware import test_middleware
from ooi import utils


def build_occi_volume(vol):
Expand All @@ -40,16 +41,26 @@ def build_occi_volume(vol):
'occi.core.id="%s"' % vol_id,
]
links = []
links.append('<%s?action=backup>; rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#backup' % vol_id)
links.append('<%s?action=resize>; rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#resize' % vol_id)
links.append('<%s?action=snapshot>; rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#snapshot' % vol_id)
links.append('<%s?action=offline>; rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#offline' % vol_id)
links.append('<%s?action=online>; rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#online' % vol_id)
links.append('<%s/storage/%s?action=backup>; '
'rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#backup' %
(fakes.application_url, vol_id))
links.append('<%s/storage/%s?action=resize>; '
'rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#resize' %
(fakes.application_url, vol_id))
links.append('<%s/storage/%s?action=online>; '
'rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#online' %
(fakes.application_url, vol_id))
links.append('<%s/storage/%s?action=snapshot>; '
'rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#snapshot' %
(fakes.application_url, vol_id))
links.append('<%s/storage/%s?action=offline>; '
'rel=http://schemas.ogf.org/occi/'
'infrastructure/storage/action#offline' %
(fakes.application_url, vol_id))

result = []
for c in cats:
Expand All @@ -76,8 +87,6 @@ def test_list_vols_empty(self):

resp = req.get_response(app)

self.assertEqual("/%s/os-volumes" % tenant["id"], req.path_info)

expected_result = ""
self.assertContentType(resp)
self.assertExpectedResult(expected_result, resp)
Expand All @@ -91,12 +100,13 @@ def test_list_vols(self):

resp = req.get_response(app)

self.assertEqual("/%s/os-volumes" % tenant["id"], req.path_info)

self.assertEqual(200, resp.status_code)
expected = []
for s in fakes.volumes[tenant["id"]]:
expected.append(("X-OCCI-Location", "/storage/%s" % s["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):
Expand Down

0 comments on commit e273dbd

Please sign in to comment.