Skip to content

Commit 3fc7e57

Browse files
committed
feat: make testnet cleanup work also outside of framework
Make the testnet cleanup script work also when the testnet was not started through framework testnet scripts, e.g. directly in bootstrap dir.
1 parent 1e80ff6 commit 3fc7e57

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

cardano_node_tests/testnet_cleanup.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import argparse
1010
import logging
1111
import os
12+
import pathlib as pl
1213
import sys
1314

14-
from cardano_node_tests.utils import cluster_nodes
15+
from cardano_clusterlib import clusterlib
16+
1517
from cardano_node_tests.utils import helpers
1618
from cardano_node_tests.utils import testnet_cleanup
1719

@@ -28,6 +30,19 @@ def get_args() -> argparse.Namespace:
2830
type=helpers.check_dir_arg,
2931
help="Path to a directory with testing artifacts",
3032
)
33+
parser.add_argument(
34+
"-f",
35+
"--address",
36+
required=True,
37+
help="Faucet address",
38+
)
39+
parser.add_argument(
40+
"-s",
41+
"--skey-file",
42+
required=True,
43+
type=helpers.check_file_arg,
44+
help="Path to faucet skey file",
45+
)
3146
return parser.parse_args()
3247

3348

@@ -38,15 +53,24 @@ def main() -> int:
3853
)
3954
args = get_args()
4055

41-
if not os.environ.get("CARDANO_NODE_SOCKET_PATH"):
56+
socket_env = os.environ.get("CARDANO_NODE_SOCKET_PATH")
57+
if not socket_env:
4258
LOGGER.error("The `CARDANO_NODE_SOCKET_PATH` environment variable is not set.")
4359
return 1
4460
if not os.environ.get("BOOTSTRAP_DIR"):
4561
LOGGER.error("The `BOOTSTRAP_DIR` environment variable is not set.")
4662
return 1
4763

48-
cluster_obj = cluster_nodes.get_cluster_type().get_cluster_obj()
49-
testnet_cleanup.cleanup(cluster_obj=cluster_obj, location=args.artifacts_base_dir)
64+
state_dir = pl.Path(socket_env).parent
65+
cluster_obj = clusterlib.ClusterLib(
66+
state_dir=state_dir,
67+
)
68+
testnet_cleanup.cleanup(
69+
cluster_obj=cluster_obj,
70+
location=args.artifacts_base_dir,
71+
faucet_address=args.address,
72+
faucet_skey_file=args.skey_file,
73+
)
5074

5175
return 0
5276

cardano_node_tests/utils/testnet_cleanup.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,37 @@ def group_files(file_paths: tp.Generator[pl.Path, None, None]) -> tp.List[tp.Lis
172172
return path_groups
173173

174174

175+
def _get_faucet_payment_rec(
176+
address: str = "",
177+
skey_file: clusterlib.FileType = "",
178+
) -> clusterlib.AddressRecord:
179+
if address or skey_file:
180+
if not (address and skey_file):
181+
err = "Both 'address' and 'skey_file' need to be set."
182+
raise ValueError(err)
183+
184+
faucet_payment = clusterlib.AddressRecord(
185+
address=address,
186+
vkey_file=pl.Path("/nonexistent"), # We don't need this for faucet
187+
skey_file=pl.Path(skey_file),
188+
)
189+
else:
190+
# Try to infer the faucet address and keys from cluster env
191+
cluster_env = cluster_nodes.get_cluster_env()
192+
faucet_addr_file = cluster_env.state_dir / "shelley" / "faucet.addr"
193+
faucet_payment = create_addr_record(faucet_addr_file)
194+
195+
return faucet_payment
196+
197+
175198
def cleanup(
176199
cluster_obj: clusterlib.ClusterLib,
177200
location: clusterlib.FileType,
201+
faucet_address: str = "",
202+
faucet_skey_file: clusterlib.FileType = "",
178203
) -> None:
179204
"""Cleanup a testnet with the help of testing artifacts."""
180-
cluster_env = cluster_nodes.get_cluster_env()
181-
faucet_addr_file = cluster_env.state_dir / "shelley" / "faucet.addr"
182-
faucet_payment = create_addr_record(faucet_addr_file)
205+
faucet_payment = _get_faucet_payment_rec(address=faucet_address, skey_file=faucet_skey_file)
183206
files_found = group_files(find_files(location))
184207
stake_deposit_amt = cluster_obj.g_query.get_address_deposit()
185208

0 commit comments

Comments
 (0)