Exemple #1
0
    def test_graph_with_dependencies(self):
        expected_rusult = '''
            <GraphNode>
                <NID>graph_node_wordpress_id</NID>
                <CNID>wordpress_id</CNID>
                <GraphDependency>
                    <CEPCID>mysqltcp_cepcid</CEPCID>
                    <ECEPID>mysqltcp</ECEPID>
                    <NID>NID</NID>
                </GraphDependency>
            </GraphNode>
        '''

        wrap_comp_type = [
            'cloudify.nodes.Root', 'cloudify.nodes.SoftwareComponent',
            'cloudify.arcadia.nodes.WrappedComponent'
        ]

        mock_wordpress = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=wrap_comp_type)
        mock_wordpress._node_instance.runtime_properties[
            'nid'] = 'graph_node_wordpress_id'
        mock_wordpress._node_instance.runtime_properties[
            'cnid'] = 'wordpress_id'

        mock_msql = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=wrap_comp_type)
        mock_msql._node_instance.runtime_properties[
            'nid'] = 'graph_node_mysql_id'
        mock_msql._node_instance.runtime_properties['cnid'] = 'mysql_id'
        mock_msql._node_instance.runtime_properties[
            'cepcid'] = 'mysqltcp_cepcid'
        mock_msql._node_instance.runtime_properties['ecepid'] = 'mysqltcp'

        con_to_type = [
            'cloudify.relationships.depends_on',
            'cloudify.relationships.connected_to',
            'cloudify.arcadia.relationships.connected_to',
            'wordpress_connected_to_mysql'
        ]

        mock_relationship = CloudifyWorkflowRelationshipInstanceMock(
            node_instance=mock_msql,
            relationship_instance={'runtime_properties': {
                'nid': 'NID'
            }},
            type_hierarchy=con_to_type)

        ComponentFactoryFacade.set_factory(ComponentFactory())
        wp_cmp = ComponentFactoryFacade.INSTANCE.create_component(
            _instance=mock_wordpress)
        mysql_cmp = ComponentFactoryFacade.INSTANCE.create_component(
            _instance=mock_msql)

        mysql_dep = ComponentFactoryFacade.INSTANCE.create_component_dependency(
            _instance=mock_relationship, _source=wp_cmp, _target=mysql_cmp)
        wp_cmp.add_dependency(mysql_dep)

        result = wp_cmp.print_element(ARCADIAXMLPrinter())
        self.assertEqual(flatten_str(result), flatten_str(expected_rusult))
Exemple #2
0
 def create_comp(self, _instance):
     use_external_resource = _instance._node._node.properties[
         'use_external_resource']
     if not use_external_resource:
         node_name = _instance._node_instance['name']
         component = ComponentFactory().create_component(_instance)
         result = self._rest_api.register_component(component)
         if result['rc'] != 0:
             raise ARCADIAServerRequestError(message=result['message'])
Exemple #3
0
 def test_graph_node_print(self):
     expected_rusult = '''
         <GraphNode>
           <NID>graph_node_mysql_id</NID>
           <CNID>mysql_id</CNID>
         </GraphNode>            
     '''
     mock_instance = CloudifyWorlkflowNodeInstanceMock()
     mock_instance._node_instance.runtime_properties[
         'nid'] = 'graph_node_mysql_id'
     mock_instance._node_instance.runtime_properties['cnid'] = 'mysql_id'
     pretty_printer = ARCADIAXMLPrinter()
     ComponentFactoryFacade.set_factory(ComponentFactory())
     mysql = ComponentFactoryFacade.INSTANCE.create_component(mock_instance)
     result = mysql.print_element(pretty_printer)
     self.assertEqual(flatten_str(result), flatten_str(expected_rusult))
