selftest: Add support for running tests using linux namespaces

This adds optional/experimental support for using linux namespaces instead of socket-wrapper.

The namespaces functionality is fairly self-contained in a few new scripts, and we only need to hook into a couple of places in selftest to use it. So it doesn't complicate selftest too much.

Socket-wrapper is still very much needed by selftest. However, using namespaces offers some potential benefits:

  • Better testing of DNS. Longer-term we'd like to be able to actually run BIND9 in selftest.
  • More realistic testing of Samba, E.g. we've previously noticed LMDB was 20% slower when run in a testenv compared to when run outside.
  • You can (in theory) join a Windows VM to the samba testenv, or point the RSAT GUI at a samba testenv.
  • You can now have multiple shells all running samba utilities simultaneously.
  • The customdc testenv becomes a lot more powerful, e.g. it essentially becomes a light-weight samba VM.

The basic usage is:

USE_NAMESPACES=1 SELFTEST_TESTENV=ad_dc make testenv

There's then a ./st/[testenv]/nsenter.sh helper script you can run to attach other shells to the testenv namespace. E.g.

timbeale@timbeale-pc:~/code/samba$ ./st/ad_dc/nsenter.sh 
DOMAIN=ADDOMAIN
DNSNAME=addom.samba.example.com
REALM=ADDOM.SAMBA.EXAMPLE.COM
DOMSID=S-1-5-21-508928020-2655384664-4115864588
DC_SERVER=addc
DC_SERVER_IP=10.0.0.30
DC_SERVER_IPV6=fd00:0000:0000:0000:0000:0000:5357:5f1e
DC_NETBIOSNAME=ADDC
SERVER=addc
SERVER_IP=10.0.0.30
SERVER_IPV6=fd00:0000:0000:0000:0000:0000:5357:5f1e
NETBIOSNAME=ADDC
SAMSID=S-1-5-21-508928020-2655384664-4115864588
SERVERCONFFILE=/home/timbeale/code/samba/st/ad_dc/etc/smb.conf
USERNAME=Administrator
PASSWORD=locDCpass1
DC_USERNAME=Administrator
DC_PASSWORD=locDCpass1
UID_RFC2307TEST=65533
GID_RFC2307TEST=65532
KRB5_CONFIG=/home/timbeale/code/samba/st/ad_dc/etc/krb5.conf
SELFTEST_WINBINDD_SOCKET_DIR=/home/timbeale/code/samba/st/ad_dc/winbindd_socket
LOCAL_PATH=/home/timbeale/code/samba/st/ad_dc/share
RESOLV_CONF=/home/timbeale/code/samba/st/dns_hub/rootdnsforwarder/resolv.conf
NSS_WRAPPER_PASSWD=/home/timbeale/code/samba/st/ad_dc/etc/passwd
NSS_WRAPPER_GROUP=/home/timbeale/code/samba/st/ad_dc/etc/group
NSS_WRAPPER_HOSTS=/home/timbeale/code/samba/st/hosts
NSS_WRAPPER_HOSTNAME=addc.addom.samba.example.com
NSS_WRAPPER_MODULE_SO_PATH=/home/timbeale/code/samba/bin/default/nsswitch/libnss-wrapper-winbind.so
NSS_WRAPPER_MODULE_FN_PREFIX=winbind
RESOLV_WRAPPER_HOSTS=/home/timbeale/code/samba/st/dns_host_file

Entered ADDC namespace, with above variables defined.
Use CTRL+D or exit to leave the namespace.

root@timbeale-pc:~/code/samba# ip -4 addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: veth30@if4:  mtu 1500 qdisc noqueue state UP group default qlen 1000 link-netnsid 0
    inet 10.0.0.30/24 scope global veth30
       valid_lft forever preferred_lft forever
root@timbeale-pc:~/code/samba# bin/ldbsearch -H ldap://$SERVER -U$USERNAME%$PASSWORD '(cn=Administrator)' dn
# record 1
dn: CN=Administrator,CN=Users,DC=addom,DC=samba,DC=example,DC=com

# Referral
ref: ldap://addom.samba.example.com/CN=Configuration,DC=addom,DC=samba,DC=example,DC=com

# Referral
ref: ldap://addom.samba.example.com/DC=DomainDnsZones,DC=addom,DC=samba,DC=example,DC=com

# Referral
ref: ldap://addom.samba.example.com/DC=ForestDnsZones,DC=addom,DC=samba,DC=example,DC=com

# returned 4 records
# 1 entries
# 3 referrals
root@timbeale-pc:~/code/samba# 
Edited by Tim Beale

Merge request reports

Loading