2019-03-10 20:02:41 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import socket
|
2019-07-25 11:03:17 +00:00
|
|
|
import sys
|
2019-03-10 20:02:41 +00:00
|
|
|
|
|
|
|
import mitogen
|
|
|
|
import mitogen.parent
|
|
|
|
|
|
|
|
import unittest2
|
|
|
|
|
|
|
|
import testlib
|
|
|
|
|
|
|
|
|
|
|
|
class DockerTest(testlib.DockerMixin, testlib.TestCase):
|
|
|
|
def test_okay(self):
|
|
|
|
# Magic calls must happen as root.
|
|
|
|
try:
|
|
|
|
root = self.router.sudo()
|
|
|
|
except mitogen.core.StreamError:
|
|
|
|
raise unittest2.SkipTest("requires sudo to localhost root")
|
|
|
|
|
|
|
|
via_ssh = self.docker_ssh(
|
|
|
|
username='mitogen__has_sudo',
|
|
|
|
password='has_sudo_password',
|
|
|
|
)
|
|
|
|
|
|
|
|
via_setns = self.router.setns(
|
|
|
|
kind='docker',
|
|
|
|
container=self.dockerized_ssh.container_name,
|
|
|
|
via=root,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEquals(
|
|
|
|
via_ssh.call(socket.gethostname),
|
|
|
|
via_setns.call(socket.gethostname),
|
|
|
|
)
|
|
|
|
|
2019-07-25 11:03:17 +00:00
|
|
|
|
|
|
|
DockerTest = unittest2.skipIf(
|
|
|
|
condition=sys.version_info < (2, 5),
|
|
|
|
reason="mitogen.setns unsupported on Python <2.4"
|
|
|
|
)(DockerTest)
|
|
|
|
|
|
|
|
|
2019-03-10 20:02:41 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest2.main()
|