Merge lp://qastaging/~jtv/launchpad/bug-488695 into lp://qastaging/launchpad
Proposed by
Jeroen T. Vermeulen
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Michael Hudson-Doyle | ||||
Approved revision: | not available | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp://qastaging/~jtv/launchpad/bug-488695 | ||||
Merge into: | lp://qastaging/launchpad | ||||
Diff against target: |
233 lines (+195/-2) 2 files modified
lib/devscripts/ec2test/instance.py (+10/-2) lib/devscripts/ec2test/tests/test_ec2instance.py (+185/-0) |
||||
To merge this branch: | bzr merge lp://qastaging/~jtv/launchpad/bug-488695 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Hudson-Doyle | Approve | ||
Graham Binns | code | Pending | |
Review via email: mp+15279@code.qastaging.launchpad.net |
Commit message
Fix premature shutdowns in headless ec2 images.
To post a comment you must log in.
= Bug 488695 =
See bug for details. Headless EC2 images were shutting down prematurely.
The method that needed fixing did, in a shell:
def set_up_ and_run( self, shutdown):
handle_ error()
really_ shutdown = shutdown
shutdown( )
# *Always* shut down unless & until we finish our work.
really_shutdown = True
try:
try:
return real_work()
except Exception:
else:
# No error; now we obey the caller's wishes.
finally:
if really_shutdown:
Fair enough, but as it turns out, the "return real_work()" in the inner "try" bypasses the "else" attached to the "try." Thus really_shutdown never becomes False.
Why does this matter for headless runs? Because in those cases, real_work() sets up the instance and then returns while the instance starts work on the actual tests. Shutting down at that point will kill the EC2 instance before it gets a fair chance to run them!
There didn't seem to be any tests for this, so with lots of stubbing and mocking, I added one. In fact this produced a nice little reusable class to mock up, disable, or inject all sorts of simple methods. We may want to make it a standard helper, except it currently has a nice short name that happens to match the IRC nick of one of our teammates.
So I added a test. That doesn't mean I'm a saint. In this review you'll see some of my darker moments:
* I mocked whatever I had to, God knows how deep into the call tree. Obviously that makes for more brittle tests. Changes in the EC2 setup may require lots of changes to the mock objects in the future.
* I suppressed a pylint warning. Apparently pylint isn't quite smart enough that "if self.simulated_ failure is not None: raise self.simulated_ failure" never raises None.
* I moved a global import into a method, and it wasn't to avoid a circular import (I think). For whatever reason, I couldn't seem to import bzrlib. plugins. launchpad. account from instance.py when running the test. Since I was in a hurry, I moved it into the one method that used it—and which my test doesn't exercise.
To test:
{{{
./bin/test -vv -t test_ec2instance
}}}
As for Q/A... any "ec2 test --headless" or "ec2 land --headless" should do. Just make sure the instance keeps running independently after detaching, and that it shuts down after completion.
There's one piece of lint:
lib/devscripts/ ec2test/ instance. py set_up_ and_run] Catch "Exception"
422: [W0703, EC2Instance.
I didn't touch that. In this case catching Exception may actually make sense, but I'm not silencing the warning because python 2.5 and later change the behaviour for this situation and I don't think it'd hurt to remind more experienced people to think about it.
Jeroen