summaryrefslogtreecommitdiff
path: root/tests/test-ovsdb.py
diff options
context:
space:
mode:
authorTed Elhourani <ted.elhourani@nutanix.com>2019-01-25 19:10:01 +0000
committerBen Pfaff <blp@ovn.org>2019-03-22 13:02:11 -0700
commitc39751e44539a014e642bcd930cb9e3a33af1805 (patch)
treef349db1eeec582fa0b992bf961282366cdba50b0 /tests/test-ovsdb.py
parent2a6d9168d68d838604d03aa46084cce1b91ebee7 (diff)
downloadopenvswitch-c39751e44539a014e642bcd930cb9e3a33af1805.tar.gz
python: Monitor Database table to manage lifecycle of IDL client.
The Python IDL implementation supports ovsdb cluster connections. This patch is a follow up to commit 31e434fc98, it adds the option of connecting to the leader (the default) in the Raft-based cluster. It mimics the exisiting C IDL support for clusters introduced in commit 1b1d2e6daa. The _Server database schema is first requested, then a monitor of the Database table in the _Server Database. Method __check_server_db verifies the eligibility of the server. If the attempt to obtain a monitor of the _Server database fails and a cluster id was not provided this implementation proceeds to request the data monitor. If a cluster id was provided via the set_cluster_id method then the connection is aborted and a connection to a different node is instead attempted, until a valid cluster node is found. Thus, when supplied, cluster id is interpreted as the intention to only allow connections to a clustered database. If not supplied, connections to standalone nodes, or nodes that do not have the _Server database are allowed. change_seqno is not incremented in the case of Database table updates. Acked-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ted Elhourani <ted.elhourani@nutanix.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'tests/test-ovsdb.py')
-rw-r--r--tests/test-ovsdb.py67
1 files changed, 66 insertions, 1 deletions
diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py
index 1d7c023da..422321a4c 100644
--- a/tests/test-ovsdb.py
+++ b/tests/test-ovsdb.py
@@ -758,6 +758,70 @@ def do_idl_passive(schema_file, remote, *commands):
print("%03d: done" % step)
+def do_idl_cluster(schema_file, remote, pid, *commands):
+ schema_helper = ovs.db.idl.SchemaHelper(schema_file)
+
+ if remote.startswith("ssl:"):
+ if len(commands) < 3:
+ sys.stderr.write("SSL connection requires private key, "
+ "certificate for private key, and peer CA "
+ "certificate as arguments\n")
+ sys.exit(1)
+ ovs.stream.Stream.ssl_set_private_key_file(commands[0])
+ ovs.stream.Stream.ssl_set_certificate_file(commands[1])
+ ovs.stream.Stream.ssl_set_ca_cert_file(commands[2])
+ commands = commands[3:]
+
+ schema_helper.register_all()
+ idl = ovs.db.idl.Idl(remote, schema_helper)
+
+ step = 0
+ seqno = 0
+ commands = list(commands)
+ for command in commands:
+ if command.startswith("+"):
+ # The previous transaction didn't change anything.
+ command = command[1:]
+ else:
+ # Wait for update.
+ while idl.change_seqno == seqno and not idl.run():
+ poller = ovs.poller.Poller()
+ idl.wait(poller)
+ poller.block()
+ step += 1
+
+ seqno = idl.change_seqno
+
+ if command == "reconnect":
+ print("%03d: reconnect" % step)
+ sys.stdout.flush()
+ step += 1
+ idl.force_reconnect()
+ elif command == "remote":
+ print("%03d: %s" % (step, idl.session_name()))
+ sys.stdout.flush()
+ step += 1
+ elif command == "remotestop":
+ r = idl.session_name()
+ remotes = remote.split(',')
+ i = remotes.index(r)
+ pids = pid.split(',')
+ command = None
+ try:
+ command = "kill %s" % pids[i]
+ except ValueError as error:
+ sys.stderr.write("Cannot find pid of remote: %s\n"
+ % os.strerror(error))
+ sys.exit(1)
+ os.popen(command)
+ print("%03d: stop %s" % (step, pids[i]))
+ sys.stdout.flush()
+ step += 1
+
+ idl.close()
+ print("%03d: done" % step)
+
+
def usage():
print("""\
%(program_name)s: test utility for Open vSwitch database Python bindings
@@ -861,7 +925,8 @@ def main(argv):
"parse-table": (do_parse_table, (2, 3)),
"parse-schema": (do_parse_schema, 1),
"idl": (do_idl, (2,)),
- "idl_passive": (do_idl_passive, (2,))}
+ "idl_passive": (do_idl_passive, (2,)),
+ "idl-cluster": (do_idl_cluster, (3,))}
command_name = args[0]
args = args[1:]