Merge "RPC callbacks: add hook to register additional resources"
This commit is contained in:
commit
2256f9a27e
|
@ -10,6 +10,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.objects.logapi import logging_resource as log_object
|
||||
from neutron.objects import network
|
||||
from neutron.objects import ports
|
||||
|
@ -61,6 +62,17 @@ def get_resource_type(resource_cls):
|
|||
return resource_cls.obj_name()
|
||||
|
||||
|
||||
def register_resource_class(resource_cls):
|
||||
resource_type = get_resource_type(resource_cls)
|
||||
if not resource_type:
|
||||
msg = _("cannot find resource type for %s class") % resource_cls
|
||||
raise ValueError(msg)
|
||||
if resource_type not in _TYPE_TO_CLS_MAP:
|
||||
_TYPE_TO_CLS_MAP[resource_type] = resource_cls
|
||||
if resource_type not in LOCAL_RESOURCE_VERSIONS:
|
||||
LOCAL_RESOURCE_VERSIONS[resource_type] = resource_cls.VERSION
|
||||
|
||||
|
||||
def is_valid_resource_type(resource_type):
|
||||
return resource_type in _TYPE_TO_CLS_MAP
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
|
||||
from neutron.api.rpc.callbacks import resources
|
||||
from neutron.objects.qos import policy
|
||||
from neutron.tests import base
|
||||
|
@ -52,3 +54,23 @@ class GetResourceClsTestCase(base.BaseTestCase):
|
|||
|
||||
def test_unknown_type(self):
|
||||
self.assertIsNone(resources.get_resource_cls('unknown-resource-type'))
|
||||
|
||||
|
||||
class RegisterResourceClass(base.BaseTestCase):
|
||||
|
||||
def test_register_resource_class(self):
|
||||
class DummyOVO(obj_base.VersionedObject):
|
||||
pass
|
||||
|
||||
self.assertFalse(
|
||||
resources.is_valid_resource_type('DummyOVO'))
|
||||
resources.register_resource_class(DummyOVO)
|
||||
self.assertTrue(
|
||||
resources.is_valid_resource_type('DummyOVO'))
|
||||
|
||||
def test_register_bogus_resource_class(self):
|
||||
class DummyOVO(object):
|
||||
pass
|
||||
|
||||
self.assertRaises(ValueError,
|
||||
resources.register_resource_class, DummyOVO)
|
||||
|
|
Loading…
Reference in New Issue