def test_security_group_precommit_create_event_fail(self):
     registry.subscribe(fake_callback, resources.SECURITY_GROUP, events.PRECOMMIT_CREATE)
     with mock.patch.object(sqlalchemy.orm.session.SessionTransaction, "rollback") as mock_rollback:
         self.assertRaises(
             securitygroup.SecurityGroupConflict, self.mixin.create_security_group, self.ctx, FAKE_SECGROUP
         )
         self.assertTrue(mock_rollback.called)
Beispiel #2
0
def register(callback, agent_type):
    """Subscribe callback to init event for the specified agent.

    :param agent_type: an agent type as defined in neutron_lib.constants.
    :param callback: a callback that can process the agent init event.
    """
    registry.subscribe(callback, agent_type, events.AFTER_INIT)
    def subscribe(self):
        # REVISIT(Ryu): Keep an extra set of strong references to the callback
        # methods so that they are not prematurely garbage collected.
        # This hack is required in the Liberty branch (not stable/kilo) because
        # currently the Liberty mechanism driver is expected to work with Kilo
        # ML2 plugin for MidoNet, and in Kilo ML2, there is a bug in which
        # these methods were referenced as weakrefs where a garbage collection
        # could remove these callbacks if they were part of an object.

        self._create_sg_f = self.create_security_group
        self._update_sg_f = self.update_security_group
        self._delete_sg_f = self.delete_security_group
        self._create_sgr_f = self.create_security_group_rule
        self._delete_sgr_f = self.delete_security_group_rule

        registry.subscribe(
            self._create_sg_f, resources.SECURITY_GROUP, events.AFTER_CREATE)
        registry.subscribe(
            self._update_sg_f, resources.SECURITY_GROUP, events.AFTER_UPDATE)
        registry.subscribe(
            self._delete_sg_f, resources.SECURITY_GROUP, events.AFTER_DELETE)
        registry.subscribe(
            self._create_sgr_f, resources.SECURITY_GROUP_RULE,
            events.AFTER_CREATE)
        registry.subscribe(
            self._delete_sgr_f, resources.SECURITY_GROUP_RULE,
            events.AFTER_DELETE)
 def setUp(self):
     super(TestStatusBarriers, self).setUp()
     self.ctx = n_ctx.get_admin_context()
     self.provisioned = mock.Mock()
     self.port = self._make_port()
     registry.subscribe(self.provisioned, resources.PORT,
                        pb.PROVISIONING_COMPLETE)
Beispiel #5
0
def subscribe():
    registry.subscribe(_update_segment_host_mapping_for_agent,
                       resources.AGENT,
                       events.AFTER_CREATE)
    registry.subscribe(_update_segment_host_mapping_for_agent,
                       resources.AGENT,
                       events.AFTER_UPDATE)
Beispiel #6
0
    def __init__(self):
        # FIXME(jamielennox): A notifier is being created for each Controller
        # and each Notifier is handling it's own auth. That means that we are
        # authenticating the exact same thing len(controllers) times. This
        # should be an easy thing to optimize.
        # FIXME(kevinbenton): remove this comment and the one above once the
        # switch to pecan is complete since only one notifier is constructed
        # in the pecan notification hook.
        auth = ks_loading.load_auth_from_conf_options(cfg.CONF, 'nova')

        session = ks_loading.load_session_from_conf_options(
            cfg.CONF,
            'nova',
            auth=auth)

        extensions = [
            ext for ext in nova_client.discover_extensions(NOVA_API_VERSION)
            if ext.name == "server_external_events"]
        self.nclient = nova_client.Client(
            NOVA_API_VERSION,
            session=session,
            region_name=cfg.CONF.nova.region_name,
            endpoint_type=cfg.CONF.nova.endpoint_type,
            extensions=extensions)
        self.batch_notifier = batch_notifier.BatchNotifier(
            cfg.CONF.send_events_interval, self.send_events)

        # register callbacks for events pertaining resources affecting Nova
        callback_resources = (
            resources.FLOATING_IP,
            resources.PORT,
        )
        for resource in callback_resources:
            registry.subscribe(self._send_nova_notification,
                               resource, events.BEFORE_RESPONSE)
