Skip to content

Commit 26b1910

Browse files
authored
Merge pull request #646 from pinheadmz/fo-addr
fork-observer: add reachable tank addr in description for each card
2 parents 0107297 + 5b50ff5 commit 26b1910

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
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: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env python3
22

3+
import json
34
import os
45
from pathlib import Path
6+
from time import sleep
57

68
import requests
79
from test_base import TestBase
810

9-
from warnet.k8s import get_ingress_ip_or_host
11+
from warnet.k8s import get_ingress_ip_or_host, wait_for_ingress_controller
1012

1113

1214
class ServicesTest(TestBase):
@@ -31,16 +33,27 @@ def check_fork_observer(self):
3133
self.log.info("Creating chain split")
3234
self.warnet("bitcoin rpc john createwallet miner")
3335
self.warnet("bitcoin rpc john -generate 1")
34-
# Port will be auto-forwarded by `warnet deploy`, routed through the enabled Caddy pod
36+
37+
self.log.info("Waiting for ingress controller")
38+
wait_for_ingress_controller()
39+
40+
self.log.info("Waiting for ingress host")
41+
ingress_ip = None
42+
attempts = 100
43+
while not ingress_ip:
44+
ingress_ip = get_ingress_ip_or_host()
45+
attempts -= 1
46+
if attempts < 0:
47+
raise Exception("Never got ingress host")
48+
sleep(1)
49+
# network id is 0xDEADBE in decimal
50+
fo_data_uri = f"http://{ingress_ip}/fork-observer/api/14593470/data.json"
3551

3652
def call_fo_api():
3753
# 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"
4054
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")
55+
self.log.info(f"Getting: {fo_data_uri}")
56+
fo_data = requests.get(fo_data_uri)
4457
# fork observed!
4558
return len(fo_data.json()["header_infos"]) == 2
4659
except Exception as e:
@@ -51,6 +64,19 @@ def call_fo_api():
5164
self.wait_for_predicate(call_fo_api)
5265
self.log.info("Fork observed!")
5366

67+
self.log.info("Checking node description...")
68+
fo_data = requests.get(fo_data_uri)
69+
nodes = fo_data.json()["nodes"]
70+
assert len(nodes) == 4
71+
assert nodes[1]["name"] == "john"
72+
assert nodes[1]["description"] == "john.default.svc:18444"
73+
74+
self.log.info("Checking reachable address is provided...")
75+
self.warnet("bitcoin rpc george addnode john.default.svc:18444 onetry")
76+
self.wait_for_predicate(
77+
lambda: len(json.loads(self.warnet("bitcoin rpc george getpeerinfo"))) > 1
78+
)
79+
5480

5581
if __name__ == "__main__":
5682
test = ServicesTest()

0 commit comments

Comments
 (0)