Skip to content

Instantly share code, notes, and snippets.

@dirkmueller
Last active August 29, 2015 14:26
Show Gist options
  • Save dirkmueller/c37ceb54f8f76b96df72 to your computer and use it in GitHub Desktop.
Save dirkmueller/c37ceb54f8f76b96df72 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import argparse
import functools
import os
import sh
import sys
import tempfile
IBS_MAPPING = {
'release/stoney/master': 'Devel:Cloud:4:Staging',
'release/tex/master': 'Devel:Cloud:5:Staging',
'master': 'Devel:Cloud:6:Staging'
}
CLOUDSRC = {
'release/stoney/master': 'develcloud4',
'release/tex/master': 'develcloud5',
'master': 'develcloud6'
}
htdocs_dir = '/suse/dmueller/Export/pr_test/'
htdocs_url = 'https://w3.suse.de/~dmueller/pr_test/'
def trigger_testbuild(repo, github_opts):
pr_id, head_sha1, pr_branch = github_opts.split(':')
iosc = functools.partial(sh.Command('/usr/bin/osc'),
'-A', 'https://api.suse.de')
olddir = os.getcwd()
workdir = tempfile.mkdtemp()
try:
patch_url = "https://github.com/crowbar/%s/pull/%s.patch" % (
repo, pr_id)
ptfdir = "%s-%s-%s" % (repo, pr_id, head_sha1)
webroot = os.path.join(htdocs_dir, ptfdir)
pkg = "crowbar-" + repo
if repo == "crowbar":
pkg = repo
os.chdir(workdir)
iosc('co', IBS_MAPPING[pr_branch], pkg)
os.chdir(os.path.join(IBS_MAPPING[pr_branch], pkg))
sh.curl('-s', '-k', '-L', patch_url, '-o', 'prtest.patch')
spec_add_patch = sh.Command('/usr/lib/build/spec_add_patch')
spec_add_patch(pkg + '.spec', 'prtest.patch')
iosc('vc', '-m', " added PR test patch from " + ptfdir)
buildroot = os.path.join(os.getcwd(), 'BUILD')
iosc('build', '--root', buildroot,
'--noverify', '--noservice', 'SLE_11_SP3', 'x86_64',
pkg + '.spec', _out=sys.stdout)
sh.rm('-rf', webroot)
sh.mkdir('-p', webroot)
sh.cp('-p',
sh.glob(os.path.join(buildroot,
'usr/src/packages/RPMS/*/*.rpm')),
webroot)
finally:
sh.sudo.rm('-rf', workdir)
os.chdir(olddir)
print("ready with " + htdocs_url + ptfdir)
jenkins = sh.Command(
os.path.abspath(
os.path.join(os.path.dirname(sys.argv[0]),
'jenkins/jenkins-job-trigger')))
jenkins(
'openstack-mkcloud',
'-p', 'mode=standard',
"github_pr=crowbar/%s:%s" % (repo, github_opts),
"cloudsource=" + CLOUDSRC[pr_branch],
"nodenumber=2",
"label=openstack-mkcloud-SLE12",
"UPDATEREPOS=" + htdocs_url + ptfdir,
"networkingplugin=openvswitch",
"mkcloudtarget=all_noreboot",
"all_noreboot")
ghs = sh.Command(
os.path.join(os.path.dirname(sys.argv[0]),
'github-status/github-status.rb'))
ghs('-r', 'crowbar/' + repo,
'-p', pr_id, '-c', head_sha1, '-a', 'set-status'
'-s', 'pending')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Test a crowbar/ PR')
parser.add_argument("repo", help='github ORG/REPO')
parser.add_argument('pr', help='github PR <PRID>:<SHA1>:<BRANCH>')
args = parser.parse_args()
trigger_testbuild(args.repo, args.pr)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment