Repository: buildbot/buildbot

Issue:
#4268 breaks Buildbot on Git step workers with different filesystem layout than the master
Resolving `abspath` in 33682e89057349fed6b72ca7613944b2687633f9 on the Buildbot master does not work in scenarios that the Buildbot worker is using a different working directory than the master.

[Master WORKDIR: /var/lib/buildbot](https://github.com/buildbot/buildbot/blob/master/master/Dockerfile#L93)
[Worker WORKDIR: /buildbot](https://github.com/buildbot/buildbot/blob/master/worker/Dockerfile#L51)

This was rather tricky to track down and I'm going to revert this commit locally and look at fixing it in a subsequent PR.


Discussion:
Indeed, this totally fell out of my mind when developing the prior PR.
@p12tic I was trying to submit patch, but `tox` in the `master` directory didn't seem to work and I wasn't really able to easily get a local testing environment together. Is there docs/how do you test things locally?
@terencehonles we don't use tox for testing, please have a look at ur development quickstart: http://docs.buildbot.net/current/developer/quickstart.html

do we have a patch for this? 
@terencehonles If you lack time, could you just push whatever you had in development and I could polish the code and finish the PR. Thanks!
I'm seeing what may be another manifestation of this issue, although it's possible it's something different.  I'm running a CENTOS docker latent worker from a build master running on Ubuntu, and get the following error during the git --version part of a Git step:

```
Upon execvpe b'git' [b'git', b'--version'] in environment id 139797679318504
:Traceback (most recent call last):
  File "/anaconda/lib/python3.6/site-packages/twisted/internet/process.py", line 445, in _fork
    environment)
  File "/anaconda/lib/python3.6/site-packages/twisted/internet/process.py", line 523, in _execChild
    os.execvpe(executable, args, environment)
  File "/anaconda/lib/python3.6/os.py", line 568, in execvpe
    _execvpe(file, args, env)
  File "/anaconda/lib/python3.6/os.py", line 604, in _execvpe
    raise last_exc.with_traceback(tb)
  File "/anaconda/lib/python3.6/os.py", line 594, in _execvpe
    exec_func(fullname, *argrest)
FileNotFoundError: [Errno 2] No such file or directory: b'/bin/git'
```

The part that doesn't quite make sense to me is that yum install in CENTOS (the worker) put git in both /usr/bin and /bin, both of which are in the PATH printed in the environment during the Git step.  The buildmaster only has /usr/bin/git, but presumably /bin/git existing on the worker is what's important.  Creating a symbolic link from /bin/git to /usr/bin/git on the master also didn't help.
Will look into this bug next week. As we didn't receive any patch, it's unlikely I'll duplicate anyone's work.
what should I do for the release? should I revert #4268?
I reverted #4268, @p12tic please feel free to resubmit the feature with appropriate workerpath joining.
LGTM.

Resolving patch:
diff --git a/master/buildbot/util/git.py b/master/buildbot/util/git.py
--- a/master/buildbot/util/git.py
+++ b/master/buildbot/util/git.py
@@ -139,7 +139,11 @@ def _getSshDataPath(self):
         path_module = self.build.path_module
 
         workdir = self._getSshDataWorkDir().rstrip('/\\')
-        parent_path = path_module.dirname(workdir)
+        if path_module.isabs(workdir):
+            parent_path = path_module.dirname(workdir)
+        else:
+            parent_path = path_module.join(self.worker.worker_basedir,
+                                           path_module.dirname(workdir))
 
         basename = '.{0}.buildbot'.format(path_module.basename(workdir))
         return path_module.join(parent_path, basename)
@@ -154,26 +158,19 @@ def _getSshWrapperScriptPath(self):
         return self.build.path_module.join(self._getSshDataPath(), 'ssh-wrapper.sh')
 
     def _getSshWrapperScript(self):
-        rel_key_path = self.build.path_module.relpath(
-                self._getSshPrivateKeyPath(), self._getSshDataWorkDir())
-
-        return getSshWrapperScriptContents(rel_key_path)
+        return getSshWrapperScriptContents(self._getSshPrivateKeyPath)
 
     def _adjustCommandParamsForSshPrivateKey(self, full_command, full_env):
 
-        rel_key_path = self.build.path_module.relpath(
-                self._getSshPrivateKeyPath(), self.workdir)
-        rel_ssh_wrapper_path = self.build.path_module.relpath(
-                self._getSshWrapperScriptPath(), self.workdir)
-        rel_host_key_path = None
+        key_path = self._getSshPrivateKeyPath()
+        ssh_wrapper_path = self._getSshWrapperScriptPath()
+        host_key_path = None
         if self.sshHostKey is not None:
-            rel_host_key_path = self.build.path_module.relpath(
-                    self._getSshHostKeyPath(), self.workdir)
+            host_key_path = self._getSshHostKeyPath()
 
         self.adjustCommandParamsForSshPrivateKey(full_command, full_env,
-                                                 rel_key_path,
-                                                 rel_ssh_wrapper_path,
-                                                 rel_host_key_path)
+                                                 key_path, ssh_wrapper_path,
+                                                 host_key_path)
 
     @defer.inlineCallbacks
     def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False, initialStdin=None):
