From 2995675c7cc54c3175bf5b8fc8597915563e5568 Mon Sep 17 00:00:00 2001 From: Amaury Chamayou Date: Tue, 8 Aug 2023 12:18:29 +0000 Subject: [PATCH] Tidy up --- tests/infra/basicperf.py | 36 +++--------------------------------- tests/infra/consortium.py | 10 +++++++++- tests/infra/network.py | 26 +++++++------------------- 3 files changed, 19 insertions(+), 53 deletions(-) diff --git a/tests/infra/basicperf.py b/tests/infra/basicperf.py index 2aff88446094..246f19c6d40c 100644 --- a/tests/infra/basicperf.py +++ b/tests/infra/basicperf.py @@ -179,37 +179,7 @@ def create_and_fill_key_space(size: int, primary: infra.node.Node) -> List[str]: return space -def create_and_add_node( - network, host, old_primary, new_primary, snapshots_dir, statistics -): - LOG.info(f"Retiring old primary {old_primary.local_node_id}") - statistics[ - "initial_primary_retirement_start_time" - ] = datetime.datetime.now().isoformat() - network.retire_node(new_primary, old_primary) - statistics[ - "initial_primary_retirement_complete_time" - ] = datetime.datetime.now().isoformat() - LOG.info("Old primary is retired") - - LOG.info(f"Adding new node: {host}") - node = network.create_node(host) - statistics["new_node_join_start_time"] = datetime.datetime.now().isoformat() - network.join_node( - node, - args.package, - args, - timeout=10, - copy_ledger=False, - snapshots_dir=snapshots_dir, - ) - network.trust_node(node, args) - statistics["new_node_join_complete_time"] = datetime.datetime.now().isoformat() - LOG.info(f"Done adding new node: {host}") - -def create_and_add_node( - network, host, old_primary, new_primary, snapshots_dir, statistics -): +def create_and_add_node(network, host, old_primary, snapshots_dir, statistics): LOG.info(f"Add new node: {host}") node = network.create_node(host) statistics["new_node_join_start_time"] = datetime.datetime.now().isoformat() @@ -222,9 +192,10 @@ def create_and_add_node( snapshots_dir=snapshots_dir, ) LOG.info(f"Replace node {old_primary.local_node_id} with {node.local_node_id}") - network.replace_node(old_primary, node, args) + network.replace_stopped_node(old_primary, node, args) LOG.info(f"Done replacing node: {host}") + def run(args): hosts = args.nodes or ["local://localhost"] @@ -392,7 +363,6 @@ def run(args): network, args.add_new_node_after_primary_stops, old_primary, - primary, latest_snapshot_dir, statistics, ) diff --git a/tests/infra/consortium.py b/tests/infra/consortium.py index c89cfa36c800..c9ad02b8b370 100644 --- a/tests/infra/consortium.py +++ b/tests/infra/consortium.py @@ -361,7 +361,15 @@ def trust_nodes( **kwargs, ) - def replace_node(self, remote_node, node_to_retire, node_to_add, valid_from, validity_period_days=None, **kwargs,): + def replace_node( + self, + remote_node, + node_to_retire, + node_to_add, + valid_from, + validity_period_days=None, + **kwargs, + ): proposal_body = {"actions": []} trust_args = {"node_id": node_to_add.node_id, "valid_from": str(valid_from)} if validity_period_days is not None: diff --git a/tests/infra/network.py b/tests/infra/network.py index 65cdb89214bc..1492adbbd2e3 100644 --- a/tests/infra/network.py +++ b/tests/infra/network.py @@ -955,7 +955,7 @@ def retire_node(self, remote_node, node_to_retire, timeout=10): self.nodes.remove(node_to_retire) - def replace_node( + def replace_stopped_node( self, node_to_retire, node_to_add, @@ -963,7 +963,7 @@ def replace_node( valid_from=None, validity_period_days=None, no_wait=False, - timeout=None, + timeout=5, ): primary, _ = self.find_primary() try: @@ -980,25 +980,15 @@ def replace_node( validity_period_days=validity_period_days, timeout=args.ledger_recovery_timeout, ) - if not no_wait: - # The main endorsed RPC interface is only open once the node - # has caught up and observed commit on the service open transaction. - node_to_add.wait_for_node_to_join( - timeout=timeout or args.ledger_recovery_timeout - ) except (ValueError, TimeoutError): - LOG.error(f"New trusted node {node_to_add.node_id} failed to join the network") + LOG.error( + f"NFailed to replace {node_to_retire.node_id} with {node_to_add.node_id}" + ) node_to_add.stop() raise node_to_add.network_state = infra.node.NodeNetworkState.joined - node_to_add.set_certificate_validity_period( - valid_from, - validity_period_days or args.maximum_node_certificate_validity_days, - ) - if not no_wait: - self.wait_for_all_nodes_to_commit(primary=primary) - end_time = time.time() + 5 + end_time = time.time() + timeout r = None while time.time() < end_time: try: @@ -1006,9 +996,7 @@ def replace_node( r = c.get("/node/network/removable_nodes").body.json() if node_to_retire.node_id in {n["node_id"] for n in r["nodes"]}: check_commit = infra.checker.Checker(c) - r = c.delete( - f"/node/network/nodes/{node_to_retire.node_id}" - ) + r = c.delete(f"/node/network/nodes/{node_to_retire.node_id}") check_commit(r) break else: