Merge lp:~abentley/launchpad/twisted-environ into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Merged at revision: not available
Proposed branch: lp:~abentley/launchpad/twisted-environ
Merge into: lp:launchpad
Diff against target: 21 lines (+6/-4)
1 file modified
lib/lp/services/job/runner.py (+6/-4)
To merge this branch: bzr merge lp:~abentley/launchpad/twisted-environ
Reviewer Review Type Date Requested Status
Paul Hummer (community) code Approve
Review via email: mp+18626@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

= Summary =
Fix environment variable handling in twisted job runner.

== Proposed fix ==
The twisted job runner must run a subprocess, and preserve PATH, PYTHONPATH,
and LPCONFIG. But LPCONFIG is an optional environment variable, so it should
be provided to the subprocess only when provided to the main process.

== Pre-implementation notes ==
None

== Implementation details ==
None

== Tests ==
None. This fix only applies to interactive use, and not the test environment.
In the test environment, LPCONFIG is always specified.

== Demo and Q/A ==
cronscripts/update_preview_diff --twisted

If this doesn't give a KeyError, it worked.

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/services/job/runner.py

== Pylint notices ==

lib/lp/services/job/runner.py
    35: [F0401] Unable to import 'lazr.delegates' (No module named delegates)

Revision history for this message
Paul Hummer (rockstar) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/job/runner.py'
2--- lib/lp/services/job/runner.py 2010-02-03 22:43:51 +0000
3+++ lib/lp/services/job/runner.py 2010-02-04 20:02:17 +0000
4@@ -287,11 +287,13 @@
5 """Run Jobs via twisted."""
6
7 def __init__(self, job_source, logger=None, error_utility=None):
8+ env = {'PYTHONPATH': os.environ['PYTHONPATH'],
9+ 'PATH': os.environ['PATH']}
10+ lp_config = os.environ.get('LPCONFIG')
11+ if lp_config is not None:
12+ env['LPCONFIG'] = lp_config
13 starter = main.ProcessStarter(
14- packages=('twisted', 'ampoule'),
15- env={'PYTHONPATH': os.environ['PYTHONPATH'],
16- 'PATH': os.environ['PATH'],
17- 'LPCONFIG': os.environ['LPCONFIG']})
18+ packages=('twisted', 'ampoule'), env=env)
19 super(TwistedJobRunner, self).__init__(logger, error_utility)
20 self.job_source = job_source
21 import_name = '%s.%s' % (