Skip to content

Commit

Permalink
Merge pull request #750 from ZeitOnline/nightwatch-image2
Browse files Browse the repository at this point in the history
ZO-5272: Add smoketest for publishing an imagegroup
  • Loading branch information
stollero authored May 17, 2024
2 parents 8904286 + c73897c commit eb0571e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/nightwatch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ jobs:
--override-type=json --overrides='[
{"op": "add", "path": "/spec/serviceAccount", "value": "baseproject"},
{"op": "add", "path": "/spec/containers/0/env", "value": [
{"name": "HTTPS_PROXY", "value": "http://static-ip-proxy.ops.zeit.de:3128"}
{"name": "HTTPS_PROXY", "value": "http://static-ip-proxy.ops.zeit.de:3128"},
{"name": "VIVI_XMLRPC_PASSWORD", "valueFrom": {"secretKeyRef": {
"name": "principals",
"key": "vivi_zeit.cms.principals_system.nightwatch"
}}}
]}
]'
Expand Down
14 changes: 14 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

function vault_read() {
local path=$1
local field=$2

if [[ -z "$VAULT_TOKEN" ]]; then
VAULT_TOKEN=$(<"$HOME/.vault-token")
fi
curl --silent -H "X-Vault-Token: $VAULT_TOKEN" \
"${VAULT_ADDR%/}/v1/zon/v1/${path}" | \
sed -e "s+^.*\"${field}\":\"\([^\"]*\).*$+\1+"
}


COMMAND=$1
case $COMMAND in
smoke)
Expand All @@ -20,6 +33,7 @@ case $COMMAND in
< k8s/base/kustomization.yaml)
docker buildx build --output type=docker --quiet --tag $image .
docker run --rm -it \
-e VIVI_XMLRPC_PASSWORD=$(vault_read vivi/$environment/nightwatch password) \
$image \
--nightwatch-environment=$environment "$@"
;;
Expand Down
26 changes: 21 additions & 5 deletions smoketest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import os

import pytest
import requests


XMLRPC_AUTH = 'nightwatch:' + os.environ['VIVI_XMLRPC_PASSWORD']
CONFIG_STAGING = {
'browser': {'baseurl': 'https://www.staging.zeit.de'},
'storage': 'http://content-storage.staging.zon.zeit.de/internal',
'vivi': f'https://{XMLRPC_AUTH}@vivi.staging.zon.zeit.de',
'elasticsearch': 'https://tms-es.staging.zon.zeit.de/zeit_content/_search',
}


CONFIG_PRODUCTION = {
'browser': {'baseurl': 'https://www.zeit.de'},
'storage': 'http://content-storage.prod.zon.zeit.de/internal',
'vivi': f'https://{XMLRPC_AUTH}@vivi-frontend.zeit.de:9090',
'elasticsearch': 'https://tms-es.zon.zeit.de/zeit_content/_search',
}

Expand All @@ -35,12 +40,13 @@ def pytest_configure(config):


class StorageClient:
def __init__(self, url):
self.url = url
def __init__(self, storage_url, vivi_url):
self.storage_url = storage_url
self.vivi_url = vivi_url
self.http = requests.Session()

def _request(self, verb, url, **kw):
r = self.http.request(verb, self.url + '/api/v1' + url, **kw)
r = self.http.request(verb, self.storage_url + '/api/v1' + url, **kw)
r.raise_for_status()
return r

Expand All @@ -56,9 +62,19 @@ def set_body(self, path, body):
)

def publish(self, path):
self._request('post', f'/publish{path}')
return self._request('post', f'/publish{path}').json()['job-id']

def job_status(self, job):
r = self.http.get(self.vivi_url + '/@@job-status', params={'job': job})
r.raise_for_status()
return r.json()

def job_result(self, job):
r = self.http.get(self.vivi_url + '/@@job-result', params={'job': job})
r.raise_for_status()
return r.text


@pytest.fixture(scope='session')
def vivi(config):
return StorageClient(config['storage'])
return StorageClient(config['storage'], config['vivi'])
14 changes: 14 additions & 0 deletions smoketest/k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ components:
- github.com/ZeitOnline/kustomize/components/nightwatch?ref=1.3
- versions

patches:
- target:
kind: Deployment
name: nightwatch
patch: |
- op: add
path: /spec/template/spec/containers/0/env
value:
- name: VIVI_XMLRPC_PASSWORD
valueFrom:
secretKeyRef:
name: principals
key: vivi_zeit.cms.principals_system.nightwatch
# See https://github.com/ZeitOnline/gh-action-workflows/blob/main/.github/workflows/nightwatch-build.yaml
images:
- name: nightwatch
Expand Down
15 changes: 15 additions & 0 deletions smoketest/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ def test_publisher_updates_metadata(vivi, http, config, content):
break
else:
pytest.fail('%s did not increase after %s seconds' % (current, timeout))


def test_publish_image_works(vivi, config):
image = '/wirtschaft/2010-01/china-exportschlager'
job = vivi.publish(image)

timeout = 60
for _ in range(timeout):
sleep(1)
if vivi.job_status(job) == 'SUCCESS':
break
else:
pytest.fail(
'Publish returned error after %s seconds:\n%s' % (timeout, vivi.job_result(job))
)

0 comments on commit eb0571e

Please sign in to comment.