Skip to content

Commit

Permalink
Merge pull request #76 from skalenetwork/enhancement/SKALE-1785-add-s…
Browse files Browse the repository at this point in the history
…gx-options

Enhancement/skale 1785 add sgx options
  • Loading branch information
dmytrotkk authored Nov 14, 2019
2 parents 87e1fcc + 92aadb9 commit 2b3715d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
9 changes: 7 additions & 2 deletions cli/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ def register_node(name, ip, port):
'--test-mode',
is_flag=True
)
@click.option(
'--sgx-url',
prompt="Enter URL of sgx server",
help='URL of sgx server endpoint'
)
@local_only
def init_node(install_deps, disk_mountpoint, test_mode):
def init_node(install_deps, disk_mountpoint, test_mode, sgx_url):
if install_deps:
install_host_dependencies()
init(disk_mountpoint, test_mode)
init(disk_mountpoint, test_mode, sgx_url)


@node.command('purge', help="Uninstall SKALE node software from the machine")
Expand Down
3 changes: 3 additions & 0 deletions configs/resource_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
DISK_MOUNTPOINT_FILENAME = 'disk_mountpoint.txt'
DISK_MOUNTPOINT_FILEPATH = os.path.join(NODE_DATA_PATH, DISK_MOUNTPOINT_FILENAME)

SGX_SERVER_URL_FILENAME = 'sgx_server_url.txt'
SGX_SERVER_URL_FILEPATH = os.path.join(NODE_DATA_PATH, SGX_SERVER_URL_FILENAME)

CONVOY_HELPER_SCRIPT_FILENAME = 'dm_dev_partition.sh'
CONVOY_HELPER_SCRIPT_FILEPATH = os.path.join(THIRDPARTY_FOLDER_PATH, CONVOY_HELPER_SCRIPT_FILENAME)

Expand Down
13 changes: 10 additions & 3 deletions core/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from configs import DEPENDENCIES_SCRIPT, ROUTES, SKALE_NODE_UI_PORT, DEFAULT_URL_SCHEME, \
INSTALL_CONVOY_SCRIPT, NODE_DATA_PATH
from configs.cli_logger import LOG_DATA_PATH
from configs.resource_allocation import DISK_MOUNTPOINT_FILEPATH, \
CONVOY_HELPER_SCRIPT_FILEPATH, CONVOY_SERVICE_TEMPLATE_PATH, CONVOY_SERVICE_PATH
from configs.resource_allocation import DISK_MOUNTPOINT_FILEPATH, CONVOY_HELPER_SCRIPT_FILEPATH, \
CONVOY_SERVICE_TEMPLATE_PATH, CONVOY_SERVICE_PATH, SGX_SERVER_URL_FILEPATH

from core.helper import safe_get_config, safe_load_texts, construct_url, clean_cookies, \
clean_host, get_localhost_endpoint
Expand Down Expand Up @@ -89,9 +89,10 @@ def fix_url(url):
return False


def prepare_host(test_mode, disk_mountpoint):
def prepare_host(test_mode, disk_mountpoint, sgx_server_url):
logger.info(f'Preparing host started, disk_mountpoint: {disk_mountpoint}')
save_disk_mountpoint(disk_mountpoint)
save_sgx_server_url(sgx_server_url)
save_resource_allocation_config()
if not test_mode:
init_convoy(disk_mountpoint)
Expand Down Expand Up @@ -131,6 +132,12 @@ def save_disk_mountpoint(disk_mountpoint):
f.write(disk_mountpoint)


def save_sgx_server_url(sgx_server_url):
logger.info(f'Saving disk_mountpoint option to {SGX_SERVER_URL_FILEPATH}')
with open(SGX_SERVER_URL_FILEPATH, 'w') as f:
f.write(sgx_server_url)


def init_logs_dir():
safe_mk_dirs(LOG_DATA_PATH)

Expand Down
5 changes: 3 additions & 2 deletions core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ def create_node(config, name, p2p_ip, public_ip, port):
print_err_response(response.json())


def init(disk_mountpoint, test_mode):
def init(disk_mountpoint, test_mode, sgx_server_url):
env_params = {
**env_settings,
'DISK_MOUNTPOINT': disk_mountpoint,
'SGX_SERVER_URL': sgx_server_url,
}
if not env_params.get('DB_ROOT_PASSWORD'):
env_params['DB_ROOT_PASSWORD'] = env_params['DB_PASSWORD']
Expand All @@ -71,7 +72,7 @@ def init(disk_mountpoint, test_mode):
f"Some services will not work", err=True)

init_data_dir()
prepare_host(test_mode, disk_mountpoint)
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}')
# todo: check execution result
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/node_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def test_init_node(skip_local_only, config):
'core.node.post_request',
resp_mock,
init_node,
input='/dev/sdp')
input='/dev/sdp\nlocalhost')
assert result.exit_code == 0
assert result.output == 'Enter data disk mount point: /dev/sdp\n'
assert result.output == 'Enter data disk mount point: /dev/sdp\nEnter URL of sgx server: localhost\n' # noqa


def test_purge(skip_local_only, config):
Expand Down

0 comments on commit 2b3715d

Please sign in to comment.