Merge "Initialize modifiable list of resources in CacheBackedPluginApi."

This commit is contained in:
Zuul 2019-08-01 05:50:49 +00:00 committed by Gerrit Code Review
commit 04b96b198e
2 changed files with 41 additions and 17 deletions

View File

@ -200,27 +200,18 @@ class PluginApi(object):
vnic_type=vnic_type, host=host)
def create_cache_for_l2_agent():
"""Create a push-notifications cache for L2 agent related resources."""
objects.register_objects()
resource_types = [
resources.PORT,
resources.SECURITYGROUP,
resources.SECURITYGROUPRULE,
resources.NETWORK,
resources.SUBNET
]
rcache = resource_cache.RemoteResourceCache(resource_types)
rcache.start_watcher()
return rcache
class CacheBackedPluginApi(PluginApi):
RESOURCE_TYPES = [resources.PORT,
resources.SECURITYGROUP,
resources.SECURITYGROUPRULE,
resources.NETWORK,
resources.SUBNET]
def __init__(self, *args, **kwargs):
super(CacheBackedPluginApi, self).__init__(*args, **kwargs)
self.remote_resource_cache = create_cache_for_l2_agent()
self.remote_resource_cache = None
self._create_cache_for_l2_agent()
def register_legacy_notification_callbacks(self, legacy_interface):
"""Emulates the server-side notifications from ml2 AgentNotifierApi.
@ -380,3 +371,10 @@ class CacheBackedPluginApi(PluginApi):
def get_devices_details_list(self, context, devices, agent_id, host=None):
return [self.get_device_details(context, device, agent_id, host)
for device in devices]
def _create_cache_for_l2_agent(self):
"""Create a push-notifications cache for L2 agent related resources."""
objects.register_objects()
rcache = resource_cache.RemoteResourceCache(self.RESOURCE_TYPES)
rcache.start_watcher()
self.remote_resource_cache = rcache

View File

@ -315,3 +315,29 @@ class TestCacheBackedPluginApi(base.BaseTestCase):
self.assertNotIn('port_id', entry)
self.assertNotIn('network_id', entry)
self.assertIn(constants.NO_ACTIVE_BINDING, entry)
@mock.patch('neutron.agent.resource_cache.RemoteResourceCache')
def test_initialization_with_default_resources(self, rcache_class):
rcache_obj = mock.MagicMock()
rcache_class.return_value = rcache_obj
rpc.CacheBackedPluginApi(lib_topics.PLUGIN)
rcache_class.assert_called_once_with(
rpc.CacheBackedPluginApi.RESOURCE_TYPES)
rcache_obj.start_watcher.assert_called_once_with()
@mock.patch('neutron.agent.resource_cache.RemoteResourceCache')
def test_initialization_with_custom_resource(self, rcache_class):
CUSTOM = 'test'
rcache_obj = mock.MagicMock()
rcache_class.return_value = rcache_obj
class CustomCacheBackedPluginApi(rpc.CacheBackedPluginApi):
RESOURCE_TYPES = [resources.PORT, CUSTOM]
CustomCacheBackedPluginApi(lib_topics.PLUGIN)
rcache_class.assert_called_once_with(
CustomCacheBackedPluginApi.RESOURCE_TYPES)
rcache_obj.start_watcher.assert_called_once_with()