diff options
author | Dileep Ranganathan <dileep.ranganathan@intel.com> | 2018-03-28 08:37:36 -0700 |
---|---|---|
committer | Dileep Ranganathan <dileep.ranganathan@intel.com> | 2018-03-28 08:37:36 -0700 |
commit | 19b159d57e21b25c2d3eb7b70a371288371c4395 (patch) | |
tree | cdfc2001bc6a14da70cdfe8a524599079018fe31 | |
parent | 0bb996194e6b2c462be39efb12f9f8b1f18f15eb (diff) |
Fixed HPA attribute translation validation
Fixed HPA Feature Atrribute parameters validation in translation
Change-Id: I2dc0c65826e07d26d49f142042e848f66f0176e8
Issue-ID: OPTFRA-168
Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
-rw-r--r-- | conductor/conductor/controller/translator.py | 28 | ||||
-rw-r--r-- | conductor/conductor/tests/unit/controller/test_translator.py | 35 |
2 files changed, 35 insertions, 28 deletions
diff --git a/conductor/conductor/controller/translator.py b/conductor/conductor/controller/translator.py index 7bc212b..2913c69 100644 --- a/conductor/conductor/controller/translator.py +++ b/conductor/conductor/controller/translator.py @@ -107,8 +107,8 @@ CONSTRAINTS = { HPA_FEATURES = ['architecture', 'hpa-feature', 'hpa-feature-attributes', 'hpa-version', 'mandatory'] HPA_OPTIONAL = ['score'] -HPA_ATTRIBUTES = ['hpa-attribute-key', 'hpa-attribute-value', 'operator', - 'unit'] +HPA_ATTRIBUTES = ['hpa-attribute-key', 'hpa-attribute-value', 'operator'] +HPA_ATTRIBUTES_OPTIONAL = ['unit'] class TranslatorException(Exception): @@ -584,16 +584,22 @@ class Translator(object): if type(attr) is not dict: raise TranslatorException( "HPA feature attributes must be a dict") - for name in attr.keys(): - if name not in HPA_ATTRIBUTES: - raise TranslatorException( - "Invalid attribute '{}' found inside HPA " - "feature attributes".format(name)) - if list(attr.keys()) < ['hpa-attribute-key', - 'hpa-attribute-value', 'operator']: + + # process mandatory hpa attribute parameter + hpa_attr_mandatory = set(HPA_ATTRIBUTES).difference( + attr.keys()) + if bool(hpa_attr_mandatory): + raise TranslatorException( + "Lack of compulsory elements inside HPA " + "feature atrributes") + # process optional hpa attribute parameter + hpa_attr_optional = set(attr.keys()).difference( + HPA_ATTRIBUTES) + if hpa_attr_optional and not hpa_attr_optional.issubset( + HPA_ATTRIBUTES_OPTIONAL): raise TranslatorException( - "Lack of compulsory elements " - "inside HPA feature attributes") + "Invalid attributes '{}' found inside HPA " + "feature attributes".format(hpa_attr_optional)) def parse_constraints(self, constraints): """Validate/prepare constraints for use by the solver.""" diff --git a/conductor/conductor/tests/unit/controller/test_translator.py b/conductor/conductor/tests/unit/controller/test_translator.py index 3dedfdf..ba0e3ec 100644 --- a/conductor/conductor/tests/unit/controller/test_translator.py +++ b/conductor/conductor/tests/unit/controller/test_translator.py @@ -392,23 +392,24 @@ class TestNoExceptionTranslator(unittest.TestCase): ], "properties": { "evaluate": [ - {'flavorLabel': 'xx', - 'flavorProperties': [ - { - 'hpa-feature': 'BasicCapabilities', - 'hpa-version': 'v1', - 'architecture': 'generic', - 'mandatory': 'False', - 'score': '5', - 'hpa-feature-attributes': [ - { - 'hpa-attribute-key': 'numVirtualCpu', - 'hpa-attribute-value': '4', - - }, - ] - } - ], } + { + "flavorLabel": "xx", + "flavorProperties": [ + { + "hpa-feature": "BasicCapabilities", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "False", + "score": "5", + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "4" + } + ] + } + ] + } ] } } |