Exemple #4
0
    def test_service_graph_builder(self):
        srv_graph_type = [
            'cloudify.nodes.Root', 'cloudify.arcadia.nodes.ServiceGraph'
        ]
        runtime_type = [
            'cloudify.nodes.Root', 'cloudify.arcadia.nodes.RuntimePolicy'
        ]
        wrap_comp_type = [
            'cloudify.nodes.Root', 'cloudify.nodes.SoftwareComponent',
            'cloudify.arcadia.nodes.WrappedComponent'
        ]
        sg_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=srv_graph_type)
        mysql_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=wrap_comp_type)
        wp_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=wrap_comp_type)
        rp_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=runtime_type)

        sg_mock._contained_instances.append(wp_mock)
        sg_mock._contained_instances.append(mysql_mock)
        sg_mock._contained_instances.append(rp_mock)

        sg_mock._node_instance['id'] = 'service_graph_gm17g6'
        mysql_mock._node_instance['id'] = 'mysql_x1m8sh'
        wp_mock._node_instance['id'] = 'wordpress_k8lr3c'
        rp_mock._node_instance['id'] = 'runtime_policy_7vy2nn'

        con_to_type = [
            'cloudify.relationships.depends_on',
            'cloudify.relationships.connected_to',
            'cloudify.arcadia.relationships.connected_to',
            'wordpress_connected_to_mysql'
        ]
        con_in_type = [
            'cloudify.relationships.contained_in',
            'cloudify.arcadia.relationships.contained_in'
        ]

        mysql_mock._relationship_instances[
            'service_graph_gm17g6'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=sg_mock, type_hierarchy=con_in_type)
        wp_mock._relationship_instances[
            'service_graph_gm17g6'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=sg_mock, type_hierarchy=con_in_type)
        wp_mock._relationship_instances[
            'mysql_x1m8sh'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=mysql_mock, type_hierarchy=con_to_type)
        rp_mock._relationship_instances[
            'service_graph_gm17g6'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=sg_mock, type_hierarchy=con_in_type)

        graph_builder = GraphBuilder(_comp_factory=ComponentFactory())
        service_graph = graph_builder.build(sg_mock)

        self.assertTrue(isinstance(service_graph, ServiceGraphElement))
        self.assertTrue(len(service_graph.components) == 2)
        self.assertTrue(len(service_graph.policies) == 1)

        def find_component(array, component):
            for comp in array:
                if comp._instance == component:
                    return comp
            return

        mysql_comp = find_component(service_graph.components, mysql_mock)
        wp_comp = find_component(service_graph.components, wp_mock)
        self.assertTrue(mysql_comp)
        self.assertTrue(wp_comp)
        self.assertTrue(len(wp_comp.dependencies) == 1)
        self.assertTrue(wp_comp.dependencies[0].target._instance == mysql_mock)
Exemple #5
0
    def test_complete_service_graph(self):
        expected_rusult = '''
            <ServiceGraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ArcadiaModellingArtefacts.xsd">
              <DescriptiveSGMetadata>
                <SGID>wordpress_mysql_service_graph_id</SGID>
                <SGName>SimpleWordPressServiceGraph</SGName>
                <SGDescription>SGDescription</SGDescription>
              </DescriptiveSGMetadata>
              <GraphNodeDescriptor>
                <GraphNode>
                  <NID>graph_node_mysql_id</NID>
                  <CNID>mysql_id</CNID>
                </GraphNode>
                <GraphNode>
                    <NID>graph_node_wordpress_id</NID>
                    <CNID>wordpress_id</CNID>
                    <GraphDependency>
                        <CEPCID>mysqltcp_cepcid</CEPCID>
                        <ECEPID>mysqltcp</ECEPID>
                        <NID>NID</NID>
                    </GraphDependency>
                </GraphNode>
              </GraphNodeDescriptor>
              <RuntimePolicyDescriptor>
                <RuntimePolicy>
                  <RPID>RPID</RPID>
                  <RPName>RPName</RPName>
                </RuntimePolicy>
              </RuntimePolicyDescriptor>
            </ServiceGraph>       
        '''

        srv_graph_type = [
            'cloudify.nodes.Root', 'cloudify.arcadia.nodes.ServiceGraph'
        ]
        runtime_type = [
            'cloudify.nodes.Root', 'cloudify.arcadia.nodes.RuntimePolicy'
        ]
        wrap_comp_type = [
            'cloudify.nodes.Root', 'cloudify.nodes.SoftwareComponent',
            'cloudify.arcadia.nodes.WrappedComponent'
        ]

        sg_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=srv_graph_type)
        sg_mock._node_instance.runtime_properties[
            'sgid'] = 'wordpress_mysql_service_graph_id'
        sg_mock._node_instance.runtime_properties[
            'sgname'] = 'SimpleWordPressServiceGraph'
        sg_mock._node_instance.runtime_properties['sgdesc'] = 'SGDescription'

        wp_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=wrap_comp_type)
        wp_mock._node_instance.runtime_properties[
            'nid'] = 'graph_node_wordpress_id'
        wp_mock._node_instance.runtime_properties['cnid'] = 'wordpress_id'

        mysql_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=wrap_comp_type)
        mysql_mock._node_instance.runtime_properties[
            'nid'] = 'graph_node_mysql_id'
        mysql_mock._node_instance.runtime_properties['cnid'] = 'mysql_id'
        mysql_mock._node_instance.runtime_properties[
            'cepcid'] = 'mysqltcp_cepcid'
        mysql_mock._node_instance.runtime_properties['ecepid'] = 'mysqltcp'

        rp_mock = CloudifyWorlkflowNodeInstanceMock(
            type_hierarchy=runtime_type)
        rp_mock._node_instance.runtime_properties['rpid'] = 'RPID'
        rp_mock._node_instance.runtime_properties['rpname'] = 'RPName'

        sg_mock._contained_instances.append(mysql_mock)
        sg_mock._contained_instances.append(wp_mock)
        sg_mock._contained_instances.append(rp_mock)

        sg_mock._node_instance['id'] = 'service_graph_gm17g6'
        mysql_mock._node_instance['id'] = 'mysql_x1m8sh'
        wp_mock._node_instance['id'] = 'wordpress_k8lr3c'
        rp_mock._node_instance['id'] = 'runtime_policy_7vy2nn'

        con_in_type = [
            'cloudify.relationships.contained_in',
            'cloudify.arcadia.relationships.contained_in'
        ]
        con_to_type = [
            'cloudify.relationships.depends_on',
            'cloudify.relationships.connected_to',
            'cloudify.arcadia.relationships.connected_to',
            'wordpress_connected_to_mysql'
        ]

        mysql_mock._relationship_instances[
            'service_graph_gm17g6'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=sg_mock, type_hierarchy=con_in_type)
        wp_mock._relationship_instances[
            'service_graph_gm17g6'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=sg_mock, type_hierarchy=con_in_type)
        wp_mock._relationship_instances[
            'mysql_x1m8sh'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=mysql_mock,
                relationship_instance={'runtime_properties': {
                    'nid': 'NID'
                }},
                type_hierarchy=con_to_type)
        rp_mock._relationship_instances[
            'service_graph_gm17g6'] = CloudifyWorkflowRelationshipInstanceMock(
                node_instance=sg_mock, type_hierarchy=con_in_type)

        graph_builder = GraphBuilder(_comp_factory=ComponentFactory())
        service_graph = graph_builder.build(sg_mock)

        result = service_graph.print_element(ARCADIAXMLPrinter())

        self.assertEqual(flatten_str(result), flatten_str(expected_rusult))
Exemple #6
0
 def generate_service_graph(self, _service_graph):
     factory = ComponentFactory()
     graph_builder = GraphBuilder(_comp_factory=factory)
     self._service_graph_tree = graph_builder.build(_service_graph)