Beispiel #7
0
    def __init__(self):
        auth = ks_loading.load_auth_from_conf_options(cfg.CONF, 'nova')

        session = ks_loading.load_session_from_conf_options(
            cfg.CONF,
            'nova',
            auth=auth)

        extensions = [
            ext for ext in nova_client.discover_extensions(NOVA_API_VERSION)
            if ext.name == "server_external_events"]
        self.nclient = nova_client.Client(
            NOVA_API_VERSION,
            session=session,
            region_name=cfg.CONF.nova.region_name,
            endpoint_type=cfg.CONF.nova.endpoint_type,
            extensions=extensions)
        self.batch_notifier = batch_notifier.BatchNotifier(
            cfg.CONF.send_events_interval, self.send_events)

        # register callbacks for events pertaining resources affecting Nova
        callback_resources = (
            resources.FLOATING_IP,
            resources.PORT,
        )
        for resource in callback_resources:
            registry.subscribe(self._send_nova_notification,
                               resource, events.BEFORE_RESPONSE)
Beispiel #8
0
 def __init__(self, l3_agent):
     self.metadata_port = l3_agent.conf.metadata_port
     self.metadata_access_mark = l3_agent.conf.metadata_access_mark
     registry.subscribe(
         after_router_added, resources.ROUTER, events.AFTER_CREATE)
     registry.subscribe(
         before_router_removed, resources.ROUTER, events.BEFORE_DELETE)
    def setup_sg_rpc_callbacks(self):
        # following way to register call back functions start in kilo
        self._create_sg_f = self.bsn_create_sg_callback
        self._delete_sg_f = self.bsn_delete_sg_callback
        self._update_sg_f = self.bsn_update_sg_callback
        self._create_sg_rule_f = self.bsn_create_sg_rule_callback
        self._delete_sg_rule_f = self.bsn_delete_sg_rule_callback
        registry.subscribe(self._create_sg_f,
                           resources.SECURITY_GROUP, events.AFTER_CREATE)
        registry.subscribe(self._delete_sg_f,
                           resources.SECURITY_GROUP, events.AFTER_DELETE)
        registry.subscribe(self._update_sg_f,
                           resources.SECURITY_GROUP, events.AFTER_UPDATE)
        registry.subscribe(self._create_sg_rule_f,
                           resources.SECURITY_GROUP_RULE, events.AFTER_CREATE)
        registry.subscribe(self._delete_sg_rule_f,
                           resources.SECURITY_GROUP_RULE, events.AFTER_DELETE)

        # the above does not cover the cases where security groups are
        # initially created or when they are deleted since those actions
        # aren't needed by the L2 agent. In order to receive those, we
        # subscribe to the notifications topic that receives all of the
        # API create/update/delete events.
        # Notifications are published at the 'info' level so they will result
        # in a call to the 'info' function below. From there we can check
        # the event type and determine what to do from there.
        target = oslo_messaging.Target(topic='#',
                                       server=cfg.CONF.host)
        keystone_target = oslo_messaging.Target(
             topic='#', exchange='keystone', server=cfg.CONF.host)
        self.listener = oslo_messaging.get_notification_listener(
            n_rpc.TRANSPORT, [target, keystone_target], [self],
            executor='eventlet', allow_requeue=False)
        self.listener.start()
Beispiel #10
0
    def setup_sg_rpc_callbacks(self):
        # following way to register call back functions start in kilo
        self._create_sg_f = self.bsn_create_sg_callback
        self._delete_sg_f = self.bsn_delete_sg_callback
        self._update_sg_f = self.bsn_update_sg_callback
        self._create_sg_rule_f = self.bsn_create_sg_rule_callback
        self._delete_sg_rule_f = self.bsn_delete_sg_rule_callback
        registry.subscribe(self._create_sg_f, resources.SECURITY_GROUP,
                           events.AFTER_CREATE)
        registry.subscribe(self._delete_sg_f, resources.SECURITY_GROUP,
                           events.AFTER_DELETE)
        registry.subscribe(self._update_sg_f, resources.SECURITY_GROUP,
                           events.AFTER_UPDATE)
        registry.subscribe(self._create_sg_rule_f,
                           resources.SECURITY_GROUP_RULE, events.AFTER_CREATE)
        registry.subscribe(self._delete_sg_rule_f,
                           resources.SECURITY_GROUP_RULE, events.AFTER_DELETE)

        # the above does not cover the cases where security groups are
        # initially created or when they are deleted since those actions
        # aren't needed by the L2 agent. In order to receive those, we
        # subscribe to the notifications topic that receives all of the
        # API create/update/delete events.
        # Notifications are published at the 'info' level so they will result
        # in a call to the 'info' function below. From there we can check
        # the event type and determine what to do from there.
        target = oslo_messaging.Target(topic='#', server=cfg.CONF.host)
        keystone_target = oslo_messaging.Target(topic='#',
                                                exchange='keystone',
                                                server=cfg.CONF.host)
        self.listener = oslo_messaging.get_notification_listener(
            n_rpc.TRANSPORT, [target, keystone_target], [self],
            executor='eventlet',
            allow_requeue=False)
        self.listener.start()
