use std attr description for the segment extension

With the work done in [1], [2] and [3], we should be able to normalize
the description for segments by relying on that from the
standardattrdescription description.

This patch removes the 'description' from the segment extension's
attribute map as well as adds the standard attribute description and
shim extension in [1] as required extensions to ensure the description
is in fact added. Also the UTs are updated to inject the std attr
description into the segment API attributes for testing and no longer
test that description can be None (not supported with std attr
description).

Additional work is needed to close up the partial bug herein:
- Updating the segment API def/ref in neutron-lib.
- Consuming the former in neutron so that the segment extension uses
the API from neutron-lib.

[1] https://review.openstack.org/#/c/562320/
[2] https://review.openstack.org/#/c/558318/
[3] https://review.openstack.org/#/c/562345/

Change-Id: I693222b7041f4f6f7f6a1096a22727a66364636a
Partial-Bug: 1757513
This commit is contained in:
Boden R 2018-05-30 13:50:42 -06:00
parent fab6bcbdcd
commit cb0782ce61
2 changed files with 15 additions and 13 deletions

View File

@ -25,6 +25,8 @@ import six
from neutron.api import extensions
from neutron.api.v2 import base
from neutron.extensions import _standard_attr_segment_lib as stdattrseg_apidef
from neutron.extensions import standardattrdescription as ext_stddesc
SEGMENT = 'segment'
SEGMENTS = '%ss' % SEGMENT
@ -73,12 +75,7 @@ RESOURCE_ATTRIBUTE_MAP = {
'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED,
'validate': {'type:string_or_none': NAME_LEN},
'is_visible': True},
'description': {'allow_post': True,
'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED,
'validate': {'type:string_or_none': DESC_LEN},
'is_visible': True},
'is_visible': True}
},
subnet_def.COLLECTION_NAME: {
SEGMENT_ID: {'allow_post': True,
@ -134,6 +131,10 @@ class Segment(api_extensions.ExtensionDescriptor):
else:
return {}
def get_required_extensions(self):
return [ext_stddesc.Standardattrdescription.get_alias(),
stdattrseg_apidef.ALIAS]
@six.add_metaclass(abc.ABCMeta)
class SegmentPluginBase(object):

View File

@ -42,6 +42,7 @@ from neutron.db import db_base_plugin_v2
from neutron.db import portbindings_db
from neutron.db import segments_db
from neutron.extensions import segment as ext_segment
from neutron.extensions import standardattrdescription as ext_stddesc
from neutron.objects import network
from neutron.services.segments import db
from neutron.services.segments import exceptions as segment_exc
@ -62,6 +63,8 @@ HTTP_NOT_FOUND = 404
class SegmentTestExtensionManager(object):
def get_resources(self):
ext_segment.Segment().update_attributes_map(
{ext_segment.SEGMENTS: ext_stddesc.DESCRIPTION_BODY})
return ext_segment.Segment.get_resources()
def get_actions(self):
@ -161,14 +164,14 @@ class TestSegmentNameDescription(SegmentTestCase):
continue
d.setdefault('network_id', self.network['id'])
d.setdefault('name', None)
d.setdefault('description', None)
d.setdefault('description', 'desc')
d.setdefault('physical_network', 'phys_net')
d.setdefault('network_type', 'net_type')
d.setdefault('segmentation_id', 200)
return super(TestSegmentNameDescription, self)._test_create_segment(
expected, **kwargs)
def test_create_segment_no_name_description(self):
def test_create_segment_no_name(self):
self._test_create_segment(expected={})
def test_create_segment_with_name(self):
@ -209,11 +212,9 @@ class TestSegmentNameDescription(SegmentTestCase):
def test_update_segment_set_description_to_none(self):
segment = self._test_create_segment(
description='A segment', name='segment')
result = self._update('segments',
segment['segment']['id'],
{'segment': {'description': None}},
expected_code=webob.exc.HTTPOk.code)
self.assertIsNone(result['segment']['description'])
self._update('segments', segment['segment']['id'],
{'segment': {'description': None}},
expected_code=webob.exc.HTTPBadRequest.code)
class TestSegment(SegmentTestCase):