Just call set-manager if connecting fails

Instead of calling set-manager every init, only call it when
getting the schema fails inside of Connection.start() which is
only called once.

Closes-Bug: #1499784
Change-Id: Ib28cd912e1f2eba318a6b0a82269919a1c95312d
(cherry picked from commit c561c7c20a)
This commit is contained in:
Terry Wilson 2015-09-28 21:01:30 -05:00 committed by Kyle Mestery
parent fa2b18c45a
commit c66fa826ab
2 changed files with 17 additions and 8 deletions

View File

@ -23,7 +23,6 @@ from ovs.db import idl
from neutron.agent.ovsdb import api
from neutron.agent.ovsdb.native import commands as cmd
from neutron.agent.ovsdb.native import connection
from neutron.agent.ovsdb.native import helpers
from neutron.agent.ovsdb.native import idlutils
from neutron.i18n import _LE
@ -123,11 +122,6 @@ class OvsdbIdl(api.API):
def __init__(self, context):
super(OvsdbIdl, self).__init__(context)
# it's a chicken and egg problem: by default, the manager that
# corresponds to the connection URI is in most cases not enabled in
# local ovsdb, so we still need ovs-vsctl to set it to allow
# connections
helpers.enable_connection_uri(self.ovsdb_connection.connection)
OvsdbIdl.ovsdb_connection.start()
self.idl = OvsdbIdl.ovsdb_connection.idl

View File

@ -19,7 +19,9 @@ import traceback
from ovs.db import idl
from ovs import poller
import retrying
from neutron.agent.ovsdb.native import helpers
from neutron.agent.ovsdb.native import idlutils
@ -62,8 +64,21 @@ class Connection(object):
if self.idl is not None:
return
helper = idlutils.get_schema_helper(self.connection,
self.schema_name)
try:
helper = idlutils.get_schema_helper(self.connection,
self.schema_name)
except Exception:
# We may have failed do to set-manager not being called
helpers.enable_connection_uri(self.connection)
# There is a small window for a race, so retry up to a second
@retrying.retry(wait_exponential_multiplier=10,
stop_max_delay=1000)
def do_get_schema_helper():
return idlutils.get_schema_helper(self.connection,
self.schema_name)
helper = do_get_schema_helper()
helper.register_all()
self.idl = idl.Idl(self.connection, helper)
idlutils.wait_for_change(self.idl, self.timeout)