Merge lp:~jamesodhunt/ubuntu/raring/sbuild/dep8-procenv into lp:ubuntu/raring/sbuild

Proposed by James Hunt
Status: Merged
Merge reported by: Martin Pitt
Merged at revision: not available
Proposed branch: lp:~jamesodhunt/ubuntu/raring/sbuild/dep8-procenv
Merge into: lp:ubuntu/raring/sbuild
Diff against target: 209 lines (+180/-0)
4 files modified
debian/changelog (+6/-0)
debian/control (+1/-0)
debian/tests/build_procenv (+170/-0)
debian/tests/control (+3/-0)
To merge this branch: bzr merge lp:~jamesodhunt/ubuntu/raring/sbuild/dep8-procenv
Reviewer Review Type Date Requested Status
Martin Pitt Approve
Jean-Baptiste Lallement (community) Needs Fixing
Review via email: mp+159596@code.launchpad.net

Description of the change

Added a DEP-8 test to exercise sbuild by performing the following:

- creates an sbuild chroot for the current release
- builds the 'procenv' package (*)
- installs the resulting .deb
- runs the command provided by the .deb

(*) - procenv was chosen to allow both the sbuild and AutoPkgTest environments to be seen by looking at the logfile for this test.

To post a comment you must log in.
Revision history for this message
James Hunt (jamesodhunt) wrote :
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Thanks for your work!

The test passes on first run, but next run will fail because schroot and sbuild configuration files created during the test are not removed at the end while the target chroot has been destroyed.

The 2 files remaining after the tests are:
- /etc/sbuild/chroot/raring-amd64-sbuild which is a broken symlink to the chroot directory
- /etc/schroot/chroot.d/raring-amd64-sbuild-XXXXXX

Note that it can potentially harm the host system if autopkgtest is run with the virt-null driver.

review: Needs Fixing
54. By James Hunt

* debian/tests/build_procenv:
  - Since schroot chroots cannot be named, avoid interfering with
    existing chroots for the current release and architecture.
  - Check schroot chroot is known.
  - Display schroot chroot info.
  - Cleanup by ending a schroot session for the chroot (if there is one)
    and removing the sbuild chroot symlink and schroot config file.

Revision history for this message
James Hunt (jamesodhunt) wrote :

Hi Jibel - thanks for testing. I've now updated the test to:

- bail (successfully) if it detects existing chroots that would interfere with the test.
- cleanup after itself.

55. By James Hunt

* debian/tests/build_procenv: Use the Debian archive as appropriate.

Revision history for this message
James Hunt (jamesodhunt) wrote :
56. By James Hunt

* debian/tests/build_procenv:
  - Use /etc/os-release rather than lsb_release for maximum portability.
  - Explicit archive url handling for debian.
  - Create chroot for latest stable debian release but latest ubuntu
    release.
  - Abort if archive cannot be determined for distribution.
  - More checks and comments.
  - Ensure package source is downloaded for correct release.
* debian/tests/control:
  - add Depends for distro-info.
  - Add 'breaks-testbed' restriction as the test manipulates files in
    /etc.

57. By James Hunt

* debian/tests/build_procenv:
  - Revert to using lsb-release: os-release is available by default, but
    does not provide release name in a portable format.
  - Only install the built .deb if the release built for matches the
    running release.
  - Perform checks on .deb since we might not be able to install it.
* debian/tests/control:
  - Removed breaks-testbed as this stops the test even running on
    Ubuntu.
  - Added lsb-release dependency.

Revision history for this message
Martin Pitt (pitti) wrote :

Verified on current saucy with "run-adt-test -sS lp:~jamesodhunt/ubuntu/raring/sbuild/dep8-procenv". Thanks!

