[PATCHES] two kcc flapping tests and an ldb debug optimisation

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Wed Oct 17 04:40:41 UTC 2018


These are in autobuild with Andrew's review.

The chaos of python 3 KCC does not like to be caged in.

Douglas
-------------- next part --------------
From 60b1a1cfcb23d581e49455ba3ef219dfd3bddd99 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Wed, 17 Oct 2018 09:50:41 +1300
Subject: [PATCH 1/3] py3/tests/kcc: turn error into failure for flapping.d/kcc

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
---
 python/samba/tests/kcc/__init__.py | 5 ++++-
 selftest/flapping.d/kcc_verify_py3 | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/python/samba/tests/kcc/__init__.py b/python/samba/tests/kcc/__init__.py
index 39167824d35..a8b50709d1b 100644
--- a/python/samba/tests/kcc/__init__.py
+++ b/python/samba/tests/kcc/__init__.py
@@ -62,7 +62,10 @@ class KCCTests(samba.tests.TestCase):
         my_kcc = kcc.KCC(unix_now, False, False, False, False)
         my_kcc.load_samdb("ldap://%s" % os.environ["SERVER"],
                           self.lp, self.creds)
-        dsas = my_kcc.list_dsas()
+        try:
+            dsas = my_kcc.list_dsas()
+        except kcc.KCCError as e:
+            self.fail("kcc.list_dsas failed with %s" % e)
         env = os.environ['TEST_ENV']
         for expected_dsa in ENV_DSAS[env]:
             self.assertIn(expected_dsa, dsas)
diff --git a/selftest/flapping.d/kcc_verify_py3 b/selftest/flapping.d/kcc_verify_py3
index 03005fca933..e96ce18ef8d 100644
--- a/selftest/flapping.d/kcc_verify_py3
+++ b/selftest/flapping.d/kcc_verify_py3
@@ -1 +1 @@
-samba.tests.kcc.python3.samba.tests.kcc.KCCTests.test_verify
+samba.tests.kcc.python3.samba.tests.kcc.KCCTests
-- 
2.17.1


From ab0791427e75e031e40f7de3e1124be7fd602c9d Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Wed, 17 Oct 2018 17:21:09 +1300
Subject: [PATCH 2/3] py3_tests/kcc : test_verify can hit KCCError as well as
 GraphError

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
---
 python/samba/tests/kcc/__init__.py | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/python/samba/tests/kcc/__init__.py b/python/samba/tests/kcc/__init__.py
index a8b50709d1b..3ca20845c58 100644
--- a/python/samba/tests/kcc/__init__.py
+++ b/python/samba/tests/kcc/__init__.py
@@ -78,22 +78,13 @@ class KCCTests(samba.tests.TestCase):
         my_kcc = kcc.KCC(unix_now, readonly=True, verify=True,
                          debug=False, dot_file_dir=None)
 
-        #
-        # The following seems to raise
-        # samba.kcc.graph_utils.GraphError when something
-        # goes wrong.
-        #
-        # Typically failureException is exceptions.AssertionError
-        # by default, see pydoc unittest.TestCase
-        #
-        # As this is flapping under python3, we need to
-        # make sure it generates a failure instead of an error.
-        #
-        # We need to make sure samba.kcc.graph_utils.GraphError
-        # will generate a failure from here on.
-        #
-        self.failureException = samba.kcc.graph_utils.GraphError
-
-        my_kcc.run("ldap://%s" % os.environ["SERVER"],
-                   self.lp, self.creds,
-                   attempt_live_connections=False)
+        # As this is flapping with errors under python3, we catch
+        # exceptions and turn them into failures..
+        try:
+            my_kcc.run("ldap://%s" % os.environ["SERVER"],
+                       self.lp, self.creds,
+                       attempt_live_connections=False)
+        except (samba.kcc.graph_utils.GraphError, kcc.KCCError):
+            import traceback
+            traceback.print_exc()
+            self.fail()
-- 
2.17.1


From bb68f750e62385dd963e4d12c042c30acd29e8d0 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Wed, 17 Oct 2018 16:28:25 +1300
Subject: [PATCH 3/3] ldb_ldif: be less horribly efficient in debugging

perf said all the time was in strlen.

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
---
 lib/ldb/common/ldb_ldif.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/ldb/common/ldb_ldif.c b/lib/ldb/common/ldb_ldif.c
index e23b568707d..ec1859b5c0d 100644
--- a/lib/ldb/common/ldb_ldif.c
+++ b/lib/ldb/common/ldb_ldif.c
@@ -313,6 +313,7 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
 
 	for (i=0;i<msg->num_elements;i++) {
 		const struct ldb_schema_attribute *a;
+		size_t namelen = strlen(msg->elements[i].name);
 
 		if (msg->elements[i].name == NULL) {
 			ldb_debug(ldb, LDB_DEBUG_ERROR,
@@ -347,7 +348,6 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
 			CHECK_RET;
 			continue;
 		}
-
 		for (j=0;j<msg->elements[i].num_values;j++) {
 			struct ldb_val v;
 			bool use_b64_encode = false;
@@ -371,7 +371,7 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
 				CHECK_RET;
 				ret = base64_encode_f(ldb, fprintf_fn, private_data,
 						      (char *)v.data, v.length,
-						      strlen(msg->elements[i].name)+3);
+						      namelen + 3);
 				CHECK_RET;
 				ret = fprintf_fn(private_data, "\n");
 				CHECK_RET;
@@ -384,7 +384,7 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
 				} else {
 					ret = fold_string(fprintf_fn, private_data,
 							  (char *)v.data, v.length,
-							  strlen(msg->elements[i].name)+2);
+							  namelen + 2);
 				}
 				CHECK_RET;
 				ret = fprintf_fn(private_data, "\n");
-- 
2.17.1



More information about the samba-technical mailing list