Change in osmo-gsm-tester[master]: modem: Move modem iface to its netns before using it

Pau Espin Pedrol gerrit-no-reply at
Thu Apr 4 16:10:20 UTC 2019

Pau Espin Pedrol has submitted this change and it was merged. ( )

Change subject: modem: Move modem iface to its netns before using it

modem: Move modem iface to its netns before using it

We used to do that once after ofono startup for all iface
(, but then if a modem crashes the interface is
re-created on the default netns, and tests fail until manual re-run of

This way now we always make sure the iface is moved to the expected
netns before it is used.

Related: OS#3881
Change-Id: I506309c424aa46684c4516a1a0217343ecbf32c6
M src/osmo_gsm_tester/
M src/osmo_gsm_tester/
A utils/
3 files changed, 34 insertions(+), 0 deletions(-)

  Jenkins Builder: Verified
  Pau Espin Pedrol: Looks good to me, approved

diff --git a/src/osmo_gsm_tester/ b/src/osmo_gsm_tester/
index 28f7f04..7e58e32 100644
--- a/src/osmo_gsm_tester/
+++ b/src/osmo_gsm_tester/
@@ -677,6 +677,7 @@
         iface = ctx_settings.get('Interface', None)
         if not iface:
             raise log.Error('%s Settings contains no iface! %r' % (ctx_id, repr(ctx_settings)))
+        util.move_iface_to_netns(iface, self.netns(), self.run_dir.new_dir('move_netns'))
         self.run_netns_wait('ifup', ('ip', 'link', 'set', 'dev', iface, 'up'))
         self.run_netns_wait('dhcp', ('udhcpc', '-q', '-i', iface))
diff --git a/src/osmo_gsm_tester/ b/src/osmo_gsm_tester/
index 21653be..b0ce041 100644
--- a/src/osmo_gsm_tester/
+++ b/src/osmo_gsm_tester/
@@ -100,6 +100,17 @@
     proc = Process(SETCAP_NET_ADMIN_BIN, run_dir, ['sudo', SETCAP_NET_ADMIN_BIN, binary])
+def move_iface_to_netns(ifname, 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.
+    '''
+    from .process import Process
+    proc = Process('move_netns', run_dir, ['sudo', NETNS_SETUP_BIN, ifname, netns])
+    proc.launch_sync()
 def import_path_prepend(pathname):
     dir = os.path.realpath(pathname)
     if dir not in sys.path:
diff --git a/utils/ b/utils/
new file mode 100755
index 0000000..1600c44
--- /dev/null
+++ b/utils/
@@ -0,0 +1,22 @@
+#!/bin/bash -e
+if [ -f "/var/run/netns/${netns}" ]; then
+    echo "netns $netns already exists"
+    echo "Creating netns $netns"
+    ip netns add "$netns"
+if [ -d "/sys/class/net/${ifname}" ]; then
+    echo "Moving iface $ifname to netns $netns"
+    ip link set $ifname netns $netns
+    ip netns exec $netns ls "/sys/class/net/${ifname}" >/dev/null && echo "iface $ifname already in netns $netns"

To view, visit
To unsubscribe, or for help writing mail filters, visit

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I506309c424aa46684c4516a1a0217343ecbf32c6
Gerrit-Change-Number: 13526
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gerrit-log mailing list