From 2925604062c03611cc494ddf846171210e631dad Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 12:30:33 -0700 Subject: [PATCH 01/16] Set up SSH key --- .github/workflows/ci.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index abd3f27..5711d4b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,6 +24,19 @@ jobs: python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 + - name: Configure SSH key for localhost + run: | + ssh-keygen -t ed25519 -f ~/.ssh/my_key -N '' + cat > ~/.ssh/config < ~/.ssh/authorized_keys + chmod og-rw ~ + ls -la ~/.ssh + ssh -o 'StrictHostKeyChecking no' mycluster.local id - uses: conda-incubator/setup-miniconda@v2 with: channels: conda-forge From a1d121ec1074aa9d82b3910e61c805d720c36a50 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 12:46:32 -0700 Subject: [PATCH 02/16] Add test_connection() --- .github/workflows/ci.yaml | 4 ++-- tests/test_core.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5711d4b..9726167 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,7 +28,7 @@ jobs: run: | ssh-keygen -t ed25519 -f ~/.ssh/my_key -N '' cat > ~/.ssh/config < ~/.ssh/authorized_keys chmod og-rw ~ ls -la ~/.ssh - ssh -o 'StrictHostKeyChecking no' mycluster.local id + ssh -o 'StrictHostKeyChecking no' eniac.local id - uses: conda-incubator/setup-miniconda@v2 with: channels: conda-forge diff --git a/tests/test_core.py b/tests/test_core.py index a004f44..da40df2 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,10 +1,14 @@ +import os import socket from unittest import mock as mock import pytest +import jupyter_forward from jupyter_forward.core import is_port_available, open_browser, parse_stdout +NOT_GITHUB_ACTIONS = os.environ.get('GITHUB_ACTIONS') is None + @pytest.mark.parametrize( 'stdout, expected', @@ -68,3 +72,12 @@ def test_open_browser(port, token, url, expected): with mock.patch('webbrowser.open') as mockwebopen: open_browser(port, token, url) mockwebopen.assert_called_once_with(expected, new=2) + + +@pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='Requires Github Actions environment') +def test_connection(): + USER = os.environ['USER'] + runner = jupyter_forward.RemoteRunner(f'{USER}@eniac.local') + assert runner.session.is_connected + assert runner.session.host == 'eniac.local' + assert runner.session.user == USER From d192ea9b3c5ba890f44aeeb968421bb640fb1ca0 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 12:49:57 -0700 Subject: [PATCH 03/16] Update test --- tests/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_core.py b/tests/test_core.py index da40df2..c7bdb47 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -79,5 +79,5 @@ def test_connection(): USER = os.environ['USER'] runner = jupyter_forward.RemoteRunner(f'{USER}@eniac.local') assert runner.session.is_connected - assert runner.session.host == 'eniac.local' + assert runner.session.host == '127.0.0.1' assert runner.session.user == USER From 25cfc478756d55033dc914bd66f21d2e5ceccec4 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 12:58:46 -0700 Subject: [PATCH 04/16] Use script --- .github/scripts/ssh_setup.sh | 13 +++++++++++++ .github/workflows/ci.yaml | 14 +++----------- .github/workflows/upstream-dev-ci.yaml | 5 +++++ 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100755 .github/scripts/ssh_setup.sh diff --git a/.github/scripts/ssh_setup.sh b/.github/scripts/ssh_setup.sh new file mode 100755 index 0000000..aac44ba --- /dev/null +++ b/.github/scripts/ssh_setup.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +ssh-keygen -t ed25519 -f ~/.ssh/my_key -N '' +cat > ~/.ssh/config < ~/.ssh/authorized_keys +chmod og-rw ~ +ls -la ~/.ssh +ssh -o 'StrictHostKeyChecking no' eniac.local id diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9726167..bdfec6e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,19 +24,11 @@ jobs: python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Configure SSH key for localhost run: | - ssh-keygen -t ed25519 -f ~/.ssh/my_key -N '' - cat > ~/.ssh/config < ~/.ssh/authorized_keys - chmod og-rw ~ - ls -la ~/.ssh - ssh -o 'StrictHostKeyChecking no' eniac.local id + .github/scripts/ssh_setup.sh - uses: conda-incubator/setup-miniconda@v2 with: channels: conda-forge diff --git a/.github/workflows/upstream-dev-ci.yaml b/.github/workflows/upstream-dev-ci.yaml index 4266f3d..30684f9 100644 --- a/.github/workflows/upstream-dev-ci.yaml +++ b/.github/workflows/upstream-dev-ci.yaml @@ -22,6 +22,11 @@ jobs: python-version: ['3.10'] steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Configure SSH key for localhost + run: | + .github/scripts/ssh_setup.sh - uses: conda-incubator/setup-miniconda@v2 id: conda with: From e90114f7f333b31c22c15fa4a715c6c6efc72739 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 13:10:53 -0700 Subject: [PATCH 05/16] Update tests --- tests/test_core.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index c7bdb47..738da56 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -10,6 +10,11 @@ NOT_GITHUB_ACTIONS = os.environ.get('GITHUB_ACTIONS') is None +@pytest.fixture(scope='session', params=[f"{os.environ['USER']}@eniac.local"]) +def runner(request): + return jupyter_forward.RemoteRunner(request.param) + + @pytest.mark.parametrize( 'stdout, expected', [ @@ -75,9 +80,16 @@ def test_open_browser(port, token, url, expected): @pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='Requires Github Actions environment') -def test_connection(): +def test_connection(runner): USER = os.environ['USER'] - runner = jupyter_forward.RemoteRunner(f'{USER}@eniac.local') assert runner.session.is_connected assert runner.session.host == '127.0.0.1' assert runner.session.user == USER + + +@pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='Requires Github Actions environment') +@pytest.mark.parametrize('command', ['echo $HOME']) +def test_run_command(runner, command): + out = runner.run_command(command) + assert not out.failed + assert out.stdout.strip() == f"{os.environ['HOME']}" From c5db82f2d71bf423e38772895ab547369808e9df Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 13:15:34 -0700 Subject: [PATCH 06/16] Capture output --- tests/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_core.py b/tests/test_core.py index 738da56..3804962 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -89,7 +89,7 @@ def test_connection(runner): @pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='Requires Github Actions environment') @pytest.mark.parametrize('command', ['echo $HOME']) -def test_run_command(runner, command): +def test_run_command(capsys, runner, command): out = runner.run_command(command) assert not out.failed assert out.stdout.strip() == f"{os.environ['HOME']}" From f6d2595370ede75aa40ed4e71e32c23ba0127095 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 13:16:44 -0700 Subject: [PATCH 07/16] Disable capturing --- setup.cfg | 2 +- tests/test_core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7bbf393..2643827 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,4 +20,4 @@ skip= [tool:pytest] console_output_style = count -addopts = --cov=./ --cov-report=xml --verbose +addopts = --cov=./ --cov-report=xml --verbose -s diff --git a/tests/test_core.py b/tests/test_core.py index 3804962..738da56 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -89,7 +89,7 @@ def test_connection(runner): @pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='Requires Github Actions environment') @pytest.mark.parametrize('command', ['echo $HOME']) -def test_run_command(capsys, runner, command): +def test_run_command(runner, command): out = runner.run_command(command) assert not out.failed assert out.stdout.strip() == f"{os.environ['HOME']}" From faa213aab2e960086353adca2d37f1e3716e2f64 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 13:19:30 -0700 Subject: [PATCH 08/16] Disable push events for upstream dev CI --- .github/workflows/upstream-dev-ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upstream-dev-ci.yaml b/.github/workflows/upstream-dev-ci.yaml index 30684f9..38dca83 100644 --- a/.github/workflows/upstream-dev-ci.yaml +++ b/.github/workflows/upstream-dev-ci.yaml @@ -1,6 +1,5 @@ name: Upstream CI on: - push: schedule: - cron: '0 0 * * *' # Daily “At 00:00” UTC workflow_dispatch: # allows you to trigger the workflow run manually @@ -54,6 +53,7 @@ jobs: - name: Report Status if: | always() + && github.ref == 'refs/heads/main' && (steps.conda.outcome != 'success' || steps.install.outcome != 'success' || steps.install.outcome != 'success') uses: actions/github-script@v6 with: From 2b29b198e03257707aa37f027badb6ba85ef86e5 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 13:28:04 -0700 Subject: [PATCH 09/16] Update tests --- tests/test_core.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 738da56..4020fd5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -8,6 +8,7 @@ from jupyter_forward.core import is_port_available, open_browser, parse_stdout NOT_GITHUB_ACTIONS = os.environ.get('GITHUB_ACTIONS') is None +requires_gha = pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='requires GITHUB_ACTIONS') @pytest.fixture(scope='session', params=[f"{os.environ['USER']}@eniac.local"]) @@ -79,7 +80,7 @@ def test_open_browser(port, token, url, expected): mockwebopen.assert_called_once_with(expected, new=2) -@pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='Requires Github Actions environment') +@requires_gha def test_connection(runner): USER = os.environ['USER'] assert runner.session.is_connected @@ -87,9 +88,20 @@ def test_connection(runner): assert runner.session.user == USER -@pytest.mark.skipif(NOT_GITHUB_ACTIONS, reason='Requires Github Actions environment') +@requires_gha @pytest.mark.parametrize('command', ['echo $HOME']) def test_run_command(runner, command): out = runner.run_command(command) assert not out.failed assert out.stdout.strip() == f"{os.environ['HOME']}" + + +@requires_gha +@pytest.mark.parametrize('command', ['echod $HOME']) +def test_run_command_failure(runner, command): + out = runner.run_command(command, exit=False) + assert out.failed + assert 'echod: command not found' in out.stdout.strip() + + with pytest.raises(SystemExit): + runner.run_command(command) From 5c00347c3c937f43f3d7eb78db13181a91ad5145 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 20:47:36 -0700 Subject: [PATCH 10/16] Add test for check_log_file_dir --- jupyter_forward/core.py | 12 +++++------- tests/test_core.py | 6 ++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/jupyter_forward/core.py b/jupyter_forward/core.py index 2da3587..8f24524 100644 --- a/jupyter_forward/core.py +++ b/jupyter_forward/core.py @@ -183,11 +183,10 @@ def _launch_jupyter(self): ) tmp_dir_env_status = self.run_command(command='printenv TMPDIR', exit=False) home_dir_env_status = self.run_command(command='printenv HOME', exit=False) - check_dir_command = 'touch ${}/foobar && rm -rf ${}/foobar && echo "${} is WRITABLE" || echo "${} is NOT WRITABLE"' if not tmp_dir_env_status.failed: - self._check_log_file_dir(check_dir_command, 'TMPDIR', '$TMPDIR') + self._check_log_file_dir('TMPDIR', '$TMPDIR') elif not home_dir_env_status.failed: - self._check_log_file_dir(check_dir_command, 'HOME', '$HOME') + self._check_log_file_dir('HOME', '$HOME') else: tmp_dir_error_message = '$TMPDIR is not defined' home_dir_error_message = '$HOME is not defined' @@ -243,10 +242,9 @@ def _launch_jupyter(self): open_browser(url=self.parsed_result['url'], path=self.notebook) self.run_command(command=f'tail -f {self.log_file}') - def _check_log_file_dir(self, check_dir_command, arg1, arg2): - _tmp_dir_status = self.run_command( - command=check_dir_command.format(arg1, arg1, arg1, arg1), exit=False - ) + def _check_log_file_dir(self, arg1, arg2): + check_dir_command = f'touch ${arg1}/foobar && rm -rf ${arg1}/foobar && echo "${arg1} is WRITABLE" || echo "${arg1} is NOT WRITABLE"' + _tmp_dir_status = self.run_command(command=check_dir_command, exit=False) if 'is WRITABLE' in _tmp_dir_status.stdout.strip(): self.log_dir = arg2 diff --git a/tests/test_core.py b/tests/test_core.py index 4020fd5..5a33de3 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -105,3 +105,9 @@ def test_run_command_failure(runner, command): with pytest.raises(SystemExit): runner.run_command(command) + + +@requires_gha +def test_check_log_file_dir(runner): + runner._check_log_file_dir('HOME', '$HOME') + assert runner.log_dir == '$HOME' From ec712eb271af45ca332e1d2939ce4a26a5c6f8fa Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 20:51:07 -0700 Subject: [PATCH 11/16] Update test --- jupyter_forward/core.py | 10 +++++----- tests/test_core.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jupyter_forward/core.py b/jupyter_forward/core.py index 8f24524..8650a03 100644 --- a/jupyter_forward/core.py +++ b/jupyter_forward/core.py @@ -184,9 +184,9 @@ def _launch_jupyter(self): tmp_dir_env_status = self.run_command(command='printenv TMPDIR', exit=False) home_dir_env_status = self.run_command(command='printenv HOME', exit=False) if not tmp_dir_env_status.failed: - self._check_log_file_dir('TMPDIR', '$TMPDIR') + self._check_log_file_dir('$TMPDIR') elif not home_dir_env_status.failed: - self._check_log_file_dir('HOME', '$HOME') + self._check_log_file_dir('$HOME') else: tmp_dir_error_message = '$TMPDIR is not defined' home_dir_error_message = '$HOME is not defined' @@ -242,12 +242,12 @@ def _launch_jupyter(self): open_browser(url=self.parsed_result['url'], path=self.notebook) self.run_command(command=f'tail -f {self.log_file}') - def _check_log_file_dir(self, arg1, arg2): - check_dir_command = f'touch ${arg1}/foobar && rm -rf ${arg1}/foobar && echo "${arg1} is WRITABLE" || echo "${arg1} is NOT WRITABLE"' + def _check_log_file_dir(self, directory): + check_dir_command = f'touch {directory}/foobar && rm -rf {directory}/foobar && echo "{directory} is WRITABLE" || echo "{directory} is NOT WRITABLE"' _tmp_dir_status = self.run_command(command=check_dir_command, exit=False) if 'is WRITABLE' in _tmp_dir_status.stdout.strip(): - self.log_dir = arg2 + self.log_dir = directory def open_browser(port: int = None, token: str = None, url: str = None, path=None): diff --git a/tests/test_core.py b/tests/test_core.py index 5a33de3..f6d43b7 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -109,5 +109,5 @@ def test_run_command_failure(runner, command): @requires_gha def test_check_log_file_dir(runner): - runner._check_log_file_dir('HOME', '$HOME') + runner._check_log_file_dir('$HOME') assert runner.log_dir == '$HOME' From d1da085b450833a3156dd3cce248ecdd93e45c41 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 21:09:12 -0700 Subject: [PATCH 12/16] Create standalone method for setting log directory --- jupyter_forward/core.py | 50 ++++++++++++++++++++++------------------- tests/test_core.py | 7 +++--- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/jupyter_forward/core.py b/jupyter_forward/core.py index 8650a03..8434d60 100644 --- a/jupyter_forward/core.py +++ b/jupyter_forward/core.py @@ -178,24 +178,7 @@ def _launch_jupyter(self): else: self.run_command(check_jupyter_status) - console.rule( - f'[bold green] Checking $TMPDIR and $HOME on {self.session.host}', characters='*' - ) - tmp_dir_env_status = self.run_command(command='printenv TMPDIR', exit=False) - home_dir_env_status = self.run_command(command='printenv HOME', exit=False) - if not tmp_dir_env_status.failed: - self._check_log_file_dir('$TMPDIR') - elif not home_dir_env_status.failed: - self._check_log_file_dir('$HOME') - else: - tmp_dir_error_message = '$TMPDIR is not defined' - home_dir_error_message = '$HOME is not defined' - console.print( - f'[bold red]Can not determine directory for log file:\n{home_dir_error_message}\n{tmp_dir_error_message}' - ) - sys.exit(1) - self.log_dir = f'{self.log_dir}/.jupyter_forward' - self.run_command(command=f'mkdir -p {self.log_dir}') + self.log_dir = self._set_log_directory() timestamp = datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S') self.log_file = f'{self.log_dir}/log.{timestamp}' self.run_command(command=f'touch {self.log_file}') @@ -242,12 +225,33 @@ def _launch_jupyter(self): open_browser(url=self.parsed_result['url'], path=self.notebook) self.run_command(command=f'tail -f {self.log_file}') - def _check_log_file_dir(self, directory): - check_dir_command = f'touch {directory}/foobar && rm -rf {directory}/foobar && echo "{directory} is WRITABLE" || echo "{directory} is NOT WRITABLE"' - _tmp_dir_status = self.run_command(command=check_dir_command, exit=False) + def _set_log_directory(self): + def _check_log_file_dir(directory): + check_dir_command = f'touch {directory}/foobar && rm -rf {directory}/foobar && echo "{directory} is WRITABLE" || echo "{directory} is NOT WRITABLE"' + _tmp_dir_status = self.run_command(command=check_dir_command, exit=False) + return directory if 'is WRITABLE' in _tmp_dir_status.stdout.strip() else None - if 'is WRITABLE' in _tmp_dir_status.stdout.strip(): - self.log_dir = directory + console.rule( + f'[bold green] Checking $TMPDIR and $HOME on {self.session.host}', characters='*' + ) + log_dir = None + tmp_dir_env_status = self.run_command(command='printenv TMPDIR', exit=False) + home_dir_env_status = self.run_command(command='printenv HOME', exit=False) + if not tmp_dir_env_status.failed: + log_dir = _check_log_file_dir('$TMPDIR') + elif not home_dir_env_status.failed: + log_dir = _check_log_file_dir('$HOME') + else: + tmp_dir_error_message = '$TMPDIR is not defined' + home_dir_error_message = '$HOME is not defined' + console.print( + f'[bold red]Can not determine directory for log file:\n{home_dir_error_message}\n{tmp_dir_error_message}' + ) + sys.exit(1) + log_dir = f'{log_dir}/.jupyter_forward' + self.run_command(command=f'mkdir -p {log_dir}') + console.print(f'[bold cyan]Log directory is set to {log_dir} on {self.session.host}') + return log_dir def open_browser(port: int = None, token: str = None, url: str = None, path=None): diff --git a/tests/test_core.py b/tests/test_core.py index f6d43b7..016939a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -108,6 +108,7 @@ def test_run_command_failure(runner, command): @requires_gha -def test_check_log_file_dir(runner): - runner._check_log_file_dir('$HOME') - assert runner.log_dir == '$HOME' +def test_set_log_directory(runner): + log_dir = runner._set_log_directory() + assert log_dir == '$TMPDIR' + assert runner.log_dir == log_dir From 1c5fc90af6ec2c4164460521187b64341a03734f Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 21:12:00 -0700 Subject: [PATCH 13/16] Fix test --- tests/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_core.py b/tests/test_core.py index 016939a..0baf9cc 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -110,5 +110,5 @@ def test_run_command_failure(runner, command): @requires_gha def test_set_log_directory(runner): log_dir = runner._set_log_directory() - assert log_dir == '$TMPDIR' + assert log_dir == '$HOME/.jupyter_forward' assert runner.log_dir == log_dir From cb328e418194e17d1b60717a16e55266d0889c5d Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 21:18:22 -0700 Subject: [PATCH 14/16] Update fixture --- tests/test_core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 0baf9cc..52f2883 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -13,7 +13,9 @@ @pytest.fixture(scope='session', params=[f"{os.environ['USER']}@eniac.local"]) def runner(request): - return jupyter_forward.RemoteRunner(request.param) + remote = jupyter_forward.RemoteRunner(request.param) + yield remote + remote.close() @pytest.mark.parametrize( @@ -111,4 +113,3 @@ def test_run_command_failure(runner, command): def test_set_log_directory(runner): log_dir = runner._set_log_directory() assert log_dir == '$HOME/.jupyter_forward' - assert runner.log_dir == log_dir From 641a4edadb3fb3730d919fa625414a6fc79a07fa Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Wed, 16 Feb 2022 21:46:35 -0700 Subject: [PATCH 15/16] Update test --- jupyter_forward/core.py | 25 +++++++++++++++---------- tests/test_core.py | 10 +++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/jupyter_forward/core.py b/jupyter_forward/core.py index 8434d60..0387a0c 100644 --- a/jupyter_forward/core.py +++ b/jupyter_forward/core.py @@ -11,6 +11,8 @@ from fabric import Connection from rich.console import Console +timestamp = datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S') + console = Console() @@ -178,11 +180,8 @@ def _launch_jupyter(self): else: self.run_command(check_jupyter_status) - self.log_dir = self._set_log_directory() - timestamp = datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S') - self.log_file = f'{self.log_dir}/log.{timestamp}' - self.run_command(command=f'touch {self.log_file}') - + self._set_log_directory() + self._set_log_file() command = r'jupyter lab --no-browser --ip=\$(hostname -f)' if self.notebook_dir: command = f'{command} --notebook-dir={self.notebook_dir}' @@ -225,15 +224,20 @@ def _launch_jupyter(self): open_browser(url=self.parsed_result['url'], path=self.notebook) self.run_command(command=f'tail -f {self.log_file}') + def _set_log_file(self): + log_file = f'{self.log_dir}/log_{timestamp}.txt' + self.run_command(command=f'touch {log_file}') + self.log_file = log_file + console.print(f'[bold cyan]:white_check_mark: Log file is set to {log_file}') + return self + def _set_log_directory(self): def _check_log_file_dir(directory): check_dir_command = f'touch {directory}/foobar && rm -rf {directory}/foobar && echo "{directory} is WRITABLE" || echo "{directory} is NOT WRITABLE"' _tmp_dir_status = self.run_command(command=check_dir_command, exit=False) return directory if 'is WRITABLE' in _tmp_dir_status.stdout.strip() else None - console.rule( - f'[bold green] Checking $TMPDIR and $HOME on {self.session.host}', characters='*' - ) + console.rule(f'[bold green] Creating log file on {self.session.host}', characters='*') log_dir = None tmp_dir_env_status = self.run_command(command='printenv TMPDIR', exit=False) home_dir_env_status = self.run_command(command='printenv HOME', exit=False) @@ -250,8 +254,9 @@ def _check_log_file_dir(directory): sys.exit(1) log_dir = f'{log_dir}/.jupyter_forward' self.run_command(command=f'mkdir -p {log_dir}') - console.print(f'[bold cyan]Log directory is set to {log_dir} on {self.session.host}') - return log_dir + console.print(f'[bold cyan]:white_check_mark: Log directory is set to {log_dir}') + self.log_dir = log_dir + return self def open_browser(port: int = None, token: str = None, url: str = None, path=None): diff --git a/tests/test_core.py b/tests/test_core.py index 52f2883..10ab21e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,3 +1,4 @@ +import datetime import os import socket from unittest import mock as mock @@ -110,6 +111,9 @@ def test_run_command_failure(runner, command): @requires_gha -def test_set_log_directory(runner): - log_dir = runner._set_log_directory() - assert log_dir == '$HOME/.jupyter_forward' +def test_set_logs(runner): + runner._set_log_directory() + assert runner.log_dir == '$HOME/.jupyter_forward' + runner._set_log_file() + now = datetime.datetime.now() + assert f"log_{now.strftime('%Y-%m-%dT%H')}" in runner.log_file From 23cb07dac360f2359b0659494010a3f3fe869292 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 17 Feb 2022 12:07:22 -0700 Subject: [PATCH 16/16] Update CI triggers --- .github/workflows/ci.yaml | 2 ++ .github/workflows/upstream-dev-ci.yaml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bdfec6e..c790d92 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,8 @@ name: CI on: push: + branches: + - main pull_request: schedule: - cron: '0 0 * * *' # Daily “At 00:00” diff --git a/.github/workflows/upstream-dev-ci.yaml b/.github/workflows/upstream-dev-ci.yaml index 38dca83..2f15511 100644 --- a/.github/workflows/upstream-dev-ci.yaml +++ b/.github/workflows/upstream-dev-ci.yaml @@ -1,5 +1,8 @@ name: Upstream CI on: + push: + branches: + - main schedule: - cron: '0 0 * * *' # Daily “At 00:00” UTC workflow_dispatch: # allows you to trigger the workflow run manually