Beispiel #11
0
 def setUp(self):
     super(TestStatusBarriers, self).setUp()
     self.ctx = n_ctx.get_admin_context()
     self.provisioned = mock.Mock()
     self.port = self._make_port()
     registry.subscribe(self.provisioned, resources.PORT,
                        pb.PROVISIONING_COMPLETE)
Beispiel #12
0
def register():
    """Register the driver."""
    global DRIVER
    DRIVER = OVSDriver.create()
    # To set the bridge_name in a parent port's vif_details.
    registry.subscribe(vif_details_bridge_name_handler, agent_consts.OVS_BRIDGE_NAME, events.BEFORE_READ)
    LOG.debug("Open vSwitch trunk driver registered")
Beispiel #13
0
 def __init__(self, l3_agent):
     self.metadata_port = l3_agent.conf.metadata_port
     self.metadata_access_mark = l3_agent.conf.metadata_access_mark
     registry.subscribe(after_router_added, resources.ROUTER,
                        events.AFTER_CREATE)
     registry.subscribe(before_router_removed, resources.ROUTER,
                        events.BEFORE_DELETE)
Beispiel #14
0
 def __init__(self):
     db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
         attributes.PORTS, [_extend_port_trunk_details])
     self._segmentation_types = {}
     registry.subscribe(rules.enforce_port_deletion_rules,
                        resources.PORT, events.BEFORE_DELETE)
     registry.notify(constants.TRUNK_PLUGIN, events.AFTER_INIT, self)
     LOG.debug('Trunk plugin loaded')
Beispiel #15
0
    def __init__(self, trunk_manager):
        self._context = n_context.get_admin_context_without_session()
        self.trunk_manager = trunk_manager
        self.trunk_rpc = agent.TrunkStub()

        registry.subscribe(self.process_trunk_port_events,
                           ovs_agent_constants.OVSDB_RESOURCE,
                           events.AFTER_READ)
Beispiel #16
0
 def __init__(self):
     db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
         attributes.PORTS, [_extend_port_trunk_details])
     self._segmentation_types = {}
     registry.subscribe(rules.enforce_port_deletion_rules, resources.PORT,
                        events.BEFORE_DELETE)
     registry.notify(constants.TRUNK_PLUGIN, events.AFTER_INIT, self)
     LOG.debug('Trunk plugin loaded')
Beispiel #17
0
 def __new__(cls, *args, **kwargs):
     inst = super(RouterAvailabilityZoneMixin, cls).__new__(
         cls, *args, **kwargs)
     registry.subscribe(inst._process_az_request,
                        resources.ROUTER, events.PRECOMMIT_CREATE)
     db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
         l3.ROUTERS, [inst._add_az_to_response])
     return inst
Beispiel #18
0
 def __init__(self, rcache):
     self.rcache = rcache
     registry.subscribe(self._clear_child_sg_rules, 'SecurityGroup',
                        events.AFTER_DELETE)
     registry.subscribe(self._add_child_sg_rules, 'SecurityGroup',
                        events.AFTER_UPDATE)
     # set this attr so agent can adjust the timeout of the client
     self.client = resources_rpc.ResourcesPullRpcApi().client
Beispiel #19
0
 def __init__(self, plumber=None, trunk_api=None):
     self._plumber = plumber or trunk_plumber.Plumber()
     self._tapi = trunk_api or _TrunkAPI(trunk_rpc.TrunkStub())
     registry.subscribe(self.agent_port_change, local_resources.PORT_DEVICE,
                        local_events.AFTER_UPDATE)
     registry.subscribe(self.agent_port_delete, local_resources.PORT_DEVICE,
                        local_events.AFTER_DELETE)
     super(LinuxBridgeTrunkDriver, self).__init__()
