#!/usr/bin/env python # -*- coding: utf-8 -*- # This file is part of Cockpit. # # Copyright (C) 2016 Red Hat, Inc. # # Cockpit is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Cockpit is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Cockpit; If not, see . TRIGGERS = { "centos-7": [ "verify/centos-7" ], "continuous-atomic": [ "verify/continuous-atomic" ], "debian-testing": [ "verify/debian-testing" ], "debian-stable": [ "verify/debian-stable" ], "fedora-25": [ "verify/fedora-25", "verify/fedora-atomic" ], "fedora-26": [ "verify/fedora-26" ], "fedora-atomic": [ "verify/fedora-atomic" ], "fedora-testing": [ "verify/fedora-testing" ], "fedora-i386": [ "verify/fedora-i386" ], "ubuntu-1604": [ "verify/ubuntu-1604" ], "ubuntu-stable": [ "verify/ubuntu-stable" ], "openshift": [ "container/kubernetes", "verify/fedora-25", "verify/rhel-7", "verify/rhel-7-4" ], "ipa": [ "verify/fedora-25", "verify/rhel-7", "verify/rhel-7-4", "verify/ubuntu-1604", "verify/debian-stable" ], "rhel-7": [ "verify/rhel-7", "verify/rhel-atomic" # builds in rhel-7 ], "rhel-atomic": [ "verify/rhel-atomic" ] } REDHAT_STORE = "https://cockpit-11.e2e.bos.redhat.com:8493" STORES = { "rhel-7": REDHAT_STORE, "rhel-7-4": REDHAT_STORE, "rhel-atomic": REDHAT_STORE } import argparse import os import subprocess import socket import sys import time sys.dont_write_bytecode = True import task from task import github BOTS = os.path.abspath(os.path.dirname(__file__)) BASE = os.path.normpath(os.path.join(BOTS, "..")) def run(image, verbose=False, **kwargs): if not image: raise RuntimeError("no image specified") triggers = TRIGGERS.get(image, [ ]) store = STORES.get(image, None) # Cleanup any extraneous disk usage elsewhere subprocess.check_call([ os.path.join(BASE, "test", "vm-reset") ]) # Setup network if necessary, any failures caught during testing prep = os.path.join(BASE, "test", "vm-prep") if os.path.exists(prep): subprocess.call(["sudo", "-n", prep ]) cmd = [ os.path.join(BOTS, "image-create"), "--verbose", "--upload" ] if store: cmd += [ "--store", store ] cmd += [ image ] os.environ['VIRT_BUILDER_NO_CACHE'] = "yes" ret = subprocess.call(cmd) if ret: return ret branch = task.branch(image, "images: Update {0} image".format(image), pathspec="bots/images", **kwargs) if branch: pull = task.pull(branch, **kwargs) # Trigger this pull request head = pull["head"]["sha"] api = github.GitHub() for trigger in triggers: api.post("statuses/{0}".format(head), { "state": "pending", "context": trigger, "description": github.NOT_TESTED }) if __name__ == '__main__': task.main(function=run, title="Refresh image")