def test_update_all_nodes(network, args): primary, _ = network.find_nodes() first_code_id, new_code_id = [ get_code_id(args.oe_binary, infra.path.build_lib_path(pkg, args.enclave_type)) for pkg in [args.package, args.replacement_package] ] LOG.info("Add new code id") network.consortium.add_new_code(primary, new_code_id) with primary.client() as uc: r = uc.get("/node/code") versions = sorted(r.body.json()["versions"], key=lambda x: x["digest"]) expected = sorted( [ {"digest": first_code_id, "status": "ALLOWED_TO_JOIN"}, {"digest": new_code_id, "status": "ALLOWED_TO_JOIN"}, ], key=lambda x: x["digest"], ) assert versions == expected, versions LOG.info("Remove old code id") network.consortium.retire_code(primary, first_code_id) with primary.client() as uc: r = uc.get("/node/code") versions = sorted(r.body.json()["versions"], key=lambda x: x["digest"]) expected = sorted( [ {"digest": new_code_id, "status": "ALLOWED_TO_JOIN"}, ], key=lambda x: x["digest"], ) assert versions == expected, versions old_nodes = network.nodes.copy() LOG.info("Start fresh nodes running new code") for _ in range(0, len(network.nodes)): new_node = network.create_and_trust_node( args.replacement_package, "local://localhost", args ) assert new_node LOG.info("Retire original nodes running old code") for node in old_nodes: primary, _ = network.find_nodes() network.consortium.retire_node(primary, node) # Elections take (much) longer than a backup removal which is just # a commit, so we need to adjust our timeout accordingly, hence this branch if node.node_id == primary.node_id: new_primary, new_term = network.wait_for_new_primary(primary.node_id) LOG.debug(f"New primary is {new_primary.node_id} in term {new_term}") primary = new_primary network.nodes.remove(node) node.stop() LOG.info("Check the network is still functional") reconfiguration.check_can_progress(new_node) return network
def test_suspend_primary(network, args): primary, _ = network.find_primary() primary.suspend() new_primary, new_term = network.wait_for_new_primary(primary.node_id) LOG.debug(f"New primary is {new_primary.node_id} in term {new_term}") reconfiguration.check_can_progress(new_primary) primary.resume() reconfiguration.check_can_progress(new_primary) return network