Beispiel #20
0
def register():
    """Register the driver."""
    global DRIVER
    DRIVER = OVSDriver.create()
    # To set the bridge_name in a parent port's vif_details.
    registry.subscribe(vif_details_bridge_name_handler,
                       agent_consts.OVS_BRIDGE_NAME, events.BEFORE_READ)
    LOG.debug('Open vSwitch trunk driver registered')
Beispiel #21
0
    def __init__(self, trunk_manager):
        self._context = n_context.get_admin_context_without_session()
        self.trunk_manager = trunk_manager
        self.trunk_rpc = agent.TrunkStub()

        registry.subscribe(self.process_trunk_port_events,
                           ovs_agent_constants.OVSDB_RESOURCE,
                           events.AFTER_READ)
Beispiel #22
0
 def test_treat_devices_removed_notify(self):
     handler = mock.Mock()
     registry.subscribe(handler, resources.PORT_DEVICE, events.AFTER_DELETE)
     devices = [DEVICE_1]
     self.agent.treat_devices_removed(devices)
     handler.assert_called_once_with(mock.ANY, mock.ANY, self.agent,
                                     context=mock.ANY, device=DEVICE_1,
                                     port_id=mock.ANY)
Beispiel #23
0
 def test_security_group_precommit_create_event_fail(self):
     registry.subscribe(fake_callback, resources.SECURITY_GROUP,
                        events.PRECOMMIT_CREATE)
     with mock.patch.object(sqlalchemy.orm.session.SessionTransaction,
                            'rollback') as mock_rollback:
         self.assertRaises(securitygroup.SecurityGroupConflict,
                           self.mixin.create_security_group, self.ctx,
                           FAKE_SECGROUP)
         self.assertTrue(mock_rollback.called)
 def __init__(self, topic=topics.DHCP_AGENT, plugin=None):
     self._plugin = plugin
     target = oslo_messaging.Target(topic=topic, version='1.0')
     self.client = n_rpc.get_client(target)
     # register callbacks for router interface changes
     registry.subscribe(self._after_router_interface_created,
                        resources.ROUTER_INTERFACE, events.AFTER_CREATE)
     registry.subscribe(self._after_router_interface_deleted,
                        resources.ROUTER_INTERFACE, events.AFTER_DELETE)
 def __init__(self, topic=topics.DHCP_AGENT, plugin=None):
     self._plugin = plugin
     target = oslo_messaging.Target(topic=topic, version='1.0')
     self.client = n_rpc.get_client(target)
     # register callbacks for router interface changes
     registry.subscribe(self._after_router_interface_created,
                        resources.ROUTER_INTERFACE, events.AFTER_CREATE)
     registry.subscribe(self._after_router_interface_deleted,
                        resources.ROUTER_INTERFACE, events.AFTER_DELETE)
 def register(self, resource, event, trigger, **kwargs):
     super(OVNTrunkDriver, self).register(resource, event, trigger,
                                          **kwargs)
     self._handler = OVNTrunkHandler(self.plugin_driver)
     for event in (events.AFTER_CREATE, events.AFTER_DELETE):
         registry.subscribe(self._handler.trunk_event, trunk_consts.TRUNK,
                            event)
         registry.subscribe(self._handler.subport_event,
                            trunk_consts.SUBPORTS, event)
Beispiel #27
0
 def __init__(self, resource, object_class, resource_push_api):
     self._resource = resource
     self._obj_class = object_class
     self._resource_push_api = resource_push_api
     self._resources_to_push = {}
     self._worker_pool = eventlet.GreenPool()
     for event in (events.AFTER_CREATE, events.AFTER_UPDATE,
                   events.AFTER_DELETE):
         registry.subscribe(self.handle_event, resource, event)
 def test_record_resource_delete_ignores_dups(self):
     received_kw = []
     receiver = lambda *a, **k: received_kw.append(k)
     registry.subscribe(receiver, 'goose', events.AFTER_DELETE)
     self.rcache.record_resource_delete(self.ctx, 'goose', 3)
     self.assertEqual(1, len(received_kw))
     self.rcache.record_resource_delete(self.ctx, 'goose', 4)
     self.assertEqual(2, len(received_kw))
     self.rcache.record_resource_delete(self.ctx, 'goose', 3)
     self.assertEqual(2, len(received_kw))
 def test_security_group_precommit_delete_event_fail(self):
     registry.subscribe(fake_callback, resources.SECURITY_GROUP,
                        events.PRECOMMIT_DELETE)
     sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
     with mock.patch.object(sqlalchemy.orm.session.SessionTransaction,
                           'rollback') as mock_rollback:
         self.assertRaises(securitygroup.SecurityGroupInUse,
                           self.mixin.delete_security_group,
                           self.ctx, sg_dict['id'])
         self.assertTrue(mock_rollback.called)
