Skip to content

Commit

Permalink
feat(test): made platform tests usable for all environments, adding c…
Browse files Browse the repository at this point in the history
…onfiguration options
  • Loading branch information
Calcagiara authored and ffais committed Jan 9, 2025
1 parent 2a566f1 commit 39a164b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion charts/digitalhub/confs/tests/init-python-script.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
cp home/src/$TEST_SCRIPT home/git/digitalhub-tutorials/$TEST_FOLDER/$TEST_SCRIPT
cd home/git/digitalhub-tutorials/$TEST_FOLDER
pip install --cache-dir home/pipcache digitalhub[full] digitalhub-runtime-python digitalhub-runtime-container digitalhub-runtime-dbt digitalhub-runtime-kfp digitalhub-runtime-modelserve requests-oauthlib
{{- include "digitalhub.testPackages" . }}
python $TEST_SCRIPT
5 changes: 2 additions & 3 deletions charts/digitalhub/confs/tests/python-test/s1-etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ def main():
# Get Core Token
client_id = os.getenv("CORE_CLIENT_ID")
client_secret = os.getenv("CORE_CLIENT_SECRET")
scope = 'tenant1-core'
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client, scope=scope)
token = oauth.fetch_token(token_url='https://core.tenant1.digitalhub-dev.smartcommunitylab.it/auth/token', client_id=client_id, client_secret=client_secret, scope=scope)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='http://{{ include "core.fullname" .Subcharts.core }}:{{ .Subcharts.core.Values.service.port }}/auth/token', client_id=client_id, client_secret=client_secret)
os.environ["DHCORE_ACCESS_TOKEN"] = token["access_token"]

# Load project
Expand Down
5 changes: 2 additions & 3 deletions charts/digitalhub/confs/tests/python-test/s2-dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ def main():
# Get Core Token
client_id = os.getenv("CORE_CLIENT_ID")
client_secret = os.getenv("CORE_CLIENT_SECRET")
scope = 'tenant1-core'
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client, scope=scope)
token = oauth.fetch_token(token_url='https://core.tenant1.digitalhub-dev.smartcommunitylab.it/auth/token', client_id=client_id, client_secret=client_secret, scope=scope)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='http://{{ include "core.fullname" .Subcharts.core }}:{{ .Subcharts.core.Values.service.port }}/auth/token', client_id=client_id, client_secret=client_secret)
os.environ["DHCORE_ACCESS_TOKEN"] = token["access_token"]

# Load project
Expand Down
5 changes: 2 additions & 3 deletions charts/digitalhub/confs/tests/python-test/s3-scikit-learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ def main():
# Get Core Token
client_id = os.getenv("CORE_CLIENT_ID")
client_secret = os.getenv("CORE_CLIENT_SECRET")
scope = 'tenant1-core'
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client, scope=scope)
token = oauth.fetch_token(token_url='https://core.tenant1.digitalhub-dev.smartcommunitylab.it/auth/token', client_id=client_id, client_secret=client_secret, scope=scope)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='http://{{ include "core.fullname" .Subcharts.core }}:{{ .Subcharts.core.Values.service.port }}/auth/token', client_id=client_id, client_secret=client_secret)
os.environ["DHCORE_ACCESS_TOKEN"] = token["access_token"]

# Load project
Expand Down
16 changes: 16 additions & 0 deletions charts/digitalhub/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,19 @@ false
{{- end }}
{{- end }}

{{/*
Set packages versions for tests
*/}}
{{- define "digitalhub.testPackages" -}}
{{- $command := "pip install --cache-dir home/pipcache" -}}
{{- range $package := .Values.platformTests.packages -}}
{{- $command = printf "%s %s" $command $package.name }}
{{- if $package.tag -}}
{{- $command = printf "%s==%s" $command $package.tag }}
{{- end -}}
{{- end }}
{{- $command = printf "%s %s" $command "requests-oauthlib" }}
{{ $command }}
{{- end }}


Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data:
{{- $files := .Files }}
{{- range $key, $value := .Files }}
{{- if hasPrefix "confs/tests/python-test/" $key }}
{{ $key | trimPrefix "confs/tests/python-test/" }}: {{ $files.Get $key | quote }}
{{ $key | trimPrefix "confs/tests/python-test/" }}: {{ tpl ($files.Get $key) $ | quote }}
{{- end }}
{{- end }}
---
Expand All @@ -15,4 +15,4 @@ kind: ConfigMap
metadata:
name: {{ include "digitalhub.fullname" . }}-python-script-test
data:
{{ (.Files.Glob "confs/tests/init-python-script.sh").AsConfig | indent 2 }}
init-python-script.sh: {{ tpl ( .Files.Get "confs/tests/init-python-script.sh") $ | quote }}
14 changes: 3 additions & 11 deletions charts/digitalhub/templates/tests/python-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
runAsUser: 0
containers:
- name: python
image: python:3.10-slim
image: "{{ $.Values.platformTests.image | default "python" }}:{{ $.Values.platformTests.tag | default "3.10-slim" }}"
command: ['sh', './home/scripts/init-python-script.sh']
volumeMounts:
- name: test-volume
Expand All @@ -40,20 +40,12 @@ spec:
mountPath: /home/git
readOnly: false
env:
- name: "POSTGRES_USER"
valueFrom:
secretKeyRef:
name: "digitalhub-owner-user.database-postgres-cluster.credentials.postgresql.acid.zalan.do"
key: "username"
- name: "POSTGRES_PASSWORD"
valueFrom:
secretKeyRef:
name: "digitalhub-owner-user.database-postgres-cluster.credentials.postgresql.acid.zalan.do"
key: "password"
- name: TEST_SCRIPT
value: {{ $key | trimPrefix "confs/tests/python-test/" }}
- name: TEST_FOLDER
value: {{ $key | trimPrefix "confs/tests/python-test/" | trimSuffix ".py" }}
- name: OAUTHLIB_INSECURE_TRANSPORT
value: "True"
{{- if $.Values.core.authentication.openId.enabled }}
- name: "CORE_CLIENT_ID"
valueFrom:
Expand Down
17 changes: 17 additions & 0 deletions charts/digitalhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,20 @@ kubeflow-pipelines:
endpointPort: *minioEndpointPort
bucket: *kfpBucket
protocol: *minioProtocol

platformTests:
image: ""
tag: ""
packages:
- name: "digitalhub[full]"
tag: ""
- name: "digitalhub-runtime-python"
tag: ""
- name: "digitalhub-runtime-container"
tag: ""
- name: "digitalhub-runtime-dbt"
tag: ""
- name: "digitalhub-runtime-kfp"
tag: ""
- name: "digitalhub-runtime-modelserve"
tag: ""

0 comments on commit 39a164b

Please sign in to comment.