vtep-ctl: Exit if database connection fails.
[cascardo/ovs.git] / tests / test-ovsdb.py
index 170476d..ab951f9 100644 (file)
@@ -105,7 +105,7 @@ def do_parse_atoms(type_string, *atom_strings):
             atom = data.Atom.from_json(base, atom_json)
             print ovs.json.to_string(atom.to_json())
         except error.Error, e:
-            print unicode(e)
+            print e.args[0].encode("utf8")
 
 
 def do_parse_data(type_string, *data_strings):
@@ -228,11 +228,27 @@ def idltest_find_simple(idl, i):
 def idl_set(idl, commands, step):
     txn = ovs.db.idl.Transaction(idl)
     increment = False
+    events = []
     for command in commands.split(','):
         words = command.split()
         name = words[0]
         args = words[1:]
 
+        if name == "notifytest":
+            name = args[0]
+            args = args[1:]
+            old_notify = idl.notify
+
+            def notify(event, row, updates=None):
+                if updates:
+                    upcol = updates._data.keys()[0]
+                else:
+                    upcol = None
+                events.append("%s|%s|%s" % (event, row.i, upcol))
+                idl.notify = old_notify
+
+            idl.notify = notify
+
         if name == "set":
             if len(args) != 3:
                 sys.stderr.write('"set" command requires 3 arguments\n')
@@ -321,6 +337,14 @@ def idl_set(idl, commands, step):
             l1_1.i = 2
             l1_1.k = [l1_0]
             l1_1.ka = [l1_0, l1_1]
+        elif name == 'getattrtest':
+            l1 = txn.insert(idl.tables["link1"])
+            i = getattr(l1, 'i', 1)
+            assert i == 1
+            l1.i = 2
+            i = getattr(l1, 'i', 1)
+            assert i == 2
+            l1.k = [l1]
         else:
             sys.stderr.write("unknown command %s\n" % name)
             sys.exit(1)
@@ -330,13 +354,25 @@ def idl_set(idl, commands, step):
                      % (step, ovs.db.idl.Transaction.status_to_string(status)))
     if increment and status == ovs.db.idl.Transaction.SUCCESS:
         sys.stdout.write(", increment=%d" % txn.get_increment_new_value())
+    if events:
+        # Event notifications from operations in a single transaction are
+        # not in a gauranteed order due to update messages being dicts
+        sys.stdout.write(", events=" + ", ".join(sorted(events)))
     sys.stdout.write("\n")
     sys.stdout.flush()
 
 
 def do_idl(schema_file, remote, *commands):
     schema_helper = ovs.db.idl.SchemaHelper(schema_file)
-    schema_helper.register_all()
+    if commands and commands[0].startswith("?"):
+        monitor = {}
+        for x in commands[0][1:].split("?"):
+            table, columns = x.split(":")
+            monitor[table] = columns.split(",")
+            schema_helper.register_columns(table, monitor[table])
+        commands = commands[1:]
+    else:
+        schema_helper.register_all()
     idl = ovs.db.idl.Idl(remote, schema_helper)
 
     if commands:
@@ -447,11 +483,22 @@ parse-table NAME OBJECT [DEFAULT-IS-ROOT]
   parse table NAME with info OBJECT
 parse-schema JSON
   parse JSON as an OVSDB schema, and re-serialize
-idl SCHEMA SERVER [TRANSACTION...]
+idl SCHEMA SERVER [?T1:C1,C2...[?T2:C1,C2,...]...] [TRANSACTION...]
   connect to SERVER (which has the specified SCHEMA) and dump the
   contents of the database as seen initially by the IDL implementation
   and after executing each TRANSACTION.  (Each TRANSACTION must modify
   the database or this command will hang.)
+  By default, all columns of all tables are monitored. The "?" option
+  can be used to monitor specific Table:Column(s). The table and their
+  columns are listed as a string of the form starting with "?":
+      ?<table-name>:<column-name>,<column-name>,...
+  e.g.:
+      ?simple:b - Monitor column "b" in table "simple"
+  Entries for multiple tables are seperated by "?":
+      ?<table-name>:<column-name>,...?<table-name>:<column-name>,...
+  e.g.:
+      ?simple:b?link1:i,k - Monitor column "b" in table "simple",
+                            and column "i", "k" in table "link1"
 
 The following options are also available:
   -t, --timeout=SECS          give up after SECS seconds