def test_image_whitelist(app, image): name = "checker" add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, DockerSpawner) user.spawner.remove_containers = True user.spawner.image_whitelist = { "0.9": "jupyterhub/singleuser:0.9", "0.8": "jupyterhub/singleuser:0.8", } token = user.new_api_token() # start the server r = yield api_request( app, "users", name, "server", method="post", data=json.dumps({"image": image}) ) if image not in user.spawner.image_whitelist: with pytest.raises(Exception): r.raise_for_status() return while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") yield gen.sleep(0.1) assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) r.raise_for_status() assert r.headers['x-jupyterhub-version'].startswith(image) r = yield api_request( app, "users", name, "server", method="delete", ) r.raise_for_status()
def test_integration(skein_client, app, configure_app): with clean_cluster(skein_client): # Create a user add_user(app.db, app, name="alice") alice = app.users["alice"] assert isinstance(alice.spawner, YarnSpawner) token = alice.new_api_token() # Not started, status should be 0 status = yield alice.spawner.poll() assert status == 0 # Stop can be called before start, no-op yield alice.spawner.stop() # Start the server, and wait for it to start resp = None while resp is None or resp.status_code == 202: yield gen.sleep(2.0) resp = yield api_request(app, "users", "alice", "server", method="post") # Check that everything is running fine url = url_path_join(public_url(app, alice), "api/status") resp = yield async_requests.get( url, headers={'Authorization': 'token %s' % token}) resp.raise_for_status() assert "kernels" in resp.json() # Save the app_id to use later app_id = alice.spawner.app_id # Shutdown the server resp = yield api_request(app, "users", "alice", "server", method="delete") resp.raise_for_status() assert_shutdown_in(skein_client, app_id, timeout=10) # Check status status = yield alice.spawner.poll() assert status == 0
def test_start_stop(app): name = "somebody" add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, SwarmSpawner) token = user.new_api_token() # start the server r = yield api_request(app, "users", name, "server", method="post") while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) assert r.url == url r.raise_for_status() print(r.text) assert "kernels" in r.json()
def test_start_stop(app): name = getuser() add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, SystemUserSpawner) token = user.new_api_token() # start the server r = yield api_request(app, "users", name, "server", method="post") while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) assert r.url == url r.raise_for_status() print(r.text) assert "kernels" in r.json()
def test_image_whitelist(app, image): name = "checker" add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, DockerSpawner) user.spawner.remove_containers = True user.spawner.image_whitelist = { "0.9": "jupyterhub/singleuser:0.9", "0.8": "jupyterhub/singleuser:0.8", } token = user.new_api_token() # start the server r = yield api_request(app, "users", name, "server", method="post", data=json.dumps({"image": image})) if image not in user.spawner.image_whitelist: with pytest.raises(Exception): r.raise_for_status() return while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") yield gen.sleep(0.1) assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) r.raise_for_status() assert r.headers['x-jupyterhub-version'].startswith(image) r = yield api_request( app, "users", name, "server", method="delete", ) r.raise_for_status()