Skip to content

Commit d4df836

Browse files
authored
Merge pull request #600 from bitcoin-dev-project/status-fix
use default namespace when checking network connections
2 parents efbb59f + 0203931 commit d4df836

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/warnet/bitcoin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from test_framework.messages import ser_uint256
1111
from test_framework.p2p import MESSAGEMAP
1212

13-
from .k8s import get_mission
13+
from .k8s import get_default_namespace, get_mission
1414
from .process import run_command
1515

1616

@@ -38,10 +38,11 @@ def rpc(tank: str, method: str, params: str):
3838
def _rpc(tank: str, method: str, params: str):
3939
# bitcoin-cli should be able to read bitcoin.conf inside the container
4040
# so no extra args like port, chain, username or password are needed
41+
namespace = get_default_namespace()
4142
if params:
42-
cmd = f"kubectl exec {tank} -- bitcoin-cli {method} {' '.join(map(str, params))}"
43+
cmd = f"kubectl -n {namespace} exec {tank} -- bitcoin-cli {method} {' '.join(map(str, params))}"
4344
else:
44-
cmd = f"kubectl exec {tank} -- bitcoin-cli {method}"
45+
cmd = f"kubectl -n {namespace} exec {tank} -- bitcoin-cli {method}"
4546
return run_command(cmd)
4647

4748

src/warnet/network.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ def _connected(end="\n"):
6262
tanks = get_mission("tank")
6363
for tank in tanks:
6464
# Get actual
65-
peerinfo = json.loads(_rpc(tank.metadata.name, "getpeerinfo", ""))
66-
actual = 0
67-
for peer in peerinfo:
68-
if is_connection_manual(peer):
69-
actual += 1
70-
expected = int(tank.metadata.annotations["init_peers"])
71-
print(f"Tank {tank.metadata.name} peers expected: {expected}, actual: {actual}", end=end)
72-
# Even if more edges are specified, bitcoind only allows
73-
# 8 manual outbound connections
74-
if min(8, expected) > actual:
75-
print("\nNetwork not connected")
65+
try:
66+
peerinfo = json.loads(_rpc(tank.metadata.name, "getpeerinfo", ""))
67+
actual = 0
68+
for peer in peerinfo:
69+
if is_connection_manual(peer):
70+
actual += 1
71+
expected = int(tank.metadata.annotations["init_peers"])
72+
print(
73+
f"Tank {tank.metadata.name} peers expected: {expected}, actual: {actual}", end=end
74+
)
75+
# Even if more edges are specified, bitcoind only allows
76+
# 8 manual outbound connections
77+
if min(8, expected) > actual:
78+
print("\nNetwork not connected")
79+
return False
80+
except Exception:
7681
return False
7782
print("Network connected ")
7883
return True

0 commit comments

Comments
 (0)