@@ -256,26 +253,20 @@ def _downloadSshPrivateKeyIfNeeded(self):
         # options
         workdir = self._getSshDataWorkDir()
 
-        rel_key_path = self.build.path_module.relpath(
-                self._getSshPrivateKeyPath(), workdir)
-        rel_host_key_path = self.build.path_module.relpath(
-                self._getSshHostKeyPath(), workdir)
-        rel_wrapper_script_path = self.build.path_module.relpath(
-                self._getSshWrapperScriptPath(), workdir)
-
         yield self.runMkdir(self._getSshDataPath())
 
         if not self.supportsSshPrivateKeyAsEnvOption:
-            yield self.downloadFileContentToWorker(rel_wrapper_script_path,
+            yield self.downloadFileContentToWorker(self._getSshWrapperScriptPath(),
                                                    self._getSshWrapperScript(),
                                                    workdir=workdir, mode=0o700)
 
-        yield self.downloadFileContentToWorker(rel_key_path, private_key,
+        yield self.downloadFileContentToWorker(self._getSshPrivateKeyPath(),
+                                               private_key,
                                                workdir=workdir, mode=0o400)
 
         if self.sshHostKey is not None:
             known_hosts_contents = getSshKnownHostsContents(host_key)
-            yield self.downloadFileContentToWorker(rel_host_key_path,
+            yield self.downloadFileContentToWorker(self._getSshHostKeyPath(),
                                                    known_hosts_contents,
                                                    workdir=workdir, mode=0o400)
 


Test patch:
diff --git a/master/buildbot/test/unit/test_steps_source_git.py b/master/buildbot/test/unit/test_steps_source_git.py
--- a/master/buildbot/test/unit/test_steps_source_git.py
+++ b/master/buildbot/test/unit/test_steps_source_git.py
@@ -18,7 +18,6 @@
 
 from twisted.internet import defer
 from twisted.internet import error
-from twisted.python.reflect import namedModule
 from twisted.trial import unittest
 
 from buildbot.interfaces import WorkerTooOldError
@@ -88,6 +87,12 @@ def test_mode_full_clean_ssh_key_2_10(self):
         self.setupStep(
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean', sshPrivateKey='sshkey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_command_config = \
+            'core.sshCommand=ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -97,13 +102,13 @@ def test_mode_full_clean_ssh_key_2_10(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
@@ -115,7 +120,7 @@ def test_mode_full_clean_ssh_key_2_10(self):
                         command=['git', 'clean', '-f', '-f', '-d'])
             + 0,
             ExpectShell(workdir='wkdir',
-                        command=['git', '-c', 'core.sshCommand=ssh -i "../.wkdir.buildbot/ssh-key"',
+                        command=['git', '-c', ssh_command_config,
                                  'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'])
@@ -128,7 +133,7 @@ def test_mode_full_clean_ssh_key_2_10(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -141,6 +146,11 @@ def test_mode_full_clean_ssh_key_2_3(self):
         self.setupStep(
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean', sshPrivateKey='sshkey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_command = 'ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -150,13 +160,13 @@ def test_mode_full_clean_ssh_key_2_3(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
@@ -171,7 +181,7 @@ def test_mode_full_clean_ssh_key_2_3(self):
                         command=['git', 'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'],
-                        env={'GIT_SSH_COMMAND': 'ssh -i "../.wkdir.buildbot/ssh-key"'})
+                        env={'GIT_SSH_COMMAND': ssh_command})
             + 0,
             ExpectShell(workdir='wkdir',
                         command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
@@ -181,7 +191,7 @@ def test_mode_full_clean_ssh_key_2_3(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -194,6 +204,11 @@ def test_mode_full_clean_ssh_key_1_7(self):
         self.setupStep(
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean', sshPrivateKey='sshkey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_wrapper_path = '/wrk/.wkdir.buildbot/ssh-wrapper.sh'
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -203,20 +218,20 @@ def test_mode_full_clean_ssh_key_1_7(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-wrapper.sh',
+                                        workerdest=ssh_wrapper_path,
                                         workdir='wkdir',
                                         mode=0o700))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
@@ -231,7 +246,7 @@ def test_mode_full_clean_ssh_key_1_7(self):
                         command=['git', 'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'],
-                        env={'GIT_SSH': '../.wkdir.buildbot/ssh-wrapper.sh'})
+                        env={'GIT_SSH': ssh_wrapper_path})
             + 0,
             ExpectShell(workdir='wkdir',
                         command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
@@ -241,7 +256,7 @@ def test_mode_full_clean_ssh_key_1_7(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -256,9 +271,14 @@ def test_mode_full_clean_ssh_host_key_2_10(self):
                            mode='full', method='clean', sshPrivateKey='sshkey',
                            sshHostKey='sshhostkey'))
 
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_known_hosts_path = '/wrk/.wkdir.buildbot/ssh-known-hosts'
         ssh_command_config = \
-            'core.sshCommand=ssh -i "../.wkdir.buildbot/ssh-key" ' \
-            '-o "UserKnownHostsFile=../.wkdir.buildbot/ssh-known-hosts"'
+            'core.sshCommand=ssh -i "{0}" ' \
+            '-o "UserKnownHostsFile={1}"'.format(ssh_key_path,
+                                                 ssh_known_hosts_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -268,20 +288,20 @@ def test_mode_full_clean_ssh_host_key_2_10(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-known-hosts',
+                        workerdest=ssh_known_hosts_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
@@ -306,7 +326,7 @@ def test_mode_full_clean_ssh_host_key_2_10(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -321,9 +341,14 @@ def test_mode_full_clean_ssh_host_key_2_3(self):
                            mode='full', method='clean', sshPrivateKey='sshkey',
                            sshHostKey='sshhostkey'))
 
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_known_hosts_path = '/wrk/.wkdir.buildbot/ssh-known-hosts'
         ssh_command = \
-            'ssh -i "../.wkdir.buildbot/ssh-key" ' \
-            '-o "UserKnownHostsFile=../.wkdir.buildbot/ssh-known-hosts"'
+            'ssh -i "{0}" ' \
+            '-o "UserKnownHostsFile={1}"'.format(ssh_key_path,
+                                                 ssh_known_hosts_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -333,20 +358,20 @@ def test_mode_full_clean_ssh_host_key_2_3(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-known-hosts',
+                        workerdest=ssh_known_hosts_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
@@ -371,7 +396,7 @@ def test_mode_full_clean_ssh_host_key_2_3(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -385,6 +410,12 @@ def test_mode_full_clean_ssh_host_key_1_7(self):
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean', sshPrivateKey='sshkey',
                            sshHostKey='sshhostkey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_wrapper_path = '/wrk/.wkdir.buildbot/ssh-wrapper.sh'
+        ssh_known_hosts_path = '/wrk/.wkdir.buildbot/ssh-known-hosts'
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -394,27 +425,27 @@ def test_mode_full_clean_ssh_host_key_1_7(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-wrapper.sh',
+                                        workerdest=ssh_wrapper_path,
                                         workdir='wkdir',
                                         mode=0o700))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-known-hosts',
+                        workerdest=ssh_known_hosts_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
@@ -429,7 +460,7 @@ def test_mode_full_clean_ssh_host_key_1_7(self):
                         command=['git', 'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'],
-                        env={'GIT_SSH': '../.wkdir.buildbot/ssh-wrapper.sh'})
+                        env={'GIT_SSH': ssh_wrapper_path})
             + 0,
             ExpectShell(workdir='wkdir',
                         command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
@@ -439,7 +470,80 @@ def test_mode_full_clean_ssh_host_key_1_7(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
+                                 logEnviron=True))
+            + 0,
+        )
+        self.expectOutcome(result=SUCCESS)
+        self.expectProperty(
+            'got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', self.sourceName)
+        return self.runStep()
+
+    def test_mode_full_clean_ssh_host_key_2_10_abs_workdir(self):
+        self.setupStep(
+            self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
+                           mode='full', method='clean', sshPrivateKey='sshkey',
+                           sshHostKey='sshhostkey'),
+            wantDefaultWorkdir=False)
+        workdir = '/myworkdir/workdir'
+        self.build.workdir = workdir
+
+        ssh_workdir = '/myworkdir/.workdir.buildbot'
+        ssh_key_path = '/myworkdir/.workdir.buildbot/ssh-key'
+        ssh_known_hosts_path = '/myworkdir/.workdir.buildbot/ssh-known-hosts'
+        ssh_command_config = \
+            'core.sshCommand=ssh -i "{0}" ' \
+            '-o "UserKnownHostsFile={1}"'.format(ssh_key_path,
+                                                 ssh_known_hosts_path)
+
+        self.expectCommands(
+            ExpectShell(workdir=workdir,
+                        command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                              stdout='git version 2.10.0')
+            + 0,
+            Expect('stat', dict(file='/myworkdir/workdir/.buildbot-patched',
+                                logEnviron=True))
+            + 1,
+            Expect('mkdir', dict(dir=ssh_workdir,
+                                 logEnviron=True))
+            + 0,
+            Expect('downloadFile', dict(blocksize=32768, maxsize=None,
+                                        reader=ExpectRemoteRef(
+                                            remotetransfer.StringFileReader),
+                                        workerdest=ssh_key_path,
+                                        workdir=workdir,
+                                        mode=0o400))
+            + 0,
+            Expect('downloadFile',
+                   dict(blocksize=32768, maxsize=None,
+                        reader=ExpectRemoteRef(remotetransfer.StringFileReader),
+                        workerdest=ssh_known_hosts_path,
+                        workdir=workdir,
+                        mode=0o400))
+            + 0,
+            Expect('listdir', {'dir': workdir, 'logEnviron': True,
+                               'timeout': 1200})
+            + Expect.update('files', ['.git'])
+            + 0,
+            ExpectShell(workdir=workdir,
+                        command=['git', 'clean', '-f', '-f', '-d'])
+            + 0,
+            ExpectShell(workdir=workdir,
+                        command=['git', '-c', ssh_command_config,
+                                 'fetch', '-t',
+                                 'http://github.com/buildbot/buildbot.git',
+                                 'HEAD'])
+            + 0,
+            ExpectShell(workdir=workdir,
+                        command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
+            + 0,
+            ExpectShell(workdir=workdir,
+                        command=['git', 'rev-parse', 'HEAD'])
+            + ExpectShell.log('stdio',
+                              stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+            + 0,
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -452,8 +556,7 @@ def test_mode_full_clean_win32path(self):
         self.setupStep(
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean'))
-        self.build.path_module = namedModule('ntpath')
-        self.worker.worker_system = 'win32'
+        self.changeWorkerSystem('win32')
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -493,8 +596,12 @@ def test_mode_full_clean_win32path_ssh_key_2_10(self):
         self.setupStep(
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean', sshPrivateKey='sshkey'))
-        self.build.path_module = namedModule('ntpath')
-        self.worker.worker_system = 'win32'
+        self.changeWorkerSystem('win32')
+
+        ssh_workdir = '\\wrk\\.wkdir.buildbot'
+        ssh_key_path = '\\wrk\\.wkdir.buildbot\\ssh-key'
+        ssh_command_config = 'core.sshCommand=ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -504,13 +611,13 @@ def test_mode_full_clean_win32path_ssh_key_2_10(self):
             Expect('stat', dict(file='wkdir\\.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='..\\.wkdir.buildbot\\ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
@@ -522,7 +629,7 @@ def test_mode_full_clean_win32path_ssh_key_2_10(self):
                         command=['git', 'clean', '-f', '-f', '-d'])
             + 0,
             ExpectShell(workdir='wkdir',
-                        command=['git', '-c', 'core.sshCommand=ssh -i "..\\.wkdir.buildbot\\ssh-key"',
+                        command=['git', '-c', ssh_command_config,
                                  'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'])
@@ -535,7 +642,7 @@ def test_mode_full_clean_win32path_ssh_key_2_10(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -548,8 +655,12 @@ def test_mode_full_clean_win32path_ssh_key_2_3(self):
         self.setupStep(
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean', sshPrivateKey='sshkey'))
-        self.build.path_module = namedModule('ntpath')
-        self.worker.worker_system = 'win32'
+        self.changeWorkerSystem('win32')
+
+        ssh_workdir = '\\wrk\\.wkdir.buildbot'
+        ssh_key_path = '\\wrk\\.wkdir.buildbot\\ssh-key'
+        ssh_command = 'ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -559,13 +670,13 @@ def test_mode_full_clean_win32path_ssh_key_2_3(self):
             Expect('stat', dict(file='wkdir\\.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='..\\.wkdir.buildbot\\ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
@@ -580,7 +691,7 @@ def test_mode_full_clean_win32path_ssh_key_2_3(self):
                         command=['git', 'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'],
-                        env={'GIT_SSH_COMMAND': 'ssh -i "..\\.wkdir.buildbot\\ssh-key"'})
+                        env={'GIT_SSH_COMMAND': ssh_command})
             + 0,
             ExpectShell(workdir='wkdir',
                         command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
@@ -590,7 +701,7 @@ def test_mode_full_clean_win32path_ssh_key_2_3(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -603,8 +714,12 @@ def test_mode_full_clean_win32path_ssh_key_1_7(self):
         self.setupStep(
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='clean', sshPrivateKey='sshkey'))
-        self.build.path_module = namedModule('ntpath')
-        self.worker.worker_system = 'win32'
+        self.changeWorkerSystem('win32')
+
+        ssh_workdir = '\\wrk\\.wkdir.buildbot'
+        ssh_key_path = '\\wrk\\.wkdir.buildbot\\ssh-key'
+        ssh_wrapper_path = '\\wrk\\.wkdir.buildbot\\ssh-wrapper.sh'
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -614,20 +729,20 @@ def test_mode_full_clean_win32path_ssh_key_1_7(self):
             Expect('stat', dict(file='wkdir\\.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='..\\.wkdir.buildbot\\ssh-wrapper.sh',
+                                        workerdest=ssh_wrapper_path,
                                         workdir='wkdir',
                                         mode=0o700))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='..\\.wkdir.buildbot\\ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
@@ -642,7 +757,7 @@ def test_mode_full_clean_win32path_ssh_key_1_7(self):
                         command=['git', 'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'],
-                        env={'GIT_SSH': '..\\.wkdir.buildbot\\ssh-wrapper.sh'})
+                        env={'GIT_SSH': ssh_wrapper_path})
             + 0,
             ExpectShell(workdir='wkdir',
                         command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
@@ -652,7 +767,7 @@ def test_mode_full_clean_win32path_ssh_key_1_7(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -1456,6 +1571,12 @@ def test_mode_incremental_branch_ssh_key_2_10(self):
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='incremental', branch='test-branch',
                            sshPrivateKey='ssh-key'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_command_config = \
+            'core.sshCommand=ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -1465,13 +1586,13 @@ def test_mode_incremental_branch_ssh_key_2_10(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.wkdir.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='wkdir',
                                         mode=0o400))
             + 0,
@@ -1480,7 +1601,7 @@ def test_mode_incremental_branch_ssh_key_2_10(self):
             + Expect.update('files', ['.git'])
             + 0,
             ExpectShell(workdir='wkdir',
-                        command=['git', '-c', 'core.sshCommand=ssh -i "../.wkdir.buildbot/ssh-key"',
+                        command=['git', '-c', ssh_command_config,
                                  'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'test-branch'])
@@ -1496,7 +1617,7 @@ def test_mode_incremental_branch_ssh_key_2_10(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -2146,6 +2267,11 @@ def test_mode_full_copy_ssh_key_2_10(self):
             self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
                            mode='full', method='copy', sshPrivateKey='sshkey'))
 
+        ssh_workdir = '/wrk/.source.buildbot'
+        ssh_key_path = '/wrk/.source.buildbot/ssh-key'
+        ssh_command_config = \
+            'core.sshCommand=ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
@@ -2155,13 +2281,13 @@ def test_mode_full_copy_ssh_key_2_10(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 1,
-            Expect('mkdir', dict(dir='.source.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile', dict(blocksize=32768, maxsize=None,
                                         reader=ExpectRemoteRef(
                                             remotetransfer.StringFileReader),
-                                        workerdest='../.source.buildbot/ssh-key',
+                                        workerdest=ssh_key_path,
                                         workdir='source',
                                         mode=0o400))
             + 0,
@@ -2173,7 +2299,7 @@ def test_mode_full_copy_ssh_key_2_10(self):
             + Expect.update('files', ['.git'])
             + 0,
             ExpectShell(workdir='source',
-                        command=['git', '-c', 'core.sshCommand=ssh -i "../.source.buildbot/ssh-key"',
+                        command=['git', '-c', ssh_command_config,
                                  'fetch', '-t',
                                  'http://github.com/buildbot/buildbot.git',
                                  'HEAD'])
@@ -2189,7 +2315,7 @@ def test_mode_full_copy_ssh_key_2_10(self):
             + ExpectShell.log('stdio',
                               stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
             + 0,
-            Expect('rmdir', dict(dir='.source.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -3232,26 +3358,30 @@ def test_push_fail(self):
 
     def test_push_ssh_key_2_10(self):
         url = 'ssh://github.com/test/test.git'
-        ssh_command_config = \
-            'core.sshCommand=ssh -i "../.wkdir.buildbot/ssh-key"'
 
         self.setupStep(
             self.stepClass(workdir='wkdir', repourl=url,
                            branch='testbranch', sshPrivateKey='sshKey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_command_config = \
+            'core.sshCommand=ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
             + ExpectShell.log('stdio',
                               stdout='git version 2.10.0')
             + 0,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-key',
+                        workerdest=ssh_key_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
@@ -3259,7 +3389,7 @@ def test_push_ssh_key_2_10(self):
                         command=['git', '-c', ssh_command_config,
                                  'push', url, 'testbranch'])
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -3268,25 +3398,29 @@ def test_push_ssh_key_2_10(self):
 
     def test_push_ssh_key_2_3(self):
         url = 'ssh://github.com/test/test.git'
-        ssh_command = 'ssh -i "../.wkdir.buildbot/ssh-key"'
 
         self.setupStep(
             self.stepClass(workdir='wkdir', repourl=url,
                            branch='testbranch', sshPrivateKey='sshKey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_command = 'ssh -i "{0}"'.format(ssh_key_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
             + ExpectShell.log('stdio',
                               stdout='git version 2.3.0')
             + 0,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-key',
+                        workerdest=ssh_key_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
@@ -3294,7 +3428,7 @@ def test_push_ssh_key_2_3(self):
                         command=['git', 'push', url, 'testbranch'],
                         env={'GIT_SSH_COMMAND': ssh_command})
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -3307,20 +3441,25 @@ def test_push_ssh_key_1_7(self):
         self.setupStep(
             self.stepClass(workdir='wkdir', repourl=url,
                            branch='testbranch', sshPrivateKey='sshKey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_wrapper_path = '/wrk/.wkdir.buildbot/ssh-wrapper.sh'
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
             + ExpectShell.log('stdio',
                               stdout='git version 1.7.0')
             + 0,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-wrapper.sh',
+                        workerdest=ssh_wrapper_path,
                         workdir='wkdir',
                         mode=0o700))
             + 0,
@@ -3328,15 +3467,15 @@ def test_push_ssh_key_1_7(self):
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-key',
+                        workerdest=ssh_key_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
             ExpectShell(workdir='wkdir',
                         command=['git', 'push', url, 'testbranch'],
-                        env={'GIT_SSH': '../.wkdir.buildbot/ssh-wrapper.sh'})
+                        env={'GIT_SSH': ssh_wrapper_path})
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -3345,35 +3484,40 @@ def test_push_ssh_key_1_7(self):
 
     def test_push_ssh_host_key_2_10(self):
         url = 'ssh://github.com/test/test.git'
-        ssh_command_config = \
-            'core.sshCommand=ssh -i "../.wkdir.buildbot/ssh-key" ' \
-            '-o "UserKnownHostsFile=../.wkdir.buildbot/ssh-known-hosts"'
-
         self.setupStep(
             self.stepClass(workdir='wkdir', repourl=url,
                            branch='testbranch', sshPrivateKey='sshkey',
                            sshHostKey='sshhostkey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_known_hosts_path = '/wrk/.wkdir.buildbot/ssh-known-hosts'
+        ssh_command_config = \
+            'core.sshCommand=ssh -i "{0}" ' \
+            '-o "UserKnownHostsFile={1}"'.format(ssh_key_path,
+                                                 ssh_known_hosts_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
             + ExpectShell.log('stdio',
                               stdout='git version 2.10.0')
             + 0,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-key',
+                        workerdest=ssh_key_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-known-hosts',
+                        workerdest=ssh_known_hosts_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
@@ -3381,7 +3525,7 @@ def test_push_ssh_host_key_2_10(self):
                         command=['git', '-c', ssh_command_config,
                                  'push', url, 'testbranch'])
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -3390,35 +3534,40 @@ def test_push_ssh_host_key_2_10(self):
 
     def test_push_ssh_host_key_2_3(self):
         url = 'ssh://github.com/test/test.git'
-        ssh_command = \
-            'ssh -i "../.wkdir.buildbot/ssh-key" ' \
-            '-o "UserKnownHostsFile=../.wkdir.buildbot/ssh-known-hosts"'
-
         self.setupStep(
             self.stepClass(workdir='wkdir', repourl=url,
                            branch='testbranch', sshPrivateKey='sshkey',
                            sshHostKey='sshhostkey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_known_hosts_path = '/wrk/.wkdir.buildbot/ssh-known-hosts'
+        ssh_command = \
+            'ssh -i "{0}" ' \
+            '-o "UserKnownHostsFile={1}"'.format(ssh_key_path,
+                                                 ssh_known_hosts_path)
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
             + ExpectShell.log('stdio',
                               stdout='git version 2.3.0')
             + 0,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-key',
+                        workerdest=ssh_key_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-known-hosts',
+                        workerdest=ssh_known_hosts_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
@@ -3426,7 +3575,7 @@ def test_push_ssh_host_key_2_3(self):
                         command=['git', 'push', url, 'testbranch'],
                         env={'GIT_SSH_COMMAND': ssh_command})
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
@@ -3435,25 +3584,30 @@ def test_push_ssh_host_key_2_3(self):
 
     def test_push_ssh_host_key_1_7(self):
         url = 'ssh://github.com/test/test.git'
-
         self.setupStep(
             self.stepClass(workdir='wkdir', repourl=url,
                            branch='testbranch', sshPrivateKey='sshkey',
                            sshHostKey='sshhostkey'))
+
+        ssh_workdir = '/wrk/.wkdir.buildbot'
+        ssh_key_path = '/wrk/.wkdir.buildbot/ssh-key'
+        ssh_wrapper_path = '/wrk/.wkdir.buildbot/ssh-wrapper.sh'
+        ssh_known_hosts_path = '/wrk/.wkdir.buildbot/ssh-known-hosts'
+
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
             + ExpectShell.log('stdio',
                               stdout='git version 1.7.0')
             + 0,
-            Expect('mkdir', dict(dir='.wkdir.buildbot',
+            Expect('mkdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-wrapper.sh',
+                        workerdest=ssh_wrapper_path,
                         workdir='wkdir',
                         mode=0o700))
             + 0,
@@ -3461,22 +3615,22 @@ def test_push_ssh_host_key_1_7(self):
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(
                             remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-key',
+                        workerdest=ssh_key_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
             Expect('downloadFile',
                    dict(blocksize=32768, maxsize=None,
                         reader=ExpectRemoteRef(remotetransfer.StringFileReader),
-                        workerdest='../.wkdir.buildbot/ssh-known-hosts',
+                        workerdest=ssh_known_hosts_path,
                         workdir='wkdir',
                         mode=0o400))
             + 0,
             ExpectShell(workdir='wkdir',
                         command=['git', 'push', url, 'testbranch'],
-                        env={'GIT_SSH': '../.wkdir.buildbot/ssh-wrapper.sh'})
+                        env={'GIT_SSH': ssh_wrapper_path})
             + 0,
-            Expect('rmdir', dict(dir='.wkdir.buildbot',
+            Expect('rmdir', dict(dir=ssh_workdir,
                                  logEnviron=True))
             + 0,
         )
diff --git a/master/buildbot/test/util/steps.py b/master/buildbot/test/util/steps.py
--- a/master/buildbot/test/util/steps.py
+++ b/master/buildbot/test/util/steps.py
@@ -24,6 +24,7 @@
 from twisted.internet import defer
 from twisted.internet import task
 from twisted.python import log
+from twisted.python.reflect import namedModule
 
 from buildbot import interfaces
 from buildbot.process import buildstep
@@ -438,3 +439,12 @@ def _remotecommand_run(self, command, step, conn, builder_name):
             if not exp.shouldKeepMatchingAfter(command):
                 self.expected_remote_commands.pop(0)
         defer.returnValue(command)
+
+    def changeWorkerSystem(self, system):
+        self.worker.worker_system = system
+        if system in ['nt', 'win32']:
+            self.build.path_module = namedModule('ntpath')
+            self.worker.worker_basedir = '\\wrk'
+        else:
+            self.build.path_module = namedModule('posixpath')
+            self.worker.worker_basedir = '/wrk'