mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Add tljh_post_install hook
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
"""
|
||||
Simplest plugin that exercises all the hooks
|
||||
"""
|
||||
from textwrap import dedent
|
||||
|
||||
from tljh import systemd
|
||||
from tljh.hooks import hookimpl
|
||||
|
||||
|
||||
@@ -40,3 +43,21 @@ def tljh_config_post_install(config):
|
||||
@hookimpl
|
||||
def tljh_custom_jupyterhub_config(c):
|
||||
c.JupyterHub.authenticator_class = 'tmpauthenticator.TmpAuthenticator'
|
||||
|
||||
|
||||
@hookimpl
|
||||
def tljh_post_install():
|
||||
post_install_service = dedent("""
|
||||
[Unit]
|
||||
Description=Post Install Test Service
|
||||
|
||||
[Service]
|
||||
ExecStart=ls
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
""")
|
||||
service = "post-install-test.service"
|
||||
systemd.install_unit(service, post_install_service)
|
||||
systemd.enable_service(service)
|
||||
systemd.reload_daemon()
|
||||
|
||||
@@ -6,6 +6,7 @@ import requests
|
||||
import os
|
||||
import subprocess
|
||||
from tljh.config import CONFIG_FILE, USER_ENV_PREFIX, HUB_ENV_PREFIX
|
||||
from tljh.systemd import check_service_enabled
|
||||
|
||||
yaml = YAML(typ='rt')
|
||||
|
||||
@@ -54,6 +55,7 @@ def test_config_hook():
|
||||
|
||||
assert data['simplest_plugin']['present']
|
||||
|
||||
|
||||
def test_jupyterhub_config_hook():
|
||||
"""
|
||||
Test that tmpauthenticator is enabled by our custom config plugin
|
||||
@@ -61,3 +63,10 @@ def test_jupyterhub_config_hook():
|
||||
resp = requests.get('http://localhost/hub/tmplogin', allow_redirects=False)
|
||||
assert resp.status_code == 302
|
||||
assert resp.headers['Location'] == '/hub/spawn'
|
||||
|
||||
|
||||
def test_post_install_hook():
|
||||
"""
|
||||
Test that the post-install-test systemd service is enabled
|
||||
"""
|
||||
assert check_service_enabled("post-install-test")
|
||||
|
||||
@@ -59,3 +59,13 @@ def tljh_config_post_install(config):
|
||||
overwrite anything the user might have explicitly set.
|
||||
"""
|
||||
pass
|
||||
|
||||
@hookspec
|
||||
def tljh_post_install():
|
||||
"""
|
||||
Post install script to be executed after installation
|
||||
and after all the other hooks.
|
||||
|
||||
This can be arbitrary Python code.
|
||||
"""
|
||||
pass
|
||||
@@ -405,6 +405,9 @@ def run_plugin_actions(plugin_manager, plugins):
|
||||
))
|
||||
conda.ensure_pip_packages(USER_ENV_PREFIX, user_pip_packages)
|
||||
|
||||
# Custom post install actions
|
||||
hook.tljh_post_install()
|
||||
|
||||
|
||||
def ensure_config_yaml(plugin_manager):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user