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, )
def _make_graph_from_rps(rps, drop_fields): nodes = [graph.RpNode(rp) for rp in rps] parent_edges = _get_parent_edges_between_rp_nodes(nodes) # TODO(gibi) handle consumer nodes and edges here # this is done late so we can drop parent_provider_uuid as well that is # still used above but not any more _drop_fields(drop_fields, rps) return graph.Graph(nodes=nodes, edges=parent_edges)
def test_extend_rp_graph_with_consumers_uses_rps_from_the_graph( self, mock_get_consumers, mock_add_consumers): 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), ], ) mock_get_consumers.return_value = mock.sentinel.consumers tree.extend_rp_graph_with_consumers(mock.sentinel.client, g) mock_get_consumers.assert_called_once_with(mock.sentinel.client, ["4", "2", "3", "1"]) mock_add_consumers.assert_called_once_with(g, mock.sentinel.consumers)
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, )
def test_add_consumers_to_the_graph(self): grandchild = graph.RpNode({ "uuid": uuids.grandchild_rp, "name": "grand" }) child1 = graph.RpNode({"uuid": uuids.child1_rp, "name": "child1"}) child2 = graph.RpNode({"uuid": uuids.child2_rp, "name": "child2"}) root = graph.RpNode({"uuid": uuids.root_rp, "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), ], ) consumer_nodes = [ graph.ConsumerNode({ "consumer_uuid": uuids.consumer1, "allocations": { uuids.root_rp: {}, uuids.child1_rp: {} }, }), graph.ConsumerNode({ "consumer_uuid": uuids.consumer2, "allocations": { uuids.grandchild_rp: {}, uuids.child2_rp: {}, }, }), ] tree._add_consumers_to_the_graph(g, consumer_nodes) for consumer_node in consumer_nodes: self.assertIn(consumer_node, g.nodes) self.assertIn( graph.AllocationEdge( g.get_node_by_id(uuids.consumer1), g.get_node_by_id(uuids.root_rp), ), g.edges, ) self.assertIn( graph.AllocationEdge( g.get_node_by_id(uuids.consumer1), g.get_node_by_id(uuids.child1_rp), ), g.edges, ) self.assertIn( graph.AllocationEdge( g.get_node_by_id(uuids.consumer2), g.get_node_by_id(uuids.grandchild_rp), ), g.edges, ) self.assertIn( graph.AllocationEdge( g.get_node_by_id(uuids.consumer2), g.get_node_by_id(uuids.child2_rp), ), g.edges, )