bots: Specify cafile for requests to learn-cockpit

Closes #12722
This commit is contained in:
Sanne Raymaekers 2019-09-12 09:02:58 +02:00 committed by Martin Pitt
parent c158ef3fb0
commit f9b8bb1509
4 changed files with 21 additions and 4 deletions

View File

@ -23,11 +23,14 @@ import os
import urllib
import json
import re
import ssl
sys.dont_write_bytecode = True
import task
BOTS = os.path.dirname(os.path.realpath(__file__))
NUMBER_OPEN_ISSUES = 7 # How many issues do we want to have open at a given time?
# How far back does our data go? If a flake gets fixed but is still
@ -102,12 +105,14 @@ def run(context, verbose=False, **kwargs):
host = os.environ.get("COCKPIT_LEARN_SERVICE_HOST", "learn-cockpit.apps.ci.centos.org")
port = os.environ.get("COCKPIT_LEARN_SERVICE_PORT", "443")
url = "{0}://{1}:{2}/active/".format("https" if port == "443" else "http", host, port)
cafile = os.path.join(BOTS, "images", "files", "ca.pem")
context = ssl.create_default_context(cafile=cafile)
failure_logs = slurp_failure_logs(url)
# Retrieve the URL
statistics = [ ]
with urllib.request.urlopen(url + "statistics.jsonl") as f:
with urllib.request.urlopen(url + "statistics.jsonl", context=context) as f:
for line in f.readlines():
try:
record = json.loads(line.decode('utf-8'))

View File

@ -27,6 +27,7 @@ SINCE = 21
import os
import socket
import ssl
import subprocess
import sys
import time
@ -72,7 +73,9 @@ def tail(url, until, verbose=False):
try:
req = urllib.request.Request(url, headers={ "Range": "bytes={0}-".format(at) })
with urllib.request.urlopen(req, cafile=os.path.join(BOTS, "images", "files", "ca.pem")) as f:
cafile = os.path.join(BOTS, "images", "files", "ca.pem")
context = ssl.create_default_context(cafile=cafile)
with urllib.request.urlopen(req, context=context) as f:
while True:
data = f.read(2048)
if not data:

View File

@ -24,6 +24,7 @@ import json
import re
import os
import socket
import ssl
import sys
import time
import traceback
@ -160,9 +161,11 @@ def guessFlake(output, context, verbose=False):
flake = False
url = "{0}://{1}:{2}/predict".format("https" if port == "443" else "http", host, port)
cafile = os.path.join(BOTS, "images", "files", "ca.pem")
context = ssl.create_default_context(cafile=cafile)
jsonl = json.dumps(item) + "\n"
try:
data = urllib.request.urlopen(url, data=jsonl.encode('utf-8')).read()
data = urllib.request.urlopen(url, data=jsonl.encode('utf-8'), context=context).read()
except (ConnectionResetError, urllib.error.URLError, socket.gaierror) as ex:
sys.stderr.write("{0}: {1}\n".format(url, ex))
data = b"{ }"

View File

@ -20,6 +20,7 @@
import json
import os
import socket
import ssl
import sys
import urllib
@ -27,6 +28,8 @@ sys.dont_write_bytecode = True
import task
BOTS = os.path.dirname(os.path.realpath(__file__))
# This parses the output JSONL format discussed here, where various
# values are grouped:
#
@ -49,17 +52,20 @@ def count(record, field, only):
return 0
def run(url, verbose=False, dry=False, **kwargs):
cafile = None
if not url:
host = os.environ.get("COCKPIT_LEARN_SERVICE_HOST", "learn-cockpit.apps.ci.centos.org")
port = os.environ.get("COCKPIT_LEARN_SERVICE_PORT", "443")
url = "{0}://{1}:{2}/active/statistics.jsonl".format("https" if port == "443" else "http", host, port)
cafile = os.path.join(BOTS, "images", "files", "ca.pem")
context = ssl.create_default_context(cafile=cafile)
statistics = [ ]
# Retrieve the URL
try:
req = urllib.request.Request(url)
with urllib.request.urlopen(req) as f:
with urllib.request.urlopen(req, context=context) as f:
for line in f.readlines():
try:
record = json.loads(line.decode('utf-8'))