mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 22:43:00 +00:00
only set service URL env if there's a URL to set
These fields are only relevant for services with a web endpoint
This commit is contained in:
@@ -225,8 +225,9 @@ class Service(LoggingConfigurable):
|
|||||||
env['JUPYTERHUB_API_TOKEN'] = self.api_token
|
env['JUPYTERHUB_API_TOKEN'] = self.api_token
|
||||||
env['JUPYTERHUB_API_URL'] = self.hub_api_url
|
env['JUPYTERHUB_API_URL'] = self.hub_api_url
|
||||||
env['JUPYTERHUB_BASE_URL'] = self.base_url
|
env['JUPYTERHUB_BASE_URL'] = self.base_url
|
||||||
env['JUPYTERHUB_SERVICE_PREFIX'] = self.server.base_url
|
if self.url:
|
||||||
env['JUPYTERHUB_SERVICE_URL'] = self.url
|
env['JUPYTERHUB_SERVICE_URL'] = self.url
|
||||||
|
env['JUPYTERHUB_SERVICE_PREFIX'] = self.server.base_url
|
||||||
|
|
||||||
self.spawner = _ServiceSpawner(
|
self.spawner = _ServiceSpawner(
|
||||||
cmd=self.command,
|
cmd=self.command,
|
||||||
@@ -248,7 +249,7 @@ class Service(LoggingConfigurable):
|
|||||||
"""Called when the service process unexpectedly exits"""
|
"""Called when the service process unexpectedly exits"""
|
||||||
self.log.error("Service %s exited with status %i", self.name, self.proc.returncode)
|
self.log.error("Service %s exited with status %i", self.name, self.proc.returncode)
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stop a managed service"""
|
"""Stop a managed service"""
|
||||||
if not self.managed:
|
if not self.managed:
|
||||||
|
@@ -66,9 +66,16 @@ class MockServiceSpawner(jupyterhub.services.service._ServiceSpawner):
|
|||||||
poll_interval = 1
|
poll_interval = 1
|
||||||
|
|
||||||
|
|
||||||
@yield_fixture
|
def _mockservice(request, app, url=False):
|
||||||
def mockservice(request, app):
|
|
||||||
name = 'mock-service'
|
name = 'mock-service'
|
||||||
|
spec = {
|
||||||
|
'name': name,
|
||||||
|
'command': mockservice_cmd,
|
||||||
|
'admin': True,
|
||||||
|
}
|
||||||
|
if url:
|
||||||
|
spec['url'] = 'http://127.0.0.1:%i' % random_port(),
|
||||||
|
|
||||||
with mock.patch.object(jupyterhub.services.service, '_ServiceSpawner', MockServiceSpawner):
|
with mock.patch.object(jupyterhub.services.service, '_ServiceSpawner', MockServiceSpawner):
|
||||||
app.services = [{
|
app.services = [{
|
||||||
'name': name,
|
'name': name,
|
||||||
@@ -88,4 +95,12 @@ def mockservice(request, app):
|
|||||||
# ensure process finishes starting
|
# ensure process finishes starting
|
||||||
with raises(TimeoutExpired):
|
with raises(TimeoutExpired):
|
||||||
service.proc.wait(1)
|
service.proc.wait(1)
|
||||||
yield service
|
return service
|
||||||
|
|
||||||
|
@yield_fixture
|
||||||
|
def mockservice(request, app):
|
||||||
|
yield _mockservice(request, app, url=False)
|
||||||
|
|
||||||
|
@yield_fixture
|
||||||
|
def mockservice_url(request, app):
|
||||||
|
yield _mockservice(request, app, url=True)
|
||||||
|
@@ -59,10 +59,11 @@ def test_managed_service(app, mockservice):
|
|||||||
assert service.proc.poll() is None
|
assert service.proc.poll() is None
|
||||||
|
|
||||||
|
|
||||||
def test_proxy_service(app, mockservice, io_loop):
|
def test_proxy_service(app, mockservice_url, io_loop):
|
||||||
name = mockservice.name
|
service = mockservice_url
|
||||||
|
name = service.name
|
||||||
routes = io_loop.run_sync(app.proxy.get_routes)
|
routes = io_loop.run_sync(app.proxy.get_routes)
|
||||||
url = public_url(app, mockservice) + '/foo'
|
url = public_url(app, service) + '/foo'
|
||||||
r = requests.get(url, allow_redirects=False)
|
r = requests.get(url, allow_redirects=False)
|
||||||
path = '/services/{}/foo'.format(name)
|
path = '/services/{}/foo'.format(name)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
@@ -99,3 +100,5 @@ def test_external_service(app, io_loop):
|
|||||||
assert len(resp) >= 1
|
assert len(resp) >= 1
|
||||||
assert isinstance(resp[0], dict)
|
assert isinstance(resp[0], dict)
|
||||||
assert 'name' in resp[0]
|
assert 'name' in resp[0]
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user