Skip to content

Commit cd46e9b

Browse files
committed
bitcoin: add ns to messages and get_messages
1 parent 9a2403c commit cd46e9b

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
@@ -139,16 +139,29 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
139139
@click.argument("tank_a", type=str, required=True)
140140
@click.argument("tank_b", type=str, required=True)
141141
@click.option("--chain", default="regtest", show_default=True)
142-
def messages(tank_a: str, tank_b: str, chain: str):
142+
@click.option("--namespace_a", default=None, show_default=True)
143+
@click.option("--namespace_b", default=None, show_default=True)
144+
def messages(
145+
tank_a: str, tank_b: str, chain: str, namespace_a: Optional[str], namespace_b: Optional[str]
146+
):
143147
"""
144148
Fetch messages sent between <tank_a pod name> and <tank_b pod name> in [chain]
145149
"""
146150
try:
151+
if not namespace_a:
152+
namespace_a = get_default_namespace()
153+
if not namespace_b:
154+
namespace_b = get_default_namespace()
155+
147156
# Get the messages
148-
messages = get_messages(tank_a, tank_b, chain)
157+
messages = get_messages(
158+
tank_a, tank_b, chain, namespace_a=namespace_a, namespace_b=namespace_b
159+
)
149160

150161
if not messages:
151-
print(f"No messages found between {tank_a} and {tank_b}")
162+
print(
163+
f"No messages found between {tank_a} ({namespace_a}) and {tank_b} ({namespace_b})"
164+
)
152165
return
153166

154167
# Process and print messages
@@ -173,23 +186,25 @@ def messages(tank_a: str, tank_b: str, chain: str):
173186
print(f"Error fetching messages between nodes {tank_a} and {tank_b}: {e}")
174187

175188

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

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

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

191206
# List directories in the message capture folder
192-
cmd = f"kubectl exec {tank_a} -- ls {base_dir}"
207+
cmd = f"kubectl exec {tank_a} --namespace {namespace_a} -- ls {base_dir}"
193208

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

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

206221
blob = subprocess.run(

0 commit comments

Comments
 (0)