Skip to content

Instantly share code, notes, and snippets.

@otherwiseguy
Last active June 24, 2021 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otherwiseguy/af8f6ede8a09ccf5cef259c93bb00792 to your computer and use it in GitHub Desktop.
Save otherwiseguy/af8f6ede8a09ccf5cef259c93bb00792 to your computer and use it in GitHub Desktop.
Test whether reconnecting block with python-ovs and eventlet
#!/usr/bin/env python3
import eventlet
eventlet.monkey_patch()
import time
import logging
from ovsdbapp.backend.ovs_idl import connection
from ovsdbapp.schema.ovn_northbound import impl_idl
from ovsdbapp.backend.ovs_idl import vlog
class MyIdl(connection.OvsdbIdl):
def notify(self, event, row, old=None):
eventlet.sleep()
logging.basicConfig(level=logging.DEBUG)
LOG = logging.getLogger(__name__)
vlog.use_python_logger()
def print_stuff():
while True:
print(time.time())
time.sleep(1)
def force_reconnect(idl):
time.sleep(4)
print("Reconnecting!")
idl.force_reconnect()
LOG.info("thread monkey_patched? %s" % eventlet.patcher.is_monkey_patched('thread'))
conn = "tcp:127.0.0.1:6641"
# The python-ovs Idl class. Take it from server's database
#i = connection.OvsdbIdl.from_server(conn, 'OVN_Northbound')
i = MyIdl.from_server(conn, 'OVN_Northbound')
# The ovsdbapp Connection object
c = connection.Connection(idl=i, timeout=300)
# The OVN_Northbound API implementation object
api = impl_idl.OvnNbApiIdlImpl(c)
with api.transaction() as txn:
for a in range(100):
sw = "test-%d" % a
txn.add(api.ls_del(sw, if_exists=True ))
with api.transaction() as txn:
for a in range(100):
sw = "test-%d" % a
txn.add(api.ls_add(sw, may_exist=True))
for b in range(100):
port = "%s-port-%s" % (sw, b)
txn.add(api.lsp_add(sw, port, may_exist=True))
gt = eventlet.spawn(print_stuff)
gt2 = eventlet.spawn(force_reconnect, i)
gt2.wait()
gt.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment