vppapigen map: raise ValueError when fieldname is python keyword 04/21204/5
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Tue, 6 Aug 2019 23:58:24 +0000 (19:58 -0400)
committerDave Wallace <dwallacelf@gmail.com>
Mon, 19 Aug 2019 14:38:12 +0000 (14:38 +0000)
When working on the lb api, one of the field names was chosen as 'as'
(application server). Since 'as' is a python keyword, the field was
renamed to _1 in vpp_papi.

This changeset instead fails early with a descriptive message,
hopefully saving others time troubleshooting the issue.

    ValueError: Fieldname 'as' is a python keyword and
    is not accessible via the python API.

Type: feature
Change-Id: Ib048d97de0e392645540092e356cf8989848c947
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
src/plugins/map/map.api
src/plugins/map/map_api.c
src/tools/vppapigen/vppapigen.py

index f751f5c..b15b38a 100644 (file)
@@ -13,7 +13,7 @@
  * limitations under the License.
  */
 
-option version = "3.1.0";
+option version = "4.0.0";
 
 import "vnet/ip/ip_types.api";
 
@@ -281,19 +281,19 @@ autoreply define map_param_set_security_check
 /** \brief Set MAP traffic class parameters
     @param client_index - opaque cookie to identify the sender
     @param context - sender context, to match reply w/ request
-    @param copy - 1 = copy packet class/TOS field, 0 = use class instead
-    @param class - class field value when copy == 0
+    @param copy - 1 = copy packet class/TOS field, 0 = use tc_class instead
+    @param tc_class - class field value when copy == 0
 */
 autoreply define map_param_set_traffic_class
 {
   u32 client_index;
   u32 context;
   bool copy;
-  u8 class;
+  u8 tc_class;
 };
 
 
-/** \brief Set MAP TCP parammeters
+/** \brief Set MAP TCP parameters
     @param client_index - opaque cookie to identify the sender
     @param context - sender context, to match reply w/ request
     @parma tcp_mss - TCP MSS clamping value
index 4a0834d..1e50ba1 100644 (file)
@@ -523,7 +523,7 @@ static void
   vl_api_map_param_set_traffic_class_reply_t *rmp;
   int rv;
 
-  rv = map_param_set_traffic_class (mp->copy, mp->class);
+  rv = map_param_set_traffic_class (mp->copy, mp->tc_class);
 
   REPLY_MACRO (VL_API_MAP_PARAM_SET_TRAFFIC_CLASS_REPLY);
 }
index 8ae991c..52ffb6a 100755 (executable)
@@ -5,6 +5,7 @@ import ply.lex as lex
 import ply.yacc as yacc
 import sys
 import argparse
+import keyword
 import logging
 import binascii
 import os
@@ -293,6 +294,9 @@ class Field():
     def __init__(self, fieldtype, name, limit=None):
         self.type = 'Field'
         self.fieldtype = fieldtype
+        if name in keyword.kwlist:
+            raise ValueError("Fieldname {!r} is a python keyword and is not "
+                             "accessible via the python API. ".format(name))
         self.fieldname = name
         self.limit = limit