-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup/Add integration/deployment tests via pytest (#922)
Setup/Add integration/deployment pytests
- Loading branch information
Showing
9 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DASK_GATEWAY_JUPYTER_SECRET_NAME = "qhub-daskgateway-gateway" | ||
JUPYTERHUB_TOKEN_SECRET_KEY_NAME = "jupyterhub_api_token" | ||
NAMESPACE = 'dev' | ||
QHUB_HOSTNAME = 'github-actions.qhub.dev' | ||
GATEWAY_ENDPOINT = 'gateway' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import dask_gateway | ||
import os | ||
|
||
import pytest | ||
from tests_deployment import constants | ||
from tests_deployment.utils import monkeypatch_ssl_context, get_jupyterhub_token | ||
|
||
monkeypatch_ssl_context() | ||
|
||
|
||
@pytest.fixture | ||
def dask_gateway_object(): | ||
"""Connects to Dask Gateway cluster from outside the cluster.""" | ||
os.environ['JUPYTERHUB_API_TOKEN'] = get_jupyterhub_token() | ||
return dask_gateway.Gateway( | ||
address=f'https://{constants.QHUB_HOSTNAME}/{constants.GATEWAY_ENDPOINT}', | ||
auth='jupyterhub', | ||
proxy_address=f'tcp://{constants.QHUB_HOSTNAME}:8786' | ||
) | ||
|
||
|
||
def test_dask_gateway(dask_gateway_object): | ||
"""This test checks if we're able to connect to dask gateway.""" | ||
assert dask_gateway_object.list_clusters() == [] | ||
|
||
|
||
def test_dask_gateway_cluster_options(dask_gateway_object): | ||
"""Tests Dask Gateway's cluster options.""" | ||
cluster_options = dask_gateway_object.cluster_options() | ||
assert cluster_options.conda_environment == "dask" | ||
assert cluster_options.profile == "Small Worker" | ||
assert cluster_options.environment_vars == {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import base64 | ||
import ssl | ||
|
||
from kubernetes import client, config | ||
|
||
from tests_deployment import constants | ||
|
||
|
||
def get_kubernetes_api_instance(): | ||
"""Returns the v1 core Kubernetes api instance for making | ||
calls to the kubernetes cluster | ||
""" | ||
config.load_kube_config() | ||
return client.CoreV1Api() | ||
|
||
|
||
def get_jupyterhub_token(): | ||
""" | ||
It fetches the secret that has the JupyterHub token to be able to | ||
connect to dask gateway. | ||
""" | ||
v1 = get_kubernetes_api_instance() | ||
secret = str(v1.read_namespaced_secret( | ||
constants.DASK_GATEWAY_JUPYTER_SECRET_NAME, constants.NAMESPACE | ||
).data) | ||
base64_encoded_token = eval(secret)[constants.JUPYTERHUB_TOKEN_SECRET_KEY_NAME] | ||
return base64.b64decode(base64_encoded_token).decode() | ||
|
||
|
||
def monkeypatch_ssl_context(): | ||
""" | ||
This is a workaround monkeypatch to disable ssl checking to avoid SSL | ||
failures. | ||
TODO: A better way to do this would be adding the Traefik's default certificate's | ||
CA public key to the trusted certificate authorities. | ||
""" | ||
def create_default_context(context): | ||
def _inner(*args, **kwargs): | ||
context.check_hostname = False | ||
context.verify_mode = ssl.CERT_NONE | ||
return context | ||
return _inner | ||
|
||
sslcontext = ssl.create_default_context() | ||
ssl.create_default_context = create_default_context(sslcontext) |