Add is_extension_supported to neutron_lib
This enables a plugin to determine if a specific extension is enabled. Change-Id: I721cb63e9163304422684d683e62e24de01796be
This commit is contained in:
parent
12c3a82756
commit
232a10d549
@ -17,6 +17,16 @@ import abc
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
|
|
||||||
|
def is_extension_supported(plugin, alias):
|
||||||
|
"""Validate that the extension is supported.
|
||||||
|
|
||||||
|
:param plugin: The plugin class.
|
||||||
|
:param alias: The alias to check.
|
||||||
|
:returns: True if the alias is supported else False.
|
||||||
|
"""
|
||||||
|
return alias in getattr(plugin, "supported_extension_aliases", [])
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class ExtensionDescriptor(object):
|
class ExtensionDescriptor(object):
|
||||||
"""Base class that defines the contract for extensions."""
|
"""Base class that defines the contract for extensions."""
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron_lib.api import extensions
|
from neutron_lib.api import extensions
|
||||||
|
from neutron_lib.services import base as service_base
|
||||||
from neutron_lib.tests import _base as base
|
from neutron_lib.tests import _base as base
|
||||||
|
|
||||||
|
|
||||||
@ -81,3 +82,29 @@ class TestExtensionDescriptor(base.BaseTestCase):
|
|||||||
extension_description.update_attributes_map(self.extended_attributes)
|
extension_description.update_attributes_map(self.extended_attributes)
|
||||||
self.assertEqual(self.extension_attrs_map,
|
self.assertEqual(self.extension_attrs_map,
|
||||||
{'resource_one': {'three': 'third'}})
|
{'resource_one': {'three': 'third'}})
|
||||||
|
|
||||||
|
|
||||||
|
class DummyPlugin(service_base.ServicePluginBase):
|
||||||
|
|
||||||
|
supported_extension_aliases = ['flash']
|
||||||
|
|
||||||
|
def get_plugin_type(self):
|
||||||
|
return 'Flash Gordon'
|
||||||
|
|
||||||
|
def get_plugin_description(self):
|
||||||
|
return 'Legend!'
|
||||||
|
|
||||||
|
|
||||||
|
class TestExtensionIsSupported(base.BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestExtensionIsSupported, self).setUp()
|
||||||
|
self._plugin = DummyPlugin()
|
||||||
|
|
||||||
|
def test_extension_exists(self):
|
||||||
|
self.assertTrue(extensions.is_extension_supported(self._plugin,
|
||||||
|
"flash"))
|
||||||
|
|
||||||
|
def test_extension_does_not_exist(self):
|
||||||
|
self.assertFalse(extensions.is_extension_supported(self._plugin,
|
||||||
|
"gordon"))
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Rehome the validation for checking if an extension is supported by the
|
||||||
|
plugin. The method ``is_extension_supported`` will now be part of
|
||||||
|
``neutron_lib.api.extensions``.
|
Loading…
Reference in New Issue
Block a user