def _validate_optional_links(self, expected, links): expected_types = [e.type_id for e in expected] for l in links.keys(): if l in expected_types: break else: raise exception.OCCISchemaMismatch( expected=', '.join(expected_types), found=l)
def _validate_category(self, category): try: if category.type_id != self.parsed_obj["category"]: raise exception.OCCISchemaMismatch( expected=category.type_id, found=self.parsed_obj["category"]) except KeyError: raise exception.OCCIMissingType(type_id=category.type_id)
def validate(self, schema): if "category" in schema: self._validate_category(schema["category"]) unmatched = copy.copy(self.parsed_obj["mixins"]) unmatched = self._validate_mandatory_mixins(schema.get("mixins", []), unmatched) unmatched = self._validate_optional_mixins( schema.get("optional_mixins", []), unmatched) unexpected = [m for m in unmatched if unmatched[m]] if unexpected: raise exception.OCCISchemaMismatch(expected="", found=unexpected) return True
def _validate_optional_links(self, expected, links): for uri, l in links.items(): try: rel = l['rel'] except KeyError: raise exception.OCCIMissingType(type_id=uri) for ex in expected: if rel == ex.type_id: break else: expected_types = ', '.join([e.type_id for e in expected]) raise exception.OCCISchemaMismatch(expected=expected_types, found=l['rel'])