def test_workflow_blueprint_import_namespaced_operation(self): imported_yaml = self.BASIC_VERSION_SECTION_DSL_1_0 + """ plugins: script: executor: central_deployment_agent install: false workflows: workflow: stub.py workflow2: mapping: stub.py parameters: key: default: value is_cascading: false """ import_base_path = self._temp_dir + '/test' self.make_file_with_name(content='content', filename='stub.py', base_dir=import_base_path) import_path = self.make_file_with_name(content=imported_yaml, filename='test.yaml', base_dir=import_base_path) resolver = Resolver({'blueprint:test': (imported_yaml, import_path)}, import_base_path) main_yaml = self.BASIC_VERSION_SECTION_DSL_1_0 + """ imports: - test--blueprint:test """ main_base_path = self._temp_dir + '/main' main_yaml_path = self.make_file_with_name(content=main_yaml, filename='blueprint.yaml', base_dir=main_base_path) parsed = self.parse_from_path(main_yaml_path, resolver=resolver, resources_base_path=main_base_path) workflow = parsed[constants.WORKFLOWS]['test--workflow'] workflow2 = parsed[constants.WORKFLOWS]['test--workflow2'] namespaced_script_plugin = 'test--' + constants.SCRIPT_PLUGIN_NAME self.assertEqual(workflow['operation'], constants.SCRIPT_PLUGIN_EXECUTE_WORKFLOW_TASK) self.assertEqual(1, len(workflow['parameters'])) self.assertEqual(workflow['parameters']['script_path']['default'], 'test--stub.py') self.assertEqual(workflow['plugin'], namespaced_script_plugin) self.assertEqual(workflow2['operation'], constants.SCRIPT_PLUGIN_EXECUTE_WORKFLOW_TASK) self.assertEqual(2, len(workflow2['parameters'])) self.assertEqual(workflow2['parameters']['script_path']['default'], 'test--stub.py') self.assertEqual(workflow2['parameters']['key']['default'], 'value') self.assertEqual(workflow['plugin'], namespaced_script_plugin) self.assertEqual(False, workflow2['is_cascading']) self.assertEqual(True, workflow['is_cascading'])
def test_dsl_definitions_with_blueprint_import(self): basic_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://local-test-resolver/types.yaml inputs: port: default: 90 dsl_definitions: config: &config region: { get_input: port } node_types: test: properties: port: default: 0 data: default: [] node_templates: vm: type: test properties: port: *config data: { get_input: port } vm2: type: test properties: port: *config data: { get_input: port } """ second_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:first_layer """ resolver = Resolver( { 'blueprint:first_layer': basic_yaml, 'blueprint:second_layer': second_layer }, rules=self._local_resolver_rules()) third_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns2--blueprint:second_layer """ parsed = self.parse(third_layer, resolver=resolver) inputs = parsed[constants.INPUTS] self.assertIn('ns2--ns--port', inputs) vm_properties = parsed[constants.NODES][0][constants.PROPERTIES] self.assertEqual(vm_properties['port']['region'], {'get_input': 'ns2--ns--port'}) vm_properties = parsed[constants.NODES][1][constants.PROPERTIES] self.assertEqual(vm_properties['port']['region'], {'get_input': 'ns2--ns--port'}) self.assertEqual(vm_properties['data'], {'get_input': 'ns2--ns--port'})
def test_node_type_properties_with_blueprint_import(self): basic_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://local-test-resolver/types.yaml inputs: port: default: 90 node_types: test: properties: rules: default: [] server: default: image: { get_input: port } node_templates: vm: type: test properties: rules: - remote_ip_prefix: 0.0.0.0/0 port: { get_input: port } """ second_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:first_layer """ resolver = Resolver( { 'blueprint:first_layer': basic_yaml, 'blueprint:second_layer': second_layer }, rules=self._local_resolver_rules()) third_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns2--blueprint:second_layer """ parsed = self.parse(third_layer, resolver=resolver) inputs = parsed[constants.INPUTS] self.assertIn('ns2--ns--port', inputs) vm_props = parsed[constants.NODES][0][constants.PROPERTIES] self.assertEqual(vm_props['server']['image'], {'get_input': 'ns2--ns--port'}) self.assertEqual( vm_props['rules'][0], { 'remote_ip_prefix': '0.0.0.0/0', 'port': { 'get_input': 'ns2--ns--port' } })
def test_node_template_properties_with_blueprint_import(self): basic_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://local-test-resolver/types.yaml inputs: port: default: 90 node_templates: node: type: cloudify.nodes.WebServer properties: port: { get_input: port} ip: type: cloudify.nodes.WebServer properties: port: { get_attribute: [node, port] } """ second_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:first_layer """ resolver = Resolver( { 'blueprint:first_layer': basic_yaml, 'blueprint:second_layer': second_layer }, rules=self._local_resolver_rules()) third_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns2--blueprint:second_layer """ parsed = self.parse(third_layer, resolver=resolver) ip = parsed[constants.NODES][0] for node in parsed[constants.NODES]: if node['name'].endswith('ip'): ip = node break else: raise RuntimeError('No node "ip" found') self.assertEqual(ip['id'], 'ns2--ns--ip') self.assertEqual(ip['properties']['port'], {'get_attribute': ['ns2--ns--node', 'port']})
def test_node_type_properties_with_blueprint_import(self): basic_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://local-test-resolver/types.yaml inputs: port: default: 90 node_types: test: properties: server: default: image: { concat: [one, { get_input: port }, three] } node_templates: vm: type: test """ second_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:first_layer """ resolver = Resolver( { 'blueprint:first_layer': basic_yaml, 'blueprint:second_layer': second_layer }, rules=self._local_resolver_rules()) third_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns2--blueprint:second_layer """ parsed = self.parse(third_layer, resolver=resolver) inputs = parsed[constants.INPUTS] self.assertIn('ns2--ns--port', inputs) vm_props = parsed[constants.NODES][0][constants.PROPERTIES] self.assertEqual( vm_props['server']['image'], {'concat': ['one', { 'get_input': 'ns2--ns--port' }, 'three']})
def test_node_template_properties_with_blueprint_import(self): basic_yaml = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - http://www.getcloudify.org/spec/cloudify/4.5/types.yaml inputs: port: default: 90 node_templates: ip: type: cloudify.nodes.WebServer properties: port: { concat: [one, { get_input: port }, three] } """ second_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns--blueprint:first_layer """ resolver = Resolver({ 'blueprint:first_layer': basic_yaml, 'blueprint:second_layer': second_layer }) third_layer = self.BASIC_VERSION_SECTION_DSL_1_3 + """ imports: - ns2--blueprint:second_layer """ parsed = self.parse(third_layer, resolver=resolver) for node in parsed[constants.NODES]: if node['name'].endswith('ip'): ip = node break else: raise RuntimeError('No node "ip" found') self.assertEqual(ip['id'], 'ns2--ns--ip') self.assertEquals( ip['properties']['port'], {'concat': ['one', { 'get_input': 'ns2--ns--port' }, 'three']})
def test_namespace_sibling_import_resolving_with_local_imports(self): layer1_import_path = self.make_yaml_file(self.basic_input) layer2 = """ tosca_definitions_version: cloudify_dsl_1_3 imports: - test--{0} """.format(layer1_import_path) layer2_import_path = self.make_yaml_file(layer2) sibling_import_path = self.make_yaml_file(self.basic_input) sibling_layer2 = """ tosca_definitions_version: cloudify_dsl_1_3 imports: - test--{0} """.format(sibling_import_path) sibling_layer2_import_path = self.make_yaml_file(sibling_layer2) main_yaml = """ imports: - other_test--{0} - else_test--{1} """.format(layer2_import_path, sibling_layer2_import_path) resolver = Resolver({'blueprint:layer1': self.basic_input, 'blueprint:layer2': layer2, 'blueprint:sibling': self.basic_input, 'blueprint:sibling_layer2': sibling_layer2}) parsed_yaml = self.parse_1_3(main_yaml, resolver=resolver) inputs = parsed_yaml[constants.INPUTS] self.assertEqual(2, len(inputs)) self.assertIn('else_test--test--port', inputs) self.assertIn('other_test--test--port', inputs)
def test_namespaced_script_plugin_interface_use_blueprint_import(self): imported_yaml = self.BASIC_VERSION_SECTION_DSL_1_0 + """ plugins: script: executor: central_deployment_agent install: false node_types: type: interfaces: test: op: implementation: stub.py inputs: {} op2: implementation: stub.py inputs: key: default: value relationships: relationship: source_interfaces: test: op: implementation: stub.py inputs: {} target_interfaces: test: op: implementation: stub.py inputs: {} node_templates: node1: type: type relationships: - target: node2 type: relationship node2: type: type """ import_base_path = self._temp_dir + '/test' self.make_file_with_name(content='content', filename='stub.py', base_dir=import_base_path) import_path = self.make_file_with_name(content=imported_yaml, filename='test.yaml', base_dir=import_base_path) resolver = Resolver({'blueprint:test': (imported_yaml, import_path)}, import_base_path) main_yaml = self.BASIC_VERSION_SECTION_DSL_1_0 + """ imports: - test--blueprint:test """ main_base_path = self._temp_dir + '/main' main_yaml_path = self.make_file_with_name(content=main_yaml, filename='blueprint.yaml', base_dir=main_base_path) result = self.parse_from_path(main_yaml_path, resolver=resolver, resources_base_path=main_base_path) node = [n for n in result[constants.NODES] if n['name'] == 'test--node1'][0] relationship = node['relationships'][0] operation = node['operations']['test.op'] operation2 = node['operations']['test.op2'] source_operation = relationship['source_operations']['test.op'] target_operation = relationship['target_operations']['test.op'] def assert_operation(op, extra_properties=False): inputs = {'script_path': 'test--stub.py'} if extra_properties: inputs.update({'key': 'value'}) self.assertEqual(op, op_struct( plugin_name='{0}--{1}'.format('test', constants.SCRIPT_PLUGIN_NAME), mapping=constants.SCRIPT_PLUGIN_RUN_TASK, inputs=inputs, executor='central_deployment_agent')) assert_operation(operation) assert_operation(operation2, extra_properties=True) assert_operation(source_operation) assert_operation(target_operation)