Add local tests for ND
This commit is contained in:
parent
8f38020952
commit
651e2daa13
|
@ -4,7 +4,7 @@ import uuid
|
||||||
import copy
|
import copy
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from node import Node
|
from .node import Node
|
||||||
|
|
||||||
CHAIN_GENESIS = {"genesis_time": "0001-01-01T00:00:00Z",
|
CHAIN_GENESIS = {"genesis_time": "0001-01-01T00:00:00Z",
|
||||||
"chain_id": "",
|
"chain_id": "",
|
||||||
|
|
|
@ -2,13 +2,14 @@ import json
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
import copy
|
import copy
|
||||||
|
import requests
|
||||||
|
|
||||||
import kubernetes
|
import kubernetes
|
||||||
from kubernetes.client.rest import ApiException
|
from kubernetes.client.rest import ApiException
|
||||||
from kubernetes.stream import stream
|
from kubernetes.stream import stream
|
||||||
|
|
||||||
TENDERMINT_PORT = 46656
|
TENDERMINT_PORT = 46656
|
||||||
|
TENDERMINT_HTTP_PORT = 46657
|
||||||
|
|
||||||
# TODO: create a default pod spec of BDB
|
# TODO: create a default pod spec of BDB
|
||||||
MONGODB_SPEC = {"name": "mongodb",
|
MONGODB_SPEC = {"name": "mongodb",
|
||||||
|
@ -120,6 +121,14 @@ class Node():
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tendermint_http_uri(self):
|
||||||
|
ip = self.ip
|
||||||
|
if ip:
|
||||||
|
return 'http://{}:{}'.format(ip, TENDERMINT_HTTP_PORT)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def stop_tendermint(self):
|
def stop_tendermint(self):
|
||||||
self._exec_command('tendermint', 'pkill tendermint')
|
self._exec_command('tendermint', 'pkill tendermint')
|
||||||
|
|
||||||
|
@ -168,6 +177,11 @@ class Node():
|
||||||
self.stop_tendermint()
|
self.stop_tendermint()
|
||||||
self.start_tendermint()
|
self.start_tendermint()
|
||||||
|
|
||||||
|
def get_peers(self):
|
||||||
|
uri = '{}/net_info'.format(self.tendermint_http_uri)
|
||||||
|
r = requests.get(uri)
|
||||||
|
return r.json()['result']['peers']
|
||||||
|
|
||||||
def _create_namespace(self, namespace):
|
def _create_namespace(self, namespace):
|
||||||
namespace_spec = kubernetes.client.V1Namespace()
|
namespace_spec = kubernetes.client.V1Namespace()
|
||||||
namespace_spec.api_version = 'v1'
|
namespace_spec.api_version = 'v1'
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -84,6 +84,7 @@ install_requires = [
|
||||||
'python-rapidjson-schema==0.1.1',
|
'python-rapidjson-schema==0.1.1',
|
||||||
'statsd==3.2.1',
|
'statsd==3.2.1',
|
||||||
'abci~=0.3.0',
|
'abci~=0.3.0',
|
||||||
|
'kubernetes~=4.0.0',
|
||||||
]
|
]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
from network_driver.network import Network
|
||||||
|
|
||||||
|
|
||||||
|
def test_peers_connected():
|
||||||
|
n = Network(2)
|
||||||
|
n.ensure_started()
|
||||||
|
|
||||||
|
assert n.nodes[0].get_peers() == []
|
||||||
|
assert n.nodes[1].get_peers() == []
|
||||||
|
|
||||||
|
n.ensure_connected()
|
||||||
|
|
||||||
|
assert len(n.nodes[0].get_peers()) == 1
|
||||||
|
assert len(n.nodes[1].get_peers()) == 1
|
||||||
|
|
||||||
|
n.stop()
|
Loading…
Reference in New Issue