Skip to content

Commit

Permalink
Merge pull request #3949 from datamel/fix-remote-init-error
Browse files Browse the repository at this point in the history
Fix remote init failures
  • Loading branch information
oliver-sanders authored Nov 20, 2020
2 parents a40886d + d0e7063 commit 0c7bdd0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cylc/flow/task_remote_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def remote_init(install_target, rund, *dirs_to_symlink, indirect_comm=None):
src = os.path.expandvars(val)
if '$' in src:
print(REMOTE_INIT_FAILED)
return
make_symlink(src, dst)
srvd = os.path.join(rund, SuiteFiles.Service.DIRNAME)
os.makedirs(srvd, exist_ok=True)
Expand All @@ -119,6 +120,7 @@ def remote_init(install_target, rund, *dirs_to_symlink, indirect_comm=None):
if pattern.match(filepath) and f"{install_target}" not in filepath:
# client key for a different install target exists
print(REMOTE_INIT_FAILED)
return
try:
remove_keys_on_client(srvd, install_target)
create_client_keys(srvd, install_target)
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/test_task_remote_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Tests for remote initialisation."""

from io import StringIO
from unittest.mock import patch

from cylc.flow.task_remote_cmd import remote_init


@patch('os.makedirs')
@patch('os.listdir')
@patch('os.path.join')
@patch('os.path.expandvars')
def test_existing_key_raises_error(
mocked_expandvars, mocked_pathjoin, mocked_listdir,
mocked_makedirs, capsys):
"""Test .service directory that contains existing incorrect key,
results in REMOTE INIT FAILED
"""
mocked_expandvars.return_value = "some/expanded/path"
mocked_pathjoin.return_value = "joined.path"
mocked_listdir.return_value = ['client_wrong.key']

remote_init('test_install_target', 'some_rund')
assert capsys.readouterr().out == "REMOTE INIT FAILED\n"


@patch('os.path.expandvars')
def test_unexpandable_symlink_env_var_returns_failed(
mocked_expandvars, capsys):
"""Test unexpandable symlinks return REMOTE INIT FAILED"""
mocked_expandvars.side_effect = ['some/rund/path', '$blah']

remote_init('test_install_target', 'some_rund', 'run=$blah')
assert capsys.readouterr().out == "REMOTE INIT FAILED\n"

0 comments on commit 0c7bdd0

Please sign in to comment.