Use Neutron's push notification for state

Registered by Antoni Segura Puimedon on 2018-02-16

When we create network resources in OpenStack we currently go into polling mode until the ports go active. It is worthy to investigate the gains we'd get (and the decreased load on the Neutron server) by using OpenStack oslo_messaging push notifications.

Blueprint information

Status:
Not started
Approver:
Antoni Segura Puimedon
Priority:
Undefined
Drafter:
Antoni Segura Puimedon
Direction:
Needs approval
Assignee:
None
Definition:
Discussion
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

Here you can see an example of connecting to the stream using Kombu (what oslo_messaging uses in the background when the transport is amqp:

https://gist.github.com/celebdor/06cf4bf06637a72358b982832c366429

Here there's a related example of consuming the events with oslo messaging: https://gist.github.com/openstacker/2f10c433232dba0a2ea6a804e47ea68f

Of course there's several questions raised:
- Do we want to have the controller connect to rabbitmq? Do we want to simplify the controller so that the port active events are watched instead by the CNI Daemon and have the Daemon set the ports active itself?
- Do we want instead to try to make a Neutron http stream agent that then we can use with the current watch facility?

Addressed by: https://review.opendev.org/669642
    Use neutron rpc for port status checking

Addressed by: https://review.opendev.org/669644
    Disable N530 PEP8 warning

Gerrit topic: https://review.opendev.org/#/q/topic:bp/neutron-push-notifications

------------------------------------------------------------------------------
Pitfalls or why this approach can't be used out of the box.

I tested oslo_messaging_notification on Ocata and on Stein. I used the same sample as in https://gist.github.com/openstacker/2f10c433232dba0a2ea6a804e47ea68

 On both of it I can receive messages which neutron server sends.
    oslo.messaging.notification.port.create.start|end message when we create new port and
    oslo.messaging.notification.port.delete.start|end message when we delete port.
    The status of the port in payload is DOWN in any cases, and oslo.messaging.notification.port.create.end comes even in case when I advisedly disable port binding (just by misconfigure or stop of neutron-openvswitch-agent).
    So I didn't find any events which can help to distinguish port status changing to ACTIVE.
    I tried to figure out by code /usr/lib/python2.7/site-packages/neutron/plugins/ml2/plugin.py has method which tracks down port creation/deletion/updating and sends notification through oslo_messaging_notification.
    REMARKS this file contains two type of notification

         registry.notify(resources.PORT, events.AFTER_CREATE, self, **kwargs)

        it's notification which working through default rabbitmq, patch for that was proposed by Ilya. But it was concern.

        self.notifier.port_update(mech_context._plugin_context, port,
                                  segment[api.NETWORK_TYPE],
                                  segment[api.SEGMENTATION_ID],
                                  segment[api.PHYSICAL_NETWORK])

        It's what we need, it works through [oslo_messaging_notification]
    I tested it on OpenStack with nova-compute, in case of nova-instance
    oslo.messaging.notification.port.update.start|end sends in this case, but w/o status ACTIVE, status still was DOWN.

As a result we can't handle port status changes this way right now

As an approach of solving it, we can add port update notification call to the neutron openvswitch agent.
Looks like /usr/lib/python2.7/site-packages/neutron/agent/resource_cache.py - record_resource_update method of the RemoteResourceCache it's a proper place for it.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.