Merge lp:~nskaggs/juju-release-tools/add-snap-script into lp:juju-release-tools

Proposed by Nicholas Skaggs on 2016-08-16
Status: Needs review
Proposed branch: lp:~nskaggs/juju-release-tools/add-snap-script
Merge into: lp:juju-release-tools
Diff against target: 94 lines (+90/-0)
1 file modified
lp-build-juju-snap.py (+90/-0)
To merge this branch: bzr merge lp:~nskaggs/juju-release-tools/add-snap-script
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code 2016-08-16 Needs Information on 2016-08-16
Review via email: mp+303055@code.launchpad.net

Description of the change

Add snap creation script for edge channel.

This script requests builds for https://launchpad.net/~jujuisquality/+snap/juju. It's installed on ci-master in the jenkins user crontab. It runs daily at 1700 UTC.

To post a comment you must log in.
Curtis Hovey (sinzui) wrote :

I have some concerns inline.

review: Needs Information (code)
Nicholas Skaggs (nskaggs) wrote :

Replied with my own set of questions. In general if you want more time invested in cleaning this up, I'll do it. It's mostly just an edited clone of lp:ubuntu-core-snap; warts and all.

Unmerged revisions

331. By Nicholas Skaggs on 2016-08-16

Add snap build request script

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'lp-build-juju-snap.py'
2--- lp-build-juju-snap.py 1970-01-01 00:00:00 +0000
3+++ lp-build-juju-snap.py 2016-08-16 17:41:36 +0000
4@@ -0,0 +1,90 @@
5+#! /usr/bin/python
6+# This script will request new snap builds for the juju package. The launchpad
7+# credentials are stored in ~/juju-daily-snap/credentials
8+# Based upon lp:ubuntu-core-snap
9+# SETUP:
10+# Create the ~/juju-daily-snap directory
11+# Run once manually to setup launchpad credentials
12+
13+import os
14+import time
15+
16+from datetime import datetime
17+from launchpadlib.launchpad import Launchpad
18+
19+# basic data
20+arches = ['amd64', 'i386', 'arm64', 'ppc64el']
21+series = 'xenial'
22+
23+# basic paths
24+home = os.getenv("HOME")
25+workdir = os.path.join(home, "juju-daily-snap")
26+
27+# we need to store credentials once for cronned builds
28+cachedir = os.path.join(workdir, "cache")
29+creds = os.path.join(workdir, "credentials")
30+
31+# log in
32+launchpad = Launchpad.login_with('Juju Snap Builds',
33+ 'production', cachedir,
34+ credentials_file=creds,
35+ version='devel')
36+
37+# get team data and ppa
38+jujuqa = launchpad.people['jujuisquality']
39+
40+# get snap
41+juju_snap = launchpad.snaps.getByName(name='juju',
42+ owner=jujuqa)
43+
44+# get distro info
45+ubuntu = launchpad.distributions['ubuntu']
46+release = ubuntu.getSeries(name_or_version=series)
47+
48+# print a stamp
49+stamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
50+print("Trying to trigger builds at: {}".format(stamp))
51+
52+# loop over arches and trigger builds
53+mybuilds = []
54+for buildarch in arches:
55+ arch = release.getDistroArchSeries(archtag=buildarch)
56+ request = juju_snap.requestBuild(archive=release.main_archive,
57+ distro_arch_series=arch,
58+ pocket='Updates')
59+ buildid = str(request).rsplit('/', 1)[-1]
60+ mybuilds.append(buildid)
61+ print("Arch: {} is building under: {}".format(buildarch,
62+ request))
63+
64+# check the status each minute til all builds have finished
65+failures = []
66+while len(mybuilds):
67+ for build in mybuilds:
68+ response = juju_snap.getBuildSummariesForSnapBuildIds(
69+ snap_build_ids=[build])
70+ status = response[build]['status']
71+ if status == "FULLYBUILT":
72+ mybuilds.remove(build)
73+ continue
74+ elif status == "FAILEDTOBUILD":
75+ failures.append(build)
76+ mybuilds.remove(build)
77+ continue
78+ elif status == "CANCELLED":
79+ mybuilds.remove(build)
80+ continue
81+ time.sleep(60)
82+
83+# if we had failures, raise them
84+if len(failures):
85+ for failure in failures:
86+ response = juju_snap.getBuildSummariesForSnapBuildIds(
87+ snap_build_ids=[failure])
88+ buildlog = response[build]['build_log_url']
89+ if buildlog != 'None':
90+ print(buildlog)
91+ arch = str(buildlog).split('_')[4]
92+ raise("juju snap {} build at {} failed for id: {} log: {}".format(
93+ arch, stamp, failure, buildlog))
94+print("Builds complete")

Subscribers

People subscribed via source and target branches