Skip to content

Commit

Permalink
Merge pull request #99 from skalenetwork/enhancement/SKALE-2000-node-…
Browse files Browse the repository at this point in the history
…registration-error

SKALE-2000 Skale node cli node registration error log
  • Loading branch information
badrogger authored Jan 17, 2020
2 parents 9648a21 + a814ccf commit 1747ed2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
19 changes: 11 additions & 8 deletions core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import click

from core.host import prepare_host, init_data_dir
from core.helper import post, print_err_response
from core.helper import post
from tools.texts import Texts
from configs import INSTALL_SCRIPT, UNINSTALL_SCRIPT, UPDATE_SCRIPT, UPDATE_NODE_PROJECT_SCRIPT
from configs.env import get_params
Expand All @@ -39,13 +39,16 @@ def create_node(config, name, p2p_ip, public_ip, port):
if response is None:
print(TEXTS['service']['empty_response'])
return None
if response['status']:
if response.get('errors') is not None:
print(f'Node registration failed with error: {response["errors"]}')
logger.error(f'Registration error {response["errors"]}')
return
if response['res']:
msg = TEXTS['node']['registered']
logging.info(msg)
logger.info(msg)
print(msg)
else:
logging.info(response.json())
print_err_response(response.json())
logger.info('Bad response. Something went wrong. Try again')


def init(disk_mountpoint, test_mode, sgx_server_url, env_filepath):
Expand Down Expand Up @@ -74,7 +77,7 @@ def init(disk_mountpoint, test_mode, sgx_server_url, env_filepath):
init_data_dir()
prepare_host(test_mode, disk_mountpoint, sgx_server_url)
res = subprocess.run(['bash', INSTALL_SCRIPT], env=env_params)
logging.info(f'Node init install script result: {res.stderr}, {res.stdout}')
logger.info(f'Node init install script result: {res.stderr}, {res.stdout}')
# todo: check execution result


Expand Down Expand Up @@ -113,14 +116,14 @@ def update(env_filepath):
['sudo', '-E', 'bash', UPDATE_NODE_PROJECT_SCRIPT],
env=env_params
)
logging.info(
logger.info(
f'Update node project script result: {res_update_project.stderr}, \
{res_update_project.stdout}')
res_update_node = subprocess.run(
['sudo', '-E', 'bash', UPDATE_SCRIPT],
env=env_params,
)
logging.info(
logger.info(
f'Update node script result: '
f'{res_update_node.stderr}, {res_update_node.stdout}')
# todo: check execution result
25 changes: 5 additions & 20 deletions tests/cli/node_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,37 @@


def test_register_node(skip_auth, config):
resp_mock = response_mock(requests.codes.created)
result = run_command_mock(
'core.node.post',
resp_mock,
{'res': 1},
register_node,
['--name', 'test-node', '--ip', '0.0.0.0', '--port', '8080'])
assert result.exit_code == 0
assert result.output == 'Node registered in SKALE manager.\nFor more info run < skale node info >\n' # noqa

result = run_command_mock(
'core.node.post',
None,
{'errors': ['Strange error']},
register_node,
['--name', 'test-node2', '--ip', '0.0.0.0', '--port', '80'])
assert result.exit_code == 0
assert result.output == 'Your request returned nothing. Something went wrong.\n'

# TODO: fix this test
# resp_mock = response_mock(requests.codes.ok,
# json_data={'errors': ['Strange error']})
# result = run_command_mock(
# 'core.node.post',
# resp_mock,
# register_node,
# ['--name', 'test-node2', '--ip', '0.0.0.0', '--port', '80'])
# assert result.exit_code == 0
# assert result.output == ''
# assert result.output == '--------------------------------------------------\nStrange error\n--------------------------------------------------\n' # noqa
assert result.output == "Node registration failed with error: ['Strange error']\n"


def test_register_node_with_prompted_ip(config, skip_auth):
resp_mock = response_mock(requests.codes.created)
result = run_command_mock(
'core.node.post',
resp_mock,
{'res': 1},
register_node,
['--name', 'test-node', '--port', '8080'], input='0.0.0.0\n')
assert result.exit_code == 0
assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager.\nFor more info run < skale node info >\n' # noqa


def test_register_node_with_default_port_and_name(config, skip_auth):
resp_mock = response_mock(requests.codes.created)
result = run_command_mock(
'core.node.post',
resp_mock,
{'res': 1},
register_node,
input='0.0.0.0\n')
assert result.exit_code == 0
Expand Down

0 comments on commit 1747ed2

Please sign in to comment.