Skip to content

Commit 41c7646

Browse files
committed
bitcoin: add ns to messages and get_messages
1 parent 2dd51f1 commit 41c7646

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/warnet/bitcoin.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,29 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
138138
@click.argument("tank_a", type=str, required=True)
139139
@click.argument("tank_b", type=str, required=True)
140140
@click.option("--chain", default="regtest", show_default=True)
141-
def messages(tank_a: str, tank_b: str, chain: str):
141+
@click.option("--namespace_a", default=None, show_default=True)
142+
@click.option("--namespace_b", default=None, show_default=True)
143+
def messages(
144+
tank_a: str, tank_b: str, chain: str, namespace_a: Optional[str], namespace_b: Optional[str]
145+
):
142146
"""
143147
Fetch messages sent between <tank_a pod name> and <tank_b pod name> in [chain]
144148
"""
145149
try:
150+
if not namespace_a:
151+
namespace_a = get_default_namespace()
152+
if not namespace_b:
153+
namespace_b = get_default_namespace()
154+
146155
# Get the messages
147-
messages = get_messages(tank_a, tank_b, chain)
156+
messages = get_messages(
157+
tank_a, tank_b, chain, namespace_a=namespace_a, namespace_b=namespace_b
158+
)
148159

149160
if not messages:
150-
print(f"No messages found between {tank_a} and {tank_b}")
161+
print(
162+
f"No messages found between {tank_a} ({namespace_a}) and {tank_b} ({namespace_b})"
163+
)
151164
return
152165

153166
# Process and print messages
@@ -172,23 +185,25 @@ def messages(tank_a: str, tank_b: str, chain: str):
172185
print(f"Error fetching messages between nodes {tank_a} and {tank_b}: {e}")
173186

174187

175-
def get_messages(tank_a: str, tank_b: str, chain: str):
188+
def get_messages(tank_a: str, tank_b: str, chain: str, namespace_a: str, namespace_b: str):
176189
"""
177190
Fetch messages from the message capture files
178191
"""
179192
subdir = "" if chain == "main" else f"{chain}/"
180193
base_dir = f"/root/.bitcoin/{subdir}message_capture"
181194

182195
# Get the IP of node_b
183-
cmd = f"kubectl get pod {tank_b} -o jsonpath='{{.status.podIP}}'"
196+
cmd = f"kubectl get pod {tank_b} -o jsonpath='{{.status.podIP}}' --namespace {namespace_b}"
184197
tank_b_ip = run_command(cmd).strip()
185198

186199
# Get the service IP of node_b
187-
cmd = f"kubectl get service {tank_b} -o jsonpath='{{.spec.clusterIP}}'"
200+
cmd = (
201+
f"kubectl get service {tank_b} -o jsonpath='{{.spec.clusterIP}}' --namespace {namespace_b}"
202+
)
188203
tank_b_service_ip = run_command(cmd).strip()
189204

190205
# List directories in the message capture folder
191-
cmd = f"kubectl exec {tank_a} -- ls {base_dir}"
206+
cmd = f"kubectl exec {tank_a} --namespace {namespace_a} -- ls {base_dir}"
192207

193208
dirs = run_command(cmd).splitlines()
194209

@@ -199,7 +214,7 @@ def get_messages(tank_a: str, tank_b: str, chain: str):
199214
for file, outbound in [["msgs_recv.dat", False], ["msgs_sent.dat", True]]:
200215
file_path = f"{base_dir}/{dir_name}/{file}"
201216
# Fetch the file contents from the container
202-
cmd = f"kubectl exec {tank_a} -- cat {file_path}"
217+
cmd = f"kubectl exec {tank_a} --namespace {namespace_a} -- cat {file_path}"
203218
import subprocess
204219

205220
blob = subprocess.run(

0 commit comments

Comments
 (0)