Skip to content

Commit

Permalink
Stronger Jenkins
Browse files Browse the repository at this point in the history
* Add timeout in the checkers
* Use requests
* Add wait for database
  • Loading branch information
sbrunner committed Aug 8, 2018
1 parent 563be68 commit d6a0f58
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
6 changes: 5 additions & 1 deletion geoportal/c2cgeoportal_geoportal/lib/check_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def check(request):
"%s/%s/health_check" % (host["url"].rstrip("/"), c2c_base.strip("/")),
request
)
r = requests.get(params={"max_level": str(host.get("max_level", max_level))}, **url_headers)
r = requests.get(
params={"max_level": str(host.get("max_level", max_level))},
timeout=120,
**url_headers
)
r.raise_for_status()
return r.json()

Expand Down
22 changes: 18 additions & 4 deletions geoportal/c2cgeoportal_geoportal/lib/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ def check(request):
url_headers = build_url("Check the printproxy request (create)", url, request)

session = requests.session()
resp = session.post(json=print_settings["spec"], **url_headers)
resp = session.post(
json=print_settings["spec"],
timeout=30,
**url_headers
)
resp.raise_for_status()

job = resp.json()
Expand All @@ -97,7 +101,10 @@ def check(request):
done = False
while not done:
sleep(1)
resp = session.get(**url_headers)
resp = session.get(
timeout=30,
**url_headers
)
resp.raise_for_status()

status = resp.json()
Expand All @@ -107,7 +114,10 @@ def check(request):

url = request.route_url("printproxy_report_get", ref=job["ref"])
url_headers = build_url("Check the printproxy pdf retrieve", url, request)
resp = session.get(**url_headers)
resp = session.get(
timeout=30,
**url_headers
)
resp.raise_for_status()

health_check.add_custom_check(name="checker_print", check_cb=check, level=print_settings["level"])
Expand Down Expand Up @@ -152,7 +162,11 @@ def check(request):

interface_url_headers = build_url("checker_themes " + interface, url, request)

response = session.get(params=params, **interface_url_headers)
response = session.get(
params=params,
timeout=120,
**interface_url_headers
)
response.raise_for_status()

result = response.json()
Expand Down
1 change: 1 addition & 0 deletions travis/create-new-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ git clean -fX

# Build
./docker-run make --makefile=travis.mk build docker-build-testdb
./docker-compose-run bash -c 'wait-for-db; PGHOST=external-db; wait-for-db;'
./docker-compose-run make --makefile=travis.mk update-po
./docker-compose-run make --makefile=travis.mk theme2fts
34 changes: 10 additions & 24 deletions travis/test-new-project
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,20 @@

import sys
import json
import subprocess
import urllib.request

initial_error_length = 0
initial_access_length = 0

curl_args = ["--connect-timeout", "1", "--max-time", "400", "--retry", "1"]

url = sys.argv[1]

try:
status_code = subprocess.check_output(
["curl", "--write-out", "%{http_code}"] + curl_args + ["--silent", "--output", "/dev/null", url]
).decode("utf-8")
except subprocess.CalledProcessError as e:
print("Exception on curl call: {}".format(e))

print("RESULT:")
sys.stdout.flush()
subprocess.call(["curl"] + curl_args + ["--verbose", url])
exit(2)
result = urllib.request.urlopen(url, timeout=300)

if status_code == "200":
if result.status == 200:
if len(sys.argv) == 3 and sys.argv[2] == "enum":
result = subprocess.check_output(
["curl"] + curl_args + [url]
).decode("utf-8")
if json.loads(result) == {
result = urllib.request.urlopen(url, timeout=600)
data = result.read().decode('urf-8')
if result.status == 200 and json.loads(data) == {
"items": [{
"label": "car",
"value": "car"
Expand All @@ -68,15 +55,14 @@ if status_code == "200":
print("enum OK")
exit()
else:
print("Incorrect result:")
print(result)
print("Incorrect result ({}):".format(result.status))
print(data)
exit(2)
print("OK")
exit()
else:
print("Bad status code {}".format(status_code))
print("Bad status code {}".format(result.status))

print("RESULT:")
sys.stdout.flush()
subprocess.call(["curl"] + curl_args + ["--verbose", url])
print(result.read().decode('urf-8'))
exit(2)

0 comments on commit d6a0f58

Please sign in to comment.