[PATCH] Create a custom testenv from backup-file for manual testing

Tim Beale timbeale at catalyst.net.nz
Thu Nov 8 23:33:47 UTC 2018


OK, try applying the attached patches. They should hopefully fix the
problem.

I'll run them through CI just to double-check them.

On 8/11/18 7:42 PM, Andreas Schneider wrote:
> On Wednesday, 7 November 2018 21:27:43 CET Tim Beale wrote:
>> Hi Andreas,
>>
>> OK, that's weird. Do you have the lmdb-utils package installed? It's
>> needed for mdb_copy(), which samba-tool is trying to run at the point it
>> fails.
> ah, I didn't have the lmdb package installed ...
>
> Now the error changed to:
>
> [47(620)/53 at 2m36s, 1 errors] 
> samba.tests.netlogonsvc.python(offlinebackupdc).python3(offlinebackupdc)                                                                  
> ERROR(runtime): uncaught exception - Unable to load default file                                                                                                            
> File "bin/python/samba/netcmd/__init__.py", line 184, in _run                                                                                                               
> return self.run(*args, **kwargs)                                                                                                                                        
> File "bin/python/samba/netcmd/domain_backup.py", line 222, in run                                                                                                           
> lp = sambaopts.get_loadparm()                                                                                                                                         
>   File "bin/python/samba/getopt.py", line 94, in get_loadparm                                                                                                             
>     self._lp.load_default()                                                                                                                                               
> Failed to create backup using:                                                                                                                   
> NSS_WRAPPER_HOSTS='/home/asn/workspace/projects/samba/st/hosts' 
> SOCKET_WRAPPER_DEFAULT_IFACE="41" RESOLV_WRAPPER_HOSTS="/home/asn/workspace/
> projects/samba/st/dns_host_fil
> e"  KRB5_CONFIG="/home/asn/workspace/projects/samba/st/backupfromdc/etc/
> krb5.conf" KRB5CCNAME="/home/asn/workspace/projects/samba/st/restoredc/
> krb5_ccache"  ./bin/samba-t
> ool domain backup online --server=127.0.0.40 -UAdministrator%locDCpass1 --
> targetdir=/home/asn/workspace/projects/samba/st/tmp/TLEybH67BV at /home/asn/
> workspace/projects/s
> amba/selftest/target/Samba4.pm line 2701.                                                                                                                                 
> failed to start up environment 'restoredc' at /home/asn/workspace/projects/
> samba/selftest/target/Samba.pm line 83.                                                        
> samba can't start up known environment 'restoredc' at /home/asn/workspace/
> projects/samba/selftest/selftest.pl line 983.
>
>
>
-------------- next part --------------
From 7574249fdddf788b65d19f0ed5a63c76f704288d Mon Sep 17 00:00:00 2001
From: Tim Beale <timbeale at catalyst.net.nz>
Date: Fri, 9 Nov 2018 11:44:18 +1300
Subject: [PATCH 1/3] selftest: Add README note: always use --configfile in
 testenv creation

We always need to specify "env->{CONFIGURATION}" when running a samba-tool
command to setup a testenv. Add a note to the README as this wasn't at
all clear.

Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
---
 selftest/target/README    | 10 ++++++++++
 selftest/target/Samba3.pm |  3 +++
 selftest/target/Samba4.pm |  3 +++
 3 files changed, 16 insertions(+)

diff --git a/selftest/target/README b/selftest/target/README
index 28a8d00..237cd6c 100644
--- a/selftest/target/README
+++ b/selftest/target/README
@@ -16,6 +16,16 @@ interference.
 
 Some of the different testenvs are described in more detail below.
 
+Important notes if adding a new testenv
+---------------------------------------
+- When adding a new testenv, in the Perl code it is recommended to always
+explicitly specify the --configfile option in the samba-tool command, i.e. add
+"env->{CONFIGURATION}" to the samba-tool command. Otherwise, the samba-tool
+can try to load smb.conf from the default install location (i.e.
+/usr/local/samba/etc/smb.conf). Loading a host-specific smb.conf that's outside
+of the testenv is obviously not ideal and something we want to avoid in a
+reliable test framework.
+
 'local' disambiguation
 ----------------------
 You may notice some variation in the target testenv that test suites are run
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 9166511..cb6bc8c 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -3,6 +3,9 @@
 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
 # Published under the GNU GPL, v3 or later.
 
+# NOTE: Refer to the README for more details about the various testenvs,
+# and tips about adding new testenvs.
+
 package Samba3;
 
 use strict;
diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
index 1f14233..5675600 100755
--- a/selftest/target/Samba4.pm
+++ b/selftest/target/Samba4.pm
@@ -3,6 +3,9 @@
 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
 # Published under the GNU GPL, v3 or later.
 
+# NOTE: Refer to the README for more details about the various testenvs,
+# and tips about adding new testenvs.
+
 package Samba4;
 
 use strict;
-- 
2.7.4


From 5ac3b897a40df8dc7c87968f499008eb0c203540 Mon Sep 17 00:00:00 2001
From: Tim Beale <timbeale at catalyst.net.nz>
Date: Fri, 9 Nov 2018 11:49:12 +1300
Subject: [PATCH 2/3] selftest: Fix backup testenv creation on certain host
 machines

When we created the backup-file for the restoredc/renamedc/labdc
testenvs we weren't explicitly a --configfile on the samba-tool command.
This meant the command tried to use the smb.conf form the default
install location, i.e. /usr/local/samba/etc/smb.conf. On the gitlab CI
runner, there's no samba installed, so it ends up using the default
settings, which is fine. However, if the host machine had an invalid
smb.conf installed there, creating the testenv would fail with an error
like:

ERROR(runtime): uncaught exception - Unable to load default file
File "bin/python/samba/netcmd/__init__.py", line 184, in _run
return self.run(*args, **kwargs)
File "bin/python/samba/netcmd/domain_backup.py", line 222, in run
lp = sambaopts.get_loadparm()
  File "bin/python/samba/getopt.py", line 94, in get_loadparm
    self._lp.load_default()

We can avoid this by always explictly specifying the backupfromdc's
smb.conf when creating the backup file.

Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
---
 selftest/target/Samba4.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
index 5675600..dac5cfc 100755
--- a/selftest/target/Samba4.pm
+++ b/selftest/target/Samba4.pm
@@ -2670,6 +2670,7 @@ sub get_backup_server_args
 	my $server = $dcvars->{DC_SERVER_IP};
 	my $server_args = "--server=$server ";
 	$server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
+	$server_args .= " $dcvars->{CONFIGURATION}";
 
 	return $server_args;
 }
-- 
2.7.4


From c54500b1c52dbc2cb9ad0d89262e3f3ae8bfcbbf Mon Sep 17 00:00:00 2001
From: Tim Beale <timbeale at catalyst.net.nz>
Date: Fri, 9 Nov 2018 12:17:40 +1300
Subject: [PATCH 3/3] mdb_util: Better error message if lmdb-utils not
 installed

mdb_copy() was dutifully checking the PATH for the mdb_copy executable,
then, if it didn't find it, blindly proceeding anyway and trying to run
a non-existent executable. This resulted in a cryptic error:

  ERROR(<type 'exceptions.OSError'>): uncaught exception - [Errno 2] No
    such file or directory

Add in an extra check that we actually find the executable and raise a
more human-readable exception if we don't.

Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
---
 python/samba/mdb_util.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/python/samba/mdb_util.py b/python/samba/mdb_util.py
index 4dbff48..1be16d5 100644
--- a/python/samba/mdb_util.py
+++ b/python/samba/mdb_util.py
@@ -19,6 +19,7 @@
 import samba
 import subprocess
 import os
+from samba.netcmd import CommandError
 
 
 def mdb_copy(file1, file2):
@@ -26,11 +27,17 @@ def mdb_copy(file1, file2):
     """
     # Find the location of the mdb_copy tool
     dirs = os.getenv('PATH').split(os.pathsep)
+    found = False
     for d in dirs:
         toolpath = os.path.join(d, "mdb_copy")
         if os.path.exists(toolpath):
+            found = True
             break
 
+    if not found:
+        raise CommandError("mdb_copy not found. "
+                           "You may need to install the lmdb-utils package")
+
     mdb_copy_cmd = [toolpath, "-n", file1, "%s.copy.mdb" % file1]
     status = subprocess.check_call(mdb_copy_cmd, close_fds=True, shell=False)
 
-- 
2.7.4



More information about the samba-technical mailing list