Python neutron_lib.callbacks.events.AFTER_UPDATE Examples

The following are 18 code examples of neutron_lib.callbacks.events.AFTER_UPDATE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module neutron_lib.callbacks.events , or try the search function .
Example #1
Source File: test_trunk_driver_v2.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def test_trunk_subports_update_status_parent_active_to_down(
            self, mock_set_subport_status, mock_get_subports_ids):
        resource = resources.PORT
        event_type = events.AFTER_UPDATE
        core_plugin = directory.get_plugin()
        port = FAKE_PARENT.copy()
        original_port = FAKE_PARENT.copy()
        port['status'] = n_const.PORT_STATUS_DOWN
        port_kwargs = {'port': port, 'original_port': original_port}

        mock_get_subports_ids.return_value = ['fake_port_id']

        self.handler.trunk_subports_update_status(resource, event_type,
                                                  mock.ANY, **port_kwargs)

        mock_set_subport_status.assert_called_once_with(
            core_plugin, mock.ANY, 'fake_port_id', n_const.PORT_STATUS_DOWN) 
Example #2
Source File: test_registry.py    From neutron-lib with Apache License 2.0 6 votes vote down vote up
def test_decorated_inst_method_receives(self):
        i1 = ObjectWithDecoratedCallback()
        registry.notify(resources.PORT, events.BEFORE_CREATE, self)
        self.assertEqual(0, i1.counter)
        registry.notify(resources.PORT, events.AFTER_CREATE, self)
        self.assertEqual(1, i1.counter)
        registry.notify(resources.PORT, events.AFTER_UPDATE, self)
        self.assertEqual(2, i1.counter)
        registry.notify(resources.NETWORK, events.AFTER_UPDATE, self)
        self.assertEqual(2, i1.counter)
        registry.notify(resources.NETWORK, events.AFTER_DELETE, self)
        self.assertEqual(3, i1.counter)
        i2 = ObjectWithDecoratedCallback()
        self.assertEqual(0, i2.counter)
        registry.notify(resources.NETWORK, events.AFTER_DELETE, self)
        self.assertEqual(4, i1.counter)
        self.assertEqual(1, i2.counter) 
Example #3
Source File: mech_driver.py    From dragonflow with Apache License 2.0 6 votes vote down vote up
def update_security_group(self, resource, event, trigger, **kwargs):
        sg = kwargs['security_group']
        sg_name = sg.get('name')
        rules = sg.get('security_group_rules', [])

        for rule in rules:
            try:
                rule['topic'] = rule.pop('project_id')
            except KeyError:
                rule['topic'] = rule.pop('tenant_id', None)
        sg_obj = neutron_secgroups.security_group_from_neutron_obj(sg)
        if event == events.AFTER_CREATE:
            self.nb_api.create(sg_obj)
            LOG.info("DFMechDriver: create security group %s", sg_name)
        elif event == events.AFTER_UPDATE:
            self.nb_api.update(sg_obj)
            LOG.info("DFMechDriver: update security group %s", sg_name)

        return sg_obj 
Example #4
Source File: mech_driver.py    From dragonflow with Apache License 2.0 6 votes vote down vote up
def subscribe_registries(self):
        registry.subscribe(self.post_fork_initialize,
                           resources.PROCESS,
                           events.AFTER_INIT)

        registry.subscribe(self.update_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.AFTER_DELETE) 
Example #5
Source File: bgp_plugin.py    From dragonflow with Apache License 2.0 6 votes vote down vote up
def _register_callbacks(self):
        registry.subscribe(self.floatingip_update_callback,
                           resources.FLOATING_IP,
                           events.AFTER_UPDATE)
        registry.subscribe(self.router_port_callback,
                           resources.ROUTER_INTERFACE,
                           events.AFTER_CREATE)
        registry.subscribe(self.router_port_callback,
                           resources.ROUTER_INTERFACE,
                           events.AFTER_DELETE)
        registry.subscribe(self.router_port_callback,
                           resources.ROUTER_GATEWAY,
                           events.AFTER_CREATE)
        registry.subscribe(self.router_port_callback,
                           resources.ROUTER_GATEWAY,
                           events.AFTER_DELETE) 
Example #6
Source File: callback.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def _subscribe(self):
        if self._precommit is not None:
            for event in (events.PRECOMMIT_CREATE, events.PRECOMMIT_DELETE):
                registry.subscribe(self.sg_callback_precommit,
                                   resources.SECURITY_GROUP, event)
                registry.subscribe(self.sg_callback_precommit,
                                   resources.SECURITY_GROUP_RULE, event)
            registry.subscribe(
                self.sg_callback_precommit, resources.SECURITY_GROUP,
                events.PRECOMMIT_UPDATE)

        for event in (events.AFTER_CREATE, events.AFTER_DELETE):
            registry.subscribe(self.sg_callback_postcommit,
                               resources.SECURITY_GROUP, event)
            registry.subscribe(self.sg_callback_postcommit,
                               resources.SECURITY_GROUP_RULE, event)

        registry.subscribe(self.sg_callback_postcommit,
                           resources.SECURITY_GROUP, events.AFTER_UPDATE) 
Example #7
Source File: bgp_plugin.py    From neutron-dynamic-routing with Apache License 2.0 6 votes vote down vote up
def _register_callbacks(self):
        registry.subscribe(self.floatingip_update_callback,
                           resources.FLOATING_IP,
                           events.AFTER_UPDATE)
        registry.subscribe(self.router_interface_callback,
                           resources.ROUTER_INTERFACE,
                           events.AFTER_CREATE)
        registry.subscribe(self.router_interface_callback,
                           resources.ROUTER_INTERFACE,
                           events.BEFORE_CREATE)
        registry.subscribe(self.router_interface_callback,
                           resources.ROUTER_INTERFACE,
                           events.AFTER_DELETE)
        registry.subscribe(self.router_gateway_callback,
                           resources.ROUTER_GATEWAY,
                           events.AFTER_CREATE)
        registry.subscribe(self.router_gateway_callback,
                           resources.ROUTER_GATEWAY,
                           events.AFTER_DELETE)
        registry.subscribe(self.port_callback,
                           resources.PORT,
                           events.AFTER_UPDATE) 
Example #8
Source File: test_trunk_driver_v2.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def test_trunk_subports_update_status_parent_down_to_active(
            self, mock_set_subport_status, mock_get_subports_ids):
        resource = resources.PORT
        event_type = events.AFTER_UPDATE
        core_plugin = directory.get_plugin()
        port = FAKE_PARENT.copy()
        original_port = FAKE_PARENT.copy()
        original_port['status'] = n_const.PORT_STATUS_DOWN
        port_kwargs = {'port': port, 'original_port': original_port}

        mock_get_subports_ids.return_value = ['fake_port_id']

        self.handler.trunk_subports_update_status(resource, event_type,
                                                  mock.ANY, **port_kwargs)

        mock_set_subport_status.assert_called_once_with(
            core_plugin, mock.ANY, 'fake_port_id', n_const.PORT_STATUS_ACTIVE) 
Example #9
Source File: test_bgp_plugin.py    From neutron-dynamic-routing with Apache License 2.0 6 votes vote down vote up
def test__register_callbacks(self):
        with mock.patch.object(registry, 'subscribe') as subscribe:
            plugin = bgp_plugin.BgpPlugin()
            expected_calls = [
                mock.call(plugin.bgp_drscheduler.schedule_bgp_speaker_callback,
                          dr_resources.BGP_SPEAKER, events.AFTER_CREATE),
                mock.call(plugin.floatingip_update_callback,
                          resources.FLOATING_IP, events.AFTER_UPDATE),
                mock.call(plugin.router_interface_callback,
                          resources.ROUTER_INTERFACE, events.AFTER_CREATE),
                mock.call(plugin.router_interface_callback,
                          resources.ROUTER_INTERFACE, events.BEFORE_CREATE),
                mock.call(plugin.router_interface_callback,
                          resources.ROUTER_INTERFACE, events.AFTER_DELETE),
                mock.call(plugin.router_gateway_callback,
                          resources.ROUTER_GATEWAY, events.AFTER_CREATE),
                mock.call(plugin.router_gateway_callback,
                          resources.ROUTER_GATEWAY, events.AFTER_DELETE),
                mock.call(plugin.port_callback,
                          resources.PORT, events.AFTER_UPDATE),
            ]
            self.assertEqual(subscribe.call_args_list, expected_calls) 
Example #10
Source File: trunk_driver_v2.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def register(self, resource, event, trigger, payload=None):
        super(OpenDaylightTrunkDriverV2, self).register(
            resource, event, trigger, payload=payload)
        self._handler = OpenDaylightTrunkHandlerV2()
        registry.subscribe(self._handler.trunk_create_precommit,
                           resources.TRUNK, events.PRECOMMIT_CREATE)
        registry.subscribe(self._handler.trunk_create_postcommit,
                           resources.TRUNK, events.AFTER_CREATE)
        registry.subscribe(self._handler.trunk_update_precommit,
                           resources.TRUNK, events.PRECOMMIT_UPDATE)
        registry.subscribe(self._handler.trunk_update_postcommit,
                           resources.TRUNK, events.AFTER_UPDATE)
        registry.subscribe(self._handler.trunk_delete_precommit,
                           resources.TRUNK, events.PRECOMMIT_DELETE)
        registry.subscribe(self._handler.trunk_delete_postcommit,
                           resources.TRUNK, events.AFTER_DELETE)
        for event_ in (events.PRECOMMIT_CREATE, events.PRECOMMIT_DELETE):
            registry.subscribe(self._handler.trunk_update_precommit,
                               resources.SUBPORTS, event_)
        for event_ in (events.AFTER_CREATE, events.AFTER_DELETE):
            registry.subscribe(self._handler.trunk_update_postcommit,
                               resources.SUBPORTS, event_)
            # Upon subport creation/deletion we need to set the right port
            # status:
            # 1. Set it to parent status when it is attached to the trunk
            # 2. Set it to down when is removed from the trunk
            registry.subscribe(self._handler.trunk_subports_set_status,
                               resources.SUBPORTS, event_)
        # NOTE(ltomasbo): if the status of the parent port changes, the
        # subports need to update their status too
        registry.subscribe(self._handler.trunk_subports_update_status,
                           resources.PORT, events.AFTER_UPDATE) 
Example #11
Source File: test_l2gw_db.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def test_l2gw_callback_update_port(self):
        service_plugin = mock.Mock()
        directory.add_plugin(constants.L2GW, service_plugin)
        fake_context = mock.Mock()
        fake_port = mock.Mock()
        fake_kwargs = {'context': fake_context,
                       'port': fake_port}
        l2gateway_db.l2gw_callback(resources.PORT,
                                   events.AFTER_UPDATE,
                                   mock.Mock(),
                                   **fake_kwargs)
        self.assertTrue(service_plugin.add_port_mac.called) 
Example #12
Source File: test_callback.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def test_callback_postcommit_sg_update(self):
        self._test_callback_postcommit_for_sg(
            events.AFTER_UPDATE, odl_const.ODL_UPDATE, mock.Mock(), FAKE_ID) 
Example #13
Source File: l2gateway_db.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def subscribe():
    interested_events = (events.AFTER_UPDATE,
                         events.AFTER_DELETE)
    for x in interested_events:
        registry.subscribe(
            l2gw_callback, resources.PORT, x) 