Beispiel #30
0
    def initialize(self):
        self._nsxv = vcns_driver.VcnsDriver(None)
        self.init_profile_id()
        self.init_security_group()
        self.init_security_group_in_profile()

        # register an event to the end of the init to handle the first upgrade
        if self._is_new_security_group:
            registry.subscribe(self.init_complete, resources.PROCESS,
                               events.BEFORE_SPAWN)
Beispiel #31
0
 def __init__(self, plumber=None, trunk_api=None):
     self._plumber = plumber or trunk_plumber.Plumber()
     self._tapi = trunk_api or _TrunkAPI(trunk_rpc.TrunkStub())
     registry.subscribe(self.agent_port_change,
                        local_resources.PORT_DEVICE,
                        local_events.AFTER_UPDATE)
     registry.subscribe(self.agent_port_delete,
                        local_resources.PORT_DEVICE,
                        local_events.AFTER_DELETE)
     super(LinuxBridgeTrunkDriver, self).__init__()
Beispiel #32
0
 def __init__(self):
     super(OVNPlugin, self).__init__()
     LOG.info(_("Starting OVNPlugin"))
     self.vif_type = portbindings.VIF_TYPE_OVS
     # When set to True, Nova plugs the VIF directly into the ovs bridge
     # instead of using the hybrid mode.
     self.vif_details = {portbindings.CAP_PORT_FILTER: True}
     registry.subscribe(self.post_fork_initialize, resources.PROCESS, events.AFTER_CREATE)
     self._setup_dhcp()
     self._start_rpc_notifiers()
Beispiel #33
0
 def test_record_resource_delete_ignores_dups(self):
     received_kw = []
     receiver = lambda *a, **k: received_kw.append(k)
     registry.subscribe(receiver, 'goose', events.AFTER_DELETE)
     self.rcache.record_resource_delete(self.ctx, 'goose', 3)
     self.assertEqual(1, len(received_kw))
     self.rcache.record_resource_delete(self.ctx, 'goose', 4)
     self.assertEqual(2, len(received_kw))
     self.rcache.record_resource_delete(self.ctx, 'goose', 3)
     self.assertEqual(2, len(received_kw))
Beispiel #34
0
    def register_legacy_notification_callbacks(self, legacy_interface):
        """Emulates the server-side notifications from ml2 AgentNotifierApi.

        legacy_interface is an object with 'delete'/'update' methods for
        core resources.
        """
        self._legacy_interface = legacy_interface
        for e in (callback_events.AFTER_UPDATE, callback_events.AFTER_DELETE):
            for r in (resources.PORT, resources.NETWORK):
                registry.subscribe(self._legacy_notifier, r, e)
Beispiel #35
0
 def register(self, resource, event, trigger, **kwargs):
     super(NsxV3TrunkDriver, self).register(resource, event, trigger,
                                            **kwargs)
     self._handler = NsxV3TrunkHandler(self.plugin_driver)
     for event in (events.AFTER_CREATE, events.AFTER_DELETE):
         registry.subscribe(self._handler.trunk_event, trunk_consts.TRUNK,
                            event)
         registry.subscribe(self._handler.subport_event,
                            trunk_consts.SUBPORTS, event)
     LOG.debug("VMware NSXv3 trunk driver initialized.")
    def register(self, resource, event, trigger, **kwargs):
        super(NexusTrunkDriver, self).register(resource, event, trigger,
                                               **kwargs)
        self._handler = NexusTrunkHandler()

        registry.subscribe(self._handler.trunk_update_postcommit,
                           bc.trunk_consts.TRUNK, events.AFTER_UPDATE)
        for event in (events.AFTER_CREATE, events.AFTER_DELETE):
            registry.subscribe(self._handler.subport_postcommit,
                               bc.trunk_consts.SUBPORTS, event)
    def __init__(self, service_plugin):
        super(BaGPipeBGPVPNDriver, self).__init__(service_plugin)

        self.agent_rpc = rpc_client.BGPVPNAgentNotifyApi()

        registry.subscribe(self.registry_port_updated, resources.PORT,
                           events.AFTER_UPDATE)

        registry.subscribe(self.registry_port_deleted, resources.PORT,
                           events.AFTER_DELETE)
