File: lxc_test.py

package info (click to toggle)
python-mitogen 0.3.26-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,456 kB
  • sloc: python: 22,134; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (36 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os

import mitogen.lxc
import mitogen.parent

from mitogen.core import any

import testlib


def has_subseq(seq, subseq):
    return any(seq[x:x+len(subseq)] == subseq for x in range(0, len(seq)))


class ConstructorTest(testlib.RouterMixin, testlib.TestCase):
    lxc_attach_path = testlib.data_path('stubs/stub-lxc-attach.py')

    def test_okay(self):
        context = self.router.lxc(
            container='container_name',
            lxc_attach_path=self.lxc_attach_path,
        )

        argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV'))
        self.assertEqual(argv[0], self.lxc_attach_path)
        self.assertIn('--clear-env', argv)
        self.assertTrue(has_subseq(argv, ['--name', 'container_name']))

    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.Connection.eof_error_hint))