diff --git a/src/backend/kubernetes_backend.py b/src/backend/kubernetes_backend.py index c1077d2e9..4f45b4209 100644 --- a/src/backend/kubernetes_backend.py +++ b/src/backend/kubernetes_backend.py @@ -420,9 +420,7 @@ def check_logging_crds_installed(self): logging_crd_name = "servicemonitors.monitoring.coreos.com" api = client.ApiextensionsV1Api() crds = api.list_custom_resource_definition() - if any(crd.metadata.name == logging_crd_name for crd in crds.items): - return True - return False + return bool(any(crd.metadata.name == logging_crd_name for crd in crds.items)) def apply_prometheus_service_monitors(self, tanks): for tank in tanks: diff --git a/src/scenarios/connect_dag.py b/src/scenarios/connect_dag.py deleted file mode 100644 index 5f65842b3..000000000 --- a/src/scenarios/connect_dag.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python3 - -import os -from time import sleep - -from warnet.test_framework_bridge import WarnetTestFramework - - -def cli_help(): - return "Connect a complete DAG from a set of unconnected nodes" - - -class ConnectDag(WarnetTestFramework): - def set_test_params(self): - # This is just a minimum - self.num_nodes = 8 - - def add_options(self, parser): - parser.add_argument( - "--network_name", - dest="network_name", - default="warnet", - help="", - ) - - def run_test(self): - while not self.warnet.network_connected(): - sleep(1) - - # All permutations of a directed acyclic graph with zero, one, or two inputs/outputs - # - # │ Node │ In │ Out │ Con In │ Con Out │ - # ├──────┼────┼─────┼────────┼─────────┤ - # │ A │ 0 │ 1 │ ─ │ C │ - # │ B │ 0 │ 2 │ ─ │ C, D │ - # │ C │ 2 │ 2 │ A, B │ D, E │ - # │ D │ 2 │ 1 │ B, C │ F │ - # │ E │ 2 │ 0 │ C, F │ ─ │ - # │ F │ 1 │ 2 │ D │ E, G │ - # │ G │ 1 │ 1 │ F │ H │ - # │ H │ 1 │ 0 │ G │ ─ │ - # - # Node Graph Corresponding Indices - # ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - # ╭──────> E ╭──────> 4 - # │ ∧ │ ∧ - # A ─> C ─┤ │ 0 ─> 2 ─┤ │ - # ∧ ╰─> D ─> F ─> G ─> H ∧ ╰─> 3 ─> 5 ─> 6 ─> 7 - # │ ∧ │ ∧ - # B ───┴──────╯ 1 ───┴──────╯ - - self.connect_nodes(0, 2) - self.connect_nodes(1, 2) - self.connect_nodes(1, 3) - self.connect_nodes(2, 3) - self.connect_nodes(2, 4) - self.connect_nodes(3, 5) - self.connect_nodes(5, 4) - self.connect_nodes(5, 6) - self.connect_nodes(6, 7) - self.sync_all() - - zero_peers = self.nodes[0].getpeerinfo() - one_peers = self.nodes[1].getpeerinfo() - two_peers = self.nodes[2].getpeerinfo() - three_peers = self.nodes[3].getpeerinfo() - four_peers = self.nodes[4].getpeerinfo() - five_peers = self.nodes[5].getpeerinfo() - six_peers = self.nodes[6].getpeerinfo() - seven_peers = self.nodes[7].getpeerinfo() - - for tank in self.warnet.tanks: - self.log.info(f"Tank {tank.index}: {tank.warnet.tanks[tank.index].get_dns_addr()} pod:" - f" {tank.warnet.tanks[tank.index].get_ip_addr()}") - - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[2].get_dns_addr() for d in - zero_peers), f"Could not find {self.options.network_name}-tank-000002-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[2].get_dns_addr() for d in - one_peers), f"Could not find {self.options.network_name}-tank-000002-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[3].get_dns_addr() for d in - one_peers), f"Could not find {self.options.network_name}-tank-000003-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[0].get_ip_addr() for d in - two_peers), f"Could not find Tank 0's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[1].get_ip_addr() for d in - two_peers), f"Could not find Tank 1's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[3].get_dns_addr() for d in - two_peers), f"Could not find {self.options.network_name}-tank-000003-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[4].get_dns_addr() for d in - two_peers), f"Could not find {self.options.network_name}-tank-000004-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[1].get_ip_addr() for d in - three_peers), f"Could not find Tank 1's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[2].get_ip_addr() for d in - three_peers), f"Could not find Tank 2's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[5].get_dns_addr() for d in - three_peers), f"Could not find {self.options.network_name}-tank-000005-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[2].get_ip_addr() for d in - four_peers), f"Could not find Tank 2's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[5].get_ip_addr() for d in - four_peers), f"Could not find Tank 5's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[3].get_ip_addr() for d in - five_peers), f"Could not find Tank 3's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[4].get_dns_addr() for d in - five_peers), f"Could not find {self.options.network_name}-tank-000004-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[6].get_dns_addr() for d in - five_peers), f"Could not find {self.options.network_name}-tank-000006-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[5].get_ip_addr() for d in - six_peers), f"Could not find Tank 5's ip addr" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[7].get_dns_addr() for d in - six_peers), f"Could not find {self.options.network_name}-tank-000007-service" - assert any(d.get("addr").split(":")[0] == self.warnet.tanks[6].get_ip_addr() for d in - seven_peers), f"Could not find Tank 6's ip addr" - - self.log.info(f"Successfully ran the {os.path.basename(__file__)} scenario.") - - -if __name__ == "__main__": - ConnectDag().main() diff --git a/src/warnet/test_framework_bridge.py b/src/warnet/test_framework_bridge.py index 1e4484590..ea8c9f029 100644 --- a/src/warnet/test_framework_bridge.py +++ b/src/warnet/test_framework_bridge.py @@ -337,8 +337,15 @@ def get_peer_ip(peer): try: # we encounter a regular ip address ip_addr = str(ipaddress.ip_address(peer['addr'].split(':')[0])) return ip_addr - except ValueError: # or we encounter a service name - tank_index = int(peer['addr'].split('-')[2]) # NETWORK-tank-INDEX-service + except ValueError as err: # or we encounter a service name + try: + # NETWORK-tank-TANK_INDEX-service + # NETWORK-test-TEST-tank-TANK_INDEX-service + tank_index = int(peer['addr'].split('-')[-2]) + except (ValueError, IndexError) as inner_err: + raise ValueError("could not derive tank index from service name: {} {}" + .format(peer['addr'], inner_err)) from err + ip_addr = self.warnet.tanks[tank_index].get_ip_addr() return ip_addr diff --git a/test/dag_connection_test.py b/test/dag_connection_test.py index 30d6b2da6..07f5fd0cf 100755 --- a/test/dag_connection_test.py +++ b/test/dag_connection_test.py @@ -6,7 +6,7 @@ from test_base import TestBase -graph_file_path = Path(os.path.dirname(__file__)) / "data" / "eight_unconnected.graphml" +graph_file_path = Path(os.path.dirname(__file__)) / "data" / "ten_semi_unconnected.graphml" base = TestBase() @@ -16,7 +16,7 @@ base.wait_for_all_edges() # Start scenario -base.warcli(f"scenarios run connect_dag --network_name={base.network_name}") +base.warcli("scenarios run-file test/framework_tests/connect_dag.py") counter = 0 seconds = 180 diff --git a/test/data/eight_unconnected.graphml b/test/data/ten_semi_unconnected.graphml similarity index 83% rename from test/data/eight_unconnected.graphml rename to test/data/ten_semi_unconnected.graphml index 5c2b7b10a..065be6127 100644 --- a/test/data/eight_unconnected.graphml +++ b/test/data/ten_semi_unconnected.graphml @@ -73,5 +73,22 @@ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdr False False + + 26.0 + + + + False + False + + + 26.0 + + + + False + False + + - \ No newline at end of file + diff --git a/test/framework_tests/__init__.py b/test/framework_tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/framework_tests/connect_dag.py b/test/framework_tests/connect_dag.py new file mode 100644 index 000000000..3ebd0ae21 --- /dev/null +++ b/test/framework_tests/connect_dag.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 + +import os +from enum import Enum, auto, unique +from time import sleep + +from warnet.test_framework_bridge import WarnetTestFramework + + +def cli_help(): + return "Connect a complete DAG from a set of unconnected nodes" + + +@unique +class ConnectionType(Enum): + IP = auto() + DNS = auto() + + +class ConnectDag(WarnetTestFramework): + def set_test_params(self): + # This is just a minimum + self.num_nodes = 10 + + def add_options(self, parser): + parser.add_argument( + "--network_name", + dest="network_name", + default="warnet", + help="", + ) + + def run_test(self): + while not self.warnet.network_connected(): + sleep(1) + + # All permutations of a directed acyclic graph with zero, one, or two inputs/outputs + # + # │ Node │ In │ Out │ Con In │ Con Out │ + # ├──────┼────┼─────┼────────┼─────────┤ + # │ A │ 0 │ 1 │ ─ │ C │ + # │ B │ 0 │ 2 │ ─ │ C, D │ + # │ C │ 2 │ 2 │ A, B │ D, E │ + # │ D │ 2 │ 1 │ B, C │ F │ + # │ E │ 2 │ 0 │ C, F │ ─ │ + # │ F │ 1 │ 2 │ D │ E, G │ + # │ G │ 1 │ 1 │ F │ H │ + # │ H │ 1 │ 0 │ G │ ─ │ + # + # Node Graph Corresponding Indices + # ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + # ╭──────> E ╭──────> 4 + # │ ∧ │ ∧ + # A ─> C ─┤ │ 0 ─> 2 ─┤ │ + # ∧ ╰─> D ─> F ─> G ─> H ∧ ╰─> 3 ─> 5 ─> 6 ─> 7 + # │ ∧ │ ∧ + # B ───┴──────╯ 1 ───┴──────╯ + + self.connect_nodes(0, 2) + self.connect_nodes(1, 2) + self.connect_nodes(1, 3) + self.connect_nodes(2, 3) + self.connect_nodes(2, 4) + self.connect_nodes(3, 5) + self.connect_nodes(5, 4) + self.connect_nodes(5, 6) + self.connect_nodes(6, 7) + + # Nodes 8 & 9 shall come pre-connected. Attempt to connect them anyway to test the handling + # of dns node addresses + self.connect_nodes(8, 9) + self.connect_nodes(9, 8) + + self.sync_all() + + zero_peers = self.nodes[0].getpeerinfo() + one_peers = self.nodes[1].getpeerinfo() + two_peers = self.nodes[2].getpeerinfo() + three_peers = self.nodes[3].getpeerinfo() + four_peers = self.nodes[4].getpeerinfo() + five_peers = self.nodes[5].getpeerinfo() + six_peers = self.nodes[6].getpeerinfo() + seven_peers = self.nodes[7].getpeerinfo() + eight_peers = self.nodes[8].getpeerinfo() + nine_peers = self.nodes[9].getpeerinfo() + + for tank in self.warnet.tanks: + self.log.info(f"Tank {tank.index}: {tank.warnet.tanks[tank.index].get_dns_addr()} pod:" + f" {tank.warnet.tanks[tank.index].get_ip_addr()}") + + self.assert_connection(zero_peers, 2, ConnectionType.DNS) + self.assert_connection(one_peers, 2, ConnectionType.DNS) + self.assert_connection(one_peers, 3, ConnectionType.DNS) + self.assert_connection(two_peers, 0, ConnectionType.IP) + self.assert_connection(two_peers, 1, ConnectionType.IP) + self.assert_connection(two_peers, 3, ConnectionType.DNS) + self.assert_connection(two_peers, 4, ConnectionType.DNS) + self.assert_connection(three_peers, 1, ConnectionType.IP) + self.assert_connection(three_peers, 2, ConnectionType.IP) + self.assert_connection(three_peers, 5, ConnectionType.DNS) + self.assert_connection(four_peers, 2, ConnectionType.IP) + self.assert_connection(four_peers, 5, ConnectionType.IP) + self.assert_connection(five_peers, 3, ConnectionType.IP) + self.assert_connection(five_peers, 4, ConnectionType.DNS) + self.assert_connection(five_peers, 6, ConnectionType.DNS) + self.assert_connection(six_peers, 5, ConnectionType.IP) + self.assert_connection(six_peers, 7, ConnectionType.DNS) + self.assert_connection(seven_peers, 6, ConnectionType.IP) + # Check the pre-connected nodes + self.assert_connection(eight_peers, 9, ConnectionType.DNS) + self.assert_connection(nine_peers, 8, ConnectionType.IP) + + self.log.info(f"Successfully ran the connect_dag.py scenario using a temporary file: " + f"{os.path.basename(__file__)} ") + + def assert_connection(self, connector, connectee_index, connection_type: ConnectionType): + if connection_type == ConnectionType.DNS: + assert any(d.get("addr") == + self.warnet.tanks[connectee_index].get_dns_addr() for d in connector), \ + f"Could not find {self.options.network_name}-tank-00000{connectee_index}-service" + elif connection_type == ConnectionType.IP: + assert any(d.get("addr").split(":")[0] == + self.warnet.tanks[connectee_index].get_ip_addr() for d in connector), \ + f"Could not find Tank {connectee_index}'s ip addr" + else: + raise ValueError("ConnectionType must be of type DNS or IP") + + +if __name__ == "__main__": + ConnectDag().main() diff --git a/test/scenarios_test.py b/test/scenarios_test.py index cd7bd55ab..445da2615 100755 --- a/test/scenarios_test.py +++ b/test/scenarios_test.py @@ -14,7 +14,7 @@ # Use rpc instead of warcli so we get raw JSON object scenarios = base.rpc("scenarios_available") -assert len(scenarios) == 5 +assert len(scenarios) == 4 # Start scenario base.warcli("scenarios run miner_std --allnodes --interval=1")