vpp_papi: remove dependency on environment var. VPP_API_DIR. 52/18352/4
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Mon, 18 Mar 2019 00:34:46 +0000 (17:34 -0700)
committerOle Trøan <otroan@employees.org>
Wed, 15 May 2019 06:56:53 +0000 (06:56 +0000)
Change-Id: I9e3af8674e8aae27079fd03f6286f165d777814f
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
src/vpp-api/python/vpp_papi/vpp_papi.py
test/vpp_papi_provider.py

index 9849d2e..8dcd63a 100644 (file)
@@ -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
index ded7318..291a904 100644 (file)
@@ -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):