Beispiel #38
0
    def __init__(self):
        common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
            attributes.NETWORKS, [_extend_network_dict_binding])
        common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
            attributes.SUBNETS, [_extend_subnet_dict_binding])
        common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
            attributes.PORTS, [_extend_port_dict_binding])

        registry.subscribe(self._prevent_segment_delete_with_subnet_associated,
                           resources.SEGMENT, events.BEFORE_DELETE)
Beispiel #39
0
 def __new__(cls, *args, **kwargs):
     # NOTE(kevinbenton): we subscribe on object construction because
     # the tests blow away the callback manager for each run
     new = super(AutoAllocatedTopologyMixin, cls).__new__(cls, *args,
                                                          **kwargs)
     registry.subscribe(_ensure_external_network_default_value_callback,
         resources.EXTERNAL_NETWORK, events.PRECOMMIT_CREATE)
     registry.subscribe(_ensure_external_network_default_value_callback,
         resources.EXTERNAL_NETWORK, events.BEFORE_UPDATE)
     return new
Beispiel #40
0
    def register_legacy_notification_callbacks(self, legacy_interface):
        """Emulates the server-side notifications from ml2 AgentNotifierApi.

        legacy_interface is an object with 'delete'/'update' methods for
        core resources.
        """
        self._legacy_interface = legacy_interface
        for e in (callback_events.AFTER_UPDATE, callback_events.AFTER_DELETE):
            for r in (resources.PORT, resources.NETWORK):
                registry.subscribe(self._legacy_notifier, r, e)
Beispiel #41
0
 def test_treat_devices_removed_notify(self):
     handler = mock.Mock()
     registry.subscribe(handler, resources.PORT_DEVICE, events.AFTER_DELETE)
     devices = [DEVICE_1]
     self.agent.treat_devices_removed(devices)
     handler.assert_called_once_with(mock.ANY,
                                     mock.ANY,
                                     self.agent,
                                     context=mock.ANY,
                                     device=DEVICE_1,
                                     port_id=mock.ANY)
Beispiel #42
0
def subscribe(mech_driver):
    registry.subscribe(mech_driver.secgroup_callback, resources.SECURITY_GROUP,
                       events.BEFORE_DELETE)
    registry.subscribe(mech_driver.secgroup_callback, resources.SECURITY_GROUP,
                       events.BEFORE_UPDATE)
    registry.subscribe(mech_driver.secgroup_callback,
                       resources.SECURITY_GROUP_RULE, events.BEFORE_DELETE)
    registry.subscribe(mech_driver.secgroup_callback,
                       resources.SECURITY_GROUP_RULE, events.BEFORE_UPDATE)
    registry.subscribe(mech_driver.secgroup_callback,
                       resources.SECURITY_GROUP_RULE, events.BEFORE_CREATE)
def subscribe():
    registry.subscribe(
        gateway_device_callback, resources.ROUTER, events.BEFORE_DELETE)

    # We can only add PRECOMMIT_DELETE events in MidoNet ML2 mechanism driver
    # while we can add both BEFORE_DELETE and PRECOMMIT_DELETE in MidoNet
    # plugin. To keep the ML2 and plugin behavior the same, use
    # PRECOMMIT_DELETE event for both ML2 and plugin.
    registry.subscribe(
        gateway_device_callback, midonet_const.MIDONET_NETWORK,
        events.PRECOMMIT_DELETE)
Beispiel #44
0
    def test__set_bridge_name_notify(self):
        def fake_callback(resource, event, trigger, **kwargs):
            trigger('fake-br-name')

        registry.subscribe(fake_callback, a_const.OVS_BRIDGE_NAME,
                           events.BEFORE_READ)
        fake_vif_details = {}
        self.driver._set_bridge_name('foo', fake_vif_details)
        self.assertEqual(
            'fake-br-name',
            fake_vif_details.get(portbindings.VIF_DETAILS_BRIDGE_NAME, ''))
