2015-01-27 15:02:14 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import json
|
|
|
|
import urllib2
|
|
|
|
import re
|
|
|
|
import urlgrabber
|
|
|
|
import os.path
|
|
|
|
import sys
|
2015-01-28 09:58:51 +00:00
|
|
|
import subprocess
|
|
|
|
|
2015-01-30 13:58:12 +00:00
|
|
|
from report_job_results import report_results
|
2015-01-27 15:02:14 +00:00
|
|
|
|
2015-01-29 09:08:05 +00:00
|
|
|
PERSISTENT = "/var/tmp/openqa_watcher.json"
|
|
|
|
CURRENT_TEST = "https://fedoraproject.org/wiki/Test_Results:Current_Installation_Test"
|
|
|
|
ISO_URL = "https://kojipkgs.fedoraproject.org/mash/rawhide-%s/rawhide/%s/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/"
|
2015-01-30 13:58:12 +00:00
|
|
|
RUN_COMMAND = "/var/lib/openqa/script/client isos post ISO=%s DISTRI=fedora VERSION=rawhide FLAVOR=server ARCH=%s BUILD=%s_%s"
|
2015-01-28 09:58:51 +00:00
|
|
|
VERSIONS = ['i386', 'x86_64']
|
2015-01-27 15:02:14 +00:00
|
|
|
|
|
|
|
# read last tested version from file
|
|
|
|
def read_last():
|
2015-01-28 09:58:51 +00:00
|
|
|
result = {}
|
2015-01-27 15:02:14 +00:00
|
|
|
try:
|
|
|
|
f = open(PERSISTENT, "r")
|
|
|
|
json_raw = f.read()
|
|
|
|
f.close()
|
|
|
|
json_parsed = json.loads(json_raw)
|
|
|
|
except IOError:
|
2015-01-28 09:58:51 +00:00
|
|
|
return result, {}
|
|
|
|
|
|
|
|
for version in VERSIONS:
|
|
|
|
result[version] = json_parsed.get(version, None)
|
|
|
|
return result, json_parsed
|
2015-01-27 15:02:14 +00:00
|
|
|
|
|
|
|
# read current version from Current Installation Test page
|
2015-01-28 09:58:51 +00:00
|
|
|
def read_currents():
|
2015-01-27 15:02:14 +00:00
|
|
|
page = urllib2.urlopen(CURRENT_TEST).read()
|
2015-01-29 12:56:07 +00:00
|
|
|
f_regex = re.compile(r'<title>.*Fedora (?P<version>\d+).*</title>')
|
|
|
|
m = f_regex.search(page)
|
2015-01-28 09:58:51 +00:00
|
|
|
for match in ISO_REGEX.finditer(page):
|
2015-01-29 12:56:07 +00:00
|
|
|
yield m.group('version'), match.group("build"), match.group(0), match.group("name"), match.group("arch")
|
2015-01-28 09:58:51 +00:00
|
|
|
|
2015-01-29 09:08:05 +00:00
|
|
|
# download rawhide iso from koji
|
|
|
|
def download_rawhide_iso(link, name, arch):
|
2015-01-28 09:58:51 +00:00
|
|
|
isoname = "%s_%s.iso" % (name, arch)
|
|
|
|
filename = os.path.join(ISO_PATH, isoname)
|
2015-01-30 13:58:12 +00:00
|
|
|
if not os.path.isfile(filename):
|
|
|
|
link = "http://" + link[len("https://"):]
|
|
|
|
urlgrabber.urlgrab(link, filename)
|
2015-01-29 09:08:05 +00:00
|
|
|
return isoname
|
2015-01-28 09:58:51 +00:00
|
|
|
|
2015-01-29 09:08:05 +00:00
|
|
|
# run OpenQA 'isos' job on selected isoname, with given arch and build
|
|
|
|
# returns list of job IDs
|
2015-01-29 12:56:07 +00:00
|
|
|
def run_openqa_jobs(isoname, arch, fedora_version, build):
|
|
|
|
command = RUN_COMMAND % (isoname, arch, fedora_version, build)
|
2015-01-28 09:58:51 +00:00
|
|
|
|
2015-01-29 09:08:05 +00:00
|
|
|
# starts OpenQA jobs
|
2015-01-28 09:58:51 +00:00
|
|
|
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)
|
2015-01-29 09:08:05 +00:00
|
|
|
if match and match.group('to'):
|
2015-01-28 09:58:51 +00:00
|
|
|
from_i = int(match.group('from'))
|
|
|
|
to_i = int(match.group('to')) + 1
|
2015-01-29 09:08:05 +00:00
|
|
|
return range(from_i, to_i)
|
|
|
|
elif match:
|
|
|
|
return [int(match.group('from'))]
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
|
|
|
# run OpenQA on rawhide if there is newer version since last run
|
|
|
|
def run_if_newer():
|
|
|
|
last_versions, json_parsed = read_last()
|
|
|
|
jobs = []
|
|
|
|
|
|
|
|
# for every architecture
|
2015-01-29 12:56:07 +00:00
|
|
|
for f_version, current_version, link, name, arch in read_currents():
|
2015-01-29 09:08:05 +00:00
|
|
|
# don't run when there is newer version
|
|
|
|
last_version = last_versions.get(arch, None)
|
2015-02-04 16:15:08 +00:00
|
|
|
print f_version, current_version, link, name, arch,
|
2015-01-29 09:08:05 +00:00
|
|
|
if last_version is not None and (last_version == current_version):
|
2015-02-04 16:15:08 +00:00
|
|
|
print " - Skipped"
|
2015-01-29 09:08:05 +00:00
|
|
|
continue
|
|
|
|
|
2015-02-04 16:15:08 +00:00
|
|
|
print ""
|
|
|
|
|
2015-01-29 09:08:05 +00:00
|
|
|
json_parsed[arch] = current_version
|
|
|
|
|
|
|
|
isoname = download_rawhide_iso(link, name, arch)
|
2015-01-29 12:56:07 +00:00
|
|
|
job_ids = run_openqa_jobs(isoname, arch, f_version, current_version)
|
2015-01-29 09:08:05 +00:00
|
|
|
|
|
|
|
jobs.extend(job_ids)
|
|
|
|
|
|
|
|
# write info about latest versions
|
|
|
|
f = open(PERSISTENT, "w")
|
|
|
|
f.write(json.dumps(json_parsed))
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
# wait for jobs to finish and display results
|
|
|
|
print jobs
|
2015-01-30 13:58:12 +00:00
|
|
|
report_results(jobs)
|
2015-01-27 15:02:14 +00:00
|
|
|
|
|
|
|
|
2015-01-29 09:08:05 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) == 1:
|
|
|
|
run_if_newer()
|
|
|
|
elif len(sys.argv) == 3:
|
|
|
|
version = sys.argv[1]
|
|
|
|
arch = sys.argv[2]
|
|
|
|
name = "rawhide-%s" % version
|
|
|
|
link = ISO_URL % (sys.argv[1], sys.argv[2])
|
|
|
|
isoname = download_rawhide_iso(link, name, arch)
|
2015-01-29 12:56:07 +00:00
|
|
|
job_ids = run_openqa_jobs(isoname, arch, "", version)
|
2015-01-29 09:08:05 +00:00
|
|
|
print job_ids
|
|
|
|
else:
|
|
|
|
print "%s [rawhide_version arch]" % sys.arv[0]
|