Samba and Python2

Tim Beale timbeale at catalyst.net.nz
Mon Feb 18 04:38:42 UTC 2019


So here's something that runs some basic tests for the nopython build.
Basically I just bypassed all the subunit-filter python code and call
the Perl code directly. We then pass a manually edited test-list to
selftest.pl, which runs a single .sh test against each s3 testenv (apart
from the ad_member ones).

The main thing we're doing is checking the testenv starts up OK, and is
basically usable (i.e. smbclient works). Instead of passing the test
output to subunit-filter to interpret, this just bails out if it ever
hits an error.

Unfortunately, this means that this approach doesn't support known-fail
or flapping tests. That's partly why it's a manually-generated
test-list, rather than generating it using tests.py.

The s3 tests I just picked at random, so there may be better ones that
we could be running.

CI link: https://gitlab.com/samba-team/devel/samba/pipelines/47936495

On 15/02/19 2:48 PM, Tim Beale via samba-technical wrote:
> I've updated the WHATSNEW text with Metze's feedback. Updated blurb
> attached. Patch uploaded to the bug:
> https://bugzilla.samba.org/show_bug.cgi?id=13785
>
> Metze, unfortunately the '-py2' magic was only used for running the
> tests using python2, not building the code itself. samba-buildpy2-only
> was the only target that was actually using PYTHON=python2 in the
> make/configure commands.
>
> At first I tried using the same '-py2' approach, i.e. adding a new
> replaceable '${PY_VERSION}' to the nopython job. But I quickly realized
> this made things quite ugly, and made it more likely I'd mess something
> up. So I just ended up duplicating the existing nopython job instead.
>
> Updated patch-set attached. New CI link:
> https://gitlab.com/samba-team/devel/samba/pipelines/47606161
>
> I think adding some basic tests for nopython is a good idea. However,
> this doesn't seem trivial - all the make test framework is based around
> subunit/smbtorture, neither of which we seem to build with
> disable-python. I'll dig into this some more, but I think in the
> meantime the new nopython-py2 target is no worse than the py3 nopython
> target is already.
>
> On 14/02/19 8:59 PM, Stefan Metzmacher wrote:
>> Am 14.02.19 um 05:13 schrieb Tim Beale via samba-technical:
>>> I've attached an updated patch-set to drop the py2 jobs from CI
>>> (.gitlab-ci.yml just got substantially reworked in master).
>>>
>>> New CI link: https://gitlab.com/samba-team/devel/samba/pipelines/47451100
>>>
>>> On 13/02/19 4:31 PM, Tim Beale via samba-technical wrote:
>>>> Hi,
>>>>
>>>> Just following up on this. How about something like the following? It
>>>> tries to merge what was discussed with what was already in the WHATSNEW.
>>>>
>>>> python3 support
>>>> ---------------
>>>> This is the first release of Samba which has full support for Python 3.
>>>> Samba 4.10 still has support for Python 2, however, Python 3 will be used by
>>>> default, i.e. 'configure' & 'make' will execute using python3.
>>>>
>>>> To build Samba with python2 you *must* set the 'PYTHON' environment variable
>>>> for both the 'configure' and 'make' steps, i.e.
>>>>    'PYTHON=python2 ./configure'
>>>>    'PYTHON=python2 make'
>>>> This will override the python3 default.
>>>>
>>>> Alternatively, it is possible to produce Samba Python bindings for both
>>>> Python 2 and Python 3. To do so, specify '--extra-python=/usr/bin/python2'
>>>> as part of the 'configure' command. Note that python3 will still be used as
>>>> the default in this case.
>>>>
>>>> Note that Samba 4.10 supports Python 3.4 onwards.
>>>>
>>>> Future Python support
>>>> ---------------------
>>>> Samba 4.10 will be the last release that comes with support for Python 2.
>>>> Unfortunately, the Samba Team doesn't have the resources to support both
>>>> Python 2 and Python 3 long-term.
>>>>
>>>> Samba 4.11 will not have any support for Python 2. This means if you use
>>>> Python 2 bindings it is time to migrate to Python 3 now.
>> I think we should make it clear that Python 2 and also any Python 3
>> version would be enough to build --without-python.
>>
>>>> Also note that Samba 4.11 will only support Python 3.6 onwards.
>> I'd say '... will most likely only support ...'
>>
>> We should actually try to keep 3.4+ (or at least 3.5+) as long as we
>> can. E.g. Ubuntu 16.04 uses 3.5.2 and I'm pretty sure it will be
>> security updates even if 3.5 is no longer supported upstream.
>> Debian jessie only has 3.4.2 and stretch 3.5.3.
>>
>> If we really make use of new async/await in important code sections
>> we can discuss it again.
>>
>> I think samba-nopython-py should not be different than samba-nopython.
>> Can't we just keep the magic '-py2' handling for that?
>>
>> I think we should also add some basic tests to it, instead of just
>> compiling it.
>>
>> metze
>>
-------------- next part --------------
From 58a239bdc65782f1d58f3de2f489bcbc39f121fa Mon Sep 17 00:00:00 2001
From: Tim Beale <timbeale at catalyst.net.nz>
Date: Mon, 18 Feb 2019 15:28:49 +1300
Subject: [PATCH 1/3] s3:tests: Set/return $failed in test_smbclient_auth.sh

