launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #01905
[Merge] lp:~jelmer/launchpad/cronjob into lp:launchpad/devel
Jelmer Vernooij has proposed merging lp:~jelmer/launchpad/cronjob into lp:launchpad/devel.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
This adds a cronjob for synchronizing packages between archives, and adds the body of the SyncPackageJob.run.
--
https://code.launchpad.net/~jelmer/launchpad/cronjob/+merge/40629
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jelmer/launchpad/cronjob into lp:launchpad/devel.
=== modified file 'configs/development/launchpad-lazr.conf'
--- configs/development/launchpad-lazr.conf 2010-10-25 20:42:59 +0000
+++ configs/development/launchpad-lazr.conf 2010-11-11 14:34:46 +0000
@@ -137,6 +137,10 @@
oops_prefix: IDSJ
error_dir: /var/tmp/soyuz.test
+[sync_packages]
+oops_prefix: IDSJ
+error_dir: /var/tmp/soyuz.test
+
[launchpad]
enable_test_openid_provider: True
openid_provider_vhost: testopenid
=== added file 'cronscripts/sync_packages.py'
--- cronscripts/sync_packages.py 1970-01-01 00:00:00 +0000
+++ cronscripts/sync_packages.py 2010-11-11 14:34:46 +0000
@@ -0,0 +1,27 @@
+#!/usr/bin/python -S
+#
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Synchronise packages.."""
+
+__metaclass__ = type
+
+import _pythonpath
+
+from lp.services.job.runner import JobCronScript
+from lp.soyuz.interfaces.distributionjob import (
+ ISyncPackageJobSource,
+ )
+
+
+class RunSyncPackageJob(JobCronScript):
+ """Run SyncPackageJob jobs."""
+
+ config_name = 'sync_packages'
+ source_interface = ISyncPackageJobSource
+
+
+if __name__ == '__main__':
+ script = RunSyncPackageJob()
+ script.lock_and_run()
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2010-11-09 10:26:19 +0000
+++ database/schema/security.cfg 2010-11-11 14:34:46 +0000
@@ -968,6 +968,49 @@
public.sourcepackagepublishinghistory = SELECT, INSERT
public.sourcepackagerelease = SELECT
+[sync_packages]
+type=user
+groups=script
+public.archive = SELECT
+public.archivepermission = SELECT, INSERT
+public.binarypackagebuild = SELECT, INSERT
+public.binarypackagefile = SELECT, INSERT
+public.binarypackagename = SELECT
+public.binarypackagepublishinghistory = SELECT, INSERT
+public.binarypackagerelease = SELECT
+public.buildfarmjob = SELECT, INSERT
+public.buildpackagejob = SELECT, INSERT, UPDATE, DELETE
+public.buildqueue = SELECT, INSERT, UPDATE
+public.component = SELECT
+public.componentselection = SELECT, INSERT
+public.distribution = SELECT
+public.distributionjob = SELECT
+public.distroarchseries = SELECT, INSERT
+public.distroseries = SELECT, UPDATE
+public.flatpackagesetinclusion = SELECT, INSERT
+public.gpgkey = SELECT
+public.job = SELECT, INSERT, UPDATE, DELETE
+public.libraryfilealias = SELECT, INSERT, UPDATE, DELETE
+public.libraryfilecontent = SELECT, INSERT
+public.packagebuild = SELECT, INSERT
+public.packageset = SELECT, INSERT
+public.packagesetgroup = SELECT, INSERT
+public.packagesetinclusion = SELECT, INSERT
+public.packagesetsources = SELECT, INSERT
+public.packageupload = SELECT
+public.packaging = SELECT, INSERT
+public.person = SELECT
+public.pocketchroot = SELECT
+public.processor = SELECT
+public.processorfamily = SELECT
+public.section = SELECT
+public.sectionselection = SELECT, INSERT
+public.sourcepackageformatselection = SELECT, INSERT
+public.sourcepackagename = SELECT
+public.sourcepackagepublishinghistory = SELECT, INSERT
+public.sourcepackagerelease = SELECT
+public.sourcepackagereleasefile = SELECT, INSERT, UPDATE
+
[write]
type=group
# Full access except for tables that are exclusively updated by
=== modified file 'lib/canonical/config/schema-lazr.conf'
--- lib/canonical/config/schema-lazr.conf 2010-11-08 05:22:26 +0000
+++ lib/canonical/config/schema-lazr.conf 2010-11-11 14:34:46 +0000
@@ -940,6 +940,20 @@
# See [error_reports].
copy_to_zlog: false
+[sync_packages]
+dbuser: sync_packages
+
+# See [error_reports].
+error_dir: none
+
+# See [error_reports].
+oops_prefix: none
+
+# See [error_reports].
+copy_to_zlog: false
+
+
+
[karmacacheupdater]
# The database user which will be used by this process.
# datatype: string
=== modified file 'lib/lp/soyuz/model/syncpackagejob.py'
--- lib/lp/soyuz/model/syncpackagejob.py 2010-11-05 12:03:15 +0000
+++ lib/lp/soyuz/model/syncpackagejob.py 2010-11-11 14:34:46 +0000
@@ -98,4 +98,8 @@
def run(self):
"""See `IRunnableJob`."""
- raise NotImplementedError(self.run)
+ self.target_archive.syncSource(
+ self.source_package_name, self.source_package_version,
+ self.source_archive, to_pocket=str(self.pocket),
+ to_series=self.distroseries.name,
+ include_binaries=self.include_binaries)
=== modified file 'lib/lp/soyuz/tests/test_syncpackagejob.py'
--- lib/lp/soyuz/tests/test_syncpackagejob.py 2010-11-04 13:37:23 +0000
+++ lib/lp/soyuz/tests/test_syncpackagejob.py 2010-11-11 14:34:46 +0000
@@ -1,13 +1,27 @@
# Copyright 2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
+"""Tests for sync package jobs."""
+
+import os
+import subprocess
+import sys
+import transaction
+
from zope.component import getUtility
+from zope.security.proxy import removeSecurityProxy
+from canonical.config import config
from canonical.testing import LaunchpadZopelessLayer
+
+from lp.registry.errors import NoSuchSourcePackageName
+
from lp.soyuz.interfaces.distributionjob import (
ISyncPackageJob,
ISyncPackageJobSource,
)
+from lp.soyuz.interfaces.publishing import PackagePublishingStatus
+from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
from lp.registry.interfaces.pocket import PackagePublishingPocket
from lp.testing import TestCaseWithFactory
@@ -45,3 +59,68 @@
PackagePublishingPocket.RELEASE,
"foo", "1.0-1", include_binaries=False)
self.assertContentEqual([job], source.getActiveJobs(archive2))
+
+ def test_cronscript(self):
+ script = os.path.join(
+ config.root, 'cronscripts', 'sync_packages.py')
+ args = [sys.executable, script, '-v']
+ process = subprocess.Popen(
+ args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = process.communicate()
+ self.assertEqual(process.returncode, 0)
+
+ def test_run_unknown_package(self):
+ # A job properly records failure.
+ distroseries = self.factory.makeDistroSeries()
+ archive1 = self.factory.makeArchive(distroseries.distribution)
+ archive2 = self.factory.makeArchive(distroseries.distribution)
+ source = getUtility(ISyncPackageJobSource)
+ job = source.create(archive1, archive2, distroseries,
+ PackagePublishingPocket.RELEASE,
+ "foo", "1.0-1", include_binaries=False)
+ self.assertRaises(NoSuchSourcePackageName, job.run)
+
+ def test_run(self):
+ publisher = SoyuzTestPublisher()
+ publisher.prepareBreezyAutotest()
+ distroseries = publisher.breezy_autotest
+
+ archive1 = self.factory.makeArchive(distroseries.distribution)
+ archive2 = self.factory.makeArchive(distroseries.distribution)
+
+ publisher.getPubBinaries(
+ distroseries=distroseries, binaryname="libc",
+ version="2.8-1",
+ status=PackagePublishingStatus.PUBLISHED,
+ archive=archive1)
+
+ source = getUtility(ISyncPackageJobSource)
+ job = source.create(archive1, archive2, distroseries,
+ PackagePublishingPocket.RELEASE,
+ "libc", "2.8-1", include_binaries=False)
+ # Make sure everything hits the database, switching db users
+ # aborts.
+ transaction.commit()
+ self.layer.switchDbUser('sync_packages')
+ job.run()
+
+ published_sources = archive2.getPublishedSources()
+ self.assertEquals(1, published_sources.count())
+ spr = published_sources[0].sourcepackagerelease
+ self.assertEquals("libc", spr.name)
+ self.assertEquals("2.8-1", spr.version)
+
+ def test_getOopsVars(self):
+ distroseries = self.factory.makeDistroSeries()
+ archive1 = self.factory.makeArchive(distroseries.distribution)
+ archive2 = self.factory.makeArchive(distroseries.distribution)
+ source = getUtility(ISyncPackageJobSource)
+ job = source.create(archive1, archive2, distroseries,
+ PackagePublishingPocket.RELEASE,
+ "foo", "1.0-1", include_binaries=False)
+ vars = job.getOopsVars()
+ naked_job = removeSecurityProxy(job)
+ self.assertIn(
+ ('distribution_id', distroseries.distribution.id), vars)
+ self.assertIn(('distroseries_id', distroseries.id), vars)
+ self.assertIn(('distribution_job_id', naked_job.context.id), vars)
Follow ups