-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup/Add integration/deployment tests via pytest #922
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
kubernetes
notpython-kubernetes
(which is very old, and doesn't work with the tests).But also, note that
pip install -e .[dev]
does not make use of this environment-dev.yaml file, so really "kubernetes" and "dask-gateway" need to be added to the dev list in setup.pyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct pip package is
kubernetes
, but the conda'skubernetes
package didn't work for me yesterday andpython-kubernetes
seems to work, either ways I'll update the dev dependency.