Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Aug 8, 2023
1 parent c2c889d commit 2995675
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 53 deletions.
36 changes: 3 additions & 33 deletions tests/infra/basicperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"]

Expand Down Expand Up @@ -392,7 +363,6 @@ def run(args):
network,
args.add_new_node_after_primary_stops,
old_primary,
primary,
latest_snapshot_dir,
statistics,
)
Expand Down
10 changes: 9 additions & 1 deletion tests/infra/consortium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 7 additions & 19 deletions tests/infra/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,15 +955,15 @@ 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,
args,
valid_from=None,
validity_period_days=None,
no_wait=False,
timeout=None,
timeout=5,
):
primary, _ = self.find_primary()
try:
Expand All @@ -980,35 +980,23 @@ 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:
with primary.client() as c:
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:
Expand Down

0 comments on commit 2995675

Please sign in to comment.