Skip to content

Commit 0ad619d

Browse files
committed
Merge branch 'develop' of github.com:MetaCell/cloud-harness into develop
2 parents c668f7c + d16f6d0 commit 0ad619d

File tree

5 files changed

+59
-26
lines changed

5 files changed

+59
-26
lines changed

applications/jupyterhub/deploy/resources/hub/jupyterhub_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
configuration_directory = os.path.dirname(os.path.realpath(__file__))
2525
sys.path.insert(0, configuration_directory)
2626

27-
from z2jh import ( # noqa
27+
from z2jh import ( # noqa
2828
get_config,
2929
get_name,
3030
get_name_env,
@@ -286,7 +286,7 @@ def camelCaseify(s):
286286
c.KubeSpawner.volumes = [
287287
{
288288
"name": volume_name_template,
289-
"persistentVolumeClaim": {"claimName": "{pvc_name_template}"},
289+
"persistentVolumeClaim": {"claimName": pvc_name_template},
290290
}
291291
]
292292
c.KubeSpawner.volume_mounts = [

applications/jupyterhub/deploy/resources/hub/z2jh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ def set_config_if_not_none(cparent, name, key):
142142
"""
143143
data = get_config(key)
144144
if data is not None:
145-
setattr(cparent, name, data)
145+
setattr(cparent, name, data)

libraries/cloudharness-common/cloudharness/workflows/operations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from collections.abc import Iterable
33
from typing import List, Union
44

5+
import argo.workflows
6+
import argo.workflows.client
57
import yaml
68

79
from cloudharness import log
@@ -10,6 +12,7 @@
1012
from . import argo
1113
from .tasks import Task, SendResultTask, CustomTask
1214
from .utils import PodExecutionContext, affinity_spec, is_accounts_present, name_from_path, volume_mount_template
15+
from argo.workflows.client import V1Toleration
1316

1417
POLLING_WAIT_SECONDS = 1
1518
SERVICE_ACCOUNT = 'argo-workflows'
@@ -120,6 +123,7 @@ def spec(self):
120123
'entrypoint': self.entrypoint,
121124
'ttlStrategy': self.ttl_strategy,
122125
'templates': [self.modify_template(template) for template in self.templates],
126+
'tolerations': [V1Toleration(key='cloudharness/temporary-job', operator='Equal', value='true').to_dict()],
123127
'serviceAccountName': SERVICE_ACCOUNT,
124128
'imagePullSecrets': [{'name': config.CloudharnessConfig.get_registry_secret()}],
125129
'volumes': [{

libraries/cloudharness-common/tests/test_workflow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def test_single_task_shared():
122122
accounts_offset = 1 if is_accounts_present() else 0
123123
assert len(op.volumes) == 1
124124
assert len(wf['spec']['volumes']) == 2 + accounts_offset
125+
assert wf['spec']['tolerations'], "Tolerations should be added to the workflow"
126+
assert wf['spec']['tolerations'][0]['key'] == 'cloudharness/temporary-job'
127+
assert wf['spec']['tolerations'][0]['operator'] == 'Equal'
128+
assert wf['spec']['tolerations'][0]['value'] == 'true'
125129
assert wf['spec']['volumes'][1 + accounts_offset]['persistentVolumeClaim']['claimName'] == 'myclaim'
126130
if accounts_offset == 1:
127131
assert wf['spec']['volumes'][1]['secret']['secretName'] == 'accounts'
Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
import os
22
import logging
3-
import requests
4-
3+
from urllib.parse import urlparse
54
import schemathesis as st
5+
from schemathesis.hooks import HookContext
66

77
from cloudharness.auth import get_token
88

9+
st.experimental.OPEN_API_3_1.enable()
10+
911
if "APP_URL" or "APP_SCHEMA_FILE" in os.environ:
1012
app_schema = os.environ.get("APP_SCHEMA_FILE", None)
1113
app_url = os.environ.get("APP_URL", "http://samples.ch.local/api")
12-
logging.info("Start schemathesis tests on %s", app_url)
14+
15+
parsed_url = urlparse(app_url)
16+
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}".rstrip("/")
17+
18+
logging.info("Start schemathesis tests on %s", base_url)
19+
1320
schema = None
21+
22+
# First, attempt to load the local file if provided
1423
if app_schema:
15-
# Test locally with harness-test -- use local schema for convenience during test development
16-
openapi_uri = app_schema
1724
try:
18-
schema = st.from_file(openapi_uri)
25+
schema = st.from_file(app_schema)
26+
logging.info("Successfully loaded schema from local file: %s", app_schema)
1927
except st.exceptions.SchemaError:
20-
logging.exception("The local schema file %s cannot be loaded. Attempting loading from URL", openapi_uri)
28+
logging.exception("The local schema file %s cannot be loaded. Attempting loading from URL", app_schema)
2129

30+
# If no schema from file, then loop over URL candidates
2231
if not schema:
23-
# remote testing: might be /api/openapi.json or /openapi.json
24-
try:
25-
openapi_uri = openapi_uri = app_url + "/openapi.json"
26-
logging.info("Using openapi spec at %s", openapi_uri)
27-
schema = st.from_uri(openapi_uri)
28-
except st.exceptions.SchemaError:
29-
# Use alternative configuration
32+
candidates = [
33+
base_url + "/openapi.json",
34+
base_url + "/api/openapi.json",
35+
]
36+
for candidate in candidates:
3037
try:
31-
openapi_uri = app_url.replace("/api", "") + "/openapi.json"
32-
print(requests.get(openapi_uri))
33-
schema = st.from_uri(openapi_uri)
38+
logging.info("Attempting to load schema from URI: %s", candidate)
39+
schema = st.from_uri(candidate)
40+
logging.info("Successfully loaded schema from %s", candidate)
41+
break # Exit loop on successful load
3442
except st.exceptions.SchemaError as e:
35-
raise Exception(
36-
f"Cannot setup api tests: {openapi_uri} not valid. Check your deployment is up and configuration") from e
37-
38-
except Exception as e:
39-
raise Exception(
40-
f"Cannot setup api tests: {openapi_uri}: {e}") from e
43+
logging.warning("Failed to load schema from %s: %s", candidate, e)
44+
except Exception as e:
45+
logging.error("Unexpected error when loading schema from %s: %s", candidate, e)
46+
if not schema:
47+
raise Exception("Cannot setup API tests: No valid schema found. Check your deployment and configuration.")
4148

4249
if "USERNAME" in os.environ and "PASSWORD" in os.environ:
4350
logging.info("Setting token from username and password")
@@ -66,3 +73,21 @@ def set(self, case, data, context):
6673
case.headers = case.headers or {}
6774
case.headers["Authorization"] = f"Bearer {data}"
6875
case.headers["Cookie"] = f"kc-access={data}"
76+
77+
UNSAFE_VALUES = ("%", )
78+
79+
@st.hook
80+
def filter_path_parameters(context: HookContext, x):
81+
# Extract the candidate value.
82+
param = x["key"] if isinstance(x, dict) and "key" in x else x
83+
84+
if param is None or param == "":
85+
return True
86+
87+
param_str = str(param)
88+
89+
# Reject if any unsafe substring is present.
90+
if any(unsafe in param_str for unsafe in UNSAFE_VALUES):
91+
return False
92+
93+
return True

0 commit comments

Comments
 (0)