def test_eq_similar_network(self, pipes_list): network_a = ZeroNetwork(pipes_list) network_b = ZeroNetwork(list(pipes_list)) assert id(network_a) != id(network_b) assert network_a.id != network_b.id assert network_a == network_b
def test_neq_network(self, pipes_list): first_batch, second_batch = _split_lists(pipes_list, 2) network_a = ZeroNetwork(first_batch) network_b = ZeroNetwork(second_batch) assert network_a != network_b
def test_output_nodes(self, pipes_list): network = ZeroNetwork() network.add_pipes(*pipes_list) assert list(network.input_nodes) == [ pipe.node_a for pipe in pipes_list if pipe.node_b == ZeroNode.OUT ]
def test_or_network(self, nodes_list, pipes_list): pipes_list1, pipes_list2 = _split_lists(pipes_list, 2) network_a = ZeroNetwork(pipes_list1) network_b = ZeroNetwork(pipes_list2) network_c = network_a | network_b assert set( network_c.pipes) == set(network_a.pipes) | set(network_b.pipes)
def test_and_network(self, nodes_list, pipes_list): pipes_list1, pipes_list2 = _split_lists(pipes_list, 2, cross=True) network_a = ZeroNetwork(pipes_list1) network_b = ZeroNetwork(pipes_list2) network_c = network_a & network_b assert set( network_c.pipes) == set(network_a.pipes) & set(network_b.pipes)
def test_iand_network(self, nodes_list, pipes_list): pipes_list1, pipes_list2 = _split_lists(pipes_list, 2) network_a = ZeroNetwork(pipes_list1) network_b = ZeroNetwork(pipes_list2) network_c = network_a.copy() network_c &= network_b assert set( network_c.pipes) == set(network_a.pipes) & set(network_b.pipes)
def test_reverse_pipes_map(self, pipes_list): network = ZeroNetwork() network.add_pipes(*pipes_list) pipes_map = network.get_pipes_map(reverse=True) test_pipes_map = defaultdict( lambda: defaultdict(lambda: defaultdict(lambda: None))) for pipe in pipes_list: node_a = pipe.node_a.id if not isinstance(pipe.node_a, str) else pipe.node_a node_b = pipe.node_b.id if not isinstance(pipe.node_b, str) else pipe.node_b test_pipes_map[node_b][node_a][pipe.id] = pipe assert pipes_map == test_pipes_map
def test_remove_pipes(self, pipes_list): network = ZeroNetwork() pipes_list1, pipes_list2 = _split_lists(pipes_list, 2) network.add_pipes(*pipes_list) network.remove_pipes(*pipes_list1) assert list(network.pipes.values()) == list(pipes_list2)
def get_network(): hello_world_node = ZeroNode( hello_world_op, _id="hello_world_node_id", # set custom id (default: uuid4) ) print_node = ZeroNode(print) # --------> [print_node] # | # <in> ----> [hello_world_node] ---- # \ # --------> <out> return ZeroNetwork([ ZeroPipe(ZeroNode.IN, hello_world_node), ZeroPipe(hello_world_node, print_node), ZeroPipe("hello_world_node_id", ZeroNode.OUT), ])
def get_network(): b = ZeroNode(RoundRobinBalancerOperator(), _id="balancer").save() n1 = ZeroNode(PythonFunctionOperator(get_file_data), _id="node1").save() n2 = ZeroNode(PythonFunctionOperator(get_file_data), _id="node2").save() n3 = OwnZeroNode(PythonFunctionOperator(get_file_data), _id="node3").save() bash_save = ZeroNode(BashPerPacketOperator(cmd_generator), _id="bash_save") return ZeroNetwork([ ZeroPipe(ZeroNode.IN, b, _id="in-balancer"), ZeroPipe("balancer", "/zero/nodes/node1", _id="balancer-node1"), ZeroPipe("balancer", "/zero/nodes/node2", _id="balancer-node2"), ZeroPipe("balancer", "/zero/nodes/own/node3", _id="balancer-node3"), ZeroPipe("node1", bash_save, _id="node1-bash_save"), ZeroPipe("node2", bash_save, _id="node2-bash_save"), ZeroPipe("/zero/nodes/own/node3", bash_save, _id="node3-bash_save"), ZeroPipe(n1, ZeroNode.OUT, _id="node1-out"), ZeroPipe(n2, ZeroNode.OUT, _id="node2-out"), ZeroPipe(n3, ZeroNode.OUT, _id="node3-out"), ])
def generate_network(name): transport = ZeroTransport(transport_connectors_factory, serializer=serializer, deserializer=deserializer) with ZeroPipe.transport_factory_context(transport): req_http = ZeroNode(ReqOperator(req_http_op)) req_ftp = ZeroNode(ReqOperator(req_ftp_op)) save = ZeroNode(PythonFunctionOperator(save_op)) http_filter = RegexMatchFilter("^https?://.*") ftp_filter = RegexMatchFilter("^ftp://.*") return ZeroNetwork( [ ZeroPipe(ZeroNode.IN, req_http, filters=[http_filter]), ZeroPipe(ZeroNode.IN, req_ftp, filters=[ftp_filter]), ZeroPipe(req_http, save), ZeroPipe(req_ftp, save), ], _id=name, )
def get_network(): node1 = ZeroNode(PythonFunctionOperator(generate_data), _id="node1").save() def f_odd(value): return value % 2 == 1 def f_even(value): return value % 2 == 0 odd_filter = SimpleJsonPathFilter("data.number", f_odd) even_filter = SimpleJsonPathFilter("data.number", f_even) custom_transport = ZeroTransport( PersistQueueConnector(TMP_FOLDER, queue_engine="file")) return ZeroNetwork([ ZeroPipe( ZeroNode.IN, node1, _id="in-node1", ), ZeroPipe( "/zero/nodes/node1", ZeroNode.OUT, filters=[even_filter], transport=custom_transport, _id="even-out", ), ZeroPipe( node1, ZeroNode.OUT, filters=[odd_filter], transport=custom_transport, _id="odd-out", ), ])
def get_network(name="l2_network"): try: return ZeroNetwork.load(name) except TethysRONotFound: return generate_network(name).save()
def test_input_pipes(self, pipes_list, input_pipes_list): network = ZeroNetwork() network.add_pipes(*pipes_list) assert list(network.input_pipes) == input_pipes_list
def test_add_pipes(self, pipes_list): network = ZeroNetwork() network.add_pipes(*pipes_list) assert list(network.pipes.values()) == pipes_list
def test_create_with_pipes(self, pipes_list): network = ZeroNetwork(pipes_list) assert list(network.pipes.values()) == pipes_list
def test_create_without_args(self): network = ZeroNetwork() assert len(network.pipes) == 0
def test_output_pipes(self, pipes_list, output_pipes_list): network = ZeroNetwork() network.add_pipes(*pipes_list) assert list(network.output_pipes) == output_pipes_list
def test_eq_network(self, pipes_list): network_a = ZeroNetwork(pipes_list) network_b = network_a.copy() assert id(network_a) != id(network_b) assert network_a == network_b