I merged this into the saucy branch, so closing manually.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-01-17 08:59:27 +0000
3+++ debian/changelog 2013-04-23 21:33:26 +0000
4@@ -1,3 +1,9 @@
5+sbuild (0.63.2-1.1ubuntu2) UNRELEASED; urgency=low
6+
7+ * Added DEP-8 autopkgtest to build procenv.
8+
9+ -- James Hunt <james.hunt@ubuntu.com> Tue, 23 Apr 2013 22:30:35 +0100
10+
11 sbuild (0.63.2-1.1ubuntu1) raring; urgency=low
12
13 * Merge from Debian unstable. Remaining changes:
14
15=== modified file 'debian/control'
16--- debian/control 2012-06-23 22:27:58 +0000
17+++ debian/control 2013-04-23 21:33:26 +0000
18@@ -8,6 +8,7 @@
19 Standards-Version: 3.9.1
20 Vcs-Browser: http://git.debian.org/?p=buildd-tools/sbuild.git
21 Vcs-Git: git://git.debian.org/git/buildd-tools/sbuild
22+XS-Testsuite: autopkgtest
23
24 Package: libsbuild-perl
25 Architecture: all
26
27=== added directory 'debian/tests'
28=== added file 'debian/tests/build_procenv'
29--- debian/tests/build_procenv 1970-01-01 00:00:00 +0000
30+++ debian/tests/build_procenv 2013-04-23 21:33:26 +0000
31@@ -0,0 +1,170 @@
32+#!/bin/sh -e
33+#---------------------------------------------------------------------
34+# DEP-8 test for sbuild.
35+#
36+# Creates a sbuild chroot, builds a package, installs the resulting
37+# .deb, then runs the command provided by the .deb.
38+#---------------------------------------------------------------------
39+
40+die()
41+{
42+ msg="$*"
43+ echo "ERROR: $msg" >&2
44+ exit 1
45+}
46+
47+# The package we'll ask sbuild to build (we know its buildable since
48+# it's already in the archive :-)
49+#
50+# The advantage of choosing this particular package being that it runs
51+# *itself* at the end of its build, which has the nice side-effect of
52+# exposing the full sbuild environment to those perusing the autopkgtest
53+# logs.
54+pkg=procenv
55+
56+distro=$(lsb_release --id|cut -d: -f2-|awk '{print $1}'|tr '[A-Z]' '[a-z]')
57+[ -z "$distro" ] && die "cannot establish distribution"
58+
59+host_release=$(lsb_release --codename|cut -d: -f2-|awk '{print $1}')
60+[ -z "$host_release" ] && die "cannot establish release running on host"
61+
62+if [ "$distro" = ubuntu ]
63+then
64+ # Build chroot for latest release.
65+ release=$(distro-info --devel)
66+
67+ url=http://archive.ubuntu.com/ubuntu
68+elif [ "$distro" = debian ]
69+then
70+ # Build chroot for latest stable release since
71+ # sid may not be buildable on a particular day.
72+ release=$(distro-info --stable)
73+
74+ url=http://archive.debian.org/debian
75+else
76+ die "need to know where archive is for distro '$distro'"
77+fi
78+
79+arch=$(dpkg --print-architecture 2>/dev/null)
80+[ -z "$arch" ] && die "cannot establish architecture"
81+
82+[ -z "$ADTTMP" ] && die "ADTTMP not set"
83+dir="$ADTTMP/schroot-$release"
84+
85+# The expected name of the schroot that sbuild-createchroot will create
86+chroot="${release}-${arch}-sbuild"
87+
88+# schroot does not allow a chroot name to be specified at creation time.
89+# As such, we must take care to avoid stomping on a developers chroots.
90+# If we find any that match the chroot we're about to try and make, exit
91+# with a message.
92+#
93+# Note that we are very cautious in the grep check below; we purposely
94+# don't match on the _type_ of schroot in case new schroot types are
95+# added and this test is not updated to take account of the new types.
96+
97+schroots=$(schroot -l 2>/dev/null)
98+
99+if [ -n "$schroots" ] && echo "$schroots"|grep -q ":${release}-${arch}"
100+then
101+ echo "INFO:"
102+ echo "INFO: Existing schroots detected for current release ($release)"
103+ echo "INFO: and architecture ($arch)"
104+ echo "INFO:"
105+ echo "INFO: Not continuing."
106+ echo "INFO:"
107+
108+ # exit successfully
109+ exit 0
110+fi
111+
112+# Use '--download-only' to avoid unpack which generates a
113+# signature warning to stderr, causing this test to fail.
114+# Take care to download the package version for the release we will
115+# create the chroot for.
116+echo "INFO: Downloading source for package '$pkg' from release '$release'"
117+apt-get source --download-only "$pkg/$release"
118+
119+dsc=$(ls ${pkg}*.dsc)
120+
121+echo "INFO: Creating sbuild chroot '$chroot' for release '$release' in directory '$dir' from url '$url'"
122+sbuild-createchroot "$release" "$dir" "$url"
123+
124+echo "INFO: Checking chroot '$chroot' is known"
125+schroot --list --all-chroots|grep "^chroot:${chroot}$"
126+
127+echo "INFO: Displaying information about chroot '$chroot'"
128+schroot --info "${chroot}"
129+
130+# crucial
131+echo "INFO: Creating sbuild key pair"
132+sbuild-update --keygen 2>&1
133+
134+echo "INFO: Building package '$pkg' for release '$release' from '$dsc'"
135+sbuild -A -d "$release" $dsc 2>&1
136+
137+pkg_and_version=$(echo "$dsc"|sed 's/\.dsc$//g')
138+deb=${pkg_and_version}_${arch}.deb
139+
140+echo "INFO: Displaying sbuild log"
141+cat ${pkg_and_version}_${arch}*.build
142+
143+# Do what we can to check if the .deb looks usable (since we may not
144+# be able to install it to test it properly)
145+echo "INFO: Listing information on '$deb'"
146+dpkg --info "$deb"
147+
148+echo "INFO: Listing contents of '$deb'"
149+dpkg --contents "$deb"
150+
151+extract="$ADTTMP/extract"
152+echo "INFO: Extracting '$deb' to '$extract'"
153+dpkg --extract "$deb" "$extract"
154+
155+if [ "$release" = "$host_release" ]
156+then
157+ echo "INFO: Installing package '$pkg' from '$deb'"
158+ dpkg -i "$deb"
159+
160+ # run the command to prove the build worked but also to expose the
161+ # auto-package-test environment used for this test.
162+ cmd=$pkg
163+ echo "INFO: Showing AutoPkgTest environment by running '$cmd' from package '$pkg'"
164+ "$cmd"
165+else
166+ echo "INFO: Not installing package '$pkg' as host release ('$host_release')"
167+ echo "INFO: differs to release package is built for ('$release')"
168+fi
169+
170+# There is no sbuild/schroot command to actually delete the chroot, but
171+# we do want to clean up fully. The best we can do is end the schroot
172+# session, and remove the sym links. Removing the chroot itself is not
173+# necessary since it is created below $ADTTMP so will be removed
174+# automatically by the AutoPkgTest environment.
175+
176+echo "INFO: Establishing schroot sessions for chroot '$chroot'"
177+session=$(schroot --list --all-sessions|grep "^session:${release}-${arch}-" || :)
178+if [ -n "$session" ]
179+then
180+ count=$(echo "$session"|wc -l)
181+ [ $count -eq 1 ] || die "expected 1 session, found $count"
182+
183+ echo "INFO: Ending schroot session '$session'"
184+ schroot --end-session --chroot "$session"
185+else
186+ echo "INFO: No schroot session to end"
187+fi
188+
189+echo "INFO: Cleaning up"
190+
191+echo "INFO: Removing sbuild chroot symbolic link for '$chroot'"
192+link=$(ls /etc/sbuild/chroot/${chroot})
193+# remove soon-to-be-broken symbolic link
194+[ -h "$link" ] && rm "$link"
195+
196+# remove soon-to-be stale configuration file
197+echo "INFO: Removing schroot configuration file for '$chroot'"
198+config=$(ls /etc/schroot/chroot.d/${chroot}-*)
199+[ -f "$config" ] && rm "$config"
200+
201+echo "INFO: SUCCESS"
202
203=== added file 'debian/tests/control'
204--- debian/tests/control 1970-01-01 00:00:00 +0000
205+++ debian/tests/control 2013-04-23 21:33:26 +0000
206@@ -0,0 +1,3 @@
207+Tests: build_procenv
208+Depends: @, distro-info, lsb-release
209+Restrictions: needs-root

Subscribers

People subscribed via source and target branches

to all changes: