Merge lp:~stevenk/launchpad/ids-no-more-sampledata into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 11682
Proposed branch: lp:~stevenk/launchpad/ids-no-more-sampledata
Merge into: lp:launchpad
Diff against target: 539 lines (+185/-166)
4 files modified
lib/lp/soyuz/interfaces/packagecloner.py (+6/-1)
lib/lp/soyuz/model/packagecloner.py (+26/-7)
lib/lp/soyuz/scripts/initialise_distroseries.py (+1/-1)
lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py (+152/-157)
To merge this branch: bzr merge lp:~stevenk/launchpad/ids-no-more-sampledata
Reviewer Review Type Date Requested Status
Michael Nelson (community) code Approve
Review via email: mp+37102@code.launchpad.net

Commit message

Remove sample data from the tests for InitialiseDistroSeries, and fix rebuild support.

Description of the change

First, a little bit of history: The tests for (what is now) InitialiseDistroSeries used to be a doctest, and I split them out in a unit test, replicating every part of the doctest. This branch now removes the tests dependence on sample data, as well as removing two unit tests that no longer make sense since they were dependent on sample data to function correctly.

The tests now creates a fresh distroseries in the setup, and populates it with four source packages, 3 binary packages and 1 failed to build. Mostly this is just moving code around, along with dropping the word 'foobuntu' everywhere I saw it.

It also fixes a bug, which was previously being masked by using the sampledata -- it now creates builds unilaterally if one doesn't exist when the rebuild=True option is passed in, and tests that correctly, rather than using hard-coded numerical values.

Finally, I cleaned up some lint that I noticed.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :
Download full text (6.3 KiB)

Hi Steven,

Great work for getting rid of the dependence on sample data!

I've just got two questions (more details below):

1) Do you think it's worth renaming createMissingBuilds() now that it also
creates builds that weren't missing (or did I mis-understand)? Or, on the
other hand (and this is my fault), if you don't see the always_create option
being used outside of the package cloner, it might be best as you originally
had it (ie. not modifying createMissingBuilds(), but just creating the builds
in the package cloner as you did originally).

2) If you do decide to keep the extra kwarg for createMissingBuilds() (or
however you rename it), we should add a test for this call specifically
(ie. test_createMissingBuilds_always_create() in test_publishing).

Cheers,
Michael

> === modified file 'lib/lp/soyuz/interfaces/publishing.py'
> --- lib/lp/soyuz/interfaces/publishing.py 2010-09-17 17:03:38 +0000
> +++ lib/lp/soyuz/interfaces/publishing.py 2010-09-30 10:48:06 +0000
> @@ -514,7 +514,7 @@
> """
>
> def createMissingBuilds(architectures_available=None, pas_verify=None,
> - logger=None):
> + logger=None, always_create=False):

The use of createMissingBuilds(always_create=True) seems a bit strange,
because if you pass always_create=True, you're not creating a missing build. What
do you think of:
       def createBuilds(..., missing_only=True) ?

hrm, I'm not sure... thoughts?

> === modified file 'lib/lp/soyuz/model/publishing.py'
> --- lib/lp/soyuz/model/publishing.py 2010-09-27 14:35:58 +0000
> +++ lib/lp/soyuz/model/publishing.py 2010-09-30 10:48:06 +0000
> @@ -563,7 +563,8 @@
> self.archive.enabled_restricted_families]
>
> def createMissingBuilds(self, architectures_available=None,
> - pas_verify=None, logger=None):
> + pas_verify=None, logger=None,
> + always_create=False):
> """See `ISourcePackagePublishingHistory`."""
> if self.archive.is_ppa:
> pas_verify = None
> @@ -581,24 +582,26 @@
> builds = []
> for arch in build_architectures:
> build_candidate = self._createMissingBuildForArchitecture(
> - arch, logger=logger)
> + arch, always_create=always_create, logger=logger)
> if build_candidate is not None:
> builds.append(build_candidate)
>
> return builds
>
> - def _createMissingBuildForArchitecture(self, arch, logger=None):
> + def _createMissingBuildForArchitecture(
> + self, arch, always_create, logger=None):
> """Create a build for a given architecture if it doesn't exist yet.

The "if it doesn't exist yet" needs to be removed I think?
>
> Return the just-created `IBinaryPackageBuild` record already
> - scored or None if a suitable build is already present.
> + scored or None if a suitable build is already present, except if
> + always_create is True, in which case a build is always created.
> """

same as above for 'always_create' as an arg to
_createMissingBuildForArchit...

Read more...

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/soyuz/interfaces/packagecloner.py'
--- lib/lp/soyuz/interfaces/packagecloner.py 2010-08-20 20:31:18 +0000
+++ lib/lp/soyuz/interfaces/packagecloner.py 2010-10-06 11:42:43 +0000
@@ -17,7 +17,9 @@
17class IPackageCloner(Interface):17class IPackageCloner(Interface):
18 """Copies publishing history data across archives."""18 """Copies publishing history data across archives."""
1919
20 def clonePackages(origin, destination, distroarchseries_list=None):20 def clonePackages(
21 origin, destination, distroarchseries_list=None,
22 proc_familes=None, always_create=False):
21 """Copies the source packages from origin to destination as23 """Copies the source packages from origin to destination as
22 well as the binary packages for the DistroArchSeries specified.24 well as the binary packages for the DistroArchSeries specified.
2325
@@ -25,6 +27,9 @@
25 :param destination: the location to which the data is to be copied.27 :param destination: the location to which the data is to be copied.
26 :param distroarchseries_list: the binary packages will be copied28 :param distroarchseries_list: the binary packages will be copied
27 for the distroarchseries pairs specified (if any).29 for the distroarchseries pairs specified (if any).
30 :param proc_familes: the processor families that builds will be
31 created for.
32 :param always_create: if builds should always be created.
28 """33 """
2934
30 def mergeCopy(origin, destination):35 def mergeCopy(origin, destination):
3136
=== modified file 'lib/lp/soyuz/model/packagecloner.py'
--- lib/lp/soyuz/model/packagecloner.py 2010-08-24 15:29:01 +0000
+++ lib/lp/soyuz/model/packagecloner.py 2010-10-06 11:42:43 +0000
@@ -26,6 +26,7 @@
26 IStoreSelector,26 IStoreSelector,
27 MAIN_STORE,27 MAIN_STORE,
28 )28 )
29from lp.registry.interfaces.pocket import PackagePublishingPocket
29from lp.soyuz.enums import PackagePublishingStatus30from lp.soyuz.enums import PackagePublishingStatus
30from lp.soyuz.interfaces.archivearch import IArchiveArchSet31from lp.soyuz.interfaces.archivearch import IArchiveArchSet
31from lp.soyuz.interfaces.packagecloner import IPackageCloner32from lp.soyuz.interfaces.packagecloner import IPackageCloner
@@ -60,7 +61,7 @@
60 implements(IPackageCloner)61 implements(IPackageCloner)
6162
62 def clonePackages(self, origin, destination, distroarchseries_list=None,63 def clonePackages(self, origin, destination, distroarchseries_list=None,
63 proc_families=None):64 proc_families=None, always_create=False):
64 """Copies packages from origin to destination package location.65 """Copies packages from origin to destination package location.
6566
66 Binary packages are only copied for the `DistroArchSeries` pairs67 Binary packages are only copied for the `DistroArchSeries` pairs
@@ -74,7 +75,11 @@
74 distroarchseries instances.75 distroarchseries instances.
75 @param distroarchseries_list: the binary packages will be copied76 @param distroarchseries_list: the binary packages will be copied
76 for the distroarchseries pairs specified (if any).77 for the distroarchseries pairs specified (if any).
77 @param the processor families to create builds for.78 @param proc_families: the processor families to create builds for.
79 @type proc_families: Iterable
80 @param always_create: if we should create builds for every source
81 package copied, useful if no binaries are to be copied.
82 @type always_create: Boolean
78 """83 """
79 # First clone the source packages.84 # First clone the source packages.
80 self._clone_source_packages(origin, destination)85 self._clone_source_packages(origin, destination)
@@ -90,9 +95,12 @@
90 proc_families = []95 proc_families = []
9196
92 self._create_missing_builds(97 self._create_missing_builds(
93 destination.distroseries, destination.archive, proc_families)98 destination.distroseries, destination.archive,
99 distroarchseries_list, proc_families, always_create)
94100
95 def _create_missing_builds(self, distroseries, archive, proc_families):101 def _create_missing_builds(
102 self, distroseries, archive, distroarchseries_list,
103 proc_families, always_create):
96 """Create builds for all cloned source packages.104 """Create builds for all cloned source packages.
97105
98 :param distroseries: the distro series for which to create builds.106 :param distroseries: the distro series for which to create builds.
@@ -126,7 +134,16 @@
126 return pub.sourcepackagerelease.sourcepackagename.name134 return pub.sourcepackagerelease.sourcepackagename.name
127135
128 for pubrec in sources_published:136 for pubrec in sources_published:
129 pubrec.createMissingBuilds(architectures_available=architectures)137 builds = pubrec.createMissingBuilds(
138 architectures_available=architectures)
139 # If the last build was sucessful, we should create a new
140 # build, since createMissingBuilds() won't.
141 if not builds and always_create:
142 for arch in architectures:
143 build = pubrec.sourcepackagerelease.createBuild(
144 distro_arch_series=arch, archive=archive,
145 pocket=PackagePublishingPocket.RELEASE)
146 build.queueBuild(suspended=not archive.enabled)
130 # Commit to avoid MemoryError: bug 304459147 # Commit to avoid MemoryError: bug 304459
131 transaction.commit()148 transaction.commit()
132149
@@ -216,7 +233,8 @@
216 in getUtility(IArchiveArchSet).getByArchive(destination.archive)]233 in getUtility(IArchiveArchSet).getByArchive(destination.archive)]
217234
218 self._create_missing_builds(235 self._create_missing_builds(
219 destination.distroseries, destination.archive, proc_families)236 destination.distroseries, destination.archive, (),
237 proc_families, False)
220238
221 def _compute_packageset_delta(self, origin):239 def _compute_packageset_delta(self, origin):
222 """Given a source/target archive find obsolete or missing packages.240 """Given a source/target archive find obsolete or missing packages.
@@ -245,7 +263,8 @@
245 secsrc.sourcepackagerelease = spr.id AND263 secsrc.sourcepackagerelease = spr.id AND
246 spr.sourcepackagename = spn.id AND264 spr.sourcepackagename = spn.id AND
247 spn.name = mcd.sourcepackagename AND265 spn.name = mcd.sourcepackagename AND
248 debversion_sort_key(spr.version) > debversion_sort_key(mcd.t_version)266 debversion_sort_key(spr.version) >
267 debversion_sort_key(mcd.t_version)
249 """ % sqlvalues(268 """ % sqlvalues(
250 origin.archive,269 origin.archive,
251 PackagePublishingStatus.PENDING,270 PackagePublishingStatus.PENDING,
252271
=== modified file 'lib/lp/soyuz/scripts/initialise_distroseries.py'
--- lib/lp/soyuz/scripts/initialise_distroseries.py 2010-09-22 06:42:40 +0000
+++ lib/lp/soyuz/scripts/initialise_distroseries.py 2010-10-06 11:42:43 +0000
@@ -203,7 +203,7 @@
203 distroarchseries_list = ()203 distroarchseries_list = ()
204 getUtility(IPackageCloner).clonePackages(204 getUtility(IPackageCloner).clonePackages(
205 origin, destination, distroarchseries_list,205 origin, destination, distroarchseries_list,
206 proc_families)206 proc_families, self.rebuild)
207207
208 def _copy_component_section_and_format_selections(self):208 def _copy_component_section_and_format_selections(self):
209 """Copy the section, component and format selections from the parent209 """Copy the section, component and format selections from the parent
210210
=== modified file 'lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py'
--- lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 2010-09-22 06:42:40 +0000
+++ lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 2010-10-06 11:42:43 +0000
@@ -13,7 +13,6 @@
13from zope.component import getUtility13from zope.component import getUtility
1414
15from canonical.config import config15from canonical.config import config
16from canonical.launchpad.interfaces import IDistributionSet
17from canonical.launchpad.interfaces.lpstorm import IStore16from canonical.launchpad.interfaces.lpstorm import IStore
18from canonical.testing.layers import LaunchpadZopelessLayer17from canonical.testing.layers import LaunchpadZopelessLayer
19from lp.buildmaster.enums import BuildStatus18from lp.buildmaster.enums import BuildStatus
@@ -21,15 +20,16 @@
21from lp.soyuz.enums import SourcePackageFormat20from lp.soyuz.enums import SourcePackageFormat
22from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet21from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
23from lp.soyuz.interfaces.packageset import IPackagesetSet22from lp.soyuz.interfaces.packageset import IPackagesetSet
23from lp.soyuz.interfaces.publishing import PackagePublishingStatus
24from lp.soyuz.interfaces.sourcepackageformat import (
25 ISourcePackageFormatSelectionSet,
26 )
24from lp.soyuz.model.distroarchseries import DistroArchSeries27from lp.soyuz.model.distroarchseries import DistroArchSeries
25from lp.soyuz.scripts.initialise_distroseries import (28from lp.soyuz.scripts.initialise_distroseries import (
26 InitialisationError,29 InitialisationError,
27 InitialiseDistroSeries,30 InitialiseDistroSeries,
28 )31 )
29from lp.testing import (32from lp.testing import TestCaseWithFactory
30 login,
31 TestCaseWithFactory,
32 )
3333
3434
35class TestInitialiseDistroSeries(TestCaseWithFactory):35class TestInitialiseDistroSeries(TestCaseWithFactory):
@@ -38,33 +38,59 @@
3838
39 def setUp(self):39 def setUp(self):
40 super(TestInitialiseDistroSeries, self).setUp()40 super(TestInitialiseDistroSeries, self).setUp()
41 login("foo.bar@canonical.com")41 self.parent = self.factory.makeDistroSeries()
42 distribution_set = getUtility(IDistributionSet)42 pf = self.factory.makeProcessorFamily()
43 self.ubuntutest = distribution_set['ubuntutest']43 pf.addProcessor('x86', '', '')
44 self.ubuntu = distribution_set['ubuntu']44 self.parent_das = self.factory.makeDistroArchSeries(
45 self.hoary = self.ubuntu['hoary']45 distroseries=self.parent, processorfamily=pf)
4646 lf = self.factory.makeLibraryFileAlias()
47 def _create_distroseries(self, parent_series):47 transaction.commit()
48 return self.ubuntutest.newSeries(48 self.parent_das.addOrUpdateChroot(lf)
49 'foobuntu', 'FooBuntu', 'The Foobuntu', 'yeck', 'doom',49 self.parent_das.supports_virtualized = True
50 '888', parent_series, self.hoary.owner)50 self.parent.nominatedarchindep = self.parent_das
5151 getUtility(ISourcePackageFormatSelectionSet).add(
52 def _set_pending_to_failed(self, distroseries):52 self.parent, SourcePackageFormat.FORMAT_1_0)
53 pending_builds = distroseries.getBuildRecords(53 self._populate_parent()
54 BuildStatus.NEEDSBUILD, pocket=PackagePublishingPocket.RELEASE)54
55 for build in pending_builds:55 def _populate_parent(self):
56 build.status = BuildStatus.FAILEDTOBUILD56 packages = {'udev': '0.1-1', 'libc6': '2.8-1',
57 'postgresql': '9.0-1', 'chromium': '3.6'}
58 for package in packages.keys():
59 spn = self.factory.makeSourcePackageName(package)
60 spph = self.factory.makeSourcePackagePublishingHistory(
61 sourcepackagename=spn, version=packages[package],
62 distroseries=self.parent,
63 pocket=PackagePublishingPocket.RELEASE,
64 status=PackagePublishingStatus.PUBLISHED)
65 status = BuildStatus.FULLYBUILT
66 if package is 'chromium':
67 status = BuildStatus.FAILEDTOBUILD
68 bpn = self.factory.makeBinaryPackageName(package)
69 build = self.factory.makeBinaryPackageBuild(
70 source_package_release=spph.sourcepackagerelease,
71 distroarchseries=self.parent_das,
72 status=status)
73 bpr = self.factory.makeBinaryPackageRelease(
74 binarypackagename=bpn, build=build,
75 version=packages[package])
76 if package is not 'chromium':
77 self.factory.makeBinaryPackagePublishingHistory(
78 binarypackagerelease=bpr,
79 distroarchseries=self.parent_das,
80 pocket=PackagePublishingPocket.RELEASE,
81 status=PackagePublishingStatus.PUBLISHED)
5782
58 def test_failure_with_no_parent_series(self):83 def test_failure_with_no_parent_series(self):
59 # Initialising a new distro series requires a parent series to be set84 # Initialising a new distro series requires a parent series to be set
60 foobuntu = self._create_distroseries(None)85 ids = InitialiseDistroSeries(self.factory.makeDistroSeries())
61 ids = InitialiseDistroSeries(foobuntu)
62 self.assertRaisesWithContent(86 self.assertRaisesWithContent(
63 InitialisationError, "Parent series required.", ids.check)87 InitialisationError, "Parent series required.", ids.check)
6488
65 def test_failure_for_already_released_distroseries(self):89 def test_failure_for_already_released_distroseries(self):
66 # Initialising a distro series that has already been used will error90 # Initialising a distro series that has already been used will error
67 ids = InitialiseDistroSeries(self.ubuntutest['breezy-autotest'])91 child = self.factory.makeDistroSeries(parent_series=self.parent)
92 self.factory.makeDistroArchSeries(distroseries=child)
93 ids = InitialiseDistroSeries(child)
68 self.assertRaisesWithContent(94 self.assertRaisesWithContent(
69 InitialisationError,95 InitialisationError,
70 "Can not copy distroarchseries from parent, there are already "96 "Can not copy distroarchseries from parent, there are already "
@@ -72,9 +98,13 @@
7298
73 def test_failure_with_pending_builds(self):99 def test_failure_with_pending_builds(self):
74 # If the parent series has pending builds, we can't initialise100 # If the parent series has pending builds, we can't initialise
75 foobuntu = self._create_distroseries(self.hoary)101 source = self.factory.makeSourcePackagePublishingHistory(
76 transaction.commit()102 distroseries=self.parent,
77 ids = InitialiseDistroSeries(foobuntu)103 pocket=PackagePublishingPocket.RELEASE)
104 source.createMissingBuilds()
105 child = self.factory.makeDistroSeries(
106 parent_series=self.parent)
107 ids = InitialiseDistroSeries(child)
78 self.assertRaisesWithContent(108 self.assertRaisesWithContent(
79 InitialisationError, "Parent series has pending builds.",109 InitialisationError, "Parent series has pending builds.",
80 ids.check)110 ids.check)
@@ -82,190 +112,155 @@
82 def test_failure_with_queue_items(self):112 def test_failure_with_queue_items(self):
83 # If the parent series has items in its queues, such as NEW and113 # If the parent series has items in its queues, such as NEW and
84 # UNAPPROVED, we can't initialise114 # UNAPPROVED, we can't initialise
85 foobuntu = self._create_distroseries(115 self.parent.createQueueEntry(
86 self.ubuntu['breezy-autotest'])116 PackagePublishingPocket.RELEASE,
87 ids = InitialiseDistroSeries(foobuntu)117 'foo.changes', 'bar', self.parent.main_archive)
118 child = self.factory.makeDistroSeries(parent_series=self.parent)
119 ids = InitialiseDistroSeries(child)
88 self.assertRaisesWithContent(120 self.assertRaisesWithContent(
89 InitialisationError, "Parent series queues are not empty.",121 InitialisationError, "Parent series queues are not empty.",
90 ids.check)122 ids.check)
91123
92 def assertDistroSeriesInitialisedCorrectly(self, foobuntu):124 def assertDistroSeriesInitialisedCorrectly(self, child):
93 # Check that 'pmount' has been copied correctly125 # Check that 'udev' has been copied correctly
94 hoary_pmount_pubs = self.hoary.getPublishedSources('pmount')126 parent_udev_pubs = self.parent.getPublishedSources('udev')
95 foobuntu_pmount_pubs = foobuntu.getPublishedSources('pmount')127 child_udev_pubs = child.getPublishedSources('udev')
96 self.assertEqual(128 self.assertEqual(
97 hoary_pmount_pubs.count(),129 parent_udev_pubs.count(), child_udev_pubs.count())
98 foobuntu_pmount_pubs.count())130 parent_arch_udev_pubs = self.parent[
99 hoary_i386_pmount_pubs = self.hoary['i386'].getReleasedPackages(131 self.parent_das.architecturetag].getReleasedPackages('udev')
100 'pmount')132 child_arch_udev_pubs = child[
101 foobuntu_i386_pmount_pubs = foobuntu['i386'].getReleasedPackages(133 self.parent_das.architecturetag].getReleasedPackages('udev')
102 'pmount')134 self.assertEqual(
103 self.assertEqual(135 len(parent_arch_udev_pubs), len(child_arch_udev_pubs))
104 len(hoary_i386_pmount_pubs), len(foobuntu_i386_pmount_pubs))
105 # And the binary package, and linked source package look fine too136 # And the binary package, and linked source package look fine too
106 pmount_binrel = (137 udev_bin = child_arch_udev_pubs[0].binarypackagerelease
107 foobuntu['i386'].getReleasedPackages(138 self.assertEqual(udev_bin.title, u'udev-0.1-1')
108 'pmount')[0].binarypackagerelease)
109 self.assertEqual(pmount_binrel.title, u'pmount-0.1-1')
110 self.assertEqual(pmount_binrel.build.id, 7)
111 self.assertEqual(139 self.assertEqual(
112 pmount_binrel.build.title,140 udev_bin.build.title,
113 u'i386 build of pmount 0.1-1 in ubuntu hoary RELEASE')141 u'%s build of udev 0.1-1 in %s %s RELEASE' % (
114 pmount_srcrel = pmount_binrel.build.source_package_release142 self.parent_das.architecturetag, self.parent.parent.name,
115 self.assertEqual(pmount_srcrel.title, u'pmount - 0.1-1')143 self.parent.name))
116 # The build of pmount 0.1-1 has been copied across.144 udev_src = udev_bin.build.source_package_release
117 foobuntu_pmount = pmount_srcrel.getBuildByArch(145 self.assertEqual(udev_src.title, u'udev - 0.1-1')
118 foobuntu['i386'], foobuntu.main_archive)146 # The build of udev 0.1-1 has been copied across.
119 hoary_pmount = pmount_srcrel.getBuildByArch(147 child_udev = udev_src.getBuildByArch(
120 self.hoary['i386'], self.hoary.main_archive)148 child[self.parent_das.architecturetag], child.main_archive)
121 self.assertEqual(foobuntu_pmount.id, hoary_pmount.id)149 parent_udev = udev_src.getBuildByArch(
150 self.parent[self.parent_das.architecturetag],
151 self.parent.main_archive)
152 self.assertEqual(parent_udev.id, child_udev.id)
122 # We also inherient the permitted source formats from our parent153 # We also inherient the permitted source formats from our parent
123 self.assertTrue(154 self.assertTrue(
124 foobuntu.isSourcePackageFormatPermitted(155 child.isSourcePackageFormatPermitted(
125 SourcePackageFormat.FORMAT_1_0))156 SourcePackageFormat.FORMAT_1_0))
126157
127 def _full_initialise(self, arches=(), rebuild=False):158 def _full_initialise(self, arches=(), rebuild=False):
128 foobuntu = self._create_distroseries(self.hoary)159 child = self.factory.makeDistroSeries(parent_series=self.parent)
129 self._set_pending_to_failed(self.hoary)160 ids = InitialiseDistroSeries(child, arches, rebuild)
130 transaction.commit()
131 ids = InitialiseDistroSeries(foobuntu, arches, rebuild)
132 ids.check()161 ids.check()
133 ids.initialise()162 ids.initialise()
134 return foobuntu163 return child
135164
136 def test_initialise(self):165 def test_initialise(self):
137 # Test a full initialise with no errors166 # Test a full initialise with no errors
138 foobuntu = self._full_initialise()167 child = self._full_initialise()
139 self.assertDistroSeriesInitialisedCorrectly(foobuntu)168 self.assertDistroSeriesInitialisedCorrectly(child)
140169
141 def test_initialise_only_i386(self):170 def test_initialise_only_one_das(self):
142 # Test a full initialise with no errors, but only copy i386 to171 # Test a full initialise with no errors, but only copy i386 to
143 # the child172 # the child
144 foobuntu = self._full_initialise(arches=('i386',))173 self.factory.makeDistroArchSeries(distroseries=self.parent)
145 self.assertDistroSeriesInitialisedCorrectly(foobuntu)174 child = self._full_initialise(
175 arches=[self.parent_das.architecturetag])
176 self.assertDistroSeriesInitialisedCorrectly(child)
146 das = list(IStore(DistroArchSeries).find(177 das = list(IStore(DistroArchSeries).find(
147 DistroArchSeries, distroseries = foobuntu))178 DistroArchSeries, distroseries = child))
148 self.assertEqual(len(das), 1)179 self.assertEqual(len(das), 1)
149 self.assertEqual(das[0].architecturetag, 'i386')180 self.assertEqual(
150181 das[0].architecturetag, self.parent_das.architecturetag)
151 def test_check_no_builds(self):
152 # Test that there is no build for pmount 0.1-2 in the
153 # newly-initialised series.
154 foobuntu = self._full_initialise()
155 pmount_source = self.hoary.getSourcePackage(
156 'pmount').currentrelease
157 self.assertEqual(
158 pmount_source.title,
159 '"pmount" 0.1-2 source package in The Hoary Hedgehog Release')
160 pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
161 self.assertEqual(
162 pmount_source.title,
163 '"pmount" 0.1-2 source package in The Foobuntu')
164 self.assertEqual(
165 pmount_source.sourcepackagerelease.getBuildByArch(
166 foobuntu['i386'], foobuntu.main_archive), None)
167 self.assertEqual(
168 pmount_source.sourcepackagerelease.getBuildByArch(
169 foobuntu['hppa'], foobuntu.main_archive), None)
170
171 def test_create_builds(self):
172 # It turns out the sampledata of hoary includes pmount 0.1-1 as well
173 # as pmount 0.1-2 source, and if foobuntu and hoary don't share a
174 # pool, 0.1-1 will be marked as NBS and removed. So let's check that
175 # builds can be created for foobuntu.
176 foobuntu = self._full_initialise()
177 pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
178 created_build = pmount_source.sourcepackagerelease.createBuild(
179 foobuntu['i386'], PackagePublishingPocket.RELEASE,
180 foobuntu.main_archive)
181 retrieved_build = pmount_source.sourcepackagerelease.getBuildByArch(
182 foobuntu['i386'], foobuntu.main_archive)
183 self.assertEqual(retrieved_build.id, created_build.id)
184 self.assertEqual(
185 'i386 build of pmount 0.1-2 in ubuntutest foobuntu RELEASE',
186 created_build.title)
187182
188 def test_copying_packagesets(self):183 def test_copying_packagesets(self):
189 # If a parent series has packagesets, we should copy them184 # If a parent series has packagesets, we should copy them
190 uploader = self.factory.makePerson()185 uploader = self.factory.makePerson()
191 test1 = getUtility(IPackagesetSet).new(186 test1 = getUtility(IPackagesetSet).new(
192 u'test1', u'test 1 packageset', self.hoary.owner,187 u'test1', u'test 1 packageset', self.parent.owner,
193 distroseries=self.hoary)188 distroseries=self.parent)
194 test2 = getUtility(IPackagesetSet).new(189 test2 = getUtility(IPackagesetSet).new(
195 u'test2', u'test 2 packageset', self.hoary.owner,190 u'test2', u'test 2 packageset', self.parent.owner,
196 distroseries=self.hoary)191 distroseries=self.parent)
197 test3 = getUtility(IPackagesetSet).new(192 test3 = getUtility(IPackagesetSet).new(
198 u'test3', u'test 3 packageset', self.hoary.owner,193 u'test3', u'test 3 packageset', self.parent.owner,
199 distroseries=self.hoary, related_set=test2)194 distroseries=self.parent, related_set=test2)
200 test1.addSources('pmount')195 test1.addSources('udev')
201 getUtility(IArchivePermissionSet).newPackagesetUploader(196 getUtility(IArchivePermissionSet).newPackagesetUploader(
202 self.hoary.main_archive, uploader, test1)197 self.parent.main_archive, uploader, test1)
203 foobuntu = self._full_initialise()198 child = self._full_initialise()
204 # We can fetch the copied sets from foobuntu199 # We can fetch the copied sets from the child
205 foobuntu_test1 = getUtility(IPackagesetSet).getByName(200 child_test1 = getUtility(IPackagesetSet).getByName(
206 u'test1', distroseries=foobuntu)201 u'test1', distroseries=child)
207 foobuntu_test2 = getUtility(IPackagesetSet).getByName(202 child_test2 = getUtility(IPackagesetSet).getByName(
208 u'test2', distroseries=foobuntu)203 u'test2', distroseries=child)
209 foobuntu_test3 = getUtility(IPackagesetSet).getByName(204 child_test3 = getUtility(IPackagesetSet).getByName(
210 u'test3', distroseries=foobuntu)205 u'test3', distroseries=child)
211 # And we can see they are exact copies, with the related_set for the206 # And we can see they are exact copies, with the related_set for the
212 # copies pointing to the packageset in the parent207 # copies pointing to the packageset in the parent
213 self.assertEqual(test1.description, foobuntu_test1.description)208 self.assertEqual(test1.description, child_test1.description)
214 self.assertEqual(test2.description, foobuntu_test2.description)209 self.assertEqual(test2.description, child_test2.description)
215 self.assertEqual(test3.description, foobuntu_test3.description)210 self.assertEqual(test3.description, child_test3.description)
216 self.assertEqual(foobuntu_test1.relatedSets().one(), test1)211 self.assertEqual(child_test1.relatedSets().one(), test1)
217 self.assertEqual(212 self.assertEqual(
218 list(foobuntu_test2.relatedSets()),213 list(child_test2.relatedSets()),
219 [test2, test3, foobuntu_test3])214 [test2, test3, child_test3])
220 self.assertEqual(215 self.assertEqual(
221 list(foobuntu_test3.relatedSets()),216 list(child_test3.relatedSets()),
222 [test2, foobuntu_test2, test3])217 [test2, child_test2, test3])
223 # The contents of the packagesets will have been copied.218 # The contents of the packagesets will have been copied.
224 foobuntu_srcs = foobuntu_test1.getSourcesIncluded(219 child_srcs = child_test1.getSourcesIncluded(
225 direct_inclusion=True)220 direct_inclusion=True)
226 hoary_srcs = test1.getSourcesIncluded(direct_inclusion=True)221 parent_srcs = test1.getSourcesIncluded(direct_inclusion=True)
227 self.assertEqual(foobuntu_srcs, hoary_srcs)222 self.assertEqual(parent_srcs, child_srcs)
228 # The uploader can also upload to the new distroseries.223 # The uploader can also upload to the new distroseries.
229 self.assertTrue(224 self.assertTrue(
230 getUtility(IArchivePermissionSet).isSourceUploadAllowed(225 getUtility(IArchivePermissionSet).isSourceUploadAllowed(
231 self.hoary.main_archive, 'pmount', uploader,226 self.parent.main_archive, 'udev', uploader,
232 distroseries=self.hoary))227 distroseries=self.parent))
233 self.assertTrue(228 self.assertTrue(
234 getUtility(IArchivePermissionSet).isSourceUploadAllowed(229 getUtility(IArchivePermissionSet).isSourceUploadAllowed(
235 foobuntu.main_archive, 'pmount', uploader,230 child.main_archive, 'udev', uploader,
236 distroseries=foobuntu))231 distroseries=child))
237232
238 def test_rebuild_flag(self):233 def test_rebuild_flag(self):
239 # No binaries will get copied if we specify rebuild=True234 # No binaries will get copied if we specify rebuild=True
240 foobuntu = self._full_initialise(rebuild=True)235 self.parent.updatePackageCount()
241 foobuntu.updatePackageCount()236 child = self._full_initialise(rebuild=True)
242 builds = foobuntu.getBuildRecords(237 child.updatePackageCount()
238 builds = child.getBuildRecords(
243 build_state=BuildStatus.NEEDSBUILD,239 build_state=BuildStatus.NEEDSBUILD,
244 pocket=PackagePublishingPocket.RELEASE, arch_tag='i386')240 pocket=PackagePublishingPocket.RELEASE)
245 self.assertEqual(foobuntu.sourcecount, 7)241 self.assertEqual(self.parent.sourcecount, child.sourcecount)
246 self.assertEqual(foobuntu.binarycount, 0)242 self.assertEqual(child.binarycount, 0)
247 self.assertEqual(builds.count(), 5)243 self.assertEqual(builds.count(), self.parent.sourcecount)
248244
249 def test_script(self):245 def test_script(self):
250 # Do an end-to-end test using the command-line tool246 # Do an end-to-end test using the command-line tool
251 uploader = self.factory.makePerson()247 uploader = self.factory.makePerson()
252 test1 = getUtility(IPackagesetSet).new(248 test1 = getUtility(IPackagesetSet).new(
253 u'test1', u'test 1 packageset', self.hoary.owner,249 u'test1', u'test 1 packageset', self.parent.owner,
254 distroseries=self.hoary)250 distroseries=self.parent)
255 test1.addSources('pmount')251 test1.addSources('udev')
256 getUtility(IArchivePermissionSet).newPackagesetUploader(252 getUtility(IArchivePermissionSet).newPackagesetUploader(
257 self.hoary.main_archive, uploader, test1)253 self.parent.main_archive, uploader, test1)
258 foobuntu = self._create_distroseries(self.hoary)254 child = self.factory.makeDistroSeries(parent_series=self.parent)
259 self._set_pending_to_failed(self.hoary)
260 transaction.commit()255 transaction.commit()
261 ifp = os.path.join(256 ifp = os.path.join(
262 config.root, 'scripts', 'ftpmaster-tools',257 config.root, 'scripts', 'ftpmaster-tools',
263 'initialise-from-parent.py')258 'initialise-from-parent.py')
264 process = subprocess.Popen(259 process = subprocess.Popen(
265 [sys.executable, ifp, "-vv", "-d", "ubuntutest", "foobuntu"],260 [sys.executable, ifp, "-vv", "-d", child.parent.name,
266 stdout=subprocess.PIPE, stderr=subprocess.PIPE)261 child.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
267 stdout, stderr = process.communicate()262 stdout, stderr = process.communicate()
268 self.assertEqual(process.returncode, 0)263 self.assertEqual(process.returncode, 0)
269 self.assertTrue(264 self.assertTrue(
270 "DEBUG Committing transaction." in stderr.split('\n'))265 "DEBUG Committing transaction." in stderr.split('\n'))
271 self.assertDistroSeriesInitialisedCorrectly(foobuntu)266 self.assertDistroSeriesInitialisedCorrectly(child)