srsue: Create netns on demand
Already existing script osmo-gsm-tester_netns_setup.sh is modified to support only creating the entns without moving an iface to it. Change-Id: I1b7e186b0146f932fe37fbea68e4dfa3120b7a74
This commit is contained in:
parent
666d6c8236
commit
69b2cf3ce2
|
@ -171,6 +171,13 @@ class RemoteHost(log.Origin):
|
|||
SETCAP_NETSYS_ADMIN_BIN = 'osmo-gsm-tester_setcap_netsys_admin.sh'
|
||||
self.run_remote_sync('setcap-netsysadm', ('sudo', SETCAP_NETSYS_ADMIN_BIN, binary_path))
|
||||
|
||||
def create_netns(self, netns):
|
||||
'''
|
||||
It creates the netns if it doesn't already exist.
|
||||
'''
|
||||
NETNS_SETUP_BIN = 'osmo-gsm-tester_netns_setup.sh'
|
||||
self.run_remote_sync('create_netns', ('sudo', NETNS_SETUP_BIN, netns))
|
||||
|
||||
def change_elf_rpath(self, binary_path, paths):
|
||||
'''
|
||||
Change RPATH field in ELF executable binary.
|
||||
|
|
|
@ -125,6 +125,9 @@ class srsUE(MS):
|
|||
self.log('Applying CAP_SYS_ADMIN+CAP_NET_ADMIN capability to srsue')
|
||||
self.rem_host.setcap_netsys_admin(remote_binary)
|
||||
|
||||
self.log('Creating netns %s' % self.netns())
|
||||
self.rem_host.create_netns(self.netns())
|
||||
|
||||
#'strace', '-ff',
|
||||
args = (remote_binary, self.remote_config_file,
|
||||
'--phy.nof_phy_threads=1',
|
||||
|
@ -159,6 +162,9 @@ class srsUE(MS):
|
|||
self.log('Applying CAP_SYS_ADMIN+CAP_NET_ADMIN capability to srsue')
|
||||
util.setcap_netsys_admin(binary, self.run_dir.new_dir('setcap_netsys_admin'))
|
||||
|
||||
self.log('Creating netns %s' % self.netns())
|
||||
util.create_netns(self.netns(), self.run_dir.new_dir('create_netns'))
|
||||
|
||||
args = (binary, os.path.abspath(self.config_file),
|
||||
'--phy.nof_phy_threads=1',
|
||||
'--gw.netns=' + self.netns(),
|
||||
|
|
|
@ -110,15 +110,22 @@ def setcap_netsys_admin(self, binary, run_dir):
|
|||
proc = Process(SETCAP_NETSYS_ADMIN_BIN, run_dir, ['sudo', SETCAP_NETSYS_ADMIN_BIN, binary])
|
||||
proc.launch_sync()
|
||||
|
||||
def move_iface_to_netns(ifname, netns, run_dir):
|
||||
def create_netns(netns, run_dir):
|
||||
'''
|
||||
Moves an iface to a netns. It creates the netns if it doesn't exist.
|
||||
fail_iface_not_found=False is handy in order to assume the iface is already
|
||||
in another netns and thus cannot be foud.
|
||||
It creates the netns if it doesn't already exist.
|
||||
'''
|
||||
from .process import Process
|
||||
NETNS_SETUP_BIN = 'osmo-gsm-tester_netns_setup.sh'
|
||||
proc = Process('move_netns', run_dir, ['sudo', NETNS_SETUP_BIN, ifname, netns])
|
||||
proc = Process('create_netns', ('sudo', NETNS_SETUP_BIN, netns))
|
||||
proc.launch_sync()
|
||||
|
||||
def move_iface_to_netns(ifname, netns, run_dir):
|
||||
'''
|
||||
Moves an iface to a netns. It creates the netns if it doesn't exist.
|
||||
'''
|
||||
from .process import Process
|
||||
NETNS_SETUP_BIN = 'osmo-gsm-tester_netns_setup.sh'
|
||||
proc = Process('move_netns', run_dir, ['sudo', NETNS_SETUP_BIN, netns, ifname])
|
||||
proc.launch_sync()
|
||||
|
||||
def import_path_prepend(pathname):
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
ifname="$1"
|
||||
netns="$2"
|
||||
shift
|
||||
shift
|
||||
|
||||
|
||||
netns="$1"
|
||||
ifname="$2" # optional
|
||||
|
||||
if [ -f "/var/run/netns/${netns}" ]; then
|
||||
echo "netns $netns already exists"
|
||||
|
@ -14,6 +10,10 @@ else
|
|||
ip netns add "$netns"
|
||||
fi
|
||||
|
||||
if [ "x$ifname" = "x" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -d "/sys/class/net/${ifname}" ]; then
|
||||
echo "Moving iface $ifname to netns $netns"
|
||||
ip link set $ifname netns $netns
|
||||
|
|
Loading…
Reference in New Issue