vppctl: Do not use sudo if already root 95/3695/2
authorPierre Pfister <ppfister@cisco.com>
Thu, 3 Nov 2016 13:14:29 +0000 (13:14 +0000)
committerDamjan Marion <dmarion.lists@gmail.com>
Fri, 4 Nov 2016 11:22:11 +0000 (11:22 +0000)
When using sudo, environment variable such as the PATH
are overwritten.
This patch just checks if user is already root and does
not use sudo in such situation.
This allows using approaches like:
sudo env PATH=path/to/vpp-binary/:$PATH vppctl

Not really important in production setups, but this is handy
for testing.

Change-Id: I079c104d026ae7d378468380b012279a6e5d765d
Signed-off-by: Pierre Pfister <ppfister@cisco.com>
vpp-api-test/scripts/vppctl

index 160bdf7..6dfa3b9 100755 (executable)
@@ -42,8 +42,12 @@ class Vppctl(Cmd):
                 input_command = input_prefix + line
                 line_remove = '^load_one_plugin:'
                 s = '\n'
+                command = ['vpp_api_test']
 
-                vpp_process = subprocess.Popen(['sudo', 'vpp_api_test'],
+                if os.geteuid() != 0:
+                    command = ['sudo', 'vpp_api_test']
+
+                vpp_process = subprocess.Popen(command,
                         stderr=subprocess.PIPE,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE)