# Path: f5lbaasdriver/v2/bigip/driver_v2.py
# class F5DriverV2(object):
#     u"""F5 Networks® LBaaSv2 Driver."""
# 
#     def __init__(self, plugin=None, env=None):
#         """Driver initialization."""
#         if not plugin:
#             LOG.error('Required LBaaS Driver and Core Driver Missing')
#             sys.exit(1)
# 
#         self.plugin = plugin
#         self.env = env
# 
#         self.loadbalancer = LoadBalancerManager(self)
#         self.listener = ListenerManager(self)
#         self.pool = PoolManager(self)
#         self.member = MemberManager(self)
#         self.healthmonitor = HealthMonitorManager(self)
#         self.l7policy = L7PolicyManager(self)
#         self.l7rule = L7RuleManager(self)
# 
#         self.unlegacy_setting_placeholder_driver_side = \
#             cfg.CONF.unlegacy_setting_placeholder_driver_side
# 
#         # what scheduler to use for pool selection
#         self.scheduler = importutils.import_object(
#             cfg.CONF.f5_loadbalancer_pool_scheduler_driver_v2)
# 
#         self.service_builder = importutils.import_object(
#             cfg.CONF.f5_loadbalancer_service_builder_v2, self)
# 
#         self.agent_rpc = agent_rpc.LBaaSv2AgentRPC(self)
#         self.plugin_rpc = plugin_rpc.LBaaSv2PluginCallbacksRPC(self)
# 
#         self.q_client = \
#             neutron_client.F5NetworksNeutronClient(self.plugin)
# 
#         # add this agent RPC to the neutron agent scheduler
#         # mixins agent_notifiers dictionary for it's env
#         self.plugin.agent_notifiers.update(
#             {q_const.AGENT_TYPE_LOADBALANCER: self.agent_rpc})
# 
#         registry.subscribe(self._bindRegistryCallback(),
#                            resources.PROCESS,
#                            events.AFTER_INIT)
# 
#     def _bindRegistryCallback(self):
#         # Defines a callback function with name tied to driver env. Need to
#         # enusre unique name, as registry callback manager references callback
#         # functions by name.
#         def post_fork_callback(resources, event, trigger):
#             LOG.debug("F5DriverV2 with env %s received post neutron child "
#                       "fork notification pid(%d) print trigger(%s)" % (
#                           self.env, os.getpid(), trigger))
#             self.plugin_rpc.create_rpc_listener()
# 
#         post_fork_callback.__name__ += '_' + str(self.env)
#         return post_fork_callback
# 
#     def _handle_driver_error(self, context, loadbalancer,
#                              loadbalancer_id, status):
#         pass


import mock
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from f5lbaasdriver.v2.bigip.driver_v2 import F5DriverV2
# limitations under the License.





@mock.patch('f5lbaasdriver.v2.bigip.agent_rpc.LBaaSv2AgentRPC')
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

# Path: f5lbaasdriver/v2/bigip/driver_v2.py
# class F5DriverV2(object):
#     u"""F5 Networks® LBaaSv2 Driver."""
# 
#     def __init__(self, plugin=None, env=None):
#         """Driver initialization."""
#         if not plugin:
#             LOG.error('Required LBaaS Driver and Core Driver Missing')
#             sys.exit(1)
# 
#         self.plugin = plugin
#         self.env = env
# 
#         self.loadbalancer = LoadBalancerManager(self)
#         self.listener = ListenerManager(self)
#         self.pool = PoolManager(self)
#         self.member = MemberManager(self)
#         self.healthmonitor = HealthMonitorManager(self)
#         self.l7policy = L7PolicyManager(self)
#         self.l7rule = L7RuleManager(self)
# 
#         self.unlegacy_setting_placeholder_driver_side = \
#             cfg.CONF.unlegacy_setting_placeholder_driver_side
# 
#         # what scheduler to use for pool selection
#         self.scheduler = importutils.import_object(
#             cfg.CONF.f5_loadbalancer_pool_scheduler_driver_v2)
# 
#         self.service_builder = importutils.import_object(
#             cfg.CONF.f5_loadbalancer_service_builder_v2, self)
# 
#         self.agent_rpc = agent_rpc.LBaaSv2AgentRPC(self)
#         self.plugin_rpc = plugin_rpc.LBaaSv2PluginCallbacksRPC(self)
# 
#         self.q_client = \
#             neutron_client.F5NetworksNeutronClient(self.plugin)
# 
#         # add this agent RPC to the neutron agent scheduler
#         # mixins agent_notifiers dictionary for it's env
#         self.plugin.agent_notifiers.update(
#             {q_const.AGENT_TYPE_LOADBALANCER: self.agent_rpc})
# 
#         registry.subscribe(self._bindRegistryCallback(),
#                            resources.PROCESS,
#                            events.AFTER_INIT)
# 
#     def _bindRegistryCallback(self):
#         # Defines a callback function with name tied to driver env. Need to
#         # enusre unique name, as registry callback manager references callback
#         # functions by name.
#         def post_fork_callback(resources, event, trigger):
#             LOG.debug("F5DriverV2 with env %s received post neutron child "
#                       "fork notification pid(%d) print trigger(%s)" % (
#                           self.env, os.getpid(), trigger))
#             self.plugin_rpc.create_rpc_listener()
# 
#         post_fork_callback.__name__ += '_' + str(self.env)
#         return post_fork_callback
# 
#     def _handle_driver_error(self, context, loadbalancer,
#                              loadbalancer_id, status):
#         pass


# Path: test/functional/test_registry_callback.py
import mock
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from f5lbaasdriver.v2.bigip.driver_v2 import F5DriverV2

# limitations under the License.





@mock.patch('f5lbaasdriver.v2.bigip.agent_rpc.LBaaSv2AgentRPC')
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')