Merge lp:~mvo/click/lp1319153-chroot-create into lp:click/devel

Proposed by Michael Vogt
Status: Merged
Approved by: Colin Watson
Approved revision: 426
Merged at revision: 438
Proposed branch: lp:~mvo/click/lp1319153-chroot-create
Merge into: lp:click/devel
Diff against target: 126 lines (+99/-12)
2 files modified
click/chroot.py (+14/-12)
click/tests/test_chroot.py (+85/-0)
To merge this branch: bzr merge lp:~mvo/click/lp1319153-chroot-create
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+219719@code.launchpad.net

This proposal supersedes a proposal from 2014-05-15.

Description of the change

This branch fixes ClickChroot._generate_sources(). Right now it will only generate a valid sources.list if the target arch is on ports.ubuntu.com and the native arch on archive.ubuntu.com.
Note that this is the common case (I'm not even sure we have a supported case that requires something different).

This branch fixes it and adds a test.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Doesn't this result in duplicate deb-src lines? I think it would be better to accumulate the necessary mirrors and emit deb-src lines at the end, for each pocket.

review: Needs Fixing
426. By Michael Vogt

don't duplicate deb-src lines (thanks to Colin)

Revision history for this message
Michael Vogt (mvo) wrote :

Thanks Colin! I fixed this in my branch and updated the tests.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click/chroot.py'
2--- click/chroot.py 2014-05-19 09:27:58 +0000
3+++ click/chroot.py 2014-05-20 06:30:53 +0000
4@@ -170,18 +170,20 @@
5 for pocket in ['updates', 'security']:
6 pockets.append('%s-%s' % (series, pocket))
7 sources = []
8- if target_arch not in primary_arches:
9- for pocket in pockets:
10- sources.append("deb [arch=%s] %s %s %s" %
11- (target_arch, ports_mirror, pocket, components))
12- sources.append("deb-src %s %s %s" %
13- (ports_mirror, pocket, components))
14- if native_arch in primary_arches:
15- for pocket in pockets:
16- sources.append("deb [arch=%s] %s %s %s" %
17- (native_arch, self.archive, pocket, components))
18- sources.append("deb-src %s %s %s" %
19- (self.archive, pocket, components))
20+ # write binary lines
21+ for arch in (target_arch, native_arch):
22+ if arch not in primary_arches:
23+ mirror = ports_mirror
24+ else:
25+ mirror = self.archive
26+ for pocket in pockets:
27+ sources.append("deb [arch=%s] %s %s %s" %
28+ (arch, mirror, pocket, components))
29+ # write source lines
30+ for pocket in pockets:
31+ sources.append("deb-src %s %s %s" %
32+ (self.archive, pocket, components))
33+
34 return sources
35
36 @property
37
38=== added file 'click/tests/test_chroot.py'
39--- click/tests/test_chroot.py 1970-01-01 00:00:00 +0000
40+++ click/tests/test_chroot.py 2014-05-20 06:30:53 +0000
41@@ -0,0 +1,85 @@
42+# Copyright (C) 2014 Canonical Ltd.
43+# Author: Michael Vogt
44+
45+# This program is free software: you can redistribute it and/or modify
46+# it under the terms of the GNU General Public License as published by
47+# the Free Software Foundation; version 3 of the License.
48+#
49+# This program is distributed in the hope that it will be useful,
50+# but WITHOUT ANY WARRANTY; without even the implied warranty of
51+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52+# GNU General Public License for more details.
53+#
54+# You should have received a copy of the GNU General Public License
55+# along with this program. If not, see <http://www.gnu.org/licenses/>.
56+
57+"""Unit tests for click.chroot."""
58+
59+from __future__ import print_function
60+
61+__metaclass__ = type
62+__all__ = [
63+ 'TestClickChroot',
64+ ]
65+
66+
67+from click.tests.helpers import TestCase
68+from click.chroot import (
69+ ClickChroot,
70+)
71+
72+
73+class TestClickChroot(TestCase):
74+ def test_gen_sources_archive_only(self):
75+ chroot = ClickChroot("amd64", "ubuntu-sdk-13.10", series="trusty")
76+ chroot.native_arch = "i386"
77+ sources = chroot._generate_sources(
78+ chroot.series, chroot.native_arch, chroot.target_arch,
79+ "main")
80+ self.assertEqual([
81+ 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu trusty main',
82+ 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu trusty-updates main',
83+ 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu trusty-security main',
84+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty main',
85+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty-updates main',
86+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty-security main',
87+ 'deb-src http://archive.ubuntu.com/ubuntu trusty main',
88+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-updates main',
89+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-security main',
90+ ], sources)
91+
92+ def test_gen_sources_mixed_archive_ports(self):
93+ chroot = ClickChroot("armhf", "ubuntu-sdk-13.10", series="trusty")
94+ chroot.native_arch = "i386"
95+ sources = chroot._generate_sources(
96+ chroot.series, chroot.native_arch, chroot.target_arch,
97+ "main")
98+ self.assertEqual([
99+ 'deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports trusty main',
100+ 'deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports trusty-updates main',
101+ 'deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports trusty-security main',
102+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty main',
103+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty-updates main',
104+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty-security main',
105+ 'deb-src http://archive.ubuntu.com/ubuntu trusty main',
106+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-updates main',
107+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-security main',
108+ ], sources)
109+
110+ def test_gen_sources_ports_only(self):
111+ chroot = ClickChroot("armhf", "ubuntu-sdk-13.10", series="trusty")
112+ chroot.native_arch = "armel"
113+ sources = chroot._generate_sources(
114+ chroot.series, chroot.native_arch, chroot.target_arch,
115+ "main")
116+ self.assertEqual([
117+ 'deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports trusty main',
118+ 'deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports trusty-updates main',
119+ 'deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports trusty-security main',
120+ 'deb [arch=armel] http://ports.ubuntu.com/ubuntu-ports trusty main',
121+ 'deb [arch=armel] http://ports.ubuntu.com/ubuntu-ports trusty-updates main',
122+ 'deb [arch=armel] http://ports.ubuntu.com/ubuntu-ports trusty-security main',
123+ 'deb-src http://archive.ubuntu.com/ubuntu trusty main',
124+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-updates main',
125+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-security main',
126+ ], sources)

Subscribers

People subscribed via source and target branches

to all changes: