def test_merging_namespaces_mapping(self): resolver = ResolverWithBlueprintSupport( {'blueprint:test': self.blueprint_imported}) layer1 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - namespace--blueprint:test """ layer1_import_path = self.make_yaml_file(layer1) layer2 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - {0}--{1} - namespace--blueprint:test """.format('test1', layer1_import_path) layer2_import_path = self.make_yaml_file(layer2) main_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - {0}--{1} - {2}--{1} """.format('test', layer2_import_path, 'other_test') parsed_yaml = self.parse(main_yaml, resolver=resolver) namespaces_mapping = parsed_yaml[constants.NAMESPACES_MAPPING] self.assertItemsEqual( { 'other_test--test1--namespace': 'test', 'test--test1--namespace': 'test', 'other_test--test1--namespace--ns': 'blueprint', 'test--test1--namespace--ns': 'blueprint', 'other_test--namespace--ns': 'blueprint', 'test--namespace': 'blueprint', 'other_test--namespace': 'blueprint', 'test--namespace--ns': 'blueprint' }, namespaces_mapping)
def test_merge_imported_lists(self): resolver =\ ResolverWithBlueprintSupport( {'blueprint:test': self.blueprint_with_blueprint_import, 'blueprint:another_test': self.blueprint_with_blueprint_import}) layer1 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:test """ layer1_import_path = self.make_yaml_file(layer1) layer2 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://www.getcloudify.org/spec/cloudify/4.5/types.yaml - {0}--{1} - ns--blueprint:another_test """.format('test1', layer1_import_path) layer2_import_path = self.make_yaml_file(layer2) main_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://www.getcloudify.org/spec/cloudify/4.5/types.yaml - {0}--{1} """.format('test', layer2_import_path) parsed_yaml = self.parse(main_yaml, resolver=resolver) imported_blueprints = parsed_yaml[constants.IMPORTED_BLUEPRINTS] self.assertEqual(len(imported_blueprints), 3) self.assertItemsEqual(['other_test', 'test', 'another_test'], imported_blueprints)
def test_merge_imported_lists(self): resolver = ResolverWithBlueprintSupport( { 'blueprint:test': self.blueprint_with_blueprint_import, 'blueprint:another_test': self.blueprint_with_blueprint_import }, rules=self._local_resolver_rules()) layer1 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:test """ layer1_import_path = self.make_yaml_file(layer1) layer2 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://local-test-resolver/types.yaml - {0}--{1} - ns--blueprint:another_test """.format('test1', layer1_import_path) layer2_import_path = self.make_yaml_file(layer2) main_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://local-test-resolver/types.yaml - {0}--{1} """.format('test', layer2_import_path) parsed_yaml = self.parse(main_yaml, resolver=resolver) imported_blueprints = parsed_yaml[constants.IMPORTED_BLUEPRINTS] self.assertEqual(len(imported_blueprints), 3) self.assertEqual({'other_test', 'test', 'another_test'}, set(imported_blueprints))
def test_basic_blueprint_import(self): resolver = ResolverWithBlueprintSupport( {'blueprint:test': self.basic_blueprint}) yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:test """ parsed_yaml = self.parse(yaml, resolver=resolver) imported_blueprints = parsed_yaml[constants.IMPORTED_BLUEPRINTS] self.assertEqual(len(imported_blueprints), 1) self.assertEqual(['test'], imported_blueprints)
def test_multi_levels_extend_with_blueprint_import(self): node_blueprint = """ tosca_definitions_version: cloudify_dsl_1_3 node_types: test_type: properties: prop1: default: value2 relationships: cloudify.relationships.depends_on: properties: connection_type: default: 'all_to_all' node_templates: other_node: type: test_type test_node: type: test_type """ middle_extender_blueprint = """ tosca_definitions_version: cloudify_dsl_1_3 node_templates: test--test_node: relationships: - type: cloudify.relationships.depends_on target: test--other_node imports: - test--blueprint:node """ resolver = ResolverWithBlueprintSupport({ 'blueprint:node': node_blueprint, 'blueprint:middle': middle_extender_blueprint }) main_yaml = """ tosca_definitions_version: cloudify_dsl_1_3 node_templates: test--test--test_node: relationships: - type: cloudify.relationships.depends_on target: test--test--other_node imports: - test--blueprint:middle """ self.validate_expected_relationships( main_yaml, 'test--test--test_node', [('test--test--other_node', 'cloudify.relationships.depends_on'), ('test--test--other_node', 'cloudify.relationships.depends_on')], resolver)
def test_blueprints_imports_with_the_same_import(self): resolver = ResolverWithBlueprintSupport({ 'blueprint:test': self.blueprint_imported, 'blueprint:other': self.blueprint_imported }) yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - same--blueprint:test - same--blueprint:other """ self.assertRaises(exceptions.DSLParsingLogicException, self.parse, yaml, resolver=resolver)
def test_cloudify_basic_types_blueprint_import(self): imported_yaml = """ tosca_definitions_version: cloudify_dsl_1_3 imports: - http://www.getcloudify.org/spec/cloudify/4.5/types.yaml inputs: port: default: 90 """ resolver = ResolverWithBlueprintSupport( {'blueprint:test': imported_yaml}) yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://www.getcloudify.org/spec/cloudify/4.5/types.yaml - ns--blueprint:test """ self.parse(yaml, resolver=resolver)
def test_cloudify_basic_types_blueprint_import(self): imported_yaml = """ tosca_definitions_version: cloudify_dsl_1_3 imports: - http://local-test-resolver/types.yaml inputs: port: default: 90 """ resolver = ResolverWithBlueprintSupport( {'blueprint:test': imported_yaml}, rules=self._local_resolver_rules()) yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://local-test-resolver/types.yaml - ns--blueprint:test """ self.parse(yaml, resolver=resolver)
def test_merging_namespaces_mapping(self): resolver = ResolverWithBlueprintSupport( {'blueprint:testbp': self.blueprint_imported}, rules=self._local_resolver_rules()) layer1 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - collision--blueprint:testbp """ layer1_import_path = self.make_yaml_file(layer1) layer2 = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - nested1--{bp_path} - collision--blueprint:testbp """.format(bp_path=layer1_import_path) layer2_import_path = self.make_yaml_file(layer2) main_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - mainns1--{bp_path} - mainns2--{bp_path} """.format(bp_path=layer2_import_path) parsed_yaml = self.parse(main_yaml, resolver=resolver) namespaces_mapping = parsed_yaml[constants.NAMESPACES_MAPPING] # If the nested namespace refers to a path to a blueprint, the value # is expected to be: 'blueprint' # If the nested namespace refers to a blueprint:<blueprint_name> then # the value is expected to be '<blueprint_name>' self.assertEqual( { 'mainns2--nested1--collision': 'testbp', 'mainns1--nested1--collision': 'testbp', 'mainns2--nested1--collision--deepns': 'blueprint', 'mainns1--nested1--collision--deepns': 'blueprint', 'mainns2--collision--deepns': 'blueprint', 'mainns1--collision': 'testbp', 'mainns2--collision': 'testbp', 'mainns1--collision--deepns': 'blueprint' }, namespaces_mapping)