Added tests for volume linked to compute.
This commit is contained in:
parent
c45cf7e1a9
commit
79d3fce5b6
|
@ -30,7 +30,9 @@ tenants = {
|
|||
"foo": {"id": uuid.uuid4().hex,
|
||||
"name": "foo"},
|
||||
"bar": {"id": uuid.uuid4().hex,
|
||||
"name": "bar"}
|
||||
"name": "bar"},
|
||||
"baz": {"id": uuid.uuid4().hex,
|
||||
"name": "baz"},
|
||||
}
|
||||
|
||||
flavors = {
|
||||
|
@ -61,6 +63,38 @@ images = {
|
|||
}
|
||||
}
|
||||
|
||||
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"]: [
|
||||
{
|
||||
|
@ -86,30 +120,18 @@ servers = {
|
|||
},
|
||||
],
|
||||
tenants["bar"]["id"]: [],
|
||||
}
|
||||
|
||||
volumes = {
|
||||
tenants["foo"]["id"]: [
|
||||
tenants["baz"]["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",
|
||||
"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"]: [],
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -194,6 +194,24 @@ class TestComputeController(test_middleware.TestMiddleware):
|
|||
self.assertEqual(400, resp.status_code)
|
||||
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):
|
||||
|
|
|
@ -53,6 +53,20 @@ class TestMiddleware(base.TestCase):
|
|||
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
|
||||
|
@ -109,3 +123,15 @@ class TestMiddlewareTextOcci(TestMiddleware):
|
|||
|
||||
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)
|
||||
|
|
|
@ -20,6 +20,7 @@ import mock
|
|||
|
||||
from ooi.tests import fakes
|
||||
from ooi.tests.middleware import test_middleware
|
||||
from ooi import utils
|
||||
|
||||
|
||||
def build_occi_volume(vol):
|
||||
|
@ -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:
|
||||
|
@ -76,8 +87,6 @@ class TestStorageController(test_middleware.TestMiddleware):
|
|||
|
||||
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)
|
||||
|
@ -91,12 +100,13 @@ class TestStorageController(test_middleware.TestMiddleware):
|
|||
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue