tdb2: create tdb2 versions of various testing TDBs.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 20 Jun 2011 09:10:33 +0000 (18:40 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 20 Jun 2011 09:18:36 +0000 (11:18 +0200)
Soon, TDB2 will handle tdb1 files, but until then, we substitute.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
13 files changed:
lib/tdb/python/tests/simple.py
lib/tdb2/pytdb.c
selftest/target/Samba3.pm
selftest/wscript
source3/selftest/ktest-secrets.tdb2 [new file with mode: 0644]
source4/scripting/python/samba/samba3.py
testdata/samba3/account_policy.tdb2 [new file with mode: 0644]
testdata/samba3/group_mapping.tdb2 [new file with mode: 0644]
testdata/samba3/passdb.tdb2 [new file with mode: 0644]
testdata/samba3/registry.tdb2 [new file with mode: 0644]
testdata/samba3/secrets.tdb2 [new file with mode: 0644]
testdata/samba3/share_info.tdb2 [new file with mode: 0644]
testdata/samba3/winbindd_idmap.tdb2 [new file with mode: 0644]

index 99f31d2..2877092 100644 (file)
@@ -20,8 +20,13 @@ class OpenTdbTests(TestCase):
 class CloseTdbTests(TestCase):
 
     def test_double_close(self):
-        self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
-                os.O_CREAT|os.O_RDWR)
+        # No hash size in tdb2.
+        if tdb.__version__.startswith("2"):
+            self.tdb = tdb.Tdb(tempfile.mkstemp()[1], tdb.DEFAULT,
+                               os.O_CREAT|os.O_RDWR)
+        else:
+            self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
+                               os.O_CREAT|os.O_RDWR)
         self.assertNotEqual(None, self.tdb)
 
         # ensure that double close does not crash python
@@ -42,8 +47,12 @@ class SimpleTdbTests(TestCase):
 
     def setUp(self):
         super(SimpleTdbTests, self).setUp()
-        self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
-                os.O_CREAT|os.O_RDWR)
+        if tdb.__version__.startswith("2"):
+            self.tdb = tdb.Tdb(tempfile.mkstemp()[1], tdb.DEFAULT,
+                               os.O_CREAT|os.O_RDWR)
+        else:
+            self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
+                               os.O_CREAT|os.O_RDWR)
         self.assertNotEqual(None, self.tdb)
 
     def tearDown(self):
@@ -56,7 +65,8 @@ class SimpleTdbTests(TestCase):
         self.tdb.lock_all()
 
     def test_max_dead(self):
-        self.tdb.max_dead = 20
+        if not tdb.__version__.startswith("2"):
+            self.tdb.max_dead = 20
 
     def test_unlockall(self):
         self.tdb.lock_all()
@@ -67,7 +77,8 @@ class SimpleTdbTests(TestCase):
         self.tdb.read_unlock_all()
 
     def test_reopen(self):
-        self.tdb.reopen()
+        if not tdb.__version__.startswith("2"):
+            self.tdb.reopen()
 
     def test_store(self):
         self.tdb.store("bar", "bla")
@@ -75,7 +86,8 @@ class SimpleTdbTests(TestCase):
 
     def test_getitem(self):
         self.tdb["bar"] = "foo"
-        self.tdb.reopen()
+        if not tdb.__version__.startswith("2"):
+            self.tdb.reopen()
         self.assertEquals("foo", self.tdb["bar"])
 
     def test_delete(self):
@@ -91,13 +103,16 @@ class SimpleTdbTests(TestCase):
         self.assertRaises(KeyError, lambda: self.tdb["bla"])
 
     def test_hash_size(self):
-        self.tdb.hash_size
+        if not tdb.__version__.startswith("2"):
+            self.tdb.hash_size
 
     def test_map_size(self):
-        self.tdb.map_size
+        if not tdb.__version__.startswith("2"):
+            self.tdb.map_size
 
     def test_freelist_size(self):
-        self.tdb.freelist_size
+        if not tdb.__version__.startswith("2"):
+            self.tdb.freelist_size
 
     def test_name(self):
         self.tdb.filename
@@ -145,17 +160,19 @@ class SimpleTdbTests(TestCase):
         self.assertEquals(0, len(list(self.tdb)))
 
     def test_repack(self):
-        self.tdb["foo"] = "abc"
-        self.tdb["bar"] = "def"
-        del self.tdb["foo"]
-        self.tdb.repack()
+        if not tdb.__version__.startswith("2"):
+            self.tdb["foo"] = "abc"
+            self.tdb["bar"] = "def"
+            del self.tdb["foo"]
+            self.tdb.repack()
 
     def test_seqnum(self):
-        self.tdb.enable_seqnum()
-        seq1 = self.tdb.seqnum
-        self.tdb.increment_seqnum_nonblock()
-        seq2 = self.tdb.seqnum
-        self.assertEquals(seq2-seq1, 1)
+        if not tdb.__version__.startswith("2"):
+            self.tdb.enable_seqnum()
+            seq1 = self.tdb.seqnum
+            self.tdb.increment_seqnum_nonblock()
+            seq2 = self.tdb.seqnum
+            self.assertEquals(seq2-seq1, 1)
 
     def test_len(self):
         self.assertEquals(0, len(list(self.tdb)))
@@ -163,8 +180,12 @@ class SimpleTdbTests(TestCase):
         self.assertEquals(1, len(list(self.tdb)))
 
     def test_add_flags(self):
-        self.tdb.add_flags(tdb.NOMMAP)
-        self.tdb.remove_flags(tdb.NOMMAP)
+        if tdb.__version__.startswith("2"):
+            self.tdb.add_flag(tdb.NOMMAP)
+            self.tdb.remove_flag(tdb.NOMMAP)
+        else:
+            self.tdb.add_flags(tdb.NOMMAP)
+            self.tdb.remove_flags(tdb.NOMMAP)
 
 
 class VersionTests(TestCase):
index 86f6048..c760045 100644 (file)
@@ -72,12 +72,21 @@ static PyObject *PyString_FromTDB_DATA(TDB_DATA data)
                return NULL; \
        }
 
+static void stderr_log(struct tdb_context *tdb,
+                      enum tdb_log_level level,
+                      const char *message,
+                      void *data)
+{
+       fprintf(stderr, "%s:%s\n", tdb_name(tdb), message);
+}
+
 static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 {
        char *name = NULL;
        int tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600;
        struct tdb_context *ctx;
        PyTdbObject *ret;
+       union tdb_attribute logattr;
        const char *kwnames[] = { "name", "tdb_flags", "flags", "mode", NULL };
 
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siii", (char **)kwnames, &name, &tdb_flags, &flags, &mode))
@@ -87,7 +96,10 @@ static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwarg
                tdb_flags |= TDB_INTERNAL;
        }
 
-       ctx = tdb_open(name, tdb_flags, flags, mode, NULL);
+       logattr.log.base.attr = TDB_ATTRIBUTE_LOG;
+       logattr.log.base.next = NULL;
+       logattr.log.fn = stderr_log;
+       ctx = tdb_open(name, tdb_flags, flags, mode, &logattr);
        if (ctx == NULL) {
                PyErr_SetFromErrno(PyExc_IOError);
                return NULL;
index 595780a..505130f 100644 (file)
@@ -424,7 +424,11 @@ $ret->{USERNAME} = KTEST\\Administrator
 #Samba4 DC with the same parameters as are being used here.  The
 #domain SID is S-1-5-21-1071277805-689288055-3486227160
 
-       system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
+       if (defined($ENV{BUILD_TDB2})) {
+           system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb2 $prefix/private/secrets.tdb");
+       } else {
+           system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
+       }
        chmod 0600, "$prefix/private/secrets.tdb";
 
 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
index ab9f269..558cb2a 100644 (file)
@@ -174,6 +174,9 @@ def cmd_testonly(opt):
     if env.USING_SYSTEM_LDB:
         os.environ['LDB_MODULES_PATH'] = 'bin/modules/ldb'
 
+    if env.BUILD_TDB2:
+        os.environ['BUILD_TDB2'] = '1'
+
     # tell build system where to find config.h
     os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
     os.environ['CONFIG_H'] = 'bin/default/include/config.h'
diff --git a/source3/selftest/ktest-secrets.tdb2 b/source3/selftest/ktest-secrets.tdb2
new file mode 100644 (file)
index 0000000..2af58b1
Binary files /dev/null and b/source3/selftest/ktest-secrets.tdb2 differ
index 2c323bd..ae5b20e 100644 (file)
@@ -50,9 +50,12 @@ class TdbDatabase(object):
     def __init__(self, file):
         """Open a file.
 
-        :param file: Path of the file to open.
+        :param file: Path of the file to open (appending "2" if TDB2 enabled).
         """
-        self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
+        if tdb.__version__.startswith("2"):
+            self.tdb = tdb.Tdb(file + "2", flags=os.O_RDONLY)
+        else:
+            self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
         self._check_version()
 
     def _check_version(self):
diff --git a/testdata/samba3/account_policy.tdb2 b/testdata/samba3/account_policy.tdb2
new file mode 100644 (file)
index 0000000..434787e
Binary files /dev/null and b/testdata/samba3/account_policy.tdb2 differ
diff --git a/testdata/samba3/group_mapping.tdb2 b/testdata/samba3/group_mapping.tdb2
new file mode 100644 (file)
index 0000000..1a6466e
Binary files /dev/null and b/testdata/samba3/group_mapping.tdb2 differ
diff --git a/testdata/samba3/passdb.tdb2 b/testdata/samba3/passdb.tdb2
new file mode 100644 (file)
index 0000000..4ef87ed
Binary files /dev/null and b/testdata/samba3/passdb.tdb2 differ
diff --git a/testdata/samba3/registry.tdb2 b/testdata/samba3/registry.tdb2
new file mode 100644 (file)
index 0000000..d747c3d
Binary files /dev/null and b/testdata/samba3/registry.tdb2 differ
diff --git a/testdata/samba3/secrets.tdb2 b/testdata/samba3/secrets.tdb2
new file mode 100644 (file)
index 0000000..5f88d6a
Binary files /dev/null and b/testdata/samba3/secrets.tdb2 differ
diff --git a/testdata/samba3/share_info.tdb2 b/testdata/samba3/share_info.tdb2
new file mode 100644 (file)
index 0000000..96e4c7a
Binary files /dev/null and b/testdata/samba3/share_info.tdb2 differ
diff --git a/testdata/samba3/winbindd_idmap.tdb2 b/testdata/samba3/winbindd_idmap.tdb2
new file mode 100644 (file)
index 0000000..a63d875
Binary files /dev/null and b/testdata/samba3/winbindd_idmap.tdb2 differ