Example #1
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)))
Example #2
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))
Example #3
0
    def test_make_rp_trees_two_simple_root(self):
        mock_client = mock.Mock()
        mock_client.get.side_effect = [
            # resource_providers call
            {
                "resource_providers": [
                    {
                        "uuid": uuids.root_rp_A,
                        "parent_provider_uuid": None
                    },
                    {
                        "uuid": uuids.root_rp_B,
                        "parent_provider_uuid": None
                    },
                ]
            },
            # extending data calls for root_rp_A
            {
                "inventories": {}
            },
            {
                "traits": []
            },
            {
                "aggregates": []
            },
            {
                "usages": {}
            },
            # extending data calls for root_rp_B
            {
                "inventories": {}
            },
            {
                "traits": []
            },
            {
                "aggregates": []
            },
            {
                "usages": {}
            },
        ]

        graph = tree.make_rp_trees(mock_client)

        self.assertEqual(2, len(graph.nodes))
        self.assertEqual(
            {uuids.root_rp_A, uuids.root_rp_B},
            {node.id()
             for node in graph.nodes},
        )
        for node in graph.nodes:
            # assert that extended data has been included
            self.assertTrue(
                all(key in node.data
                    for key in ["inventories", "traits", "aggregates"]))

        mock_client.get.assert_any_call("/resource_providers")

        for uuid in [uuids.root_rp_A, uuids.root_rp_B]:
            mock_client.get.assert_any_call(
                "/resource_providers/%s/inventories" % uuid)
            mock_client.get.assert_any_call("/resource_providers/%s/traits" %
                                            uuid)
            mock_client.get.assert_any_call(
                "/resource_providers/%s/aggregates" % uuid)
            mock_client.get.assert_any_call("/resource_providers/%s/usages" %
                                            uuid)

        self.assertEqual(9, mock_client.get.call_count)