+ def validate_hpa_constraints(self, req_prop, value):
+ for para in value.get(req_prop):
+ # Make sure there is at least one
+ # set of id, type, directives and flavorProperties
+ if not para.get('id') \
+ or not para.get('type') \
+ or not para.get('directives') \
+ or not para.get('flavorProperties') \
+ or para.get('id') == '' \
+ or para.get('type') == '' \
+ or not isinstance(para.get('directives'), list) \
+ or para.get('flavorProperties') == '':
+ raise TranslatorException(
+ "HPA requirements need at least "
+ "one set of id, type, directives and flavorProperties"
+ )
+ for feature in para.get('flavorProperties'):
+ if type(feature) is not dict:
+ raise TranslatorException("HPA feature must be a dict")
+ # process mandatory parameter
+ hpa_mandatory = set(HPA_FEATURES).difference(feature.keys())
+ if bool(hpa_mandatory):
+ raise TranslatorException(
+ "Lack of compulsory elements inside HPA feature")
+ # process optional parameter
+ hpa_optional = set(feature.keys()).difference(HPA_FEATURES)
+ if hpa_optional and not hpa_optional.issubset(HPA_OPTIONAL):
+ raise TranslatorException(
+ "Got unrecognized elements inside HPA feature")
+ if feature.get('mandatory') == 'False' and not feature.get(
+ 'score'):
+ raise TranslatorException(
+ "Score needs to be present if mandatory is False")
+
+ for attr in feature.get('hpa-feature-attributes'):
+ if type(attr) is not dict:
+ raise TranslatorException(
+ "HPA feature attributes must be a dict")
+
+ # 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 attributes")
+ # 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(
+ "Invalid attributes '{}' found inside HPA "
+ "feature attributes".format(hpa_attr_optional))
+