def test_instance_relationships_standard_relationship(self):
        yaml = self.MINIMAL_BLUEPRINT + """
    test_node2:
        type: test_type
        relationships:
            -   type: test_relationship
                target: test_node
                source_interfaces:
                    test_interface1:
                        install: test_plugin.install
relationships:
    test_relationship: {}
plugins:
    test_plugin:
        executor: central_deployment_agent
        source: dummy
        """
        result = self.parse(yaml)
        self.assertEquals(2, len(result['nodes']))
        nodes = self._sort_result_nodes(result['nodes'],
                                        ['test_node', 'test_node2'])
        self.assertEquals('test_node2', nodes[1]['id'])
        self.assertEquals(1, len(nodes[1]['relationships']))
        relationship = nodes[1]['relationships'][0]
        self.assertEquals('test_relationship', relationship['type'])
        self.assertEquals('test_node', relationship['target_id'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['source_interfaces']['test_interface1']['install'])
        relationship_source_operations = relationship['source_operations']
        self.assertEqual(
            op_struct('test_plugin',
                      'install',
                      executor='central_deployment_agent'),
            relationship_source_operations['install'])
        self.assertEqual(
            op_struct('test_plugin',
                      'install',
                      executor='central_deployment_agent'),
            relationship_source_operations['test_interface1.install'])
        self.assertEqual(2, len(relationship_source_operations))

        self.assertEquals(8, len(relationship))
        plugin_def = nodes[1]['plugins'][0]
        self.assertEquals('test_plugin', plugin_def['name'])
Beispiel #2
0
 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'))
    def test_instance_relationships_target_node_plugins(self):
        # tests that plugins defined on instance relationships as
        # "run_on_node"="target" will
        # indeed appear in the output on the target node's plugins section
        yaml = self.MINIMAL_BLUEPRINT + """
    test_node2:
        type: test_type
        relationships:
            -   type: test_relationship
                target: test_node
                source_interfaces:
                    test_interface1:
                        install: test_plugin1.install
            -   type: test_relationship
                target: test_node
                target_interfaces:
                    test_interface1:
                        install: test_plugin2.install
relationships:
    test_relationship: {}
plugins:
    test_plugin1:
        executor: central_deployment_agent
        source: dummy
    test_plugin2:
        executor: central_deployment_agent
        source: dummy
"""
        result = self.parse(yaml)
        self.assertEquals(2, len(result['nodes']))
        nodes = self._sort_result_nodes(result['nodes'],
                                        ['test_node', 'test_node2'])
        self.assertEquals('test_node2', nodes[1]['id'])
        self.assertEquals(2, len(nodes[1]['relationships']))

        relationship1 = nodes[1]['relationships'][0]
        self.assertEquals('test_relationship', relationship1['type'])
        self.assertEquals('test_node', relationship1['target_id'])
        rel1_source_ops = relationship1['source_operations']
        self.assertEqual(
            op_struct('test_plugin1',
                      'install',
                      executor='central_deployment_agent'),
            rel1_source_ops['install'])
        self.assertEqual(
            op_struct('test_plugin1',
                      'install',
                      executor='central_deployment_agent'),
            rel1_source_ops['test_interface1.install'])
        self.assertEquals(2, len(rel1_source_ops))
        self.assertEquals(8, len(relationship1))
        plugin1_def = nodes[1]['plugins'][0]
        self.assertEquals('test_plugin1', plugin1_def['name'])

        relationship2 = nodes[1]['relationships'][1]
        self.assertEquals('test_relationship', relationship2['type'])
        self.assertEquals('test_node', relationship2['target_id'])
        rel2_source_ops = relationship2['target_operations']
        self.assertEqual(
            op_struct('test_plugin2',
                      'install',
                      executor='central_deployment_agent'),
            rel2_source_ops['install'])
        self.assertEqual(
            op_struct('test_plugin2',
                      'install',
                      executor='central_deployment_agent'),
            rel2_source_ops['test_interface1.install'])
        self.assertEquals(2, len(rel2_source_ops))
        self.assertEquals(8, len(relationship2))

        # expecting the other plugin to be under test_node rather than
        # test_node2:
        plugin2_def = nodes[0]['plugins'][0]
        self.assertEquals('test_plugin2', plugin2_def['name'])
    def test_instance_relationships_target_node_plugins(self):
        # tests that plugins defined on instance relationships as
        # "run_on_node"="target" will
        # indeed appear in the output on the target node's plugins section
        yaml = self.MINIMAL_BLUEPRINT + """
    test_node2:
        type: test_type
        relationships:
            -   type: test_relationship
                target: test_node
                source_interfaces:
                    test_interface1:
                        install: test_plugin1.install
            -   type: test_relationship
                target: test_node
                target_interfaces:
                    test_interface1:
                        install: test_plugin2.install
relationships:
    test_relationship: {}
plugins:
    test_plugin1:
        executor: central_deployment_agent
        source: dummy
    test_plugin2:
        executor: central_deployment_agent
        source: dummy
"""
        result = self.parse(yaml)
        self.assertEquals(2, len(result['nodes']))
        nodes = self._sort_result_nodes(result['nodes'], ['test_node',
                                                          'test_node2'])
        self.assertEquals('test_node2', nodes[1]['id'])
        self.assertEquals(2, len(nodes[1]['relationships']))

        relationship1 = nodes[1]['relationships'][0]
        self.assertEquals('test_relationship', relationship1['type'])
        self.assertEquals('test_node', relationship1['target_id'])
        rel1_source_ops = relationship1['source_operations']
        self.assertEqual(op_struct('test_plugin1', 'install',
                                   executor='central_deployment_agent'),
                         rel1_source_ops['install'])
        self.assertEqual(op_struct('test_plugin1', 'install',
                                   executor='central_deployment_agent'),
                         rel1_source_ops['test_interface1.install'])
        self.assertEquals(2, len(rel1_source_ops))
        self.assertEquals(8, len(relationship1))
        plugin1_def = nodes[1]['plugins'][0]
        self.assertEquals('test_plugin1', plugin1_def['name'])

        relationship2 = nodes[1]['relationships'][1]
        self.assertEquals('test_relationship', relationship2['type'])
        self.assertEquals('test_node', relationship2['target_id'])
        rel2_source_ops = relationship2['target_operations']
        self.assertEqual(op_struct('test_plugin2', 'install',
                                   executor='central_deployment_agent'),
                         rel2_source_ops['install'])
        self.assertEqual(op_struct('test_plugin2', 'install',
                                   executor='central_deployment_agent'),
                         rel2_source_ops['test_interface1.install'])
        self.assertEquals(2, len(rel2_source_ops))
        self.assertEquals(8, len(relationship2))

        # expecting the other plugin to be under test_node rather than
        # test_node2:
        plugin2_def = nodes[0]['plugins'][0]
        self.assertEquals('test_plugin2', plugin2_def['name'])
    def test_relationship_interfaces_inheritance_merge(self):
        # testing for a complete inheritance path for relationships
        # from top-level relationships to a relationship instance
        yaml = self.MINIMAL_BLUEPRINT + """
    test_node2:
        type: test_type
        relationships:
            -   type: relationship
                target: test_node
                target_interfaces:
                    test_interface:
                        destroy: test_plugin.destroy1
                source_interfaces:
                    test_interface:
                        install2: test_plugin.install2
                        destroy2: test_plugin.destroy2
relationships:
    parent_relationship:
        target_interfaces:
            test_interface:
                install: {}
        source_interfaces:
            test_interface:
                install2: {}
    relationship:
        derived_from: parent_relationship
        target_interfaces:
            test_interface:
                install:
                    implementation: test_plugin.install
                    inputs: {}
                terminate:
                    implementation: test_plugin.terminate
                    inputs: {}
        source_interfaces:
            test_interface:
                install2:
                    implementation: test_plugin.install
                    inputs: {}
                terminate2:
                    implementation: test_plugin.terminate
                    inputs: {}

plugins:
    test_plugin:
        executor: central_deployment_agent
        source: dummy
        """
        result = self.parse(yaml)
        self.assertEquals(2, len(result['nodes']))
        nodes = self._sort_result_nodes(result['nodes'],
                                        ['test_node', 'test_node2'])
        node_relationship = nodes[1]['relationships'][0]
        relationship = result['relationships']['relationship']
        parent_relationship = result['relationships']['parent_relationship']
        self.assertEquals(2, len(result['relationships']))
        self.assertEquals(5, len(parent_relationship))
        self.assertEquals(6, len(relationship))
        self.assertEquals(8, len(node_relationship))

        self.assertEquals('parent_relationship', parent_relationship['name'])
        self.assertEquals(1, len(parent_relationship['target_interfaces']))
        self.assertEquals(
            1, len(parent_relationship['target_interfaces']['test_interface']))
        self.assertIn(
            'install',
            parent_relationship['target_interfaces']['test_interface'])
        self.assertEquals(1, len(parent_relationship['source_interfaces']))
        self.assertEquals(
            1, len(parent_relationship['source_interfaces']['test_interface']))
        self.assertIn(
            'install2',
            parent_relationship['source_interfaces']['test_interface'])

        self.assertEquals('relationship', relationship['name'])
        self.assertEquals('parent_relationship', relationship['derived_from'])
        self.assertEquals(1, len(relationship['target_interfaces']))
        self.assertEquals(
            2, len(relationship['target_interfaces']['test_interface']))
        self.assertEqual(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['target_interfaces']['test_interface']['install'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.terminate',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['target_interfaces']['test_interface']['terminate'])
        self.assertEquals(1, len(relationship['source_interfaces']))
        self.assertEquals(
            2, len(relationship['source_interfaces']['test_interface']))
        self.assertEqual(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['source_interfaces']['test_interface']['install2'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.terminate',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['source_interfaces']['test_interface']['terminate2'])

        self.assertEquals('relationship', node_relationship['type'])
        self.assertEquals('test_node', node_relationship['target_id'])
        self.assertEquals(1, len(node_relationship['target_interfaces']))
        self.assertEquals(
            3, len(node_relationship['target_interfaces']['test_interface']))
        self.assertEqual(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['target_interfaces']['test_interface']
            ['install'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.terminate',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['target_interfaces']['test_interface']['terminate'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.destroy1',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['target_interfaces']['test_interface']
            ['destroy'])
        self.assertEquals(1, len(node_relationship['source_interfaces']))
        self.assertEquals(
            3, len(node_relationship['source_interfaces']['test_interface']))
        self.assertEquals(
            operation_mapping(implementation='test_plugin.install2',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['source_interfaces']['test_interface']
            ['install2'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.terminate',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['source_interfaces']['test_interface']['terminate2'])
        self.assertEquals(
            operation_mapping(implementation='test_plugin.destroy2',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['source_interfaces']['test_interface']
            ['destroy2'])

        rel_source_ops = node_relationship['source_operations']
        self.assertEqual(
            op_struct('test_plugin',
                      'install2',
                      executor='central_deployment_agent'),
            rel_source_ops['install2'])
        self.assertEqual(
            op_struct('test_plugin',
                      'install2',
                      executor='central_deployment_agent'),
            rel_source_ops['test_interface.install2'])
        self.assertEqual(
            op_struct('test_plugin',
                      'terminate',
                      executor='central_deployment_agent'),
            rel_source_ops['terminate2'])
        self.assertEqual(
            op_struct('test_plugin',
                      'terminate',
                      executor='central_deployment_agent'),
            rel_source_ops['test_interface.terminate2'])
        self.assertEqual(
            op_struct('test_plugin',
                      'destroy2',
                      executor='central_deployment_agent'),
            rel_source_ops['destroy2'])
        self.assertEqual(
            op_struct('test_plugin',
                      'destroy2',
                      executor='central_deployment_agent'),
            rel_source_ops['test_interface.destroy2'])
        self.assertEquals(6, len(rel_source_ops))

        rel_target_ops = node_relationship['target_operations']
        self.assertEqual(
            op_struct('test_plugin',
                      'install',
                      executor='central_deployment_agent'),
            rel_target_ops['install'])
        self.assertEqual(
            op_struct('test_plugin',
                      'install',
                      executor='central_deployment_agent'),
            rel_target_ops['test_interface.install'])
        self.assertEqual(
            op_struct('test_plugin',
                      'terminate',
                      executor='central_deployment_agent'),
            rel_target_ops['terminate'])
        self.assertEqual(
            op_struct('test_plugin',
                      'terminate',
                      executor='central_deployment_agent'),
            rel_target_ops['test_interface.terminate'])
        self.assertEqual(
            op_struct('test_plugin',
                      'destroy1',
                      executor='central_deployment_agent'),
            rel_target_ops['destroy'])
        self.assertEqual(
            op_struct('test_plugin',
                      'destroy1',
                      executor='central_deployment_agent'),
            rel_target_ops['test_interface.destroy'])
        self.assertEquals(6, len(rel_source_ops))
    def test_relationships_and_node_recursive_inheritance(self):
        # testing for a complete inheritance path for relationships
        # from top-level relationships to a relationship instance
        yaml = self.MINIMAL_BLUEPRINT + """
    test_node2:
        type: test_type
        relationships:
            -   type: relationship
                target: test_node
                source_interfaces:
                    test_interface3:
                        install: test_plugin.install
                target_interfaces:
                    test_interface1:
                        install: test_plugin.install
relationships:
    relationship:
        derived_from: parent_relationship
        source_interfaces:
            test_interface2:
                install:
                    implementation: test_plugin.install
                    inputs: {}
                terminate:
                    implementation: test_plugin.terminate
                    inputs: {}
    parent_relationship:
        target_interfaces:
            test_interface3:
                install: {}
plugins:
    test_plugin:
        executor: central_deployment_agent
        source: dummy
        """
        result = self.parse(yaml)
        self.assertEquals(2, len(result['nodes']))
        nodes = self._sort_result_nodes(result['nodes'],
                                        ['test_node', 'test_node2'])
        node_relationship = nodes[1]['relationships'][0]
        relationship = result['relationships']['relationship']
        parent_relationship = result['relationships']['parent_relationship']
        self.assertEquals(2, len(result['relationships']))
        self.assertEquals(5, len(parent_relationship))
        self.assertEquals(6, len(relationship))
        self.assertEquals(8, len(node_relationship))

        self.assertEquals('parent_relationship', parent_relationship['name'])
        self.assertEquals(1, len(parent_relationship['target_interfaces']))
        self.assertEquals(
            1,
            len(parent_relationship['target_interfaces']['test_interface3']))
        self.assertEquals(
            {
                'implementation': '',
                'inputs': {},
                'executor': None,
                'max_retries': None,
                'retry_interval': None,
                'timeout': None,
                'timeout_recoverable': None
            }, parent_relationship['target_interfaces']['test_interface3']
            ['install'])

        self.assertEquals('relationship', relationship['name'])
        self.assertEquals('parent_relationship', relationship['derived_from'])
        self.assertEquals(1, len(relationship['target_interfaces']))
        self.assertEquals(
            1, len(relationship['target_interfaces']['test_interface3']))
        self.assertEquals(
            NO_OP,
            relationship['target_interfaces']['test_interface3']['install'])
        self.assertEquals(1, len(relationship['source_interfaces']))
        self.assertEquals(
            2, len(relationship['source_interfaces']['test_interface2']))
        self.assertEqual(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['source_interfaces']['test_interface2']['install'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.terminate',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['source_interfaces']['test_interface2']['terminate'])

        self.assertEquals('relationship', node_relationship['type'])
        self.assertEquals('test_node', node_relationship['target_id'])
        self.assertEquals(2, len(node_relationship['target_interfaces']))
        self.assertEquals(
            1, len(node_relationship['target_interfaces']['test_interface3']))
        self.assertEquals(
            NO_OP, node_relationship['target_interfaces']['test_interface3']
            ['install'])
        self.assertEquals(
            1, len(node_relationship['target_interfaces']['test_interface1']))
        self.assertEqual(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['target_interfaces']['test_interface1']
            ['install'])
        self.assertEquals(2, len(node_relationship['source_interfaces']))
        self.assertEquals(
            1, len(node_relationship['source_interfaces']['test_interface3']))
        self.assertEquals(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['source_interfaces']['test_interface2']
            ['install'])
        self.assertEquals(
            2, len(node_relationship['source_interfaces']['test_interface2']))
        self.assertEquals(
            operation_mapping(implementation='test_plugin.install',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['source_interfaces']['test_interface2']
            ['install'])
        self.assertEquals(
            operation_mapping(implementation='test_plugin.terminate',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            node_relationship['source_interfaces']['test_interface2']
            ['terminate'])

        rel_source_ops = node_relationship['source_operations']
        self.assertEquals(4, len(rel_source_ops))
        self.assertEqual(
            op_struct('test_plugin',
                      'install',
                      executor='central_deployment_agent'),
            rel_source_ops['test_interface2.install'])
        self.assertEqual(
            op_struct('test_plugin',
                      'install',
                      executor='central_deployment_agent'),
            rel_source_ops['test_interface3.install'])
        self.assertEqual(
            op_struct('test_plugin',
                      'terminate',
                      executor='central_deployment_agent'),
            rel_source_ops['terminate'])
        self.assertEqual(
            op_struct('test_plugin',
                      'terminate',
                      executor='central_deployment_agent'),
            rel_source_ops['test_interface2.terminate'])

        rel_target_ops = node_relationship['target_operations']
        self.assertEquals(2, len(rel_target_ops))
        self.assertEqual(op_struct('', '', {}),
                         rel_target_ops['test_interface3.install'])
        self.assertEqual(
            op_struct('test_plugin',
                      'install',
                      executor='central_deployment_agent'),
            rel_target_ops['test_interface1.install'])
    def test_instance_relationships_relationship_inheritance(self):
        # possibly 'inheritance' is the wrong term to use here,
        # the meaning is for checking that the relationship properties from the
        # top-level relationships
        # section are used for instance-relationships which declare their types
        # note there are no overrides in this case; these are tested in the
        # next, more thorough test
        yaml = self.MINIMAL_BLUEPRINT + """
    test_node2:
        type: test_type
        relationships:
            -   type: test_relationship
                target: test_node
                source_interfaces:
                    interface1:
                        op1: test_plugin.task_name1
relationships:
    relationship: {}
    test_relationship:
        derived_from: relationship
        target_interfaces:
            interface2:
                op2:
                    implementation: test_plugin.task_name2
                    inputs: {}
plugins:
    test_plugin:
        executor: central_deployment_agent
        source: dummy
        """
        result = self.parse(yaml)
        self.assertEquals(2, len(result['nodes']))
        nodes = self._sort_result_nodes(result['nodes'],
                                        ['test_node', 'test_node2'])
        relationship = nodes[1]['relationships'][0]
        self.assertEquals('test_relationship', relationship['type'])
        self.assertEquals('test_node', relationship['target_id'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.task_name1',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['source_interfaces']['interface1']['op1'])
        self.assertEqual(
            operation_mapping(implementation='test_plugin.task_name2',
                              inputs={},
                              executor=None,
                              max_retries=None,
                              retry_interval=None,
                              timeout=None,
                              timeout_recoverable=None),
            relationship['target_interfaces']['interface2']['op2'])

        rel_source_ops = relationship['source_operations']

        self.assertEqual(
            op_struct('test_plugin',
                      'task_name1',
                      executor='central_deployment_agent'),
            rel_source_ops['op1'])
        self.assertEqual(
            op_struct('test_plugin',
                      'task_name1',
                      executor='central_deployment_agent'),
            rel_source_ops['interface1.op1'])
        self.assertEquals(2, len(rel_source_ops))

        rel_target_ops = relationship['target_operations']
        self.assertEqual(
            op_struct('test_plugin',
                      'task_name2',
                      executor='central_deployment_agent'),
            rel_target_ops['op2'])
        self.assertEqual(
            op_struct('test_plugin',
                      'task_name2',
                      executor='central_deployment_agent'),
            rel_target_ops['interface2.op2'])
        self.assertEquals(2, len(rel_target_ops))

        self.assertEquals(8, len(relationship))