Attempt to fetch the schema from any remote
The current implementation of the get_schema_helper function assumes one remote is provided. When ovsdbapp is used to connect to a clustered ovsdb, multiple comma separated remotes may be provided in the connection argument of get_schema_helper. This function must therefore attempt to fetch the schema from any of the provided remotes. This change implements this functionality. Change-Id: Ib4614401632e64421952777a60920796179d602f
This commit is contained in:
parent
15de3c66aa
commit
5458269972
|
@ -13,6 +13,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -27,6 +28,7 @@ import six
|
||||||
from ovsdbapp import api
|
from ovsdbapp import api
|
||||||
from ovsdbapp import exceptions
|
from ovsdbapp import exceptions
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
RowLookup = collections.namedtuple('RowLookup',
|
RowLookup = collections.namedtuple('RowLookup',
|
||||||
['table', 'column', 'uuid_column'])
|
['table', 'column', 'uuid_column'])
|
||||||
|
@ -114,21 +116,48 @@ def get_schema_helper(connection, schema_name):
|
||||||
:param schema_name: The schema on the server to pull
|
:param schema_name: The schema on the server to pull
|
||||||
:type schema_name: string
|
:type schema_name: string
|
||||||
"""
|
"""
|
||||||
err, strm = stream.Stream.open_block(
|
parsed_connections = parse_connection(connection)
|
||||||
stream.Stream.open(connection))
|
|
||||||
if err:
|
for c in parsed_connections:
|
||||||
raise Exception("Could not connect to %s" % connection)
|
err, strm = stream.Stream.open_block(
|
||||||
rpc = jsonrpc.Connection(strm)
|
stream.Stream.open(c))
|
||||||
req = jsonrpc.Message.create_request('get_schema', [schema_name])
|
if err:
|
||||||
err, resp = rpc.transact_block(req)
|
LOG.error("Unable to open stream to %(conn)s to retrieve schema: "
|
||||||
rpc.close()
|
"%(err)s", {'conn': c,
|
||||||
if err:
|
'err': os.strerror(err)})
|
||||||
raise Exception("Could not retrieve schema from %(conn)s: "
|
continue
|
||||||
"%(err)s" % {'conn': connection,
|
rpc = jsonrpc.Connection(strm)
|
||||||
'err': os.strerror(err)})
|
req = jsonrpc.Message.create_request('get_schema', [schema_name])
|
||||||
elif resp.error:
|
err, resp = rpc.transact_block(req)
|
||||||
raise Exception(resp.error)
|
rpc.close()
|
||||||
return idl.SchemaHelper(None, resp.result)
|
if err:
|
||||||
|
LOG.info("Could not retrieve schema from %(conn)s: "
|
||||||
|
"%(err)s", {'conn': c,
|
||||||
|
'err': os.strerror(err)})
|
||||||
|
continue
|
||||||
|
elif resp.error:
|
||||||
|
LOG.error("TRXN error, failed to retrieve schema from %(conn)s: "
|
||||||
|
"%(err)s", {'conn': c,
|
||||||
|
'err': resp.error})
|
||||||
|
continue
|
||||||
|
return idl.SchemaHelper(None, resp.result)
|
||||||
|
raise Exception("Could not retrieve schema from %s" % connection)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_connection(connection_string):
|
||||||
|
"""Parse a connection string.
|
||||||
|
|
||||||
|
The connection string must be of the form
|
||||||
|
proto:address:port,proto:address:port,...
|
||||||
|
|
||||||
|
The parsing logic here must be identical to the one at
|
||||||
|
https://github.com/openvswitch/ovs/blob/master/python/ovs/db/idl.py#L162
|
||||||
|
for remote connections.
|
||||||
|
|
||||||
|
:param connection_string: The ovsdb-server connection string
|
||||||
|
:type connection_string: string
|
||||||
|
"""
|
||||||
|
return [c.strip() for c in connection_string.split(',')]
|
||||||
|
|
||||||
|
|
||||||
def wait_for_change(_idl, timeout, seqno=None):
|
def wait_for_change(_idl, timeout, seqno=None):
|
||||||
|
|
Loading…
Reference in New Issue