← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wallyworld/launchpad/sharing-jobs-config into lp:launchpad

 

Ian Booth has proposed merging lp:~wallyworld/launchpad/sharing-jobs-config into lp:launchpad with lp:~wallyworld/launchpad/bug-unsubscribe-pillar-infotype-change as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/sharing-jobs-config/+merge/107148

== Implementation ==

Tweak the configs to allow the sharing jobs to be run via cron.

== Tests ==

Add a new test case to ensure the jobs are correctly run via cronscripts/process-job-source.py

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  configs/development/launchpad-lazr.conf
  lib/lp/registry/model/sharingjob.py
  lib/lp/registry/tests/test_sharingjob.py
  lib/lp/services/config/schema-lazr.conf

o./configs/development/launchpad-lazr.conf
      62: Line exceeds 80 characters.
      91: Line exceeds 80 characters.
w./lib/lp/services/config/schema-lazr.conf
     445: Line exceeds 80 characters.
    1038: Line exceeds 80 characters.
    1045: Line exceeds 80 characters.
    1586: Line exceeds 80 characters.

-- 
https://code.launchpad.net/~wallyworld/launchpad/sharing-jobs-config/+merge/107148
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wallyworld/launchpad/sharing-jobs-config into lp:launchpad.
=== modified file 'configs/development/launchpad-lazr.conf'
--- configs/development/launchpad-lazr.conf	2012-05-24 02:19:18 +0000
+++ configs/development/launchpad-lazr.conf	2012-05-15 07:22:45 +0000
@@ -191,9 +191,6 @@
 password: guest
 virtual_host: /
 
-[sharing_jobs]
-error_dir: /var/tmp/sharing.test
-
 [txlongpoll]
 launch: True
 frontend_port: 22435

=== modified file 'lib/lp/registry/model/sharingjob.py'
--- lib/lp/registry/model/sharingjob.py	2012-05-24 02:19:18 +0000
+++ lib/lp/registry/model/sharingjob.py	2012-05-24 02:19:19 +0000
@@ -174,7 +174,7 @@
     @contextlib.contextmanager
     def contextManager():
         """See `IJobSource`."""
-        errorlog.globalErrorUtility.configure('sharing_jobs')
+        errorlog.globalErrorUtility.configure('ISharingJobSource')
         yield
 
     def __init__(self, job):
@@ -265,7 +265,7 @@
     classProvides(IRemoveGranteeSubscriptionsJobSource)
     class_job_type = SharingJobType.REMOVE_GRANTEE_SUBSCRIPTIONS
 
-    config = config.sharing_jobs
+    config = config.IRemoveGranteeSubscriptionsJobSource
 
     @classmethod
     def create(cls, pillar, grantee, requestor, information_types=None,
@@ -388,7 +388,7 @@
     classProvides(IRemoveBugSubscriptionsJobSource)
     class_job_type = SharingJobType.REMOVE_BUG_SUBSCRIPTIONS
 
-    config = config.sharing_jobs
+    config = config.IRemoveBugSubscriptionsJobSource
 
     @classmethod
     def create(cls, bugs, requestor):

=== modified file 'lib/lp/registry/tests/test_sharingjob.py'
--- lib/lp/registry/tests/test_sharingjob.py	2012-05-24 02:19:18 +0000
+++ lib/lp/registry/tests/test_sharingjob.py	2012-05-24 02:19:19 +0000
@@ -7,6 +7,8 @@
 
 import transaction
 
+from testtools.content import Content
+from testtools.content_type import UTF8_TEXT
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
 
@@ -34,12 +36,15 @@
     SharingJobDerived,
     SharingJobType,
     )
+from lp.services.database.lpstorm import IStore
 from lp.services.features.testing import FeatureFixture
+from lp.services.job.interfaces.job import JobStatus
 from lp.services.job.tests import block_on_job
 from lp.services.mail.sendmail import format_address_for_person
 from lp.testing import (
     login_person,
     person_logged_in,
+    run_script,
     TestCaseWithFactory,
     )
 from lp.testing.fixture import DisableTriggerFixture
@@ -399,6 +404,68 @@
             person_grantee, removeSecurityProxy(bug2).getDirectSubscribers())
 
 
