def _resolve_blueprint_imports(dsl_location, dsl_string, resolver, resources_base_path, validate_version): """ Goes over all the blueprint's imports and constructs a merged blueprint from them. """ parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string, error_message='Failed to parse DSL', filename=dsl_location) if not resolver: resolver = DefaultImportResolver() # validate version schema and extract actual version used result = parser.parse(parsed_dsl_holder, element_cls=blueprint.BlueprintVersionExtractor, inputs={'validate_version': validate_version}, strict=False) version = result['plan_version'] # handle imports result = parser.parse(value=parsed_dsl_holder, inputs={ 'main_blueprint_holder': parsed_dsl_holder, 'resources_base_path': resources_base_path, 'blueprint_location': dsl_location, 'version': version, 'resolver': resolver, 'validate_version': validate_version }, element_cls=blueprint.BlueprintImporter, strict=False) return result['resource_base'],\ result['merged_blueprint']
def _parse(dsl_string, resources_base_url, dsl_location=None): parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string, error_message='Failed to parse DSL', filename=dsl_location) # validate version result = parser.parse(parsed_dsl_holder, element_cls=blueprint.BlueprintVersionExtractor, strict=False) version = result['plan_version'] # handle imports result = parser.parse( value=parsed_dsl_holder, inputs={ 'main_blueprint_holder': parsed_dsl_holder, 'resources_base_url': resources_base_url, 'blueprint_location': dsl_location, 'version': version }, element_cls=blueprint.BlueprintImporter, strict=False) resource_base = result['resource_base'] merged_blueprint_holder = result['merged_blueprint'] # parse blueprint plan = parser.parse( value=merged_blueprint_holder, inputs={ 'resource_base': resource_base }, element_cls=blueprint.Blueprint) functions.validate_functions(plan) return plan
def validate(obj, element_cls): class TestElement(Element): schema = { 'tosca_definitions_version': misc.ToscaDefinitionsVersion, 'test': element_cls } obj = { 'tosca_definitions_version': 'cloudify_dsl_1_1', 'test': obj } parser.parse(obj, element_cls=TestElement, strict=True)
def _parse(dsl_string, resources_base_path, dsl_location=None, resolver=None, validate_version=True, additional_resource_sources=()): parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string, error_message='Failed to parse DSL', filename=dsl_location) if not resolver: resolver = DefaultImportResolver() # validate version schema and extract actual version used result = parser.parse( parsed_dsl_holder, element_cls=blueprint.BlueprintVersionExtractor, inputs={ 'validate_version': validate_version }, strict=False) version = result['plan_version'] # handle imports result = parser.parse( value=parsed_dsl_holder, inputs={ 'main_blueprint_holder': parsed_dsl_holder, 'resources_base_path': resources_base_path, 'blueprint_location': dsl_location, 'version': version, 'resolver': resolver, 'validate_version': validate_version }, element_cls=blueprint.BlueprintImporter, strict=False) resource_base = [result['resource_base']] if additional_resource_sources: resource_base.extend(additional_resource_sources) merged_blueprint_holder = result['merged_blueprint'] # parse blueprint plan = parser.parse( value=merged_blueprint_holder, inputs={ 'resource_base': resource_base, 'validate_version': validate_version }, element_cls=blueprint.Blueprint) functions.validate_functions(plan) return plan
def validate(obj, element_cls): class TestElement(Element): schema = { 'tosca_definitions_version': version.ToscaDefinitionsVersion, 'test': element_cls, 'data_types': data_types.DataTypes } obj = {'tosca_definitions_version': 'cloudify_dsl_1_1', 'test': obj} parser.parse(obj, element_cls=TestElement, inputs={'validate_version': True}, strict=True)
def _parse(dsl_string, resources_base_path, dsl_location=None, resolver=None, validate_version=True, additional_resource_sources=()): parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string, error_message='Failed to parse DSL', filename=dsl_location) if not resolver: resolver = DefaultImportResolver() # validate version schema and extract actual version used result = parser.parse(parsed_dsl_holder, element_cls=blueprint.BlueprintVersionExtractor, inputs={'validate_version': validate_version}, strict=False) version = result['plan_version'] # handle imports result = parser.parse(value=parsed_dsl_holder, inputs={ 'main_blueprint_holder': parsed_dsl_holder, 'resources_base_path': resources_base_path, 'blueprint_location': dsl_location, 'version': version, 'resolver': resolver, 'validate_version': validate_version }, element_cls=blueprint.BlueprintImporter, strict=False) resource_base = [result['resource_base']] if additional_resource_sources: resource_base.extend(additional_resource_sources) merged_blueprint_holder = result['merged_blueprint'] # parse blueprint plan = parser.parse(value=merged_blueprint_holder, inputs={ 'resource_base': resource_base, 'validate_version': validate_version }, element_cls=blueprint.Blueprint) functions.validate_functions(plan) return plan
def validate(obj, element_cls): class TestElement(Element): schema = { 'tosca_definitions_version': version.ToscaDefinitionsVersion, 'test': element_cls, 'data_types': data_types.DataTypes } obj = { 'tosca_definitions_version': 'cloudify_dsl_1_1', 'test': obj } parser.parse(obj, element_cls=TestElement, inputs={ 'validate_version': True }, strict=True)
def _parse(dsl_string, resources_base_url, dsl_location=None, resolver=None, validate_version=True): parsed_dsl_holder = utils.load_yaml(raw_yaml=dsl_string, error_message="Failed to parse DSL", filename=dsl_location) if not resolver: resolver = DefaultImportResolver() # validate version schema and extract actual version used result = parser.parse( parsed_dsl_holder, element_cls=blueprint.BlueprintVersionExtractor, inputs={"validate_version": validate_version}, strict=False, ) version = result["plan_version"] # handle imports result = parser.parse( value=parsed_dsl_holder, inputs={ "main_blueprint_holder": parsed_dsl_holder, "resources_base_url": resources_base_url, "blueprint_location": dsl_location, "version": version, "resolver": resolver, "validate_version": validate_version, }, element_cls=blueprint.BlueprintImporter, strict=False, ) resource_base = result["resource_base"] merged_blueprint_holder = result["merged_blueprint"] # parse blueprint plan = parser.parse( value=merged_blueprint_holder, inputs={"resource_base": resource_base, "validate_version": validate_version}, element_cls=blueprint.Blueprint, ) functions.validate_functions(plan) return plan
def _parse(dsl_string, resources_base_path, dsl_location=None, resolver=None, validate_version=True, validate_intrinsic_function=True, additional_resource_sources=(), validate_input_defaults=True): """ :param dsl_string: parsing input in form of a string. :param resources_base_path: resources base path. :param dsl_location: yaml location. :param resolver: resolver. :param validate_version: whether to validate version of the DSL. :param validate_intrinsic_function: whether to validate intrinsic functions. :param additional_resource_sources: additional resource sources. :param validate_input_defaults: whether to validate given input constraints on input default values. """ resource_base, merged_blueprint_holder =\ _resolve_blueprint_imports(dsl_location, dsl_string, resolver, resources_base_path, validate_version) resource_base = [resource_base] if additional_resource_sources: resource_base.extend(additional_resource_sources) # parse blueprint plan = parser.parse(value=merged_blueprint_holder, inputs={ 'resource_base': resource_base, 'validate_version': validate_version }, element_cls=blueprint.Blueprint) if validate_input_defaults: constraints.validate_input_defaults(plan) if validate_intrinsic_function: functions.validate_functions(plan) return plan, merged_blueprint_holder
def _parse(dsl_string, resources_base_path, dsl_location=None, resolver=None, validate_version=True, additional_resource_sources=()): resource_base, merged_blueprint_holder =\ resolve_blueprint_imports(dsl_location, dsl_string, resolver, resources_base_path, validate_version) resource_base = [resource_base] if additional_resource_sources: resource_base.extend(additional_resource_sources) # parse blueprint plan = parser.parse(value=merged_blueprint_holder, inputs={ 'resource_base': resource_base, 'validate_version': validate_version }, element_cls=blueprint.Blueprint) functions.validate_functions(plan) return plan
def assert_valid(self, value, element_cls, strict=True): self.assertEqual( parser.parse(value=value, element_cls=element_cls, strict=strict), value)
def assert_valid(self, value, element_cls, strict=True): self.assertEqual(parser.parse(value=value, element_cls=element_cls, strict=strict), value)
def assert_invalid(self, value, element_cls, strict=True, error_code=1): with self.assertRaises(exceptions.DSLParsingException) as cm: parser.parse(value=value, element_cls=element_cls, strict=strict) self.assertEqual(cm.exception.err_code, error_code)