summaryrefslogtreecommitdiff
path: root/tests/test_chroot.py
blob: c98a889563f8e9f1f31b42f76c45fa7fc34b96aa (plain)
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
37
38
39
40
41
42
43
44
#!/usr/bin/python

import os
import sys
import shutil
import tarfile
import StringIO
import unittest
from mic import chroot

CWD = os.path.dirname(__file__) or '.'
TEST_CHROOT_LOC = os.path.join(CWD, 'chroot_fixtures')
TEST_CHROOT_TAR = os.path.join(TEST_CHROOT_LOC, 'minchroot.tar.gz')
TEST_CHROOT_DIR = os.path.join(TEST_CHROOT_LOC, 'minchroot')

def suite():
    return unittest.makeSuite(ChrootTest)

class ChrootTest(unittest.TestCase):

    def setUp(self):
        tar = tarfile.open(TEST_CHROOT_TAR, "r:gz")
        tar.extractall(path=TEST_CHROOT_LOC)
        self.chrootdir = TEST_CHROOT_DIR
        self.stdout = sys.stdout
        self.stderr = sys.stderr
        sys.stdout = StringIO.StringIO()
        sys.stderr = StringIO.StringIO()

    def tearDown(self):
        sys.stdout = self.stdout
        sys.stderr = self.stderr
        shutil.rmtree(TEST_CHROOT_DIR, ignore_errors=True)

if os.getuid() == 0:
    def testChroot(self):
        try:
            chroot.chroot(TEST_CHROOT_DIR, None, 'exit')
        except Exception as e:
            raise self.failureException(e)

if __name__ == "__main__":
    unittest.main()