← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilasc/launchpad:add-oci-feature-flag into launchpad:master

 

Ioana Lasc has proposed merging ~ilasc/launchpad:add-oci-feature-flag into launchpad:master.

Commit message:
Add OCI builds feature flag

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Added an OCI feature flag (oci.distro.arch.series) and integrated 
it with the distro_arch_series property of OCIRecipeBuild. 
When the feature flag is enabled, for all Ubuntu builds 
we default to Bionic, otherwise we default to current series.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:add-oci-feature-flag into launchpad:master.
diff --git a/lib/lp/oci/model/ocirecipebuild.py b/lib/lp/oci/model/ocirecipebuild.py
index 12688cd..2b57b65 100644
--- a/lib/lp/oci/model/ocirecipebuild.py
+++ b/lib/lp/oci/model/ocirecipebuild.py
@@ -55,6 +55,7 @@ from lp.services.database.interfaces import (
     IMasterStore,
     IStore,
     )
+from lp.services.features import getFeatureFlag
 from lp.services.librarian.model import (
     LibraryFileAlias,
     LibraryFileContent,
@@ -62,6 +63,10 @@ from lp.services.librarian.model import (
 from lp.services.propertycache import cachedproperty
 
 
+USE_OCI_DISTRO_ARCH_SERIES_FEATURE = (
+    'oci.distro.arch.series')
+
+
 @implementer(IOCIFile)
 class OCIFile(Storm):
 
@@ -267,6 +272,13 @@ class OCIRecipeBuild(PackageBuildMixin, Storm):
 
     @property
     def distro_arch_series(self):
+        # For OCI builds if the distribution is Ubuntu we default to Bionic,
+        # otherwise we default to current series under distribution.
+        use_oci_distro_arch_series_feature = bool(
+            getFeatureFlag(USE_OCI_DISTRO_ARCH_SERIES_FEATURE))
+        if use_oci_distro_arch_series_feature:
+            if self.distribution.name == 'ubuntu':
+                return self.distribution.getSeries('bionic')
         return self.distribution.currentseries.getDistroArchSeriesByProcessor(
             self.processor)
 
diff --git a/lib/lp/oci/tests/test_ocirecipebuild.py b/lib/lp/oci/tests/test_ocirecipebuild.py
index 60aaf93..123955d 100644
--- a/lib/lp/oci/tests/test_ocirecipebuild.py
+++ b/lib/lp/oci/tests/test_ocirecipebuild.py
@@ -21,8 +21,14 @@ from lp.oci.interfaces.ocirecipebuild import (
     IOCIRecipeBuild,
     IOCIRecipeBuildSet,
     )
-from lp.oci.model.ocirecipebuild import OCIRecipeBuildSet
+from lp.oci.model.ocirecipebuild import (
+    OCIRecipeBuildSet,
+    USE_OCI_DISTRO_ARCH_SERIES_FEATURE,
+    )
+from lp.registry.interfaces.distribution import IDistributionSet
+from lp.registry.interfaces.distroseries import IDistroSeriesSet
 from lp.registry.interfaces.series import SeriesStatus
+from lp.services.features.testing import FeatureFixture
 from lp.services.propertycache import clear_property_cache
 from lp.testing import (
     admin_logged_in,
@@ -165,6 +171,32 @@ class TestOCIRecipeBuildSet(TestCaseWithFactory):
         with admin_logged_in():
             self.assertProvides(target, IOCIRecipeBuild)
 
+    def test_new_oci_feature_flag_enabled(self):
+        requester = self.factory.makePerson()
+        distribution = getUtility(IDistributionSet).getByName('ubuntu')
+        if distribution is None:
+            distribution = self.factory.makeDistribution(name='ubuntu')
+
+        distroseries = getUtility(IDistroSeriesSet).queryByName(
+            distribution, 'bionic')
+        if distroseries is None:
+            distroseries = self.factory.makeDistroSeries(
+                distribution=distribution, status=SeriesStatus.CURRENT,
+                name='bionic')
+        processor = getUtility(IProcessorSet).getByName("386")
+        self.useFixture(FeatureFixture(
+            {USE_OCI_DISTRO_ARCH_SERIES_FEATURE: True}))
+        distro_arch_series = self.factory.makeDistroArchSeries(
+            distroseries=distroseries, architecturetag="i386",
+            processor=processor)
+        distro_arch_series = self.factory.makeDistroArchSeries()
+        oci_project = self.factory.makeOCIProject(pillar=distribution)
+        recipe = self.factory.makeOCIRecipe(oci_project=oci_project)
+        target = getUtility(IOCIRecipeBuildSet).new(
+            requester, recipe, distro_arch_series)
+        with admin_logged_in():
+            self.assertProvides(target, IOCIRecipeBuild)
+
     def test_getByID(self):
         builds = [self.factory.makeOCIRecipeBuild() for x in range(3)]
         result = getUtility(IOCIRecipeBuildSet).getByID(builds[1].id)
diff --git a/lib/lp/services/features/flags.py b/lib/lp/services/features/flags.py
index 9fdb4a0..dcc6844 100644
--- a/lib/lp/services/features/flags.py
+++ b/lib/lp/services/features/flags.py
@@ -227,6 +227,13 @@ flag_info = sorted([
      'bing',
      'Site search engine',
      ''),
+    ('oci.distro.arch.series',
+     'boolean',
+     'For OCI builds if the distribution is Ubuntu we default to Bionic, '
+     'otherwise we default to current series under distribution.',
+     'disabled',
+     '',
+     ''),
     ])
 
 # The set of all flag names that are documented.