From 4598b551c64b2f47db5f550f76c84507d28439d8 Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Thu, 12 Feb 2015 19:32:27 -0800
Subject: [PATCH] use python-wikitcms and fedfind to find current images

This replaces read_currents() by finding the 'current' release
validation event from python-wikitcms and using fedfind to
locate its images. Doesn't yet cover the case where you pass
in a version with args.
---
 tools/openqa_trigger/openqa_trigger.py | 48 +++++++++++++---------------------
 1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/tools/openqa_trigger/openqa_trigger.py b/tools/openqa_trigger/openqa_trigger.py
index 9406d0c..fdfd5fa 100755
--- a/tools/openqa_trigger/openqa_trigger.py
+++ b/tools/openqa_trigger/openqa_trigger.py
@@ -7,13 +7,13 @@ import urlgrabber
 import os.path
 import sys
 import subprocess
+import wikitcms.wiki
+import fedfind.release
 
 from report_job_results import report_results
 
 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/"
 RUN_COMMAND = "/var/lib/openqa/script/client isos post ISO=%s DISTRI=fedora VERSION=rawhide FLAVOR=server ARCH=%s BUILD=%s_%s"
 VERSIONS = ['i386', 'x86_64']
@@ -33,22 +33,13 @@ def read_last():
         result[version] = json_parsed.get(version, None)
     return result, json_parsed
 
-# read current version from Current Installation Test page
-def read_currents():
-    page = urllib2.urlopen(CURRENT_TEST).read()
-    f_regex = re.compile(r'<title>.*Fedora (?P<version>\d+).*</title>')
-    m = f_regex.search(page)
-    for match in ISO_REGEX.finditer(page):
-        yield m.group('version'), match.group("build"), match.group(0), match.group("name"), match.group("arch")
-
 # download rawhide iso from koji
-def download_rawhide_iso(link, name, arch):
-    isoname = "%s_%s.iso" % (name, arch)
+def download_rawhide_iso(image, event):
+    isoname = "{0}_{1}.iso".format(event.version.replace(' ', '_'), image.arch)
     filename = os.path.join(ISO_PATH, isoname)
     if not os.path.isfile(filename):
-        link = "http://" + link[len("https://"):]
-        urlgrabber.urlgrab(link, filename)
-    return isoname
+        urlgrabber.urlgrab(image.url, filename)
+    return filename
 
 # run OpenQA 'isos' job on selected isoname, with given arch and build
 # returns list of job IDs
@@ -75,22 +66,19 @@ def run_if_newer():
     last_versions, json_parsed = read_last()
     jobs = []
 
-    # for every architecture
-    for f_version, current_version, link, name, arch in read_currents():
-        # don't run when there is newer version
-        last_version = last_versions.get(arch, None)
-        print f_version, current_version, link, name, arch,
-        if last_version is not None and (last_version >= current_version):
-            print " - Skipped"
+    wiki = wikitcms.wiki.Wiki(('https', 'fedoraproject.org'), '/w/')
+    currev = wiki.current_event
+    query1 = fedfind.release.Query('imagetype', ('boot',))
+    query2 = fedfind.release.Query('arch', VERSIONS)
+    for image in currev.ff_release.find_images((query1, query2)):
+        last_version = last_versions.get(image.arch, None)
+        print("{0} {1}".format(image.url, image.desc))
+        if last_version and last_version >= currev.version:
+            print(" - Skipped")
             continue
-
-        print ""
-
-        json_parsed[arch] = current_version
-
-        isoname = download_rawhide_iso(link, name, arch)
-        job_ids = run_openqa_jobs(isoname, arch, f_version, current_version)
-
+        json_parsed[image.arch] = currev.version
+        isoname = download_rawhide_iso(image, currev)
+        job_ids = run_openqa_jobs(isoname, image.arch, currev.version)
         jobs.extend(job_ids)
 
     # write info about latest versions
-- 
2.1.0

