Commit ac5c03ce authored by Sandipan Das's avatar Sandipan Das Committed by Brenden Blanco

Add a generic utility to check any binary availability

In order to run, some test programs depend on the availability
of binaries in locations that are part of PATH. So, we add a
generic utility to simplify this.
Signed-off-by: default avatarSandipan Das <sandipan@linux.vnet.ibm.com>
parent 50060541
from pyroute2 import NSPopen
from distutils.spawn import find_executable
def has_executable(name):
path = find_executable(name)
if path is None:
raise Exception(name + ": command not found")
return path
class NSPopenWithCheck(NSPopen):
"""
A wrapper for NSPopen that additionally checks if the program
......@@ -11,8 +17,5 @@ class NSPopenWithCheck(NSPopen):
def __init__(self, nsname, *argv, **kwarg):
name = list(argv)[0][0]
path = find_executable(name)
if path is None:
raise Exception(name + ": command not found")
else:
super(NSPopenWithCheck, self).__init__(nsname, *argv, **kwarg)
has_executable(name)
super(NSPopenWithCheck, self).__init__(nsname, *argv, **kwarg)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment