예제 #1
0
    def test_graph_to_dot_filters_node_data(
        self, mock_get_html_key_value, mock_add_node
    ):
        mock_get_html_key_value.return_value = ""
        child = graph.RpNode(
            {"uuid": "2", "name": "child", "not_needed_field": 42}
        )
        root = graph.RpNode(
            {"uuid": "1", "name": "root", "not_needed_field": 42}
        )
        g = graph.Graph(
            nodes=[root, child],
            edges=[graph.ParentEdge(node1=child, node2=root)],
        )

        filter = lambda name: name in ["uuid", "name"]
        dot.graph_to_dot(g, field_filter=filter)

        self.assertEqual(
            [
                mock.call("name", "root", filter),
                mock.call("uuid", "1", filter),
                mock.call("name", "child", filter),
                mock.call("uuid", "2", filter),
            ],
            mock_get_html_key_value.mock_calls,
        )
예제 #2
0
    def take_action(self, parsed_args):
        http = self.app.client_manager.placement_tree
        client = ClientAdapter(http)

        graph = tree.make_rp_trees(client, drop_fields=DROP_DATA_FIELDS)

        if parsed_args.show_consumers:
            tree.extend_rp_graph_with_consumers(client, graph)

        print(
            dot.graph_to_dot(graph,
                             field_filter=_get_field_filter(parsed_args)))
예제 #3
0
    def test_graph_to_dot_walks_nodes_and_edges(
        self, mock_add_node, mock_add_edge
    ):
        grandchild = graph.RpNode({"uuid": "4", "name": "grand"})
        child1 = graph.RpNode({"uuid": "2", "name": "child1"})
        child2 = graph.RpNode({"uuid": "3", "name": "child2"})
        root = graph.RpNode({"uuid": "1", "name": "root"})

        g = graph.Graph(
            nodes=[grandchild, child1, child2, root],
            edges=[
                graph.ParentEdge(node1=child1, node2=root),
                graph.ParentEdge(node1=child2, node2=root),
                graph.ParentEdge(node1=grandchild, node2=child2),
            ],
        )

        dot.graph_to_dot(g)

        some_html = mock.ANY
        self.assertEqual(
            [
                mock.call("4", some_html),
                mock.call("2", some_html),
                mock.call("3", some_html),
                mock.call("1", some_html),
            ],
            mock_add_node.mock_calls,
        )
        self.assertEqual(
            [
                mock.call("1", "2", dir="back", label="parent"),
                mock.call("1", "3", dir="back", label="parent"),
                mock.call("3", "4", dir="back", label="parent"),
            ],
            mock_add_edge.mock_calls,
        )
예제 #4
0
def dump_placement_db_to_dot(placement_client, out_file, hidden_fields=()):
    """Export the placement db content to a dot file

    Usage in nova functional test env:

        from osc_placement_tree import utils as placement_visual

        placement_visual.dump_placement_db_to_dot(
            placement_visual.PlacementFixtureAsClientWrapper(
                self.placement_api),
            '/tmp/dump.dot')

    Usage in placement functional env:

        from osc_placement_tree import utils as placement_visual
        from placement import direct

        with direct.PlacementDirect(
                self.conf_fixture.conf, latest_microversion=True) as client:
            placement_visual.dump_placement_db_to_dot(
                placement_visual.PlacementDirectAsClientWrapper(client),
                '/tmp/dump.dot')


    :param placement_client: A placement client wrapper to call the placement
        service. Use PlacementFixtureAsClientWrapper or
        PlacementDirectAsClientWrapper depending on your environment.
    :param out_file: The file path to store the dot file
    :param hidden_fields: The list of the name of the resource provider fields
        not to include in the output
    """

    graph = tree.make_rp_trees(placement_client, drop_fields=DROP_DATA_FIELDS)
    tree.extend_rp_graph_with_consumers(placement_client, graph)

    with open(out_file, "wb") as f:
        f.write(
            dot.graph_to_dot(
                graph, field_filter=lambda name: name not in hidden_fields))