Beispiel #45
0
    def __init__(self):
        resource_extend.register_funcs(attributes.NETWORKS,
                                       [_extend_network_dict_binding])
        resource_extend.register_funcs(attributes.SUBNETS,
                                       [_extend_subnet_dict_binding])
        resource_extend.register_funcs(attributes.PORTS,
                                       [_extend_port_dict_binding])
        self.nova_updater = NovaSegmentNotifier()

        registry.subscribe(self._prevent_segment_delete_with_subnet_associated,
                           resources.SEGMENT, events.BEFORE_DELETE)
 def register(self, resource, event, trigger, **kwargs):
     super(OVNTrunkDriver, self).register(
         resource, event, trigger, **kwargs)
     self._handler = OVNTrunkHandler(self.plugin_driver)
     for event in (events.AFTER_CREATE, events.AFTER_DELETE):
         registry.subscribe(self._handler.trunk_event,
                            trunk_consts.TRUNK,
                            event)
         registry.subscribe(self._handler.subport_event,
                            trunk_consts.SUBPORTS,
                            event)
 def test_adding_component_for_new_resource_type(self):
     provisioned = mock.Mock()
     registry.subscribe(provisioned, 'NETWORK', pb.PROVISIONING_COMPLETE)
     net = self._make_net()
     # expect failed because the model was not registered for the type
     with testtools.ExpectedException(RuntimeError):
         pb.add_provisioning_component(self.ctx, net.id, 'NETWORK', 'ent')
     pb.add_model_for_resource('NETWORK', models_v2.Network)
     pb.add_provisioning_component(self.ctx, net.id, 'NETWORK', 'ent')
     pb.provisioning_complete(self.ctx, net.id, 'NETWORK', 'ent')
     self.assertTrue(provisioned.called)
 def test_adding_component_for_new_resource_type(self):
     provisioned = mock.Mock()
     registry.subscribe(provisioned, 'NETWORK', pb.PROVISIONING_COMPLETE)
     net = self._make_net()
     # expect failed because the model was not registered for the type
     with testtools.ExpectedException(RuntimeError):
         pb.add_provisioning_component(self.ctx, net.id, 'NETWORK', 'ent')
     pb.add_model_for_resource('NETWORK', models_v2.Network)
     pb.add_provisioning_component(self.ctx, net.id, 'NETWORK', 'ent')
     pb.provisioning_complete(self.ctx, net.id, 'NETWORK', 'ent')
     self.assertTrue(provisioned.called)
Beispiel #49
0
 def subscribe(self, event_type):
     registry.subscribe(self.sg_callback, resources.SECURITY_GROUP,
                        getattr(events, "%s_CREATE" % event_type))
     registry.subscribe(self.sg_callback, resources.SECURITY_GROUP,
                        getattr(events, "%s_UPDATE" % event_type))
     registry.subscribe(self.sg_callback, resources.SECURITY_GROUP,
                        getattr(events, "%s_DELETE" % event_type))
     registry.subscribe(self.sg_callback, resources.SECURITY_GROUP_RULE,
                        getattr(events, "%s_CREATE" % event_type))
     registry.subscribe(self.sg_callback, resources.SECURITY_GROUP_RULE,
                        getattr(events, "%s_DELETE" % event_type))
 def test_security_group_rule_precommit_create_event_fail(self):
     registry.subscribe(fake_callback, resources.SECURITY_GROUP_RULE, events.PRECOMMIT_CREATE)
     sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
     fake_rule = FAKE_SECGROUP_RULE
     fake_rule["security_group_rule"]["security_group_id"] = sg_dict["id"]
     with mock.patch.object(
         sqlalchemy.orm.session.SessionTransaction, "rollback"
     ) as mock_rollback, mock.patch.object(self.mixin, "_get_security_group"):
         self.assertRaises(
             securitygroup.SecurityGroupConflict, self.mixin.create_security_group_rule, self.ctx, fake_rule
         )
         self.assertTrue(mock_rollback.called)
Beispiel #51
0
    def __init__(self):
        common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
            attributes.NETWORKS, [_extend_network_dict_binding])
        common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
            attributes.SUBNETS, [_extend_subnet_dict_binding])
        common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
            attributes.PORTS, [_extend_port_dict_binding])

        registry.subscribe(
            self._prevent_segment_delete_with_subnet_associated,
            resources.SEGMENT,
            events.BEFORE_DELETE)
    def test__set_bridge_name_notify(self):

        def fake_callback(resource, event, trigger, **kwargs):
            trigger('fake-br-name')

        registry.subscribe(fake_callback, a_const.OVS_BRIDGE_NAME,
                           events.BEFORE_READ)
        fake_vif_details = {}
        self.driver._set_bridge_name('foo', fake_vif_details)
        self.assertEqual(
            'fake-br-name',
            fake_vif_details.get(portbindings.VIF_DETAILS_BRIDGE_NAME, ''))
