From 4d84c10ba4430752bf8c1227c770fb3c4f0a1618 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Mon, 2 Apr 2018 23:11:38 +0000 Subject: [PATCH] Add standard attributes to segment resource Standard attributes (i.e. revision_number, created_at, updated_at) are missing in the segment resource. This is because the controller doesn't process extensions on rendering the response. This patch fixes it. In particular, this patch does the following: * Process extensions when making the segment dict. This allows other extensions to add attributes to segment response. * Make segment extension implement update_attributes_map. Tempest test: https://review.openstack.org/#/c/558609/ APIImpact update api reference of segments Closes-Bug: #1760902 Change-Id: I3c93818002c2d7753454547231ba08544b6fa1c0 --- neutron/extensions/segment.py | 4 ++++ neutron/services/segments/db.py | 2 ++ ...add-standard-attributes-to-segment-d39c4b89988aa701.yaml | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 releasenotes/notes/add-standard-attributes-to-segment-d39c4b89988aa701.yaml diff --git a/neutron/extensions/segment.py b/neutron/extensions/segment.py index 0eb19f4f3be..e0eb49358c9 100644 --- a/neutron/extensions/segment.py +++ b/neutron/extensions/segment.py @@ -122,6 +122,10 @@ class Segment(api_extensions.ExtensionDescriptor): controller, attr_map=resource_attributes)] + def update_attributes_map(self, attributes): + super(Segment, self).update_attributes_map( + attributes, extension_attrs_map=RESOURCE_ATTRIBUTE_MAP) + def get_extended_resources(self, version): if version == "2.0": return RESOURCE_ATTRIBUTE_MAP diff --git a/neutron/services/segments/db.py b/neutron/services/segments/db.py index a2ff5bc8748..2eed58da287 100644 --- a/neutron/services/segments/db.py +++ b/neutron/services/segments/db.py @@ -25,6 +25,7 @@ from oslo_db import exception as db_exc from oslo_log import helpers as log_helpers from oslo_utils import uuidutils +from neutron.db import _resource_extend as resource_extend from neutron.db import _utils as db_utils from neutron.db import api as db_api from neutron.db import common_db_mixin @@ -50,6 +51,7 @@ class SegmentDbMixin(common_db_mixin.CommonDbMixin): db.SEGMENTATION_ID: segment_obj[db.SEGMENTATION_ID], 'hosts': segment_obj['hosts'], 'segment_index': segment_obj['segment_index']} + resource_extend.apply_funcs('segments', res, segment_obj.db_obj) return db_utils.resource_fields(res, fields) def _get_segment(self, context, segment_id): diff --git a/releasenotes/notes/add-standard-attributes-to-segment-d39c4b89988aa701.yaml b/releasenotes/notes/add-standard-attributes-to-segment-d39c4b89988aa701.yaml new file mode 100644 index 00000000000..ebab2136a98 --- /dev/null +++ b/releasenotes/notes/add-standard-attributes-to-segment-d39c4b89988aa701.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fix an issue that standard attributes, such as ``created_at``, + ``updated_at`` and ``revision_number``, are not rendered in the response + of segment resource.