Fix context naming for sudo and via=.

pull/45/head
David Wilson 7 years ago
parent 8fec1f985e
commit f57a12b3f9

@ -977,8 +977,8 @@ class Router(mitogen.core.Router):
name = via_context.call(_proxy_connect, name = via_context.call(_proxy_connect,
name, context_id, method_name, kwargs 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 = Context(self, context_id, name=name)
context.via = via_context context.via = via_context
self._context_by_id[context.context_id] = context self._context_by_id[context.context_id] = context

@ -51,6 +51,9 @@ class Stream(mitogen.master.Stream):
self.sudo_path = sudo_path self.sudo_path = sudo_path
if password: if password:
self.password = password self.password = password
def connect(self):
super(Stream, self).connect()
self.name = 'sudo.' + self.username self.name = 'sudo.' + self.username
def get_boot_command(self): def get_boot_command(self):

@ -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()

@ -24,6 +24,27 @@ class FakeSshTest(testlib.RouterMixin, unittest.TestCase):
class SshTest(testlib.DockerMixin, unittest.TestCase): class SshTest(testlib.DockerMixin, unittest.TestCase):
stream_class = mitogen.ssh.Stream 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): def test_password_required(self):
try: try:
context = self.docker_ssh( context = self.docker_ssh(
@ -74,3 +95,7 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
) )
sentinel = 'i-am-mitogen-test-docker-image\n' sentinel = 'i-am-mitogen-test-docker-image\n'
assert sentinel == context.call(plain_old_module.get_sentinel_value) assert sentinel == context.call(plain_old_module.get_sentinel_value)
if __name__ == '__main__':
unittest.main()

Loading…
Cancel
Save