launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24215
[Merge] ~pappacena/launchpad:process-job-respecting-config-section into launchpad:master
Thiago F. Pappacena has proposed merging ~pappacena/launchpad:process-job-respecting-config-section into launchpad:master.
Commit message:
Adding the option for process-job-source to link a script configuration to another section, in order to avoid duplicating config
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/377330
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:process-job-respecting-config-section into launchpad:master.
diff --git a/cronscripts/process-job-source.py b/cronscripts/process-job-source.py
index ad74c2a..6a257c0 100755
--- a/cronscripts/process-job-source.py
+++ b/cronscripts/process-job-source.py
@@ -31,8 +31,8 @@ class ProcessJobSource(LaunchpadCronScript):
description = (
"Takes pending jobs of the given type off the queue and runs them.")
- def __init__(self):
- super(ProcessJobSource, self).__init__()
+ def __init__(self, test_args=None):
+ super(ProcessJobSource, self).__init__(test_args=test_args)
# The fromlist argument is necessary so that __import__()
# returns the bottom submodule instead of the top one.
module = __import__(self.config_section.module,
@@ -45,7 +45,13 @@ class ProcessJobSource(LaunchpadCronScript):
@property
def config_section(self):
- return getattr(config, self.config_name)
+ cfg = getattr(config, self.config_name)
+
+ # If the config section is just a link to another section,
+ # use the linked one
+ if hasattr(cfg, 'link'):
+ return getattr(config, cfg.link)
+ return cfg
@property
def dbuser(self):
diff --git a/lib/lp/registry/tests/test_process_job_sources_cronjob.py b/lib/lp/registry/tests/test_process_job_sources_cronjob.py
index 5b29570..7372b7b 100644
--- a/lib/lp/registry/tests/test_process_job_sources_cronjob.py
+++ b/lib/lp/registry/tests/test_process_job_sources_cronjob.py
@@ -1,10 +1,11 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test cron script for processing jobs from any job source class."""
__metaclass__ = type
+import mock
import transaction
from zope.component import getUtility
@@ -16,12 +17,50 @@ from lp.services.config import config
from lp.services.scripts.tests import run_script
from lp.testing import (
login_person,
+ TestCase,
TestCaseWithFactory,
)
from lp.testing.layers import LaunchpadScriptLayer
from lp.testing.matchers import DocTestMatches
+class AScript:
+ link = 'BScript'
+
+
+class BScript:
+ module = 'lp.registry.tests.test_process_job_sources_cronjob'
+
+
+class ProcessJobSourceConfigTest(TestCase):
+ """
+ This test case is specific for unit testing ProcessJobSource's usage of
+ config.
+ """
+ def test_config_section_link(self):
+ import sys
+ sys.path.append('./cronscripts/')
+ process_job_source = __import__('process-job-source')
+
+ # Overrides config to mimic the following config file:
+ # [AScript]
+ # link: BScript
+ #
+ # [BScript]
+ # module: lp.registry.tests.test_process_job_sources_cronjob
+ cfg = mock.Mock()
+ cfg.AScript = AScript()
+ cfg.BScript = BScript()
+
+ process_job_source.config = cfg
+
+ # Now, tries to ProcessJobSource the AScript and check if it uses
+ # BScript config section
+ proc = process_job_source.ProcessJobSource(test_args=['AScript'])
+
+ self.assertEqual(proc.config_section, cfg.BScript)
+
+
class ProcessJobSourceTest(TestCaseWithFactory):
"""Test the process-job-source.py script."""
layer = LaunchpadScriptLayer
diff --git a/lib/lp/services/config/schema-lazr.conf b/lib/lp/services/config/schema-lazr.conf
index 0e778f9..63ca108 100644
--- a/lib/lp/services/config/schema-lazr.conf
+++ b/lib/lp/services/config/schema-lazr.conf
@@ -2096,6 +2096,9 @@ module: lp.registry.interfaces.productjob
dbuser: product-job
crontab_group: MAIN
+[IUpdatePreviewDiffJobSource]
+link: IBranchMergeProposalJobSource
+
[IWebhookDeliveryJobSource]
module: lp.services.webhooks.interfaces
dbuser: webhookrunner