diff --git a/.github/scripts/generate_ci_config.sh b/.github/scripts/generate_ci_config.sh index 86d960c..86316a8 100755 --- a/.github/scripts/generate_ci_config.sh +++ b/.github/scripts/generate_ci_config.sh @@ -3,7 +3,7 @@ set -xeuo pipefail if [[ $# -lt 2 ]]; then cat >&2 <<'USAGE' -Usage: generate_ci_config.sh [--minio] [--jupyterhub] [--weko] [--flowable] [--s3compatsigv4] [--s3compatsigv4-inst] [--wiki] +Usage: generate_ci_config.sh [--minio] [--jupyterhub] [--binderhub] [--weko] [--flowable] [--s3compatsigv4] [--s3compatsigv4-inst] [--wiki] USAGE exit 1 fi @@ -13,6 +13,7 @@ BASE_CONFIG=$2 shift 2 MINIO=false JUPYTERHUB=false +BINDERHUB=false WEKO=false FLOWABLE=false S3COMPATSIGV4=false @@ -27,6 +28,9 @@ for arg in "$@"; do --jupyterhub) JUPYTERHUB=true ;; + --binderhub) + BINDERHUB=true + ;; --weko) WEKO=true ;; @@ -105,6 +109,22 @@ jupyterhub_enabled: false EOF fi +if [[ "${BINDERHUB}" == "true" ]]; then + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + python3 - "$script_dir/../../docker/binderhub/.state/config.json" "$OUTPUT" <<'PYTHON' +import json +from pathlib import Path +import sys +import yaml +config = json.loads(Path(sys.argv[1]).read_text()) +with open(sys.argv[2], 'a') as out: + out.write('\n') + yaml.safe_dump(dict(binderhub_enabled=True, + binderhub_binderhub_url=config['binder_origin'], + jupyterhub_username=config['username'], jupyterhub_password=config['password']), out) +PYTHON +fi + if [[ "${WEKO}" == "true" ]]; then WEKO_URL_VALUE=${WEKO_URL:-http://localhost} WEKO_ADMIN_EMAIL_VALUE=${WEKO_ADMIN_EMAIL:-} diff --git a/.github/scripts/setup_binderhub.py b/.github/scripts/setup_binderhub.py new file mode 100644 index 0000000..21d29b4 --- /dev/null +++ b/.github/scripts/setup_binderhub.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +"""Prepare OAuth settings for both the local Hub and the existing RDM deployment.""" +import argparse +import json +import os +from pathlib import Path +import secrets + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('rdm_root', type=Path) + parser.add_argument('--rdm-origin', default='http://192.168.168.167:5000') + parser.add_argument('--rdm-api', default='http://192.168.168.167:8000/v2/') + parser.add_argument('--hub-origin', default='http://192.168.168.167:18000') + parser.add_argument('--binder-origin', default='http://192.168.168.167:18010') + parser.add_argument('--host-ip', required=True) + args = parser.parse_args() + local = args.rdm_root / 'addons/binderhub/settings/local.py' + if not local.is_file(): + parser.error('Run setup_rdm.sh setup_config_files first') + root = Path(__file__).resolve().parents[2] / 'docker/binderhub' + state = root / '.state' + state.mkdir(mode=0o700, exist_ok=True) + if (state / 'config.json').exists(): + parser.error('Existing Hub state found; stop and remove it before preparing another deployment') + os.umask(0o077) + d = dict(hub_origin=args.hub_origin.rstrip('/'), binder_origin=args.binder_origin.rstrip('/'), rdm_origin=args.rdm_origin.rstrip('/'), + rdm_api=args.rdm_api, host_ip=args.host_ip, username='rdm-e2e', + password=secrets.token_urlsafe(24), binder_secret=secrets.token_hex(32), + hub_secret=secrets.token_hex(32), admin_token=secrets.token_hex(32), + mount_root=str(state.resolve() / 'rdmfs')) + (state / 'config.json').write_text(json.dumps(d, indent=2)+'\n') + bh = d['binder_origin'] + jh = d['hub_origin']+'/' + settings = dict(DEFAULT_BINDER_URL=bh, + BINDERHUB_OAUTH_CLIENT=dict(client_id='rdm-binder', client_secret=d['binder_secret'], + authorize_url=bh+'/api/oauth2/authorize', token_url=bh+'/api/oauth2/token', + services_url=bh+'/api/services', scope=['identity']), + JUPYTERHUB_OAUTH_CLIENTS={jh: dict(client_id='service-rdm', client_secret=d['hub_secret'], + admin_api_token=d['admin_token'], authorize_url=jh+'hub/api/oauth2/authorize', + token_url=jh+'hub/api/oauth2/token', api_url=jh+'hub/api/', scope=['identity'], max_servers=10)}) + # setup_rdm.sh has already written the deployment image choices. Preserve them. + with local.open('a') as out: + out.write('\n# Local OAuth E2E configuration\n') + out.write('\n'.join(f'{key} = {value!r}' for key, value in settings.items())+'\n') + if os.environ.get('GITHUB_ACTIONS') == 'true': + for key in ('password', 'binder_secret', 'hub_secret', 'admin_token'): + print('::add-mask::'+d[key]) + print('Prepared BinderHub/JupyterHub and RDM OAuth settings') + + +if __name__ == '__main__': + main() diff --git a/.github/scripts/setup_binderhub.sh b/.github/scripts/setup_binderhub.sh new file mode 100755 index 0000000..c8247b8 --- /dev/null +++ b/.github/scripts/setup_binderhub.sh @@ -0,0 +1,49 @@ +#!/bin/bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +STACK_ROOT="${SCRIPT_DIR}/../../docker/binderhub" +COMMAND=${1:-} +case "$COMMAND" in + prepare) + : "${2:?Usage: setup_binderhub.sh prepare }" + default_interface=$(ip -4 route show default | awk 'NR==1 {print $5}') + host_ip=${BINDERHUB_HOST_IP:-$(ip -4 addr show "$default_interface" scope global | awk '/inet / {split($2, address, "/"); print address[1]; exit}')} + python3 "${SCRIPT_DIR}/setup_binderhub.py" "$2" --host-ip "$host_ip" + ;; + install) + mount_root=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["mount_root"])' "${STACK_ROOT}/.state/config.json") + mkdir -p "$mount_root" + sudo modprobe fuse + if ! mountpoint -q "$mount_root"; then + sudo mount --bind "$mount_root" "$mount_root" + fi + sudo mount --make-rshared "$mount_root" + docker pull gcr.io/nii-ap-ops/rdmfs:2026.02.1 + docker compose -f "${STACK_ROOT}/compose.yaml" up --build -d + # Fail during setup if the builder cannot reach the host Docker daemon. + docker compose -f "${STACK_ROOT}/compose.yaml" exec -T hub docker version + for attempt in $(seq 1 90); do + if status=$(curl --silent --show-error -o /dev/null -w '%{http_code}' http://192.168.168.167:18010/api/services); then + if [ "$status" = 302 ]; then exit 0; fi + fi + sleep 2 + done + echo 'BinderHub did not become ready' >&2 + exit 1 + ;; + down) + docker compose -f "${STACK_ROOT}/compose.yaml" down + docker ps -aq --filter name=rdm-e2e-binder- | xargs -r docker rm -f + if [ -f "${STACK_ROOT}/.state/config.json" ]; then + mount_root=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["mount_root"])' "${STACK_ROOT}/.state/config.json") + if mountpoint -q "$mount_root"; then + sudo umount --recursive --lazy "$mount_root" + fi + fi + ;; + *) + echo 'Usage: setup_binderhub.sh [rdm_root]' >&2 + exit 1 + ;; +esac diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index bcf5dff..c678409 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -473,12 +473,26 @@ jobs: flowable_enabled: false wiki_enabled: false mapcore_group_enabled: true + - name: user-binderhub-oauth + display_name: "User Tests (BinderHub OAuth)" + include_admin: false + skip_admin: true + skip_metadata: true + skip_default_storage: true + skip_login: true + skip_130mb_upload: true + minio_enabled: false + weko_enabled: false + jupyterhub_enabled: false + binderhub_enabled: true + flowable_enabled: false name: E2E ${{ matrix.test-group.display_name }} env: MINIO_ENABLED: ${{ matrix.test-group.minio_enabled == true && 'true' || 'false' }} S3COMPATSIGV4_ENABLED: ${{ matrix.test-group.s3compatsigv4_enabled == true && 'true' || 'false' }} S3COMPATSIGV4_INST_ENABLED: ${{ matrix.test-group.s3compatsigv4_institutional_storage == true && 'true' || 'false' }} WEKO_ENABLED: ${{ matrix.test-group.weko_enabled == true && 'true' || 'false' }} + BINDERHUB_ENABLED: ${{ matrix.test-group.binderhub_enabled == true && 'true' || 'false' }} JUPYTERHUB_ENABLED: ${{ matrix.test-group.jupyterhub_enabled == true && 'true' || 'false' }} FLOWABLE_ENABLED: ${{ matrix.test-group.flowable_enabled == true && 'true' || 'false' }} MIBYO_DB_ENABLED: ${{ matrix.test-group.mibyo_db_enabled == true && 'true' || 'false' }} @@ -888,6 +902,11 @@ jobs: export INCLUDE_ADMIN=${{ matrix.test-group.include_admin }} setup_config_files + - name: Prepare OAuth BinderHub settings + if: env.BINDERHUB_ENABLED == 'true' + working-directory: e2e-tests + run: .github/scripts/setup_binderhub.sh prepare ../RDM-osf.io + - name: Parse PR body and workflow parameters run: | if [[ "${{ github.event_name }}" == "pull_request" ]]; then @@ -1295,6 +1314,11 @@ jobs: echo "WORKFLOW_BATCH_PROJECT_COUNT=${{ matrix.test-group.workflow_batch_project_count || 50 }}" >> $GITHUB_ENV echo "WORKFLOW_TEST_MODE=${{ matrix.test-group.workflow_test_mode }}" >> $GITHUB_ENV + - name: Install OAuth BinderHub stack + if: env.BINDERHUB_ENABLED == 'true' + working-directory: e2e-tests + run: .github/scripts/setup_binderhub.sh install + - name: Install TLJH stack if: env.JUPYTERHUB_ENABLED == 'true' working-directory: e2e-tests @@ -1503,6 +1527,9 @@ jobs: args+=(--wiki) fi + if [ "${BINDERHUB_ENABLED}" = "true" ]; then + args+=(--binderhub) + fi .github/scripts/generate_ci_config.sh "${args[@]}" rm base_ci.config.yaml @@ -1641,6 +1668,24 @@ jobs: path: e2e-tests/weko-docker-logs.txt retention-days: 7 + - name: Collect OAuth BinderHub logs + if: always() && env.BINDERHUB_ENABLED == 'true' + working-directory: e2e-tests + run: | + docker compose -f docker/binderhub/compose.yaml logs --no-color > binderhub-logs.txt 2>&1 + for container in $(docker ps -a --filter name=rdm-e2e-binder- --format '{{.Names}}'); do + echo "Container: $container" >> binderhub-logs.txt + docker logs "$container" >> binderhub-logs.txt 2>&1 + done + + - name: Upload OAuth BinderHub logs + if: always() && env.BINDERHUB_ENABLED == 'true' + uses: actions/upload-artifact@v4 + with: + name: binderhub-logs-${{ matrix.test-group.name }} + path: e2e-tests/binderhub-logs.txt + retention-days: 7 + - name: Collect TLJH logs if: always() && env.JUPYTERHUB_ENABLED == 'true' run: | @@ -1688,6 +1733,11 @@ jobs: run: | .github/scripts/setup_weko.sh down ../weko + - name: Stop OAuth BinderHub stack + if: always() && env.BINDERHUB_ENABLED == 'true' + working-directory: e2e-tests + run: .github/scripts/setup_binderhub.sh down + - name: Stop TLJH stack if: always() && env.JUPYTERHUB_ENABLED == 'true' working-directory: e2e-tests diff --git a/docker/binderhub/.dockerignore b/docker/binderhub/.dockerignore new file mode 100644 index 0000000..da850dd --- /dev/null +++ b/docker/binderhub/.dockerignore @@ -0,0 +1,2 @@ +.state +__pycache__ diff --git a/docker/binderhub/.gitignore b/docker/binderhub/.gitignore new file mode 100644 index 0000000..95f7491 --- /dev/null +++ b/docker/binderhub/.gitignore @@ -0,0 +1 @@ +.state/ diff --git a/docker/binderhub/Dockerfile b/docker/binderhub/Dockerfile new file mode 100644 index 0000000..88a5df6 --- /dev/null +++ b/docker/binderhub/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.12-slim-trixie +# Use the host daemon through the socket; only its CLI belongs in this image. +RUN apt-get update && apt-get install -y --no-install-recommends git nodejs npm docker-cli docker-buildx ca-certificates patch && docker --version && docker buildx version && rm -rf /var/lib/apt/lists/* +RUN npm install -g configurable-http-proxy +ARG BINDERHUB_REV=9282cd4d +RUN git clone https://github.com/RCOSDP/CS-binderhub.git /opt/binderhub && cd /opt/binderhub && git checkout "$BINDERHUB_REV" +# The local builder must forward per-request RDM credentials, as the Kubernetes builder does. +COPY local-build-optional-envs.patch /tmp/local-build-optional-envs.patch +RUN cd /opt/binderhub && patch -p1 < /tmp/local-build-optional-envs.patch && pip install . dockerspawner +WORKDIR /opt/e2e +COPY jupyterhub_config.py binderhub_config.py rdm_spawner.py ./ +CMD ["jupyterhub", "--config=/opt/e2e/jupyterhub_config.py"] diff --git a/docker/binderhub/binderhub_config.py b/docker/binderhub/binderhub_config.py new file mode 100644 index 0000000..06f3bfe --- /dev/null +++ b/docker/binderhub/binderhub_config.py @@ -0,0 +1,39 @@ +import json +from urllib.parse import urlsplit +from pathlib import Path +from binderhub.build_local import LocalRepo2dockerBuild +from binderhub.quota import LaunchQuota + +root = Path(__file__).resolve().parent +d = json.loads((root / '.state/config.json').read_text()) +c = get_config() # noqa +# CS forks use this host list for browser CORS responses (health checks and builds). +c.BinderHub.allowed_hosts = [urlsplit(d['rdm_origin']).hostname] +c.BinderHub.use_registry = False +c.BinderHub.builder_required = False +c.BinderHub.build_class = LocalRepo2dockerBuild +c.BinderHub.launch_quota_class = LaunchQuota +# RDM checks /health at the origin root; serve BinderHub on its own public origin. +c.BinderHub.base_url = '/' +c.HubOAuth.base_url = '/' +c.HubOAuth.hub_host = d['hub_origin'] +c.HubOAuth.oauth_redirect_uri = d['binder_origin']+'/oauth_callback' +c.BinderHub.hub_url = d['hub_origin'] + '/' +c.BinderHub.auth_enabled = True +c.Launcher.allow_named_servers = True +c.Launcher.named_server_limit_per_user = 10 +c.BinderHub.oauth2_provider_enabled = True +c.BinderHub.oauth_db_url = 'sqlite:///' + str(root / '.state/binderhub-oauth.sqlite') +c.BinderHub.oauth_clients = [dict(client_id='rdm-binder', client_secret=d['binder_secret'], + redirect_uri=d['rdm_origin']+'/project/binderhub/callback', description='RDM E2E')] +c.BinderHub.oauth_no_confirm_list = ['rdm-binder'] +# RDM's frontend handles the provider's `auth` event by creating a personal +# token and retrying with repo_token. The provider must still be able to build +# that event's authorization URL; these client metadata are not exchanged with +# fakecas (which does not implement repository OAuth). +c.RDMProvider.hosts = [{ + 'hostname': [d['rdm_origin']], 'api': d['rdm_api'], + 'client_id': 'binderhub-e2e-repository', + 'scope': ['osf.full_read', 'osf.full_write'], + 'oauth_authorize_url': 'http://192.168.168.167:8080/oauth2.0/authorize', +}] diff --git a/docker/binderhub/compose.yaml b/docker/binderhub/compose.yaml new file mode 100644 index 0000000..533118c --- /dev/null +++ b/docker/binderhub/compose.yaml @@ -0,0 +1,9 @@ +services: + hub: + build: . + network_mode: host + environment: + OAUTHLIB_INSECURE_TRANSPORT: '1' + volumes: + - ./.state:/opt/e2e/.state + - /var/run/docker.sock:/var/run/docker.sock diff --git a/docker/binderhub/jupyterhub_config.py b/docker/binderhub/jupyterhub_config.py new file mode 100644 index 0000000..d0cf857 --- /dev/null +++ b/docker/binderhub/jupyterhub_config.py @@ -0,0 +1,54 @@ +"""OAuth Hub used by the existing RDM E2E Notebook suite (Linux Docker host).""" +import json +from pathlib import Path +import sys +from urllib.parse import urlsplit +root = Path(__file__).resolve().parent +sys.path.insert(0, str(root)) +from rdm_spawner import LocalContainerSpawner # noqa: E402 + +d = json.loads((root / '.state/config.json').read_text()) +c = get_config() # noqa +# CS forks use this host list for browser CORS responses (health checks and builds). +c.JupyterHub.allowed_hosts = [urlsplit(d['rdm_origin']).hostname] + + +# RDM already uses ports 8000 (API) and 8001 (admin). +c.JupyterHub.bind_url = 'http://0.0.0.0:18000' +c.ConfigurableHTTPProxy.api_url = 'http://127.0.0.1:18001' +c.JupyterHub.hub_port = 18081 +c.JupyterHub.hub_ip = '0.0.0.0' +c.JupyterHub.hub_connect_ip = d['host_ip'] +c.JupyterHub.db_url = 'sqlite:///' + str(root / '.state/jupyterhub.sqlite') +c.JupyterHub.pid_file = str(root / '.state/jupyterhub.pid') +c.JupyterHub.cookie_secret_file = str(root / '.state/jupyterhub_cookie_secret') +c.JupyterHub.authenticator_class = 'dummy' +c.Authenticator.allowed_users = {d['username']} +c.DummyAuthenticator.password = d['password'] +c.JupyterHub.spawner_class = LocalContainerSpawner +LocalContainerSpawner.rdmfs_mount_root = d['mount_root'] +LocalContainerSpawner.rdmfs_local_root = str(root / '.state/rdmfs') +c.JupyterHub.allow_named_servers = True +c.JupyterHub.named_server_limit_per_user = 10 +c.LocalContainerSpawner.auth_enabled = True +c.LocalContainerSpawner.start_timeout = 180 +c.LocalContainerSpawner.http_timeout = 120 +c.DockerSpawner.allowed_images = '*' +c.DockerSpawner.remove = True +c.DockerSpawner.name_template = 'rdm-e2e-binder-{username}-{servername}' +c.JupyterHub.default_url = '/hub/home' +c.JupyterHub.load_roles = [ + {'name': 'user', 'scopes': ['self', 'access:services!service=binder', 'access:services!service=rdm']}, +] +c.JupyterHub.services = [ + {'name': 'binder', 'admin': True, 'oauth_no_confirm': True, + 'url': 'http://127.0.0.1:18010', + 'oauth_redirect_uri': d['binder_origin']+'/oauth_callback', + 'command': [sys.executable, '-m', 'binderhub', '--config='+str(root / 'binderhub_config.py'), '--port=18010'], + 'environment': {'OAUTHLIB_INSECURE_TRANSPORT': '1', + 'JUPYTERHUB_HOST': d['hub_origin'], + 'JUPYTERHUB_OAUTH_CALLBACK_URL': d['binder_origin']+'/oauth_callback'}}, + {'name': 'rdm', 'api_token': d['hub_secret'], 'oauth_client_id': 'service-rdm', + 'oauth_redirect_uri': d['rdm_origin']+'/project/binderhub/callback', 'oauth_no_confirm': False}, + {'name': 'rdm-token-admin', 'admin': True, 'api_token': d['admin_token']}, +] diff --git a/docker/binderhub/local-build-optional-envs.patch b/docker/binderhub/local-build-optional-envs.patch new file mode 100644 index 0000000..c3becfc --- /dev/null +++ b/docker/binderhub/local-build-optional-envs.patch @@ -0,0 +1,4 @@ +--- a/binderhub/build_local.py ++++ b/binderhub/build_local.py +@@ -139,0 +140 @@ ++ env.update(self.optional_envs or {}) diff --git a/docker/binderhub/rdm_spawner.py b/docker/binderhub/rdm_spawner.py new file mode 100644 index 0000000..ed696d6 --- /dev/null +++ b/docker/binderhub/rdm_spawner.py @@ -0,0 +1,91 @@ +"""Docker-backed BinderHub with RDMFS, following CS-tljh-repo2docker's setup. + +Each server has its own RDMFS container and shared /mnt bind. No Hub admin +credentials are passed to the file system or the single-user container. +""" +import asyncio +from pathlib import Path +import re + +from binderhub.binderspawner_mixin import BinderSpawnerMixin +from docker.types import Mount +from dockerspawner import DockerSpawner + + +PROVISION_COMMAND = '''set -e +for provision in "$REPO_DIR/binder/provision.sh" "$REPO_DIR/.binder/provision.sh" "$HOME/binder/provision.sh" "$HOME/.binder/provision.sh"; do + if [ -f "$provision" ]; then + exec bash "$provision" jupyterhub-singleuser + fi +done +exec jupyterhub-singleuser +''' + + +class LocalContainerSpawner(BinderSpawnerMixin, DockerSpawner): + rdmfs_mount_root: str + rdmfs_local_root: str + rdmfs_image = 'gcr.io/nii-ap-ops/rdmfs:2026.02.1' + + @property + def mount_binds(self): + mounts = super().mount_binds + if self.user_options: + mounts.append(Mount( + type='bind', source=str(Path(self.rdmfs_mount_root) / self.container_name), + target='/mnt', propagation='rshared')) + return mounts + + async def _remove_rdmfs(self): + name = self.container_name + '_rdmfs' + containers = await self.docker('containers', all=True, filters={'name': '^/' + re.escape(name) + '$'}) + if not containers: + return + container = await self.docker('inspect_container', name) + if container['State']['Running']: + terminate = await self.docker( + 'exec_create', name, ['sh', '-c', 'xattr -w command terminate /mnt/rdms']) + await self.docker('exec_start', terminate['Id'], detach=True) + await self.docker('stop', name, timeout=10) + await self.docker('remove_container', name, force=True) + + async def start(self): + options = self.user_options + project = options['rdm_node_id'] + if not re.fullmatch(r'[a-zA-Z0-9]+', project) or not options['repo_token']: + raise ValueError('BinderHub RDM project and repository token are required') + local = Path(self.rdmfs_local_root) / self.container_name + local.mkdir(parents=True, exist_ok=True) + local.chmod(0o777) + await self._remove_rdmfs() + mount = self.mount_binds[-1] + host_config = self.client.create_host_config(privileged=True, mounts=[mount]) + sidecar = await self.docker( + 'create_container', image=self.rdmfs_image, name=self.container_name + '_rdmfs', + environment={'RDM_API_URL': options['rdm_api_url'], + 'RDM_TOKEN': options['repo_token'], 'MOUNT_PATH': '/mnt/rdms'}, + host_config=host_config) + try: + await self.docker('start', sidecar['Id']) + # Wait for the actual project mount, rather than a container status. + for _ in range(60): + check = await self.docker( + 'exec_create', sidecar['Id'], ['test', '-d', '/mnt/rdms/' + project + '/osfstorage']) + await self.docker('exec_start', check['Id']) + status = await self.docker('exec_inspect', check['Id']) + if status['ExitCode'] == 0: + break + await asyncio.sleep(1) + else: + raise RuntimeError('RDMFS project mount did not become ready') + self.cmd = ['bash', '-lc', PROVISION_COMMAND] + return await super().start() + except BaseException: + await self._remove_rdmfs() + raise + + async def stop(self, now=False): + try: + return await super().stop(now=now) + finally: + await self._remove_rdmfs() diff --git a/run_tests.py b/run_tests.py index dd25b22..23d066e 100644 --- a/run_tests.py +++ b/run_tests.py @@ -47,6 +47,11 @@ def __init__(self, config_path, show_disk_usage=False, failed_result_path=None): self.skip_login = False self.enable_1gb_file_upload = False self.skip_autofill = False + self.binderhub_enabled = False + self.binderhub_binderhub_url = None + self.binderhub_use_default_server = False + self.jupyterhub_username = None + self.jupyterhub_password = None self.jupyterhub_enabled = False self.tljh_url = None self.tljh_username = None @@ -499,6 +504,23 @@ def run_jupyterhub_tests(self): ) ) + def run_binderhub_tests(self): + """Run the same OAuth BinderHub notebooks used for interactive acceptance tests.""" + if not self.binderhub_enabled: + return + if not all((self.binderhub_binderhub_url, self.jupyterhub_username, self.jupyterhub_password)): + raise ValueError('BinderHub URL, JupyterHub username and password are required') + self.result_notebooks.append(self.run_notebook( + '取りまとめ-BinderHub-BinderHubアドオン.ipynb', + binderhub_binderhub_url=self.binderhub_binderhub_url, + binderhub_use_default_server=self.binderhub_use_default_server, + binderhub_auth_mode='jupyterhub', + jupyterhub_username=self.jupyterhub_username, + jupyterhub_password=self.jupyterhub_password, + skip_failed_test=self.skip_failed_test, + exclude_notebooks=self.exclude_notebooks, + )) + def run_weko_tests(self): """Run WEKO addon tests.""" print('\n=== WEKO Tests ===') @@ -790,6 +812,7 @@ def run_all_tests(self): self.run_admin_tests() self.run_project_limit_tests() self.run_jupyterhub_tests() + self.run_binderhub_tests() self.run_weko_tests() self.run_mibyo_db_tests() self.run_workflow_tests() diff --git a/scripts/jupyterhub.py b/scripts/jupyterhub.py new file mode 100644 index 0000000..211a832 --- /dev/null +++ b/scripts/jupyterhub.py @@ -0,0 +1,15 @@ +from playwright.async_api import expect + +async def login(page, username, password, transition_timeout=30000): + # Login to JupyterHub + jupyterhub_signin_button = page.locator('//*[@id = "login_submit"]') + await expect(jupyterhub_signin_button).to_be_visible(timeout=transition_timeout) + await page.locator('//*[@id = "username_input"]').fill(username) + await page.locator('//*[@id = "password_input"]').fill(password) + await jupyterhub_signin_button.click() + +async def authorize(page, transition_timeout=30000): + # JupyterHub authorizes a service (e.g. BinderHub addon of RDM OSF Integration) + authorize_button = page.get_by_role('button', name='Authorize', exact=True) + await expect(authorize_button).to_be_visible(timeout=transition_timeout) + await authorize_button.click() diff --git a/scripts/playwright.py b/scripts/playwright.py index 9334f26..459404b 100644 --- a/scripts/playwright.py +++ b/scripts/playwright.py @@ -72,6 +72,12 @@ async def run_pw(f, last_path=default_last_path, screenshot=True, permissions=No "type": msg.type, "text": msg.text })) + page.on("pageerror", lambda error: console_messages.append({ + "timestamp": time.time(), + "url": page.url, + "type": "pageerror", + "text": str(error) + })) current_pages.append(page) current_time = time.time() @@ -214,7 +220,6 @@ async def _finish_pw_context(screenshot=False, last_path=None): if current_contexts is None or len(current_contexts) == 0: return current_context, current_pages = current_contexts[-1] - current_contexts = current_contexts[:-1] os.makedirs(last_path or default_last_path, exist_ok=True) timeout_on_screenshot = False if screenshot and current_pages is not None and len(current_pages) > 0: @@ -226,6 +231,7 @@ async def _finish_pw_context(screenshot=False, last_path=None): timeout_on_screenshot = True if timeout_on_screenshot: return + current_contexts = current_contexts[:-1] pages = list(current_pages) for page in pages: if not page.is_closed(): diff --git "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-Dockerfile.ipynb" "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-Dockerfile.ipynb" index f1f0d2a..fe1a512 100644 --- "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-Dockerfile.ipynb" +++ "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-Dockerfile.ipynb" @@ -20,6 +20,11 @@ "idp_name_1 = None\n", "idp_username_1 = None\n", "idp_password_1 = None\n", + "\n", + "binderhub_auth_mode = 'auto'\n", + "jupyterhub_username = None\n", + "jupyterhub_password = None\n", + "\n", "default_result_path = None\n", "close_on_fail = False\n", "transition_timeout = 60 * 1000\n", @@ -49,6 +54,15 @@ " idp_username_1 = input(prompt=f'Username for {idp_name_1}')\n", "if idp_password_1 is None:\n", " idp_password_1 = getpass(prompt=f'Password for {idp_username_1}@{idp_name_1}')\n", + "if binderhub_auth_mode == 'jupyterhub':\n", + " if jupyterhub_username is None:\n", + " jupyterhub_username = input(prompt='Username for JupyterHub')\n", + " if jupyterhub_password is None:\n", + " jupyterhub_password = getpass(prompt=f'Password for {jupyterhub_username}@JupyterHub')\n", + " if jupyterhub_username is None or jupyterhub_password is None:\n", + " raise ValueError(\n", + " \"binderhub_auth_mode='jupyterhub' requires jupyterhub_username and jupyterhub_password\"\n", + " )\n", "if project_name is None:\n", " project_name = datetime.now().strftime('TEST-BINDERHUB-%Y%m%d%H%M')\n", "\n", @@ -101,7 +115,7 @@ "importlib.reload(scripts.playwright)\n", "\n", "from scripts.playwright import *\n", - "from scripts import grdm\n", + "from scripts import grdm, jupyterhub\n", "\n", "await init_pw_context(close_on_fail=close_on_fail, last_path=default_result_path)\n" ] @@ -277,13 +291,37 @@ "source": [ "async def _step(page):\n", " await page.locator('//a[contains(text(), \"解析\")]').click()\n", + "\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", - " await expect(open_idp_list.or_(launch_button)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " authentication_complete = page.locator('//*[@data-test-jupyterhub-user]').filter(has_text=jupyterhub_username)\n", + " else:\n", + " authentication_complete = launch_button\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " await expect(authentication_complete).to_have_text(jupyterhub_username, timeout=transition_timeout)\n", + "\n", " await expect(launch_button).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" @@ -428,13 +466,30 @@ "outputs": [], "source": [ "async def _step(page):\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " start_ipykernel = page.locator(f'//*[@class = \"jp-LauncherCard\" and @title = \"Python 3 (ipykernel)\" and @data-category = \"Notebook\"]')\n", - " await expect(open_idp_list.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + "\n", " await expect(start_ipykernel).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" diff --git "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" index 9dedcaf..9772b55 100644 --- "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" +++ "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" @@ -19,6 +19,11 @@ "idp_name_1 = None\n", "idp_username_1 = None\n", "idp_password_1 = None\n", + "\n", + "binderhub_auth_mode = 'auto'\n", + "jupyterhub_username = None\n", + "jupyterhub_password = None\n", + "\n", "default_result_path = None\n", "close_on_fail = False\n", "project_name = None\n", @@ -32,7 +37,7 @@ "binderhub_r_packages = ['remotes', 'eegkit']\n", "\n", "binderhub_post_build_script = '''#!/bin/bash\n", - "date \u003e ~/uptime'''\n", + "date > ~/uptime'''\n", "binderhub_binder_files = ['apt.txt', 'environment.yml', 'install.R', 'postBuild']\n", "binderhub_launch_timeout = 30 * 60 * 1000 # 30 minutes\n", "binderhub_test_filename = 'grdm_test_file.txt'\n", @@ -54,6 +59,15 @@ " idp_username_1 = input(prompt=f'Username for {idp_name_1}')\n", "if idp_password_1 is None:\n", " idp_password_1 = getpass(prompt=f'Password for {idp_username_1}@{idp_name_1}')\n", + "if binderhub_auth_mode == 'jupyterhub':\n", + " if jupyterhub_username is None:\n", + " jupyterhub_username = input(prompt='Username for JupyterHub')\n", + " if jupyterhub_password is None:\n", + " jupyterhub_password = getpass(prompt=f'Password for {jupyterhub_username}@JupyterHub')\n", + " if jupyterhub_username is None or jupyterhub_password is None:\n", + " raise ValueError(\n", + " \"binderhub_auth_mode='jupyterhub' requires jupyterhub_username and jupyterhub_password\"\n", + " )\n", "if project_name is None:\n", " project_name = datetime.now().strftime('TEST-BINDERHUB-%Y%m%d%H%M')\n", "\n", @@ -105,7 +119,7 @@ "importlib.reload(scripts.playwright)\n", "\n", "from scripts.playwright import *\n", - "from scripts import grdm\n", + "from scripts import grdm, jupyterhub\n", "\n", "await init_pw_context(close_on_fail=close_on_fail, last_path=default_result_path)\n" ] @@ -281,13 +295,37 @@ "source": [ "async def _step(page):\n", " await page.locator('//a[contains(text(), \"解析\")]').click()\n", + "\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", - " await expect(open_idp_list.or_(launch_button)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " authentication_complete = page.locator('//*[@data-test-jupyterhub-user]').filter(has_text=jupyterhub_username)\n", + " else:\n", + " authentication_complete = launch_button\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " await expect(authentication_complete).to_have_text(jupyterhub_username, timeout=transition_timeout)\n", + "\n", " await expect(launch_button).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" @@ -678,13 +716,30 @@ "outputs": [], "source": [ "async def _step(page):\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " start_ipykernel = page.locator(f'//*[@class = \"jp-LauncherCard\" and @title = \"Python 3 (ipykernel)\" and @data-category = \"Notebook\"]')\n", - " await expect(open_idp_list.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + "\n", " await expect(start_ipykernel).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" diff --git "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\202\242\343\203\211\343\202\252\343\203\263\350\277\275\345\212\240.ipynb" "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\202\242\343\203\211\343\202\252\343\203\263\350\277\275\345\212\240.ipynb" index 75525c4..1b0972d 100644 --- "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\202\242\343\203\211\343\202\252\343\203\263\350\277\275\345\212\240.ipynb" +++ "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\202\242\343\203\211\343\202\252\343\203\263\350\277\275\345\212\240.ipynb" @@ -18,11 +18,17 @@ "idp_name_1 = None\n", "idp_username_1 = None\n", "idp_password_1 = None\n", + "\n", + "binderhub_auth_mode = 'auto'\n", + "jupyterhub_username = None\n", + "jupyterhub_password = None\n", + "\n", "default_result_path = None\n", "close_on_fail = False\n", "transition_timeout = 60 * 1000\n", "\n", "binderhub_binderhub_url = None\n", + "binderhub_use_default_server = False\n", "binderhub_launch_timeout = 30 * 60 * 1000 # 30 minutes\n", "\n", "project_name = None\n", @@ -49,6 +55,15 @@ " idp_username_1 = input(prompt=f'Username for {idp_name_1}')\n", "if idp_password_1 is None:\n", " idp_password_1 = getpass(prompt=f'Password for {idp_username_1}@{idp_name_1}')\n", + "if binderhub_auth_mode == 'jupyterhub':\n", + " if jupyterhub_username is None:\n", + " jupyterhub_username = input(prompt='Username for JupyterHub')\n", + " if jupyterhub_password is None:\n", + " jupyterhub_password = getpass(prompt=f'Password for {jupyterhub_username}@JupyterHub')\n", + " if jupyterhub_username is None or jupyterhub_password is None:\n", + " raise ValueError(\n", + " \"binderhub_auth_mode='jupyterhub' requires jupyterhub_username and jupyterhub_password\"\n", + " )\n", "if project_name is None:\n", " project_name = datetime.now().strftime('TEST-BINDERHUB-%Y%m%d%H%M')\n", "\n", @@ -99,7 +114,7 @@ "importlib.reload(scripts.playwright)\n", "\n", "from scripts.playwright import *\n", - "from scripts import grdm\n", + "from scripts import grdm, jupyterhub\n", "\n", "await init_pw_context(close_on_fail=close_on_fail, last_path=default_result_path)\n" ] @@ -237,9 +252,10 @@ "id": "1f849fbb", "metadata": {}, "source": [ - "## 「BinderHubを追加」ボタンをクリックする\n", + "## (デフォルトサーバーを使用しない場合) 「BinderHubを追加」ボタンをクリックする (デフォルトサーバーを使用する場合) 左メニューの「アドオンを構成」をクリックする\n", "\n", - "BinderHubクライアント情報の設定ダイアログが表示されること" + "- デフォルトサーバーを使用しない場合:BinderHubクライアント情報の設定ダイアログが表示されること。\n", + "- デフォルトサーバーを使用する場合:既定のBinderHubのURLが接続先一覧に表示されること。" ] }, { @@ -250,6 +266,12 @@ "outputs": [], "source": [ "async def _step(page):\n", + " if binderhub_use_default_server:\n", + " await page.locator('//a[text() = \"アドオンを構成\"]').click()\n", + " binder_entry = page.locator(f'//*[@id = \"binderhubScope\"]//tbody//a[text() = \"{binderhub_binderhub_url}\"]')\n", + " await binder_entry.scroll_into_view_if_needed(timeout=transition_timeout)\n", + " await expect(binder_entry).to_be_visible(timeout=transition_timeout)\n", + " return\n", " binder_entry = page.locator(f'//a[text() = \"{binderhub_binderhub_url}\"]')\n", " if await binder_entry.count():\n", " print('BinderHub entry already exists')\n", @@ -272,9 +294,9 @@ "id": "6f10608f", "metadata": {}, "source": [ - "## 追加したBinderHubのチェックボックスをクリックする\n", + "## 利用するBinderHubのチェックボックスをクリックする(すでにチェックされている場合は実施しない)\n", "\n", - "Default BinderHub URL が追加したBinderHubのURLになること" + "Default BinderHub URL が利用するBinderHubのURLになること。" ] }, { @@ -314,13 +336,37 @@ "source": [ "async def _step(page):\n", " await page.locator('//a[contains(text(), \"解析\")]').click()\n", + "\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", - " await expect(open_idp_list.or_(launch_button)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " authentication_complete = page.locator('//*[@data-test-jupyterhub-user]').filter(has_text=jupyterhub_username)\n", + " else:\n", + " authentication_complete = launch_button\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " await expect(authentication_complete).to_have_text(jupyterhub_username, timeout=transition_timeout)\n", + "\n", " await expect(launch_button).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" @@ -408,13 +454,30 @@ "outputs": [], "source": [ "async def _step(page):\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " start_ipykernel = page.locator(f'//*[@class = \"jp-LauncherCard\" and @title = \"Python 3 (ipykernel)\" and @data-category = \"Notebook\"]')\n", - " await expect(open_idp_list.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + "\n", " await expect(start_ipykernel).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" diff --git "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\203\207\343\203\225\343\202\251\343\203\253\343\203\210\343\202\271\343\203\210\343\203\254\343\203\274\343\202\270\343\201\256\343\202\263\343\203\224\343\203\274\345\210\266\345\276\241.ipynb" "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\203\207\343\203\225\343\202\251\343\203\253\343\203\210\343\202\271\343\203\210\343\203\254\343\203\274\343\202\270\343\201\256\343\202\263\343\203\224\343\203\274\345\210\266\345\276\241.ipynb" index 871f84c..74d2af0 100644 --- "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\203\207\343\203\225\343\202\251\343\203\253\343\203\210\343\202\271\343\203\210\343\203\254\343\203\274\343\202\270\343\201\256\343\202\263\343\203\224\343\203\274\345\210\266\345\276\241.ipynb" +++ "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\343\203\207\343\203\225\343\202\251\343\203\253\343\203\210\343\202\271\343\203\210\343\203\254\343\203\274\343\202\270\343\201\256\343\202\263\343\203\224\343\203\274\345\210\266\345\276\241.ipynb" @@ -21,6 +21,11 @@ "idp_name_1 = None\n", "idp_username_1 = None\n", "idp_password_1 = None\n", + "\n", + "binderhub_auth_mode = 'auto'\n", + "jupyterhub_username = None\n", + "jupyterhub_password = None\n", + "\n", "default_result_path = None\n", "close_on_fail = False\n", "transition_timeout = 60 * 1000\n", @@ -50,6 +55,15 @@ " idp_username_1 = input(prompt=f'Username for {idp_name_1}')\n", "if idp_password_1 is None:\n", " idp_password_1 = getpass(prompt=f'Password for {idp_username_1}@{idp_name_1}')\n", + "if binderhub_auth_mode == 'jupyterhub':\n", + " if jupyterhub_username is None:\n", + " jupyterhub_username = input(prompt='Username for JupyterHub')\n", + " if jupyterhub_password is None:\n", + " jupyterhub_password = getpass(prompt=f'Password for {jupyterhub_username}@JupyterHub')\n", + " if jupyterhub_username is None or jupyterhub_password is None:\n", + " raise ValueError(\n", + " \"binderhub_auth_mode='jupyterhub' requires jupyterhub_username and jupyterhub_password\"\n", + " )\n", "if project_name is None:\n", " project_name = datetime.now().strftime('TEST-BINDERHUB-%Y%m%d%H%M')\n", "\n", @@ -102,7 +116,7 @@ "importlib.reload(scripts.playwright)\n", "\n", "from scripts.playwright import *\n", - "from scripts import grdm\n", + "from scripts import grdm, jupyterhub\n", "\n", "await init_pw_context(close_on_fail=close_on_fail, last_path=default_result_path)\n" ] @@ -278,13 +292,37 @@ "source": [ "async def _step(page):\n", " await page.locator('//a[contains(text(), \"解析\")]').click()\n", + "\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", - " await expect(open_idp_list.or_(launch_button)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " authentication_complete = page.locator('//*[@data-test-jupyterhub-user]').filter(has_text=jupyterhub_username)\n", + " else:\n", + " authentication_complete = launch_button\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " await expect(authentication_complete).to_have_text(jupyterhub_username, timeout=transition_timeout)\n", + "\n", " await expect(launch_button).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" @@ -365,14 +403,40 @@ "source": [ "async def _step(page):\n", " await page.locator('//a[contains(text(), \"解析\")]').click()\n", - " auth_page = page.locator('//*[@id = \"dropdown_img\"]')\n", - " analysis_page = page.locator('//*[@data-test-binderhub-launch]')\n", - " await expect(auth_page.or_(analysis_page)).to_be_visible(timeout=transition_timeout)\n", "\n", - " if await auth_page.is_visible():\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", + " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", + " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " authentication_complete = page.locator('//*[@data-test-jupyterhub-user]').filter(has_text=jupyterhub_username)\n", + " else:\n", + " authentication_complete = launch_button\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", - "await run_pw(_step)\n" + " await expect(authorize_button.or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " await expect(authentication_complete).to_have_text(jupyterhub_username, timeout=transition_timeout)\n", + "\n", + " await expect(launch_button).to_be_visible(timeout=transition_timeout)\n", + "\n", + "await run_pw(_step)" ] }, { @@ -417,13 +481,30 @@ "outputs": [], "source": [ "async def _step(page):\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " start_ipykernel = page.locator(f'//*[@class = \"jp-LauncherCard\" and @title = \"Python 3 (ipykernel)\" and @data-category = \"Notebook\"]')\n", - " await expect(open_idp_list.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + "\n", " await expect(start_ipykernel).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" @@ -549,6 +630,7 @@ " checkbox = page.locator('//*[@data-test-copy-default-storage]')\n", " await expect(checkbox).to_be_checked(timeout=transition_timeout)\n", " await checkbox.click()\n", + " await asyncio.sleep(transition_timeout / 1000)\n", "\n", "await run_pw(_step)\n" ] @@ -595,13 +677,30 @@ "outputs": [], "source": [ "async def _step(page):\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " start_ipykernel = page.locator(f'//*[@class = \"jp-LauncherCard\" and @title = \"Python 3 (ipykernel)\" and @data-category = \"Notebook\"]')\n", - " await expect(open_idp_list.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + "\n", " await expect(start_ipykernel).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" @@ -700,6 +799,7 @@ " checkbox = page.locator('//*[@data-test-copy-default-storage]')\n", " await expect(checkbox).not_to_be_checked(timeout=transition_timeout)\n", " await checkbox.click()\n", + " await asyncio.sleep(transition_timeout / 1000)\n", "\n", "await run_pw(_step)\n" ] @@ -845,13 +945,30 @@ "outputs": [], "source": [ "async def _step(page):\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " start_ipykernel = page.locator(f'//*[@class = \"jp-LauncherCard\" and @title = \"Python 3 (ipykernel)\" and @data-category = \"Notebook\"]')\n", - " await expect(open_idp_list.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(start_ipykernel)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + "\n", " await expect(start_ipykernel).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" diff --git "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\345\201\234\346\255\242\344\270\255\343\201\256BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\345\201\234\346\255\242\344\270\255\343\201\256BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" index 05e502f..a98383e 100644 --- "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\345\201\234\346\255\242\344\270\255\343\201\256BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" +++ "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-\345\201\234\346\255\242\344\270\255\343\201\256BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" @@ -18,6 +18,11 @@ "idp_name_1 = None\n", "idp_username_1 = None\n", "idp_password_1 = None\n", + "\n", + "binderhub_auth_mode = 'auto'\n", + "jupyterhub_username = None\n", + "jupyterhub_password = None\n", + "\n", "default_result_path = None\n", "close_on_fail = False\n", "transition_timeout = 60 * 1000\n", @@ -52,6 +57,15 @@ " idp_username_1 = input(prompt=f'Username for {idp_name_1}')\n", "if idp_password_1 is None:\n", " idp_password_1 = getpass(prompt=f'Password for {idp_username_1}@{idp_name_1}')\n", + "if binderhub_auth_mode == 'jupyterhub':\n", + " if jupyterhub_username is None:\n", + " jupyterhub_username = input(prompt='Username for JupyterHub')\n", + " if jupyterhub_password is None:\n", + " jupyterhub_password = getpass(prompt=f'Password for {jupyterhub_username}@JupyterHub')\n", + " if jupyterhub_username is None or jupyterhub_password is None:\n", + " raise ValueError(\n", + " \"binderhub_auth_mode='jupyterhub' requires jupyterhub_username and jupyterhub_password\"\n", + " )\n", "if project_name is None:\n", " project_name = datetime.now().strftime('TEST-BINDERHUB-%Y%m%d%H%M')\n", "\n", @@ -102,7 +116,7 @@ "importlib.reload(scripts.playwright)\n", "\n", "from scripts.playwright import *\n", - "from scripts import grdm\n", + "from scripts import grdm, jupyterhub\n", "\n", "await init_pw_context(close_on_fail=close_on_fail, last_path=default_result_path)\n" ] @@ -254,13 +268,36 @@ "source": [ "async def _step(page):\n", " await page.locator('//a[contains(text(), \"解析\")]').click()\n", + " jh_login = page.locator('//*[@id = \"login_submit\"]')\n", " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", - " await expect(open_idp_list.or_(launch_button)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", + " authorize_button = page.get_by_role('button', name='Authorize', exact=True)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " authentication_complete = page.locator('//*[@data-test-jupyterhub-user]').filter(has_text=jupyterhub_username)\n", + " else:\n", + " authentication_complete = launch_button\n", + "\n", + " await expect(jh_login.or_(open_idp_list).or_(authorize_button).or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + "\n", + " if await jh_login.is_visible():\n", + " if binderhub_auth_mode == 'sso':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='sso' but JupyterHub login form appeared\"\n", + " )\n", + " await jupyterhub.login(page, jupyterhub_username, jupyterhub_password, transition_timeout)\n", + " elif await open_idp_list.is_visible():\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " raise AssertionError(\n", + " \"binderhub_auth_mode='jupyterhub' but SSO Discovery Service appeared\"\n", + " )\n", " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", "\n", + " await expect(authorize_button.or_(authentication_complete)).to_be_visible(timeout=transition_timeout)\n", + " if await authorize_button.is_visible():\n", + " await jupyterhub.authorize(page, transition_timeout)\n", + " if binderhub_auth_mode == 'jupyterhub':\n", + " await expect(authentication_complete).to_have_text(jupyterhub_username, timeout=transition_timeout)\n", + "\n", " await expect(launch_button).to_be_visible(timeout=transition_timeout)\n", "\n", "await run_pw(_step)" @@ -352,54 +389,26 @@ "source": [ "## プロジェクトダッシュボードの上部メニューから「解析」をクリックする\n", "\n", - "BinderHubアドオンページが表示されること" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6e4013a8", - "metadata": {}, - "outputs": [], - "source": [ - "async def _step(page):\n", - " await page.locator('//a[contains(text(), \"解析\")]').click()\n", - " open_idp_list = page.locator('//*[@id = \"dropdown_img\"]')\n", - " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", - " await expect(open_idp_list.or_(launch_button)).to_be_visible(timeout=transition_timeout)\n", - "\n", - " if await open_idp_list.is_visible():\n", - " await grdm.login(page, idp_name_1, idp_username_1, idp_password_1, transition_timeout=transition_timeout)\n", - "\n", - " await expect(launch_button).to_be_visible(timeout=transition_timeout)\n", - "\n", - "await run_pw(_step)" - ] - }, - { - "cell_type": "markdown", - "id": "473ae23c", - "metadata": {}, - "source": [ - "## 解析機能ページがBinderHub停止中を示唆していることを確かめる\n", - "\n", + "BinderHubアドオンページが表示されること\n", "BinderHub停止中を案内するバナーが表示されること、解析環境を作成するボタンが無効状態となっていること\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "54a033fc", + "id": "5e52d3b7", "metadata": {}, "outputs": [], "source": [ "async def _step(page):\n", + " await page.locator('//a[contains(text(), \"解析\")]').click()\n", + " await expect(page.locator('//*[@data-test-binderhub-launch]')).to_be_visible(timeout=transition_timeout)\n", " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", " await expect(launch_button).to_be_disabled(timeout=transition_timeout)\n", " banner = page.locator('//p[contains(text(), \"選択されたJupyterHubは現在停止中です。現在、新規の解析環境は作成できません。\")]')\n", " await expect(banner).to_be_visible(timeout=transition_timeout)\n", "\n", - "await run_pw(_step)" + "await run_pw(_step)\n" ] }, { @@ -436,7 +445,8 @@ "source": [ "## 初期設定されるホストを選択する\n", "\n", - "ホスト選択ダイアログが閉じられること" + "ホスト選択ダイアログが閉じられること\n", + "BinderHub停止中を案内するバナーが非表示となること、解析環境作成ボタンが有効になっていること\n" ] }, { @@ -452,35 +462,12 @@ " await topmost.click()\n", " await page.locator('//*[@data-test-host-selector-dialogue-ok]').click()\n", " await expect(page.locator('//*[text() = \"ホスト選択\"]')).not_to_be_visible(timeout=transition_timeout)\n", - " \n", - "\n", - "await run_pw(_step)" - ] - }, - { - "cell_type": "markdown", - "id": "5ffb82ea", - "metadata": {}, - "source": [ - "## 解析機能ページがBinderHub停止中を示唆していないことを確かめる\n", - "\n", - "BinderHub停止中を案内するバナーが非表示となること、解析環境作成ボタンが有効になっていること" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "82a9ad18", - "metadata": {}, - "outputs": [], - "source": [ - "async def _step(page):\n", " launch_button = page.locator('//*[@data-test-binderhub-launch]')\n", " await expect(launch_button).to_be_enabled(timeout=transition_timeout)\n", " banner = page.locator('//p[contains(text(), \"選択されたJupyterHubは現在停止中です。現在、新規の解析環境は作成できません。\")]')\n", " await expect(banner).not_to_be_visible(timeout=transition_timeout)\n", "\n", - "await run_pw(_step)" + "await run_pw(_step)\n" ] }, { diff --git "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" index 841d226..460dc32 100644 --- "a/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" +++ "b/\343\203\206\343\202\271\343\203\210\346\211\213\351\240\206-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263-repo2docker.ipynb" @@ -809,7 +809,7 @@ " await expect(save_button).to_be_visible(timeout=transition_timeout)\n", " await save_button.click()\n", "\n", - " rename_dialog = page.locator('//div[text() = \"Rename\"]')\n", + " rename_dialog = page.locator('//div[text() = \"Rename\" or text() = \"Rename and Save\"]')\n", " await expect(rename_dialog).to_be_visible(timeout=transition_timeout)\n", " await rename_dialog.click()\n", " await expect(rename_dialog).not_to_be_visible(timeout=transition_timeout)\n", diff --git "a/\345\217\226\343\202\212\343\201\276\343\201\250\343\202\201-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" "b/\345\217\226\343\202\212\343\201\276\343\201\250\343\202\201-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" index 6f2a6fd..35c2cf8 100644 --- "a/\345\217\226\343\202\212\343\201\276\343\201\250\343\202\201-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" +++ "b/\345\217\226\343\202\212\343\201\276\343\201\250\343\202\201-BinderHub-BinderHub\343\202\242\343\203\211\343\202\252\343\203\263.ipynb" @@ -45,6 +45,15 @@ "idp_name_1 = None\n", "idp_username_1 = None\n", "idp_password_1 = None\n", + "\n", + "# Auth flow when transitioning from RDM to BinderHub / JupyterLab.\n", + "# 'auto' : detect which login UI appears and follow it\n", + "# 'sso' : assert the GakuNin Discovery Service path\n", + "# 'jupyterhub' : assert the local JupyterHub form + OAuth Authorize path\n", + "binderhub_auth_mode = 'auto'\n", + "jupyterhub_username = None\n", + "jupyterhub_password = None\n", + "\n", "project_name_prefix = datetime.now().strftime('TEST-BINDERHUB-%Y%m%d%H%M')\n", "default_result_path = None\n", "close_on_fail = False\n", @@ -53,7 +62,8 @@ "skip_failed_test = True\n", "skip_preview_check = False\n", "exclude_notebooks = []\n", - "binderhub_binderhub_url = None" + "binderhub_binderhub_url = None\n", + "binderhub_use_default_server = False" ] }, { @@ -240,7 +250,16 @@ " idp_username_1 = input(prompt=f'Username for {idp_name_1}: ')\n", "if idp_password_1 is None:\n", " idp_password_1 = getpass(prompt=f'Password for {idp_username_1}@{idp_name_1}: ')\n", - "(rdm_url, idp_name_1, idp_username_1)" + "if binderhub_auth_mode == 'jupyterhub':\n", + " if jupyterhub_username is None:\n", + " jupyterhub_username = input(prompt='Username for JupyterHub')\n", + " if jupyterhub_password is None:\n", + " jupyterhub_password = getpass(prompt=f'Password for {jupyterhub_username}@JupyterHub')\n", + " if jupyterhub_username is None or jupyterhub_password is None:\n", + " raise ValueError(\n", + " \"binderhub_auth_mode='jupyterhub' requires jupyterhub_username and jupyterhub_password\"\n", + " )\n", + "(rdm_url, idp_name_1, idp_username_1, jupyterhub_username)" ] }, { @@ -640,7 +659,6 @@ "from datetime import datetime\n", "import os\n", "import papermill as pm\n", - "import traceback\n", "from scripts.papermillHelpers import gen_run_notebook\n", "\n", "def make_result_dir(base_path):\n", @@ -658,6 +676,8 @@ " idp_name_1=idp_name_1,\n", " idp_username_1=idp_username_1,\n", " idp_password_1=idp_password_1,\n", + " jupyterhub_username=jupyterhub_username,\n", + " jupyterhub_password=jupyterhub_password,\n", " transition_timeout=transition_timeout,\n", " binderhub_launch_timeout=binderhub_launch_timeout,\n", " ),\n", @@ -697,6 +717,8 @@ " dict(\n", " project_name=f'{project_name_prefix}-add-binderhub-addon',\n", " binderhub_binderhub_url=binderhub_binderhub_url,\n", + " binderhub_use_default_server=binderhub_use_default_server,\n", + " binderhub_auth_mode=binderhub_auth_mode,\n", " ),\n", " )\n", ")\n", @@ -730,6 +752,7 @@ " 'テスト手順-BinderHub-BinderHubアドオン-repo2docker.ipynb',\n", " dict(\n", " project_name=f'{project_name_prefix}-repo2docker',\n", + " binderhub_auth_mode=binderhub_auth_mode,\n", " ),\n", " )\n", ")\n", @@ -764,6 +787,7 @@ " 'テスト手順-BinderHub-BinderHubアドオン-Dockerfile.ipynb',\n", " dict(\n", " project_name=f'{project_name_prefix}-Dockerfile',\n", + " binderhub_auth_mode=binderhub_auth_mode,\n", " )\n", " ),\n", ")\n", @@ -797,6 +821,7 @@ " 'テスト手順-BinderHub-BinderHubアドオン-デフォルトストレージのコピー制御.ipynb',\n", " dict(\n", " project_name=f'{project_name_prefix}-default-storage-copy-control',\n", + " binderhub_auth_mode=binderhub_auth_mode,\n", " ),\n", " )\n", ")\n", @@ -829,6 +854,7 @@ " 'テスト手順-BinderHub-BinderHubアドオン-停止中のBinderHubアドオン.ipynb',\n", " dict(\n", " project_name=f'{project_name_prefix}-halted-binderhub',\n", + " binderhub_auth_mode=binderhub_auth_mode,\n", " ),\n", " )\n", ")\n", diff --git "a/\347\265\220\345\220\210\350\251\246\351\250\223-\345\256\237\350\241\214.ipynb" "b/\347\265\220\345\220\210\350\251\246\351\250\223-\345\256\237\350\241\214.ipynb" index 21da8ab..bfd3642 100644 --- "a/\347\265\220\345\220\210\350\251\246\351\250\223-\345\256\237\350\241\214.ipynb" +++ "b/\347\265\220\345\220\210\350\251\246\351\250\223-\345\256\237\350\241\214.ipynb" @@ -743,6 +743,7 @@ "skip_autofill = False\n", "skip_admin = False\n", "skip_binderhub = False\n", + "skip_local_binderhub = False\n", "skip_wiki = False\n", "\n", "storages_oauth = [\n", @@ -795,6 +796,10 @@ "# BinderHubアドオンのテスト\n", "# アドオン追加テストにおいて追加するBinderHubの情報\n", "binderhub_binderhub_url = 'https://example.com/binderhub'\n", + "# ローカルでのBinderHubアドオンのテスト\n", + "# JupyterHubのユーザ情報\n", + "jupyterhub_username = None\n", + "jupyterhub_password = None\n", "\n", "# グループ管理連携機能テスト専用ユーザー\n", "idp_username_3 = None\n", @@ -4179,7 +4184,44 @@ "outputs": [], "source": [ "if not skip_binderhub:\n", - " result_notebooks.append(run_notebook(result_dir, '取りまとめ-BinderHub-BinderHubアドオン.ipynb', binderhub_binderhub_url=binderhub_binderhub_url))\n", + " result_notebooks.append(\n", + " run_notebook(\n", + " result_dir,\n", + " '取りまとめ-BinderHub-BinderHubアドオン.ipynb',\n", + " binderhub_binderhub_url=binderhub_binderhub_url,\n", + " binderhub_auth_mode='auto'\n", + " )\n", + " )\n", + "\n", + "result_notebooks" + ] + }, + { + "cell_type": "markdown", + "id": "cc24a05c", + "metadata": {}, + "source": [ + "## ローカル環境でのBinderHubアドオン関連テスト" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e880b02", + "metadata": {}, + "outputs": [], + "source": [ + "if not skip_local_binderhub:\n", + " result_notebooks.append(\n", + " run_notebook(\n", + " result_dir,\n", + " '取りまとめ-BinderHub-BinderHubアドオン.ipynb',\n", + " binderhub_binderhub_url=binderhub_binderhub_url,\n", + " binderhub_auth_mode='jupyterhub',\n", + " jupyterhub_username=jupyterhub_username,\n", + " jupyterhub_password=jupyterhub_password,\n", + " )\n", + " )\n", "\n", "result_notebooks" ]