Fix target host variable from being overwritten

Modify relevant test to cover this.

Resolves bug 1133204.

Change-Id: I517b2dc19d9561723391150105b4943b56dba637