fix 1261: change parameter to int/bool according to data-type 30/9830/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 14 Oct 2020 14:59:36 +0000 (14:59 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 14 Oct 2020 15:21:07 +0000 (15:21 +0000)
when executing a VCA primitive, parameter values are always a
string (defined at yang model), but key 'data-type' can indicate
that this is a STRING, INTEGER or BOOLEAN. In case of not a string
data is converted to the target type

Change-Id: I77babb1859b99df9290373deb3568686663d2015
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_lcm/ns.py

index dce1887..7439d26 100644 (file)
@@ -3557,6 +3557,14 @@ class NsLcm(LcmBase):
                                                                width=256)
             elif isinstance(calculated_params[param_name], str) and calculated_params[param_name].startswith("!!yaml "):
                 calculated_params[param_name] = calculated_params[param_name][7:]
+            if parameter.get("data-type") == "INTEGER":
+                try:
+                    calculated_params[param_name] = int(calculated_params[param_name])
+                except ValueError:  # error converting string to int
+                    raise LcmException(
+                        "Parameter {} of primitive {} must be integer".format(param_name, primitive_desc["name"]))
+            elif parameter.get("data-type") == "BOOLEAN":
+                calculated_params[param_name] = not ((str(calculated_params[param_name])).lower() == 'false')
 
         # add always ns_config_info if primitive name is config
         if primitive_desc["name"] == "config":