From 4ae77ea8c20e20b4c53491e3cb7357add8853c6a Mon Sep 17 00:00:00 2001 From: Garret Raziel Date: Tue, 27 Jan 2015 16:02:14 +0100 Subject: [PATCH] Start of OpenQA trigger --- openqa_trigger.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 openqa_trigger.py diff --git a/openqa_trigger.py b/openqa_trigger.py new file mode 100644 index 0000000..9004c9f --- /dev/null +++ b/openqa_trigger.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +import json +import urllib2 +import re +import urlgrabber +import os.path +import sys + +PERSISTENT="/var/tmp/openqa_watcher.json" +CURRENT_TEST="https://fedoraproject.org/wiki/Test_Results:Current_Installation_Test" +ISO_REGEX=re.compile(r'https://kojipkgs\.fedoraproject\.org/mash/(?Prawhide-(?P\d+))/rawhide/(?P(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" + +# read last tested version from file +def read_last(): + try: + f = open(PERSISTENT, "r") + json_raw = f.read() + f.close() + json_parsed = json.loads(json_raw) + except IOError: + return None, None + return json_parsed["last_version"], json_all + +# read current version from Current Installation Test page +def read_current(): + page = urllib2.urlopen(CURRENT_TEST).read() + match = ISO_REGEX.search(page) + if match: + return match.group("build"), match.group(0), match.group("name"), match.group("arch") + else: + return None, None, None, None + +last, json_all = read_last() +current, link, name, arch = read_current() + +# don't run when there is newer version +if last is not None and (last == current): + sys.exit() + +isoname = "%s_%s.iso" % (name, arch) +filename = os.path.join(ISO_PATH, isoname) +urlgrabber.urlgrab(link, filename) + +command = RUN_COMMAND % (isoname, arch, current)