← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:charm-distinct-architectures into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:charm-distinct-architectures into launchpad:master.

Commit message:
Apply DISTINCT in CharmRecipe.getAllowedArchitectures

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/405450

We're looking for DistroArchSeries rows that have PocketChroots, but it's possible for a DAS to have more than one PocketChroot for different base image types, so we need to apply `DISTINCT` here.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:charm-distinct-architectures into launchpad:master.
diff --git a/lib/lp/charms/model/charmrecipe.py b/lib/lp/charms/model/charmrecipe.py
index 40bdd2a..163d393 100644
--- a/lib/lp/charms/model/charmrecipe.py
+++ b/lib/lp/charms/model/charmrecipe.py
@@ -451,7 +451,7 @@ class CharmRecipe(StormBase):
         # determine_architectures_to_build.
         results = store.using(*origin).find(
             (DistroArchSeries, DistroSeries, Distribution),
-            DistroSeries.status.is_in(ACTIVE_STATUSES))
+            DistroSeries.status.is_in(ACTIVE_STATUSES)).config(distinct=True)
         all_buildable_dases = DecoratedResultSet(results, itemgetter(0))
         return [
             das for das in all_buildable_dases
diff --git a/lib/lp/charms/tests/test_charmrecipe.py b/lib/lp/charms/tests/test_charmrecipe.py
index 5dabfe9..d4efb7c 100644
--- a/lib/lp/charms/tests/test_charmrecipe.py
+++ b/lib/lp/charms/tests/test_charmrecipe.py
@@ -24,6 +24,7 @@ from zope.security.proxy import removeSecurityProxy
 from lp.app.enums import InformationType
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
 from lp.buildmaster.enums import (
+    BuildBaseImageType,
     BuildQueueStatus,
     BuildStatus,
     )
@@ -221,9 +222,15 @@ class TestCharmRecipe(TestCaseWithFactory):
                     supports_nonvirtualized=supports_nonvirtualized)
         das = self.factory.makeDistroArchSeries(
             architecturetag=architecturetag, processor=processor, **kwargs)
+        # Add both a chroot and a LXD image to test that
+        # getAllowedArchitectures doesn't get confused by multiple
+        # PocketChroot rows for a single DistroArchSeries.
         fake_chroot = self.factory.makeLibraryFileAlias(
             filename="fake_chroot.tar.gz", db_only=True)
         das.addOrUpdateChroot(fake_chroot)
+        fake_lxd = self.factory.makeLibraryFileAlias(
+            filename="fake_lxd.tar.gz", db_only=True)
+        das.addOrUpdateChroot(fake_lxd, image_type=BuildBaseImageType.LXD)
         return das
 
     def test_requestBuild(self):