1LTP namespaces helper tools 2=========================== 3 4 51. Introduction 6--------------- 7 8LTP provides helper tools for creating and working with namespaces. These are 9located in ltp/testcases/kernel/containers/share directory and include: 10 11* tst_ns_create 12** creates a child process in the new specified namespace(s) 13** child is then daemonized and is running in the background 14** PID of the daemonized child process is printed on the stdout 15** the new namespace(s) is(are) maintained by the daemonized child process 16** namespace(s) can be removed by killing the daemonized process 17* tst_ns_exec 18** enters the namespace(s) of a process specified by a PID 19** then executes the indicated program inside that namespace(s) 20* tst_ns_ifmove 21** moves a network interface to the namespace of a process specified by a PID 22 23Purpose of these helper tools is the ability to execute test cases utilizing 24namespaces even on older kernels which do not provide tooling (i.e. unshare(1) 25or nsenter(1) from util-linux) required for working with namespaces. The only 26requirement from kernel side is the support of "setns" syscall. 27 282. Example usage 29---------------- 30 31The following code shows how test cases can use the namespaces helper tools: 32 33[source,sh] 34------------------------------------------------------------------------------- 35# Creates a new network and ipc namespace and stores the PID of the daemonized 36# process inside that namespace into variable myns 37myns=$(tst_ns_create net,ipc) 38 39ip link add veth0 type veth peer name veth1 40 41# Executes command 'ip a' inside the namespace specified by PID in myns variable 42tst_ns_exec $myns net,ipc ip a 431: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN 44 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 45 46# Moves interface veth1 into the namespace specified by PID in myns variable 47tst_ns_ifmove veth1 $myns 48tst_ns_exec $myns net,ipc ip a 491: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN 50 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 516: veth1: <BROADCAST> mtu 1500 qdisc noop state DOWN qlen 1000 52 link/ether 6a:0a:45:ed:6e:d0 brd ff:ff:ff:ff:ff:ff 53 54# cleanup 55ip link del veth0 56# By killing the daemonized process we also delete the namespace 57kill -9 $myns 58------------------------------------------------------------------------------- 59