Do not crash on volume attachments without device
Sometimes OpenStack does not return any device in the attached volumes, this change avoids a KeyError when not defined. Change-Id: If96fa02a7d6fd93e31667b2481943c6294173f72 Closes-Bug: #1663491
This commit is contained in:
parent
bb194c3e8e
commit
a8cfcb58e8
|
@ -268,7 +268,8 @@ class Controller(ooi.api.base.Controller):
|
|||
for v in vols:
|
||||
st = storage.StorageResource(title="storage", id=v["volumeId"])
|
||||
comp.add_link(storage_link.StorageLink(comp, st,
|
||||
deviceid=v["device"]))
|
||||
deviceid=v.get("device",
|
||||
None)))
|
||||
|
||||
# network links
|
||||
addresses = s.get("addresses", {})
|
||||
|
|
|
@ -40,7 +40,8 @@ class Controller(base.Controller):
|
|||
id=attach["serverId"])
|
||||
s = storage.StorageResource(title="Storage", id=v["id"])
|
||||
l = storage_link.StorageLink(c, s,
|
||||
deviceid=attach["device"])
|
||||
deviceid=attach.get("device",
|
||||
None))
|
||||
occi_link_resources.append(l)
|
||||
|
||||
return collection.Collection(resources=occi_link_resources)
|
||||
|
@ -61,7 +62,7 @@ class Controller(base.Controller):
|
|||
v = self._get_attachment_from_id(req, id)
|
||||
c = compute.ComputeResource(title="Compute", id=v["serverId"])
|
||||
s = storage.StorageResource(title="Storage", id=v["volumeId"])
|
||||
return storage_link.StorageLink(c, s, deviceid=v["device"])
|
||||
return storage_link.StorageLink(c, s, deviceid=v.get("device", None))
|
||||
|
||||
def create(self, req, body):
|
||||
parser = req.get_parser()(req.headers, req.body)
|
||||
|
|
|
@ -95,6 +95,12 @@ volumes = {
|
|||
"size": 5,
|
||||
"status": "in-use",
|
||||
},
|
||||
{
|
||||
"id": uuid.uuid4().hex,
|
||||
"displayName": "volume-nodev",
|
||||
"size": 6,
|
||||
"status": "in-use",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
@ -213,7 +219,8 @@ servers = {
|
|||
"image": {"id": images["bar"]["id"]},
|
||||
"status": "ACTIVE",
|
||||
"os-extended-volumes:volumes_attached": [
|
||||
{"id": volumes[tenants["baz"]["id"]][0]["id"]}
|
||||
{"id": volumes[tenants["baz"]["id"]][0]["id"]},
|
||||
{"id": volumes[tenants["baz"]["id"]][1]["id"]}
|
||||
],
|
||||
"addresses": {
|
||||
"private": [
|
||||
|
@ -249,6 +256,15 @@ volumes[tenants["baz"]["id"]][0]["attachments"] = [{
|
|||
"id": volumes[tenants["baz"]["id"]][0]["id"],
|
||||
}]
|
||||
|
||||
volumes[tenants["baz"]["id"]][1]["attachments"] = [{
|
||||
"server_id": servers[tenants["baz"]["id"]][0]["id"],
|
||||
"serverId": servers[tenants["baz"]["id"]][0]["id"],
|
||||
"attachment_id": uuid.uuid4().hex,
|
||||
"volumeId": volumes[tenants["baz"]["id"]][1]["id"],
|
||||
"volume_id": volumes[tenants["baz"]["id"]][1]["id"],
|
||||
"id": volumes[tenants["baz"]["id"]][0]["id"],
|
||||
}]
|
||||
|
||||
|
||||
def fake_query_results():
|
||||
cats = []
|
||||
|
|
|
@ -186,8 +186,11 @@ class TestComputeController(base.TestController):
|
|||
flavor = fakes.flavors[server["flavor"]["id"]]
|
||||
image = fakes.images[server["image"]["id"]]
|
||||
volumes = fakes.volumes.get(tenant["id"], [])
|
||||
if volumes:
|
||||
volumes = volumes[0]["attachments"]
|
||||
attachments = []
|
||||
for v in volumes:
|
||||
for att in v["attachments"]:
|
||||
if att["server_id"] == server["id"]:
|
||||
attachments.append(att)
|
||||
net_id = fakes.networks.get(tenant["id"], [])
|
||||
if net_id:
|
||||
net_id = net_id[0]['id']
|
||||
|
@ -195,7 +198,7 @@ class TestComputeController(base.TestController):
|
|||
m_server.return_value = server
|
||||
m_flavor.return_value = flavor
|
||||
m_image.return_value = image
|
||||
m_vol.return_value = volumes
|
||||
m_vol.return_value = attachments
|
||||
|
||||
ret = self.controller.show(None, server["id"])
|
||||
# FIXME(aloga): Should we test the resource?
|
||||
|
|
Loading…
Reference in New Issue