Browse code

Fix error in 'ip netns' parsing

Sometimes when doing worlddump would see a command line like this:
sudo ip netns exec (id: ip addr

This would cause an error to be seen in console.log:
2017-02-07 00:03:03.659570 | /bin/sh: 1: Syntax error: "(" unexpected

This is caused by there sometimes being extra data returned from the
'ip netns' command [1]. For example it might look like:
qrouter-0805fd7d-c493-4fa6-82ca-1c6c9b23cd9e (id: 1)
qdhcp-bb2cc6ae-2ae8-474f-adda-a94059b872b5 (id: 0)

[1] https://lwn.net/Articles/629715/

Change-Id: Icece442023125ef55696b8d92a975d37e358b1b4
Closes-Bug: 1653969

John L. Villalovos authored on 2017/02/07 07:24:42
Showing 1 changed files
... ...
@@ -151,7 +151,11 @@ def iptables_dump():
151 151
 def _netns_list():
152 152
     process = subprocess.Popen(['ip', 'netns'], stdout=subprocess.PIPE)
153 153
     stdout, _ = process.communicate()
154
-    return stdout.split()
154
+    # NOTE(jlvillal): Sometimes 'ip netns list' can return output like:
155
+    #   qrouter-0805fd7d-c493-4fa6-82ca-1c6c9b23cd9e (id: 1)
156
+    #   qdhcp-bb2cc6ae-2ae8-474f-adda-a94059b872b5 (id: 0)
157
+    output = [x.split()[0] for x in stdout.splitlines()]
158
+    return output
155 159
 
156 160
 
157 161
 def network_dump():