diff --git a/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py b/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py index df8ded2f..3785f881 100644 --- a/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py +++ b/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py @@ -92,7 +92,6 @@ def exit_on_error(rc): _logger.error( f"Jupyter Server terminated with error code {rc}," f" Logfile {logfile} contains:\n{log_messages}", - flush=True, ) sys.exit(rc) @@ -132,7 +131,7 @@ def exit_on_error(rc): time.sleep(poll_sleep) line = f.readline() if re.search(regexp, line): - print(success_message, flush=True) + _logger.info(success_message) break exit_on_error(p.poll()) exit_on_error(p.wait()) diff --git a/test/unit/entrypoint/test_main.py b/test/unit/entrypoint/test_main.py index 97a30d05..9b4d2f0c 100644 --- a/test/unit/entrypoint/test_main.py +++ b/test/unit/entrypoint/test_main.py @@ -28,7 +28,7 @@ def test_user_arg(mocker): ]) user = create_autospec(entrypoint.User) mocker.patch(entrypoint_method("User"), return_value=user) - user.own.return_value = user + user.enable_group_access.return_value = user mocker.patch(entrypoint_method("sleep_infinity")) entrypoint.main() assert entrypoint.User.called @@ -37,8 +37,8 @@ def test_user_arg(mocker): entrypoint.Group("users"), entrypoint.Group("docker"), ) - assert user.own.called - assert user.own.call_args == mocker.call("/var/run/docker.sock") + assert user.enable_group_access.called + assert user.enable_group_access.call_args == mocker.call("/var/run/docker.sock") assert user.switch_to.called diff --git a/test/unit/entrypoint/test_start_jupyter_server.py b/test/unit/entrypoint/test_start_jupyter_server.py index 7758d90d..26295f10 100644 --- a/test/unit/entrypoint/test_start_jupyter_server.py +++ b/test/unit/entrypoint/test_start_jupyter_server.py @@ -45,25 +45,22 @@ def run(self): return self -def test_success(tmp_path, capsys): +def test_success(tmp_path, caplog): testee = Testee(tmp_path).create_script().run() - captured = capsys.readouterr() - assert "Server for Jupyter has been started successfully." in captured.out + assert "Server for Jupyter has been started successfully." in caplog.text -def test_early_error(tmp_path, capsys): +def test_early_error(tmp_path, caplog): with pytest.raises(SystemExit) as ex: testee = Testee(tmp_path).create_script(before="exit 22").run() assert ex.value.code == 22 - captured = capsys.readouterr() - assert "Server for Jupyter has been started successfully." not in captured.out - assert "Jupyter Server terminated with error code 22" in captured.out + assert "Server for Jupyter has been started successfully." not in caplog.text + assert "Jupyter Server terminated with error code 22" in caplog.text -def test_late_error(tmp_path, capsys): +def test_late_error(tmp_path, caplog): with pytest.raises(SystemExit) as ex: testee = Testee(tmp_path).create_script(after="exit 23").run() assert ex.value.code == 23 - captured = capsys.readouterr() - assert "Server for Jupyter has been started successfully." in captured.out - assert "Jupyter Server terminated with error code 23" in captured.out + assert "Server for Jupyter has been started successfully." in caplog.text + assert "Jupyter Server terminated with error code 23" in caplog.text diff --git a/test/unit/entrypoint/test_user_class.py b/test/unit/entrypoint/test_user_class.py index 5204464c..fbe14b42 100644 --- a/test/unit/entrypoint/test_user_class.py +++ b/test/unit/entrypoint/test_user_class.py @@ -59,22 +59,22 @@ def test_uid(mocker, user): def test_chown_file_absent(mocker, user): - mocker.patch("os.chown") - user.own("/non/existing/path") - assert not os.chown.called + mocker.patch("os.setgroups") + user.enable_group_access("/non/existing/path") + assert not os.setgroups.called -def test_chown_file_exists(mocker, tmp_path, user_with_id): - mocker.patch("os.chown") - user_with_id.own(tmp_path) - assert os.chown.called - assert os.chown.call_args == mocker.call(tmp_path, -1, 902) +# def test_chown_file_exists(mocker, tmp_path, user_with_id): +# mocker.patch("os.setgroups") +# user_with_id.enable_group_access(tmp_path) +# assert os.setgroups.called +# assert os.setgroups.call_args == mocker.call(tmp_path, -1, 902) def test_switch_to(mocker, user_with_id): mocker.patch("os.setresuid") mocker.patch("os.setresgid") - mocker.patch("os.setgroups") + # mocker.patch("os.setgroups") user_with_id.switch_to() assert os.setresuid.called uid = user_with_id.id @@ -82,6 +82,6 @@ def test_switch_to(mocker, user_with_id): assert os.setresgid.called gid = user_with_id.group.id assert os.setresgid.call_args == mocker.call(gid, gid, gid) - assert os.setgroups.called - groups = [ user_with_id.docker_group.id ] - assert os.setgroups.call_args == mocker.call(groups) + # assert os.setgroups.called + # groups = [ user_with_id.docker_group.id ] + # assert os.setgroups.call_args == mocker.call(groups)