+class TestRunViaCron(TestCaseWithFactory):
+    """Sharing jobs run via cron."""
+
+    layer = DatabaseFunctionalLayer
+
+    def _assert_run_cronscript(self, create_job):
+        # The cronscript is configured: schema-lazr.conf and security.cfg.
+        # The job runs correctly and the requested bug subscriptions are
+        # removed.
+        distro = self.factory.makeDistribution()
+        grantee = self.factory.makePerson()
+        owner = self.factory.makePerson()
+        bug = self.factory.makeBug(
+            owner=owner, distribution=distro,
+            information_type=InformationType.USERDATA)
+        with person_logged_in(owner):
+            bug.subscribe(grantee, owner)
+
+        job, job_type = create_job(distro, bug, grantee, owner)
+        transaction.commit()
+
+        out, err, exit_code = run_script(
+            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
+                job_type))
+        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
+        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))
+        self.assertEqual(0, exit_code)
+        self.assertTrue(
+            'Traceback (most recent call last)' not in err)
+        IStore(job.job).invalidate()
+        self.assertEqual(JobStatus.COMPLETED, job.job.status)
+        self.assertNotIn(
+            grantee, removeSecurityProxy(bug).getDirectSubscribers())
+
+    def test_run_remove_grantee_subscriptions_cronscript(self):
+        # The cronscript is configured: schema-lazr.conf and security.cfg.
+        # The job runs correctly and the requested bug subscriptions are
+        # removed.
+
+        def create_job(distro, bug, grantee, owner):
+            return (
+                getUtility(IRemoveGranteeSubscriptionsJobSource).create(
+                    distro, grantee, owner, bugs=[bug]),
+                IRemoveGranteeSubscriptionsJobSource.getName())
+
+        self._assert_run_cronscript(create_job)
+
+    def test_run_remove_bug_subscriptions_cronscript(self):
+        # The cronscript is configured: schema-lazr.conf and security.cfg.
+        # The job runs correctly and the requested bug subscriptions are
+        # removed.
+
+        def create_job(distro, bug, grantee, owner):
+            job = getUtility(IRemoveBugSubscriptionsJobSource).create(
+                [bug], owner)
+            removeSecurityProxy(bug).information_type = (
+                        InformationType.EMBARGOEDSECURITY)
+            return job, IRemoveBugSubscriptionsJobSource.getName()
+
+        self._assert_run_cronscript(create_job)
+
+
 class RemoveBugSubscriptionsJobTestCase(TestCaseWithFactory):
     """Test case for the RemoveBugSubscriptionsJob class."""
 

=== modified file 'lib/lp/services/config/schema-lazr.conf'
--- lib/lp/services/config/schema-lazr.conf	2012-05-24 02:19:18 +0000
+++ lib/lp/services/config/schema-lazr.conf	2012-05-24 02:19:19 +0000
@@ -1508,11 +1508,6 @@
 # datatype: string
 virtual_host: none
 
-[sharing_jobs]
-# The database user which will be used by this process.
-# datatype: string
-dbuser: sharing-jobs
-
 # See [error_reports].
 error_dir: none
 
@@ -1760,7 +1755,9 @@
     IMembershipNotificationJobSource,
     IPersonMergeJobSource,
     IPlainPackageCopyJobSource,
-    IQuestionEmailJobSource
+    IQuestionEmailJobSource,
+    IRemoveBugSubscriptionsJobSource,
+    IRemoveGranteeSubscriptionsJobSource
 
 [IMembershipNotificationJobSource]
 # This section is used by cronscripts/process-job-source.py.
@@ -1786,6 +1783,18 @@
 dbuser: answertracker
 crontab_group: MAIN
 
+[IRemoveBugSubscriptionsJobSource]
+# This section is used by cronscripts/process-job-source.py.
+module: lp.registry.interfaces.sharingjob
+dbuser: sharing-jobs
+crontab_group: MAIN
+
+[IRemoveGranteeSubscriptionsJobSource]
+# This section is used by cronscripts/process-job-source.py.
+module: lp.registry.interfaces.sharingjob
+dbuser: sharing-jobs
+crontab_group: MAIN
+
 [job_runner_queues]
 # The names of all queues.
 queues: job job_slow branch_write_job branch_write_job_slow


Follow ups