Merge "Save socket fd to be cleaned up in functional test"
This commit is contained in:
commit
b4f53a2af0
2 files changed
+19
No files matched your search
@@ -19,6 +19,7 @@ import logging
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
import weakref
|
||||
|
||||
from oslo_log import log
|
||||
from pyroute2 import iproute
|
||||
@@ -43,6 +44,7 @@ class NetlinkDispatcher:
|
||||
self._groups = groups
|
||||
self._replay_start_callbacks = []
|
||||
self._replay_end_callbacks = []
|
||||
self._ipr = lambda: None
|
||||
|
||||
def register_handler(self, event_type, handler):
|
||||
"""Register a handler for a specific netlink message type.
|
||||
@@ -75,6 +77,7 @@ class NetlinkDispatcher:
|
||||
def _sock(self):
|
||||
ipr = iproute.IPRoute()
|
||||
ipr.bind(self._groups)
|
||||
self._ipr = weakref.ref(ipr)
|
||||
try:
|
||||
yield ipr
|
||||
finally:
|
||||
|
||||
@@ -17,6 +17,7 @@ import socket
|
||||
from unittest import mock
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
from pyroute2 import iproute
|
||||
from pyroute2.netlink import rtnl
|
||||
|
||||
from neutron.agent.linux import ip_lib
|
||||
@@ -44,6 +45,20 @@ class TestVrfHandlerLifecycle(functional_base.BaseSudoTestCase):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _stop_dispatcher(self, dispatcher):
|
||||
dispatcher.RETRY_BACKOFF = 0
|
||||
with mock.patch.object(nl_dispatcher.os, '_exit',
|
||||
side_effect=SystemExit):
|
||||
with mock.patch.object(iproute, 'IPRoute',
|
||||
side_effect=RuntimeError):
|
||||
ipr = dispatcher._ipr()
|
||||
if ipr:
|
||||
ipr.close()
|
||||
try:
|
||||
dispatcher._thread.join(timeout=5)
|
||||
except SystemExit:
|
||||
pass
|
||||
|
||||
def test_vrf_handler_lifecycle(self):
|
||||
vrf_handler = netlink_monitor.VrfHandler(fsm.EvpnFSM())
|
||||
|
||||
@@ -63,6 +78,7 @@ class TestVrfHandlerLifecycle(functional_base.BaseSudoTestCase):
|
||||
self.addCleanup(self._safe_delete, preexisting_vrf)
|
||||
|
||||
dispatcher.start()
|
||||
self.addCleanup(self._stop_dispatcher, dispatcher)
|
||||
utils.wait_until_true(
|
||||
lambda: preexisting_vrf in vrf_handler._known_vrfs,
|
||||
timeout=10, sleep=0.1)
|
||||
|
||||
Reference in new issue
Block a user