diff --git a/core/node.py b/core/node.py index c65b0b3b..82b0b14a 100644 --- a/core/node.py +++ b/core/node.py @@ -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 @@ -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): @@ -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 @@ -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 diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index 4c43a380..6d7a5b69 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -26,10 +26,9 @@ 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 @@ -37,30 +36,17 @@ def test_register_node(skip_auth, config): 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 @@ -68,10 +54,9 @@ def test_register_node_with_prompted_ip(config, skip_auth): 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