diff --git a/mitogen/master.py b/mitogen/master.py index 1a8335e8..f94c46da 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -977,8 +977,8 @@ class Router(mitogen.core.Router): name = via_context.call(_proxy_connect, name, context_id, method_name, kwargs ) + name = '%s.%s' % (via_context.name, name) - # name = '%s.%s' % (via_context.name, name) context = Context(self, context_id, name=name) context.via = via_context self._context_by_id[context.context_id] = context diff --git a/mitogen/sudo.py b/mitogen/sudo.py index 58a30111..8ea2913c 100644 --- a/mitogen/sudo.py +++ b/mitogen/sudo.py @@ -51,6 +51,9 @@ class Stream(mitogen.master.Stream): self.sudo_path = sudo_path if password: self.password = password + + def connect(self): + super(Stream, self).connect() self.name = 'sudo.' + self.username def get_boot_command(self): diff --git a/tests/local_test.py b/tests/local_test.py new file mode 100644 index 00000000..ff39490a --- /dev/null +++ b/tests/local_test.py @@ -0,0 +1,23 @@ + +import os +import unittest + +import mitogen +import mitogen.ssh +import mitogen.utils + +import testlib +import plain_old_module + + +class LocalTest(testlib.RouterMixin, unittest.TestCase): + stream_class = mitogen.ssh.Stream + + def test_stream_name(self): + context = self.router.local() + pid = context.call(os.getpid) + self.assertEquals('local.%d' % (pid,), context.name) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/ssh_test.py b/tests/ssh_test.py index c18a5229..19a7405b 100644 --- a/tests/ssh_test.py +++ b/tests/ssh_test.py @@ -24,6 +24,27 @@ class FakeSshTest(testlib.RouterMixin, unittest.TestCase): class SshTest(testlib.DockerMixin, unittest.TestCase): stream_class = mitogen.ssh.Stream + def test_stream_name(self): + context = self.docker_ssh( + username='has-sudo', + password='y', + ) + self.assertEquals('ssh.u1704:%s' % (self.dockerized_ssh.port,), + context.name) + + def test_via_stream_name(self): + context = self.docker_ssh( + username='has-sudo-nopw', + password='y', + ) + sudo = self.router.sudo(via=context) + + name = 'ssh.%s:%s.sudo.root' % ( + self.dockerized_ssh.host, + self.dockerized_ssh.port, + ) + self.assertEquals(name, sudo.name) + def test_password_required(self): try: context = self.docker_ssh( @@ -74,3 +95,7 @@ class SshTest(testlib.DockerMixin, unittest.TestCase): ) sentinel = 'i-am-mitogen-test-docker-image\n' assert sentinel == context.call(plain_old_module.get_sentinel_value) + + +if __name__ == '__main__': + unittest.main()