Update the test so the shell script returns pass/fail as the exit code.

Note that subunit is just looking for 'failure:' in the test output for
whether the test passed or failed, so setting $failed isn't strictly
required.

Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
---
 source3/script/tests/test_smbclient_auth.sh | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/source3/script/tests/test_smbclient_auth.sh b/source3/script/tests/test_smbclient_auth.sh
index e5a7984..9334dd1 100755
--- a/source3/script/tests/test_smbclient_auth.sh
+++ b/source3/script/tests/test_smbclient_auth.sh
@@ -18,6 +18,8 @@ SMBCLIENT="$VALGRIND ${SMBCLIENT}"
 shift 5
 ADDARGS="$*"
 
+failed=0
+
 incdir=`dirname $0`/../../../testprogs/blackbox
 . $incdir/subunit.sh
 
@@ -27,18 +29,19 @@ echo "${SERVER_IP}" | grep -q ':.*:' && {
 	# we also try
 	# fd00-0000-0000-0000-0000-0000-5357-5f03.ipv6-literal.net
 	IPV6LITERAL=$(echo "${SERVER_IP}.ipv6-literal.net" | sed -e 's!:!-!g' -e 's!%!s!')
-	testit "smbclient //${IPV6LITERAL}/tmpguest as user" $SMBCLIENT //${IPV6LITERAL}/tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -c quit $ADDARGS
-	testit "smbclient //${IPV6LITERAL}./tmpguest as user" $SMBCLIENT //${IPV6LITERAL}./tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -c quit $ADDARGS
+	testit "smbclient //${IPV6LITERAL}/tmpguest as user" $SMBCLIENT //${IPV6LITERAL}/tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -c quit $ADDARGS || failed=`expr $failed + 1`
+	testit "smbclient //${IPV6LITERAL}./tmpguest as user" $SMBCLIENT //${IPV6LITERAL}./tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -c quit $ADDARGS || failed=`expr $failed + 1`
 }
-testit "smbclient //${SERVER_IP}/tmpguest as user" $SMBCLIENT //${SERVER_IP}/tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -p 139 -c quit $ADDARGS
+testit "smbclient //${SERVER_IP}/tmpguest as user" $SMBCLIENT //${SERVER_IP}/tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
 
-testit "smbclient //$SERVER/guestonly as user" $SMBCLIENT //$SERVER/guestonly $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/guestonly as anon" $SMBCLIENT //$SERVER/guestonly $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/tmpguest as user" $SMBCLIENT //$SERVER/tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/tmpguest as anon" $SMBCLIENT //$SERVER/tmpguest $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/forceuser as user" $SMBCLIENT //$SERVER/forceuser $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/forceuser as anon" $SMBCLIENT //$SERVER/forceuser $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/forceuser_unixonly as user" $SMBCLIENT //$SERVER/forceuser_unixonly $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/forceuser_wkngroup as user" $SMBCLIENT //$SERVER/forceuser_wkngroup $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/forcegroup as user" $SMBCLIENT //$SERVER/forcegroup $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
-testit "smbclient //$SERVER/forcegroup as anon" $SMBCLIENT //$SERVER/forcegroup $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS
+testit "smbclient //$SERVER/guestonly as user" $SMBCLIENT //$SERVER/guestonly $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/guestonly as anon" $SMBCLIENT //$SERVER/guestonly $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/tmpguest as user" $SMBCLIENT //$SERVER/tmpguest $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/tmpguest as anon" $SMBCLIENT //$SERVER/tmpguest $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/forceuser as user" $SMBCLIENT //$SERVER/forceuser $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/forceuser as anon" $SMBCLIENT //$SERVER/forceuser $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/forceuser_unixonly as user" $SMBCLIENT //$SERVER/forceuser_unixonly $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/forceuser_wkngroup as user" $SMBCLIENT //$SERVER/forceuser_wkngroup $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/forcegroup as user" $SMBCLIENT //$SERVER/forcegroup $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+testit "smbclient //$SERVER/forcegroup as anon" $SMBCLIENT //$SERVER/forcegroup $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS || failed=`expr $failed + 1`
+exit $failed
-- 
2.7.4


From 8bf407a1fb628e91bcd2c8b87bdde3ffaea8c287 Mon Sep 17 00:00:00 2001
From: Tim Beale <timbeale at catalyst.net.nz>
Date: Mon, 18 Feb 2019 15:34:51 +1300
Subject: [PATCH 2/3] selftest: Abort if we fail to startup testenv with
 '--one' option

The --one selftest.pl option means abort when the first test fails.
However, when 'make test' fails to startup a testenv, it'll try to
continue and run other tests by default. When '--one' is used,
selftest.pl can just die() at that point.

Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
---
 selftest/selftest.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/selftest/selftest.pl b/selftest/selftest.pl
index 3ee266c..eb12003 100755
--- a/selftest/selftest.pl
+++ b/selftest/selftest.pl
@@ -980,7 +980,11 @@ sub setup_env($$)
 		        $testenv_vars->{target} = $target;
 		}
 		if (not defined($testenv_vars)) {
-			warn("$opt_target can't start up known environment '$envname'");
+			if ($opt_one) {
+				die("$opt_target can't start up known environment '$envname'");
+			} else {
+				warn("$opt_target can't start up known environment '$envname'");
+			}
 		}
 	}
 
-- 
2.7.4


From de4002faf5bf19b8497eea4134adf36257b43f99 Mon Sep 17 00:00:00 2001
From: Tim Beale <timbeale at catalyst.net.nz>
Date: Mon, 18 Feb 2019 12:52:41 +1300
Subject: [PATCH 3/3] selftest: Add basic sanity-check tests for nopython
 target

Previously we were only checking samba compiled OK with
--disable-python, not that it actually ran.

The main problem is all the make test framework is based around
subunit/smbtorture, neither of which we seem to build with
disable-python. However, for just a simple sanity-check, we can just
bypass all the subunit-filter work and just call the Perl code directly.
This works OK as long as it's just simple shell script tests that we're
running, as we can check the script's exit code directly.

The main thing that we really want to test is that we can start up the
smbd testenv and connect to it (i.e. a simple smbclient test).

This patch adds a new 'make test-nopython' target. This disables the
subunit filtering, and runs a small test-list that was generated manually.

Note that currently this has the limitation that it doesn't support known
failures or flapping tests. However, just checking that smd starts up OK
is probably OK for now.

Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
---
 Makefile                     |  3 +++
 script/autobuild.py          |  2 ++
 selftest/no-python-tests.txt | 32 ++++++++++++++++++++++++++++++++
 selftest/wscript             | 11 ++++++++++-
 4 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 selftest/no-python-tests.txt

diff --git a/Makefile b/Makefile
index c2de1df..d456a41 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,9 @@ randomized-test:
 testlist:
 	$(WAF) test --list $(TEST_OPTIONS)
 
+test-nopython:
+	$(WAF) test --no-subunit-filter --test-list=selftest/no-python-tests.txt $(TEST_OPTIONS)
+
 dist:
 	touch .tmplock
 	WAFLOCK=.tmplock $(WAF) dist