Beispiel #53
0
 def subscribe(self):
     # Subscribe to the events related to security groups and rules
     registry.subscribe(self.create_security_group,
                        resources.SECURITY_GROUP, events.AFTER_CREATE)
     registry.subscribe(self.update_security_group,
                        resources.SECURITY_GROUP, events.AFTER_UPDATE)
     registry.subscribe(self.delete_security_group,
                        resources.SECURITY_GROUP, events.BEFORE_DELETE)
     registry.subscribe(self.create_security_group_rule,
                        resources.SECURITY_GROUP_RULE, events.AFTER_CREATE)
     registry.subscribe(self.delete_security_group_rule,
                        resources.SECURITY_GROUP_RULE, events.BEFORE_DELETE)
Beispiel #54
0
    def __init__(self):
        super(DFPlugin, self).__init__()
        LOG.info(_LI("Starting DFPlugin"))
        self.vif_type = portbindings.VIF_TYPE_OVS
        self._set_base_port_binding()
        # When set to True, Nova plugs the VIF directly into the ovs bridge
        # instead of using the hybrid mode.
        self.vif_details = {portbindings.CAP_PORT_FILTER: True}
        registry.subscribe(self.post_fork_initialize, resources.PROCESS,
                           events.AFTER_CREATE)

        self._setup_dhcp()
        self._start_rpc_notifiers()
Beispiel #55
0
 def test_security_group_rule_precommit_create_event_fail(self):
     registry.subscribe(fake_callback, resources.SECURITY_GROUP_RULE,
                        events.PRECOMMIT_CREATE)
     sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
     fake_rule = FAKE_SECGROUP_RULE
     fake_rule['security_group_rule']['security_group_id'] = sg_dict['id']
     with mock.patch.object(sqlalchemy.orm.session.SessionTransaction,
                           'rollback') as mock_rollback,\
         mock.patch.object(self.mixin, '_get_security_group'):
         self.assertRaises(securitygroup.SecurityGroupConflict,
                           self.mixin.create_security_group_rule, self.ctx,
                           fake_rule)
         self.assertTrue(mock_rollback.called)
Beispiel #56
0
    def test_security_groups_created_outside_transaction(self):
        def record_after_state(r, e, t, context, *args, **kwargs):
            self.was_active = context.session.is_active

        registry.subscribe(record_after_state, resources.SECURITY_GROUP,
                           events.AFTER_CREATE)
        with self.subnet() as s:
            self.assertFalse(self.was_active)
            self._delete(
                'security-groups',
                self._list('security-groups')['security_groups'][0]['id'])
            with self.port(subnet=s):
                self.assertFalse(self.was_active)
Beispiel #57
0
 def subscribe(self):
     registry.subscribe(
         self.sg_callback, resources.SECURITY_GROUP, events.AFTER_CREATE)
     registry.subscribe(
         self.sg_callback, resources.SECURITY_GROUP, events.AFTER_UPDATE)
     registry.subscribe(
         self.sg_callback, resources.SECURITY_GROUP, events.AFTER_DELETE)
     registry.subscribe(
         self.sg_callback, resources.SECURITY_GROUP_RULE,
         events.AFTER_CREATE)
     registry.subscribe(
         self.sg_callback, resources.SECURITY_GROUP_RULE,
         events.AFTER_DELETE)
Beispiel #58
0
 def __init__(self):
     super(DFPlugin, self).__init__()
     LOG.info(_LI("Starting DFPlugin"))
     self.vif_type = portbindings.VIF_TYPE_OVS
     self._set_base_port_binding()
     # When set to True, Nova plugs the VIF directly into the ovs bridge
     # instead of using the hybrid mode.
     self.vif_details = {portbindings.CAP_PORT_FILTER: True}
     registry.subscribe(self.post_fork_initialize, resources.PROCESS, events.AFTER_CREATE)
     nb_driver_class = importutils.import_class(cfg.CONF.df.nb_db_class)
     self.nb_api = api_nb.NbApi(nb_driver_class())
     self.nb_api.initialize(db_ip=cfg.CONF.df.remote_db_ip, db_port=cfg.CONF.df.remote_db_port)
     self._setup_dhcp()
     self._start_rpc_notifiers()