work on openqa_trigger.py

This commit is contained in:
Garret Raziel 2015-01-28 10:58:51 +01:00
parent 4ae77ea8c2
commit fe2f200fe1

View File

@ -6,42 +6,69 @@ import re
import urlgrabber import urlgrabber
import os.path import os.path
import sys import sys
import subprocess
import jozuv_bomba_script
PERSISTENT="/var/tmp/openqa_watcher.json" PERSISTENT="/var/tmp/openqa_watcher.json"
CURRENT_TEST="https://fedoraproject.org/wiki/Test_Results:Current_Installation_Test" CURRENT_TEST="https://fedoraproject.org/wiki/Test_Results:Current_Installation_Test"
ISO_REGEX=re.compile(r'https://kojipkgs\.fedoraproject\.org/mash/(?P<name>rawhide-(?P<build>\d+))/rawhide/(?P<arch>(x86_64|i386))/os/images/boot\.iso') ISO_REGEX=re.compile(r'https://kojipkgs\.fedoraproject\.org/mash/(?P<name>rawhide-(?P<build>\d+))/rawhide/(?P<arch>x86_64|i386)/os/images/boot\.iso')
ISO_PATH="/var/lib/openqa/factory/iso/" ISO_PATH="/var/lib/openqa/factory/iso/"
RUN_COMMAND="/var/lib/openqa/script/client isos post ISO=%s DISTRI=fedora VERSION=rawhide FLAVOR=server ARCH=%s BUILD=%s" RUN_COMMAND="/var/lib/openqa/script/client isos post ISO=%s DISTRI=fedora VERSION=rawhide FLAVOR=server ARCH=%s BUILD=%s"
VERSIONS = ['i386', 'x86_64']
# read last tested version from file # read last tested version from file
def read_last(): def read_last():
result = {}
try: try:
f = open(PERSISTENT, "r") f = open(PERSISTENT, "r")
json_raw = f.read() json_raw = f.read()
f.close() f.close()
json_parsed = json.loads(json_raw) json_parsed = json.loads(json_raw)
except IOError: except IOError:
return None, None return result, {}
return json_parsed["last_version"], json_all
for version in VERSIONS:
result[version] = json_parsed.get(version, None)
return result, json_parsed
# read current version from Current Installation Test page # read current version from Current Installation Test page
def read_current(): def read_currents():
page = urllib2.urlopen(CURRENT_TEST).read() page = urllib2.urlopen(CURRENT_TEST).read()
match = ISO_REGEX.search(page) for match in ISO_REGEX.finditer(page):
if match: yield match.group("build"), match.group(0), match.group("name"), match.group("arch")
return match.group("build"), match.group(0), match.group("name"), match.group("arch")
else:
return None, None, None, None
last, json_all = read_last() last_versions, json_parsed = read_last()
current, link, name, arch = read_current() jobs = []
# for every architecture
for current_version, link, name, arch in read_currents():
# don't run when there is newer version # don't run when there is newer version
if last is not None and (last == current): last_version = last_versions.get(arch, None)
sys.exit() if last_version is not None and (last_version == current_version):
continue
json_parsed[arch] = current_version
isoname = "%s_%s.iso" % (name, arch) isoname = "%s_%s.iso" % (name, arch)
filename = os.path.join(ISO_PATH, isoname) filename = os.path.join(ISO_PATH, isoname)
urlgrabber.urlgrab(link, filename) urlgrabber.urlgrab(link, filename)
command = RUN_COMMAND % (isoname, arch, current) command = RUN_COMMAND % (isoname, arch, current_version)
output = subprocess.check_output(command.split())
# read ids from OpenQA to wait for
r = re.compile(r'ids => \[(?P<from>\d+)( \.\. (?P<to>\d+))?\]')
match = r.search(output)
if match:
from_i = int(match.group('from'))
to_i = int(match.group('to')) + 1
jobs.append(tuple(range(from_i, to_i)))
# write info about latest versions
f = open(PERSISTENT, "w")
f.write(json.dumps(json_parsed))
f.close()
jozuv_bomba_script.vyres_problemy(jobs)