X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=conductor%2Fconductor%2Fcontroller%2Ftranslator.py;h=2913c695b6f5982c4dc37c491f6a827d37133fad;hb=19b159d57e21b25c2d3eb7b70a371288371c4395;hp=7bc212baa9d0e6c344ab783c13ea9ffb84ef957e;hpb=0bb996194e6b2c462be39efb12f9f8b1f18f15eb;p=optf%2Fhas.git 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."""