Merge lp:~jtv/launchpad/bug-814141 into lp:launchpad
Status: | Merged |
---|---|
Approved by: | Graham Binns |
Approved revision: | no longer in the source branch. |
Merged at revision: | 13525 |
Proposed branch: | lp:~jtv/launchpad/bug-814141 |
Merge into: | lp:launchpad |
Diff against target: |
311 lines (+108/-50) 5 files modified
lib/canonical/launchpad/scripts/__init__.py (+7/-4) lib/canonical/launchpad/scripts/logger.py (+74/-31) lib/lp/archivepublisher/scripts/generate_contents_files.py (+1/-2) lib/lp/archivepublisher/scripts/publish_ftpmaster.py (+6/-4) lib/lp/services/scripts/base.py (+20/-9) |
To merge this branch: | bzr merge lp:~jtv/launchpad/bug-814141 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Graham Binns (community) | code | Approve | |
Review via email: mp+69285@code.launchpad.net |
Commit message
[r=gmb][bug=814141] Pass loggers to LaunchpadScripts to protect global logging config.
Description of the change
= Summary =
When publish-ftpmaster instantiates and calls a publish-distro script object, it overrides (without restoring it afterwards!) the logging options you passed in.
As it turns out, the LaunchpadScript constructor messes with the process-global logging settings, which causes strange effects.
== Proposed fix ==
When instantiating a script object, allow the caller to pass in a logger. This doesn't really do much, exactly because loggers are global, but I do like the clarity of it and it does kill two birds with one stone:
1. It ensures a meaningful self.logger (which we'd otherwise have to look up anyway).
2. It clearly says "don't configure logging; use this instead."
Now you can run publish-
== Pre-implementation notes ==
We came up with several approaches. I tried even more. Almost gave up; Julian (who requested the fix, leading me to discover the underlying problem) would have been willing to accept a hack that spewed "-v" and "-q" options to the sub-script. But that would have been unspeakable.
Stuart suggested creating a new option. At first I tried to make do with test_args, but it wasn't quite as transparent and I didn't quite get it to work. I also tried just a boolean ("initialize global logging?") but that left self.logging uninitialized.
== Implementation details ==
The options code uses callbacks to change log levels. There was a fair bit of duplication, and they took the default value straight from a variable in the surrounding function. I replaced them with a single class which I hope is cleaner.
Hopefully in the future we'll be able to quench more test noise by passing logger=
== Tests ==
Since this messes with the global log level, I didn't add any unit tests. Obviously scripts still work though. However, do run this to ensure that I haven't broken anything:
{{{
./bin/test -vvc lp.archivepubli
}}}
== Demo and Q/A ==
Run "publish-
You may need to “rm -rf /var/tmp/
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/canonical
lib/lp/
lib/canonical
lib/lp/
lib/lp/