diff --git a/mitogen/lxc.py b/mitogen/lxc.py index 4d6c21db..71b12221 100644 --- a/mitogen/lxc.py +++ b/mitogen/lxc.py @@ -52,7 +52,7 @@ class Stream(mitogen.parent.Stream): super(Stream, self).construct(**kwargs) self.container = container if lxc_attach_path: - self.lxc_attach_path = lxc_attach_apth + self.lxc_attach_path = lxc_attach_path def connect(self): super(Stream, self).connect() diff --git a/tests/data/fake_lxc.py b/tests/data/fake_lxc.py new file mode 100755 index 00000000..2fedb961 --- /dev/null +++ b/tests/data/fake_lxc.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +import sys +import os + +os.environ['ORIGINAL_ARGV'] = repr(sys.argv) +os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:]) diff --git a/tests/data/fake_lxc_attach.py b/tests/data/fake_lxc_attach.py new file mode 100755 index 00000000..2fedb961 --- /dev/null +++ b/tests/data/fake_lxc_attach.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +import sys +import os + +os.environ['ORIGINAL_ARGV'] = repr(sys.argv) +os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:]) diff --git a/tests/lxc_test.py b/tests/lxc_test.py new file mode 100644 index 00000000..a30cd186 --- /dev/null +++ b/tests/lxc_test.py @@ -0,0 +1,29 @@ +import os + +import mitogen + +import unittest2 + +import testlib + + +def has_subseq(seq, subseq): + return any(seq[x:x+len(subseq)] == subseq for x in range(0, len(seq))) + + +class FakeLxcAttachTest(testlib.RouterMixin, unittest2.TestCase): + def test_okay(self): + lxc_attach_path = testlib.data_path('fake_lxc_attach.py') + context = self.router.lxc( + container='container_name', + lxc_attach_path=lxc_attach_path, + ) + + argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV')) + self.assertEquals(argv[0], lxc_attach_path) + self.assertTrue('--clear-env' in argv) + self.assertTrue(has_subseq(argv, ['--name', 'container_name'])) + + +if __name__ == '__main__': + unittest2.main() diff --git a/tests/lxd_test.py b/tests/lxd_test.py new file mode 100644 index 00000000..c5e4c485 --- /dev/null +++ b/tests/lxd_test.py @@ -0,0 +1,26 @@ +import os + +import mitogen + +import unittest2 + +import testlib + + +class FakeLxcTest(testlib.RouterMixin, unittest2.TestCase): + def test_okay(self): + lxc_path = testlib.data_path('fake_lxc.py') + context = self.router.lxd( + container='container_name', + lxc_path=lxc_path, + ) + + argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV')) + self.assertEquals(argv[0], lxc_path) + self.assertEquals(argv[1], 'exec') + self.assertEquals(argv[2], '--force-noninteractive') + self.assertEquals(argv[3], 'container_name') + + +if __name__ == '__main__': + unittest2.main()