fabric/fabric — Issue #568: execute() on different host does not change back to original host when done
Author: jsdalton
Created: 2012-02-24 14:18:33+00:00
State: open

Here's a quick demonstration of the issue:

fabfile.py:

```python
from fabric.api import *

@task
@hosts('localhost')
def test():
run("echo hi")
execute(test_other_host)
run("echo hi")

@task
@hosts('otherhost')
def test_other_host():
run("echo howdy")
```

The output is:

$ fab test
[localhost] Executing task 'test'
[localhost] run: echo hi
[localhost] out: hi

[otherhost] Executing task 'test_other_host'
[otherhost] run: echo howdy
[otherhost] out: howdy

[otherhost] run: echo hi
[otherhost] out: hi

Done.
Disconnecting from otherhost... done.
Disconnecting from localhost... done.

The problem is that when test_other_host() is done executing, the remaining tasks in test() are executing under that host's context, not the original context it was decorated with. This appears to happen regardless of how the hosts are specified (e.g. via the command line, explicitly as an arg to execute(), etc).

I'm running the latest version of Fabric:

$ fab --version
Fabric 1.4.0
ssh (library) 1.7.13

So I'm not sure whether it's always been like this or whether this is a regression.