diff options
-rw-r--r-- | src/vpp-api/python/vpp_papi/vpp_papi.py | 15 | ||||
-rw-r--r-- | test/vpp_papi_provider.py | 19 |
2 files changed, 18 insertions, 16 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py index 9849d2e487c..8dcd63a0c55 100644 --- a/src/vpp-api/python/vpp_papi/vpp_papi.py +++ b/src/vpp-api/python/vpp_papi/vpp_papi.py @@ -121,7 +121,7 @@ class VPPValueError(ValueError): pass -class VPP(object): +class VPPApiClient(object): """VPP interface. This class provides the APIs to VPP. The APIs are loaded @@ -133,6 +133,7 @@ class VPP(object): provides a means to register a callback function to receive these messages in a background thread. """ + apidir = None VPPApiError = VPPApiError VPPRuntimeError = VPPRuntimeError VPPValueError = VPPValueError @@ -211,6 +212,9 @@ class VPP(object): loglevel, if supplied, is the log level this logger is set to report at (from the loglevels in the logging module). """ + if apifiles is None and self.__class__.apidir is None: + raise ValueError("Either apifiles or apidir must be specified.") + if logger is None: logger = logging.getLogger(__name__) if loglevel is not None: @@ -288,10 +292,7 @@ class VPP(object): :returns: A single directory name, or None if no such directory could be found. """ - dirs = [] - - if 'VPP_API_DIR' in os.environ: - dirs.append(os.environ['VPP_API_DIR']) + dirs = [cls.apidir] # perhaps we're in the 'src/scripts' or 'src/vpp-api/python' dir; # in which case, plot a course to likely places in the src tree @@ -353,7 +354,7 @@ class VPP(object): # finally, try the location system packages typically install into dirs.append(os.path.sep.join(('', 'usr', 'share', 'vpp', 'api'))) - # check the directories for existance; first one wins + # check the directories for existence; first one wins for dir in dirs: if os.path.isdir(dir): return dir @@ -713,5 +714,7 @@ class VPP(object): if self.event_callback: self.event_callback(msgname, r) +# Provide the old name for backward compatibility. +VPP = VPPApiClient # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index ded73189e00..291a904dd6f 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -10,7 +10,7 @@ import time from collections import deque from six import moves, iteritems -from vpp_papi import VPP, mac_pton +from vpp_papi import VPPApiClient, mac_pton from hook import Hook from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID @@ -191,11 +191,9 @@ class VppPapiProvider(object): self._expect_api_retval = self._zero self._expect_stack = [] - install_dir = os.getenv('VPP_INSTALL_PATH') - - # Vapi requires 'VPP_API_DIR', not set when run from Makefile. - if 'VPP_API_DIR' not in os.environ: - os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH') + # install_dir is a class attribute. We need to set it before + # calling the constructor. + VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH') use_socket = False try: @@ -203,10 +201,11 @@ class VppPapiProvider(object): use_socket = True except KeyError: pass - self.vpp = VPP(logger=test_class.logger, - read_timeout=read_timeout, - use_socket=use_socket, - server_address=test_class.api_sock) + + self.vpp = VPPApiClient(logger=test_class.logger, + read_timeout=read_timeout, + use_socket=use_socket, + server_address=test_class.api_sock) self._events = deque() def __enter__(self): |