mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
c68537d5dd
This patch adds some helper scripts that make talking to a given testenv's namespace slightly easier. One of the really cool things about namespaces is you can run multiple different programs that can all talk to the testenv DC. However, the command to do this is a bit unweildly, it's based on PID so it changes everytime you start up a testenv, and you loose all the environment variables that selftest normally sets up. This patch adds a couple of helper scripts: - nsenter-helper.sh: this takes the variables defined in an exports_file and exports them all. It prints some basic help and then starts a new shell session (this whole script gets run in the new namespace). Essentially this achieves something similar to the legacy selftest-vars.sh script (except this one actually works). - mk_nsenter.sh: this generates a simple wrapper script that'll run nsenter and then call nsenter-helper.sh. A separate wrapper script gets created for each testenv. E.g. to run it, just go: ./st/ad_dc/nsenter.sh This is a wrapper for a more complicated command underneath like: nsenter -t 437353 --net --user --preserve-credentials \ /home/timbeale/code/samba/selftest/ns/nsenter-helper.sh \ /home/timbeale/code/samba/st/ad_dc/exports.sh Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
33 lines
1.2 KiB
Bash
Executable File
33 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Helper script. If you want a 2nd shell that communicates with the testenv DC
|
|
# you can use the nsenter command to change the namespace you're in. However,
|
|
# this command is a bit unwieldly and changes depending on the testenv PID.
|
|
# We can generate a helper script on the fly that abstracts all this
|
|
# complexity, allowing you to use the same, simple command to change the
|
|
# namespace that you're in, e.g.
|
|
# st/ad_dc/nsenter.sh
|
|
|
|
pid=$1
|
|
exports_file=$2
|
|
|
|
# The basic command to enter the testenv's network namespace.
|
|
# We enter the user namespace as well (as ourself, which is really the root
|
|
# user for the namespace), otherwise we need sudo to make this work.
|
|
nsenter_cmd="nsenter -t $pid --net --user --preserve-credentials"
|
|
|
|
# By default, the nsenter command will just start a new shell in the namespace.
|
|
# we use a wrapper helper script, which first loads all the environment
|
|
# variables that are usually defined in selftest (and prints some basic help).
|
|
helper_script="$(dirname $0)/nsenter-helper.sh $exports_file"
|
|
|
|
# generate the dynamic script
|
|
dyn_script="$(dirname $2)/nsenter.sh"
|
|
echo "#!/bin/sh" > $dyn_script
|
|
echo "$nsenter_cmd $helper_script" >> $dyn_script
|
|
chmod 755 $dyn_script
|
|
|
|
# return the script we created
|
|
echo "$dyn_script"
|
|
|