Example #14
Source File: driver.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def _register_subport_events(self):
        registry.subscribe(self._add_subports_handler,
                           resources.SUBPORTS, events.AFTER_CREATE)
        registry.subscribe(self._delete_subports_handler,
                           resources.SUBPORTS, events.AFTER_DELETE)
        registry.subscribe(self._update_port_handler,
                           resources.PORT, events.AFTER_UPDATE) 
Example #15
Source File: l2gateway_db.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def l2gw_callback(resource, event, trigger, **kwargs):
    l2gwservice = directory.get_plugin(constants.L2GW)
    context = kwargs.get('context')
    port_dict = kwargs.get('port')
    if l2gwservice:
        if event == events.AFTER_UPDATE:
            l2gwservice.add_port_mac(context, port_dict)
        elif event == events.AFTER_DELETE:
            l2gwservice.delete_port_mac(context, port_dict) 
Example #16
Source File: l3_router_plugin.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def _register_callbacks(self):
        registry.subscribe(self.router_create_callback,
                           resources.ROUTER,
                           events.PRECOMMIT_CREATE)
        registry.subscribe(self._update_port_handler,
                           resources.PORT, events.AFTER_UPDATE) 
Example #17
Source File: bgp_plugin.py    From neutron-dynamic-routing with Apache License 2.0 5 votes vote down vote up
def port_callback(self, resource, event, trigger, **kwargs):
        if event != events.AFTER_UPDATE:
            return

        original_port = kwargs['original_port']
        updated_port = kwargs['port']
        if not updated_port.get('fixed_ips'):
            return

        original_host = original_port.get(portbindings.HOST_ID)
        updated_host = updated_port.get(portbindings.HOST_ID)
        device_owner = updated_port.get('device_owner')

        # if host in the port binding has changed, update next-hops
        if original_host != updated_host and bool('compute:' in device_owner):
            ctx = context.get_admin_context()
            with ctx.session.begin(subtransactions=True):
                ext_nets = self.get_external_networks_for_port(ctx,
                                                               updated_port)
                for ext_net in ext_nets:
                    bgp_speakers = (
                        self._get_bgp_speaker_ids_by_binding_network(
                            ctx, ext_nets))

                    # Refresh any affected BGP speakers
                    for bgp_speaker in bgp_speakers:
                        routes = self.get_advertised_routes(ctx, bgp_speaker)
                        self.start_route_advertisements(ctx, self._bgp_rpc,
                                                        bgp_speaker, routes) 
Example #18
Source File: bgp_plugin.py    From neutron-dynamic-routing with Apache License 2.0 5 votes vote down vote up
def floatingip_update_callback(self, resource, event, trigger, **kwargs):
        if event != events.AFTER_UPDATE:
            return

        ctx = context.get_admin_context()
        new_router_id = kwargs['router_id']
        last_router_id = kwargs.get('last_known_router_id')
        floating_ip_address = kwargs['floating_ip_address']
        dest = floating_ip_address + '/32'
        bgp_speakers = self._bgp_speakers_for_gw_network_by_family(
            ctx,
            kwargs['floating_network_id'],
            n_const.IP_VERSION_4)

        if last_router_id and new_router_id != last_router_id:
            # Here gives the old route next_hop a `None` value, then
            # the DR agent side will withdraw it.
            old_host_route = {'destination': dest, 'next_hop': None}
            for bgp_speaker in bgp_speakers:
                self.stop_route_advertisements(ctx, self._bgp_rpc,
                                               bgp_speaker.id,
                                               [old_host_route])

        if new_router_id and new_router_id != last_router_id:
            next_hop = self._get_fip_next_hop(
                ctx, new_router_id, floating_ip_address)
            new_host_route = {'destination': dest, 'next_hop': next_hop}
            for bgp_speaker in bgp_speakers:
                self.start_route_advertisements(ctx, self._bgp_rpc,
                                                bgp_speaker.id,
                                                [new_host_route])