From d260bcdec99a2b49396e1132e48fb505e163581e Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 6 Jan 2015 05:56:25 +0000 Subject: [PATCH] Fix v2.1 os-tenant-networks/networks API Ied70ab493982896cd974bb5a98ca92d95352e80f has changed neutronapi values to objects from bare dicts, and has changed v2.0 API code to handle objects. However it didn't change v2.1 API code and v2.1 API is broken now. This patch applies the above commit to v2.1 API. Closes-Bug: #1407885 Change-Id: Ieedbd2cc394a3d0ae99be115987377509f6841c9 --- nova/api/openstack/compute/plugins/v3/networks.py | 12 ++++++++---- .../openstack/compute/plugins/v3/tenant_networks.py | 9 ++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/nova/api/openstack/compute/plugins/v3/networks.py b/nova/api/openstack/compute/plugins/v3/networks.py index a3c823feb3db..f509cc4e1cac 100644 --- a/nova/api/openstack/compute/plugins/v3/networks.py +++ b/nova/api/openstack/compute/plugins/v3/networks.py @@ -47,7 +47,7 @@ def network_dict(context, network): if context.is_admin: fields += admin_fields # TODO(mriedem): Remove the NovaObject type check once the - # neutronv2 API is returning Network objects from get/get_all. + # network.create API is returning objects. is_obj = isinstance(network, base_obj.NovaObject) result = {} for field in fields: @@ -56,14 +56,18 @@ def network_dict(context, network): # before the objects conversion. if is_obj and isinstance(network.fields[field].AUTO_TYPE, obj_fields.IPAddress): - val = network.get(field) + # NOTE(danms): Here, network should be an object, which could + # have come from neutron and thus be missing most of the + # attributes. Providing a default to get() avoids trying to + # lazy-load missing attributes. + val = network.get(field, None) if val is not None: - result[field] = str(network.get(field)) + result[field] = str(val) else: result[field] = val else: # It's either not an object or it's not an IPAddress field. - result[field] = network.get(field) + result[field] = network.get(field, None) uuid = network.get('uuid') if uuid: result['id'] = uuid diff --git a/nova/api/openstack/compute/plugins/v3/tenant_networks.py b/nova/api/openstack/compute/plugins/v3/tenant_networks.py index 0261cedb075b..1218cbd16a18 100644 --- a/nova/api/openstack/compute/plugins/v3/tenant_networks.py +++ b/nova/api/openstack/compute/plugins/v3/tenant_networks.py @@ -50,9 +50,12 @@ authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS) def network_dict(network): - return {"id": network.get("uuid") or network.get("id"), - "cidr": str(network.get("cidr")), - "label": network.get("label")} + # NOTE(danms): Here, network should be an object, which could have come + # from neutron and thus be missing most of the attributes. Providing a + # default to get() avoids trying to lazy-load missing attributes. + return {"id": network.get("uuid", None) or network.get("id", None), + "cidr": str(network.get("cidr", None)), + "label": network.get("label", None)} class TenantNetworkController(wsgi.Controller):