コード例 #1
0
 def test_router_delete_event_exception_preserved(self):
     super(L3CfgAgentRouterApplianceTestCase,
           self).test_router_delete_event_exception_preserved()
     registry.clear()
コード例 #2
0
def test_neutron_registry_callback(mock_agent_rpc):
    """Test callback functions used for registering for RPC events in driver.

    Creates two drivers to simulate a differentiated environment
    deployment, then tests that each driver registers different functions
    to receive notification from Neutron after subscribing for events, and
    that the functions are called by the Neutron callback manager.

    Also, see related unit test,
    f5lbaasdriver/v2/bigip/test/test_bind_registry_callback.py

    :param mock_agent_rpc: Not used. Mock needed to create F5DriverV2.
    """
    plugin = mock.MagicMock()

    # start with empty Neutron RPC callback registry
    registry.clear()

    # create default driver
    default_driver = F5DriverV2(plugin)
    default_driver.plugin_rpc = mock.MagicMock()

    # create a differentiated environment driver
    dmz_driver = F5DriverV2(plugin, 'dmz')
    dmz_driver.plugin_rpc = mock.MagicMock()

    default_callback_func = default_driver._bindRegistryCallback()
    dmz_callback_func = dmz_driver._bindRegistryCallback()

    # two different callback functions created
    assert default_callback_func != dmz_callback_func

    # registry holds two callbacks
    callback_mgr = registry._get_callback_manager()
    assert len(
        callback_mgr._callbacks[resources.PROCESS][events.AFTER_CREATE]) == 2

    # both callbacks are in registry
    callbacks = callback_mgr._callbacks[resources.PROCESS][events.AFTER_CREATE]
    callback_iter = iter(callbacks)

    callback_name = next(callback_iter).split('.')[-1]
    assert callback_name == default_callback_func.__name__

    callback_name = next(callback_iter).split('.')[-1]
    assert callback_name == dmz_callback_func.__name__

    # callbacks can be called back
    with mock.patch('f5lbaasdriver.v2.bigip.driver_v2.LOG') as mock_log:
        # invoke callbacks from callback manager
        callback_mgr.notify(
            resources.PROCESS, events.AFTER_CREATE, mock.MagicMock())

        # create_rpc_listener called
        assert default_driver.plugin_rpc.create_rpc_listener.called
        assert dmz_driver.plugin_rpc.create_rpc_listener.called

        # debug messages logged
        log_iter = iter(mock_log.debug.call_args_list)
        args, kwargs = log_iter.next()
        assert str(args[0]).startswith("F5DriverV2 with env None received")

        args, kwargs = log_iter.next()
        assert str(args[0]).startswith("F5DriverV2 with env dmz received")
コード例 #3
0
def test_neutron_registry_callback(mock_agent_rpc):
    """Test callback functions used for registering for RPC events in driver.

    Creates two drivers to simulate a differentiated environment
    deployment, then tests that each driver registers different functions
    to receive notification from Neutron after subscribing for events, and
    that the functions are called by the Neutron callback manager.

    Also, see related unit test,
    f5lbaasdriver/v2/bigip/test/test_bind_registry_callback.py

    :param mock_agent_rpc: Not used. Mock needed to create F5DriverV2.
    """
    plugin = mock.MagicMock()

    # start with empty Neutron RPC callback registry
    registry.clear()

    # create default driver
    default_driver = F5DriverV2(plugin)
    default_driver.plugin_rpc = mock.MagicMock()

    # create a differentiated environment driver
    dmz_driver = F5DriverV2(plugin, 'dmz')
    dmz_driver.plugin_rpc = mock.MagicMock()

    default_callback_func = default_driver._bindRegistryCallback()
    dmz_callback_func = dmz_driver._bindRegistryCallback()

    # two different callback functions created
    assert default_callback_func != dmz_callback_func

    # registry holds two callbacks
    callback_mgr = registry._get_callback_manager()
    assert len(
        callback_mgr._callbacks[resources.PROCESS][events.AFTER_CREATE]) == 2

    # both callbacks are in registry
    callbacks = callback_mgr._callbacks[resources.PROCESS][events.AFTER_CREATE]
    callback_iter = iter(callbacks)

    callback_name = next(callback_iter).split('.')[-1]
    assert callback_name == default_callback_func.__name__

    callback_name = next(callback_iter).split('.')[-1]
    assert callback_name == dmz_callback_func.__name__

    # callbacks can be called back
    with mock.patch('f5lbaasdriver.v2.bigip.driver_v2.LOG') as mock_log:
        # invoke callbacks from callback manager
        callback_mgr.notify(resources.PROCESS, events.AFTER_CREATE,
                            mock.MagicMock())

        # create_rpc_listener called
        assert default_driver.plugin_rpc.create_rpc_listener.called
        assert dmz_driver.plugin_rpc.create_rpc_listener.called

        # debug messages logged
        log_iter = iter(mock_log.debug.call_args_list)
        args, kwargs = log_iter.next()
        assert str(args[0]).startswith("F5DriverV2 with env None received")

        args, kwargs = log_iter.next()
        assert str(args[0]).startswith("F5DriverV2 with env dmz received")
 def test_router_delete_event_exception_preserved(self):
     super(L3CfgAgentRouterApplianceTestCase,
           self).test_router_delete_event_exception_preserved()
     registry.clear()