2018-08-10 19:18:41 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import mitogen
|
2018-10-30 22:39:35 +00:00
|
|
|
import mitogen.lxc
|
2018-08-10 19:18:41 +00:00
|
|
|
|
|
|
|
import unittest2
|
|
|
|
|
|
|
|
import testlib
|
|
|
|
|
|
|
|
|
|
|
|
def has_subseq(seq, subseq):
|
|
|
|
return any(seq[x:x+len(subseq)] == subseq for x in range(0, len(seq)))
|
|
|
|
|
|
|
|
|
2018-10-30 22:39:35 +00:00
|
|
|
class ConstructorTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
lxc_attach_path = testlib.data_path('stubs/lxc-attach.py')
|
|
|
|
|
2018-08-10 19:18:41 +00:00
|
|
|
def test_okay(self):
|
|
|
|
context = self.router.lxc(
|
|
|
|
container='container_name',
|
2018-10-30 22:39:35 +00:00
|
|
|
lxc_attach_path=self.lxc_attach_path,
|
2018-08-10 19:18:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV'))
|
2018-10-30 22:39:35 +00:00
|
|
|
self.assertEquals(argv[0], self.lxc_attach_path)
|
2018-08-10 19:18:41 +00:00
|
|
|
self.assertTrue('--clear-env' in argv)
|
|
|
|
self.assertTrue(has_subseq(argv, ['--name', 'container_name']))
|
|
|
|
|
2018-10-30 22:39:35 +00:00
|
|
|
def test_eof(self):
|
|
|
|
e = self.assertRaises(mitogen.parent.EofError,
|
|
|
|
lambda: self.router.lxc(
|
|
|
|
container='container_name',
|
|
|
|
lxc_attach_path='true',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertTrue(str(e).endswith(mitogen.lxc.Stream.eof_error_hint))
|
|
|
|
|
2018-08-10 19:18:41 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest2.main()
|