-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into task/process-snow/3254
- Loading branch information
Showing
26 changed files
with
319 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
""" Test the health endpoint | ||
""" | ||
import os | ||
import json | ||
import requests | ||
from starlette.testclient import TestClient | ||
import app.main | ||
from app.tests.common import MockResponse | ||
|
||
|
||
def test_ready_ok(): | ||
""" Test health endpoint, given that everything is fine """ | ||
client = TestClient(app.main.app) | ||
response = client.get('/api/ready/') | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_health_ok(): | ||
""" Test health endpoint, given that everything is fine """ | ||
client = TestClient(app.main.app) | ||
response = client.get('/api/health/') | ||
assert response.json().get('healthy') | ||
|
||
|
||
def test_health_fail(monkeypatch): | ||
""" Test the health endpoint, given that pods aren't up """ | ||
|
||
def mock_requests_fail_condition(*args, **kwargs): | ||
""" Mock request response """ | ||
fixture_path = ('fixtures/console.pathfinder.gov.bc.ca:8443/apis/' | ||
'apps/v1beta1/namespaces/project_namespace/' | ||
'statefulsets/some_suffix_fail.json') | ||
fixture_path = os.path.join(os.path.dirname(__file__), fixture_path) | ||
with open(fixture_path, 'r', encoding="utf-8") as fixture_file: | ||
return MockResponse(json=json.load(fixture_file)) | ||
|
||
monkeypatch.setattr(requests, 'get', mock_requests_fail_condition) | ||
|
||
client = TestClient(app.main.app) | ||
response = client.get('/api/health/') | ||
assert not response.json().get('healthy') | ||
# import os | ||
# import json | ||
# import requests | ||
# from starlette.testclient import TestClient | ||
# import app.main | ||
# from app.tests.common import MockResponse | ||
|
||
# TODO reenable | ||
|
||
# | ||
# def test_ready_ok(): | ||
# """ Test health endpoint, given that everything is fine """ | ||
# client = TestClient(app.main.app) | ||
# response = client.get('/api/ready/') | ||
# assert response.status_code == 200 | ||
|
||
|
||
# def test_health_ok(): | ||
# """ Test health endpoint, given that everything is fine """ | ||
# client = TestClient(app.main.app) | ||
# response = client.get('/api/health/') | ||
# assert response.json().get('healthy') | ||
|
||
|
||
# def test_health_fail(monkeypatch): | ||
# """ Test the health endpoint, given that pods aren't up """ | ||
|
||
# def mock_requests_fail_condition(*args, **kwargs): | ||
# """ Mock request response """ | ||
# fixture_path = ('fixtures/console.pathfinder.gov.bc.ca:8443/apis/' | ||
# 'apps/v1beta1/namespaces/project_namespace/' | ||
# 'statefulsets/some_suffix_fail.json') | ||
# fixture_path = os.path.join(os.path.dirname(__file__), fixture_path) | ||
# with open(fixture_path, 'r', encoding="utf-8") as fixture_file: | ||
# return MockResponse(json=json.load(fixture_file)) | ||
|
||
# monkeypatch.setattr(requests, 'get', mock_requests_fail_condition) | ||
|
||
# client = TestClient(app.main.app) | ||
# response = client.get('/api/health/') | ||
# assert not response.json().get('healthy') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/sh -l | ||
# | ||
source "$(dirname ${0})/common/common" | ||
|
||
#% | ||
#% OpenShift Deploy Helper | ||
#% | ||
#% Intended for use with a pull request-based pipeline. | ||
#% Suffixes incl.: pr-###. | ||
#% | ||
#% Usage: | ||
#% | ||
#% ${THIS_FILE} [SUFFIX] [apply] | ||
#% | ||
#% Examples: | ||
#% | ||
#% Provide a PR number. Defaults to a dry-run. | ||
#% ${THIS_FILE} pr-0 | ||
#% | ||
#% Apply when satisfied. | ||
#% ${THIS_FILE} pr-0 apply | ||
#% | ||
|
||
|
||
# Target project override for Dev or Prod deployments | ||
# | ||
PROJ_TARGET="${PROJ_TARGET:-${PROJ_DEV}}" | ||
|
||
# Prepare names for crunchy ephemeral instance for this PR. | ||
IMAGE_STREAM_NAMESPACE=${IMAGE_STREAM_NAMESPACE:-${PROJ_TOOLS}} | ||
EPHEMERAL_STORAGE=${EPHEMERAL_STORAGE:-'False'} | ||
|
||
# Process template | ||
OC_PROCESS="oc -n ${PROJ_TARGET} process -f ${TEMPLATE_PATH}/crunchy.yaml \ | ||
-p NAME=\"crunchy-${APP_NAME}-${SUFFIX}\" \ | ||
-p SUFFIX=\"${SUFFIX}\" \ | ||
-p TARGET_NAMESPACE=${PROJ_TARGET} \ | ||
${BUCKET:+ " -p BUCKET=${BUCKET}"} \ | ||
${DATA_SIZE:+ " -p DATA_SIZE=${DATA_SIZE}"} \ | ||
${WAL_SIZE:+ " -p WAL_SIZE=${WAL_SIZE}"} \ | ||
${IMAGE_NAME:+ " -p IMAGE_NAME=${IMAGE_NAME}"} \ | ||
${IMAGE_TAG:+ " -p IMAGE_TAG=${IMAGE_TAG}"} \ | ||
${IMAGE_REGISTRY:+ " -p IMAGE_REGISTRY=${IMAGE_REGISTRY}"} \ | ||
${PVC_SIZE:+ " -p PVC_SIZE=${PVC_SIZE}"} \ | ||
${CPU_REQUEST:+ "-p CPU_REQUEST=${CPU_REQUEST}"} \ | ||
${CPU_LIMIT:+ "-p CPU_LIMIT=${CPU_LIMIT}"} \ | ||
${MEMORY_REQUEST:+ "-p MEMORY_REQUEST=${MEMORY_REQUEST}"} \ | ||
${MEMORY_LIMIT:+ "-p MEMORY_LIMIT=${MEMORY_LIMIT}"}" | ||
|
||
|
||
# In order to avoid running out of storage quota in our development environment, use | ||
# ephemeral storage by removing the pvc request from the template. | ||
if [ "$EPHEMERAL_STORAGE" = "True" ] | ||
then | ||
# Pipe the template to jq, and delete the pvc and volume claim items from the template. | ||
OC_PROCESS="${OC_PROCESS} | jq 'del(.items[2].spec.template.spec.volumes[0].persistentVolumeClaim) \ | ||
| del(.items[2].spec.volumeClaimTemplates)'" | ||
fi | ||
|
||
# Apply template (apply or use --dry-run) | ||
# | ||
OC_APPLY="oc -n ${PROJ_TARGET} apply -f -" | ||
[ "${APPLY}" ] || OC_APPLY="${OC_APPLY} --dry-run=client" | ||
|
||
# Execute commands | ||
# | ||
|
||
eval "${OC_PROCESS}" | ||
eval "${OC_PROCESS} | ${OC_APPLY}" | ||
|
||
# Provide oc command instruction | ||
# | ||
display_helper "${OC_PROCESS} | ${OC_APPLY}" |
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
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
Oops, something went wrong.