Skip to content

Commit 6f95964

Browse files
committed
fork-observer: add reachable tank addr in description for each card
1 parent 6684692 commit 6f95964

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/warnet/deploy.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,20 @@ def deploy_fork_observer(directory: Path, debug: bool) -> bool:
184184
# Add an entry for each node in the graph
185185
for i, tank in enumerate(get_mission("tank")):
186186
node_name = tank.metadata.name
187+
for container in tank.spec.containers:
188+
if container.name == "bitcoincore":
189+
for port in container.ports:
190+
if port.name == "rpc":
191+
rpcport = port.container_port
192+
if port.name == "p2p":
193+
p2pport = port.container_port
187194
node_config = f"""
188195
[[networks.nodes]]
189196
id = {i}
190197
name = "{node_name}"
191-
description = ""
198+
description = "{node_name}.{default_namespace}.svc:{int(p2pport)}"
192199
rpc_host = "{node_name}.{default_namespace}.svc"
193-
rpc_port = {int(tank.metadata.labels["RPCPort"])}
200+
rpc_port = {int(rpcport)}
194201
rpc_user = "forkobserver"
195202
rpc_password = "tabconf2024"
196203
"""

test/services_test.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python3
22

3+
import json
34
import os
45
from pathlib import Path
56

67
import requests
78
from test_base import TestBase
89

9-
from warnet.k8s import get_ingress_ip_or_host
10+
from warnet.k8s import get_ingress_ip_or_host, wait_for_ingress_controller
1011

1112

1213
class ServicesTest(TestBase):
@@ -32,15 +33,16 @@ def check_fork_observer(self):
3233
self.warnet("bitcoin rpc john createwallet miner")
3334
self.warnet("bitcoin rpc john -generate 1")
3435
# Port will be auto-forwarded by `warnet deploy`, routed through the enabled Caddy pod
36+
self.log.info("Waiting for ingress controller")
37+
wait_for_ingress_controller()
38+
ingress_ip = get_ingress_ip_or_host()
39+
fo_data_uri = f"http://{ingress_ip}/fork-observer/api/14593470/data.json"
3540

3641
def call_fo_api():
3742
# if on minikube remember to run `minikube tunnel` for this test to run
38-
ingress_ip = get_ingress_ip_or_host()
39-
fo_root = f"http://{ingress_ip}/fork-observer"
4043
try:
41-
fo_res = requests.get(f"{fo_root}/api/networks.json")
42-
network_id = fo_res.json()["networks"][0]["id"]
43-
fo_data = requests.get(f"{fo_root}/api/{network_id}/data.json")
44+
# network id is 0xDEADBE in decimal
45+
fo_data = requests.get(fo_data_uri)
4446
# fork observed!
4547
return len(fo_data.json()["header_infos"]) == 2
4648
except Exception as e:
@@ -51,6 +53,19 @@ def call_fo_api():
5153
self.wait_for_predicate(call_fo_api)
5254
self.log.info("Fork observed!")
5355

56+
self.log.info("Checking node description...")
57+
fo_data = requests.get(fo_data_uri)
58+
nodes = fo_data.json()["nodes"]
59+
assert len(nodes) == 4
60+
assert nodes[1]["name"] == "john"
61+
assert nodes[1]["description"] == "john.default.svc:18444"
62+
63+
self.log.info("Checking reachable address is provided...")
64+
self.warnet("bitcoin rpc george addnode john.default.svc:18444 onetry")
65+
self.wait_for_predicate(
66+
lambda: len(json.loads(self.warnet("bitcoin rpc george getpeerinfo"))) > 1
67+
)
68+
5469

5570
if __name__ == "__main__":
5671
test = ServicesTest()

0 commit comments

Comments
 (0)