diff --git a/script/autobuild.py b/script/autobuild.py
index f2a2949..729f118 100755
--- a/script/autobuild.py
+++ b/script/autobuild.py
@@ -310,6 +310,7 @@ tasks = {
                       ("configure", "./configure.developer --picky-developer ${PREFIX} --with-profiling-data --disable-python --without-ad-dc", "text/plain"),
                       ("make", "make -j", "text/plain"),
                       ("install", "make install", "text/plain"),
+                      ("test", "make test-nopython", "text/plain"),
                       ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
                       ("clean", "make clean", "text/plain"),
 
@@ -343,6 +344,7 @@ tasks = {
                       ("configure", "PYTHON=python2 ./configure.developer --picky-developer ${PREFIX} --with-profiling-data --disable-python --without-ad-dc", "text/plain"),
                       ("make", "PYTHON=python2 make -j", "text/plain"),
                       ("install", "PYTHON=python2 make install", "text/plain"),
+                      ("test", "make test-nopython", "text/plain"),
                       ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
                       ("clean", "PYTHON=python2 make clean", "text/plain"),
 
diff --git a/selftest/no-python-tests.txt b/selftest/no-python-tests.txt
new file mode 100644
index 0000000..33c2f01
--- /dev/null
+++ b/selftest/no-python-tests.txt
@@ -0,0 +1,32 @@
+# A small subset of tests/testenvs to run as a sanity-check when samba
+# is built with --disable-python. One test-suite for each s3 testenv was
+# selected from 'python source3/selftest/tests.py' (and manually edited to
+# remove the filter-subunit portion of the command).
+# Notes:
+# - you cannot add knownfail tests to this list.
+# - only .sh tests supported here, and they must set and return $failed
+#   appropriately
+-- TEST --
+samba3.blackbox.smb2.not_casesensitive (fileserver)(fileserver)
+fileserver
+./source3/script/tests/test_smb2_not_casesensitive.sh //$SERVER/tmp $SERVER_IP $USERNAME $PASSWORD $LOCAL_PATH bin/smbclient || exit 1
+-- TEST --
+samba3.blackbox.rpcclient_srvsvc(simpleserver)
+simpleserver
+./source3/script/tests/test_rpcclientsrvsvc.sh $USERNAME $PASSWORD $SERVER bin/rpcclient tmp || exit 1
+-- TEST --
+samba3.blackbox.smbclient_large_file  krb5(ktest:local)
+ktest:local
+./source3/script/tests/test_smbclient_large_file.sh $PREFIX/ktest/krb5_ccache-3 bin/smbclient $SERVER $PREFIX  -k --configfile=$SMB_CONF_PATH || exit 1
+-- TEST --
+samba3.blackbox.smbclient_auth.plain (maptoguest) local creds(maptoguest)
+maptoguest
+./source3/script/tests/test_smbclient_auth.sh $SERVER $SERVER_IP $USERNAME $PASSWORD bin/smbclient --configfile=$SMB_CONF_PATH --option=clientntlmv2auth=no --option=clientlanmanauth=yes || exit 1
+-- TEST --
+samba3.blackbox.smbclient_auth.plain (nt4_dc) (nt4_dc)
+nt4_dc
+./source3/script/tests/test_smbclient_auth.sh $SERVER $SERVER_IP $DC_USERNAME $DC_PASSWORD bin/smbclient --configfile=$SMB_CONF_PATH  || exit 1
+-- TEST --
+samba3.blackbox.net_cred_change.(nt4_member:local)(nt4_member:local)
+nt4_member:local
+./source3/script/tests/test_net_cred_change.sh --configfile=$SMB_CONF_PATH || exit 1
diff --git a/selftest/wscript b/selftest/wscript
index b7eec2c..727adcf 100644
--- a/selftest/wscript
+++ b/selftest/wscript
@@ -90,6 +90,10 @@ def options(opt):
                   help=("use tests listed here, not defaults "
                         "(--test-list='FOO|' will execute FOO; "
                         "--test-list='FOO' will read it)"))
+    gr.add_option('--no-subunit-filter',
+                  help=("no (xfail) subunit filtering"),
+                  action="store_true", dest='NO_SUBUNIT_FILTER', default=False)
+
 
 def configure(conf):
     conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
@@ -305,7 +309,12 @@ def cmd_testonly(opt):
     else:
         env.OPTIONS += ' --socket-wrapper'
         cmd = '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
-        if (os.environ.get('RUN_FROM_BUILD_FARM') is None and
+
+        if Options.options.NO_SUBUNIT_FILTER:
+            # Skip subunit filtering (i.e. because python is disabled).
+            # Use --one to bail out upon any failure
+            cmd = '(${CORE_COMMAND} --one && touch ${SELFTEST_PREFIX}/st_done)'
+        elif (os.environ.get('RUN_FROM_BUILD_FARM') is None and
             not Options.options.FILTERED_SUBUNIT):
             subunit_cache = os.path.join(env.SELFTEST_PREFIX, "subunit")
             cmd += ' | tee %s | ${FORMAT_TEST_OUTPUT}' % subunit_cache
-- 
2.7.4



More information about the samba-technical mailing list