Commit 3e86f19c30065ee16f7b841ff3cbb3b86d8bcfb2

Authored by Alexis Koralewski
1 parent 282540c5
Exists in dev

config class : improving the validation of enum values, exit program if value isn't in enum

Showing 1 changed file with 7 additions and 1 deletions   Show diff stats
src/core/pyros_django/obsconfig/configpyros.py
... ... @@ -200,6 +200,9 @@ class ConfigPyros:
200 200 if "is_enum" in component_attributes[attribute_name].keys():
201 201 # make an intersection of both list of values
202 202 new_attributes["value"] = list(set(attributes[attribute_name]["value"]) & set(component_attributes[attribute_name]["value"]))
  203 + if len(new_attributes["value"]) == 0:
  204 + print(f"Value of lastly read device's attribute '{attribute_name}' isn't one of the values of component configuration for this device (component configuration value(s): {component_attributes[attribute_name]['value']}) (actual value : {attributes[attribute_name]['value']})")
  205 + exit(1)
203 206 component_attributes[attribute_name] = new_attributes
204 207  
205 208 # return inherited and overwritten attributes of capability
... ... @@ -284,7 +287,7 @@ class ConfigPyros:
284 287 if current_config_component == generic_config_capability["component"]:
285 288 is_capability_in_generic_config = True
286 289 # we're merging their attributes
287   - new_attributes = generic_config_capability["attributes"]
  290 + new_attributes = generic_config_capability["attributes"].copy()
288 291 attributes = {}
289 292 current_config_attributes = current_config_capability["attributes"]
290 293 generic_config_attributes = generic_config_capability["attributes"]
... ... @@ -298,6 +301,9 @@ class ConfigPyros:
298 301 if "is_enum" in generic_config_attributes[attribute_name].keys():
299 302 # make an intersection of both list of values
300 303 new_attributes[attribute_name]["value"] = list(set(attributes[attribute_name]["value"]) & set(generic_config_attributes[attribute_name]["value"]))
  304 + if len(new_attributes[attribute_name]["value"]) == 0:
  305 + print(f"Value of device '{config_file_name}' for attribute '{attribute_name}' isn't one of the values of generic configuration for this device (generic value(s): {generic_config_attributes[attribute_name]['value']}) (actual value : {attributes[attribute_name]['value']})")
  306 + exit(1)
301 307 # removing this capability from generic device configuration
302 308 generic_device_config["DEVICE"]["CAPABILITIES"].pop(index)
303 309 capabilities.append({"component": current_config_component,"attributes":new_attributes})
... ...