summaryrefslogtreecommitdiff
path: root/tests/test_configmgr.py
blob: 2f15f10cf1f7385dee815f1b2c54befb6a0bfb8f (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python

import os
import sys
import shutil
import StringIO
import unittest

from mic import conf, msger
from pykickstart.parser import KickstartParser

CWD = os.path.dirname(__file__) or '.'
SITECONF = os.path.join(CWD, 'configmgr_fixtures', 'mic.conf')
KSCONF = os.path.join(CWD, 'configmgr_fixtures', 'test.ks')
KSBAK = os.path.join(CWD, 'configmgr_fixtures', 'test.ks.bak')
REPOURI = os.path.join(CWD, 'configmgr_fixtures', 'packages')
CACHEDIR = os.path.join(CWD, 'configmgr_fixtures', 'cache')

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

class ConfigMgrTest(unittest.TestCase):

    def setUp(self):
        self.configmgr = conf.ConfigMgr(siteconf=SITECONF)
        shutil.copy2(KSCONF, KSBAK)
        with open(KSCONF, 'r') as f:
            content = f.read()
        content = content.replace('$$$$$$', "file://" + REPOURI)
        with open(KSCONF, 'w') as f:
            f.write(content)
        if not os.path.exists(CACHEDIR):
            os.makedirs(CACHEDIR)
        self.configmgr.create['cachedir'] = CACHEDIR
        self.level = msger.get_loglevel()
        msger.set_loglevel('RAWTEXT')

    def tearDown(self):
        msger.set_loglevel(self.level)
        shutil.copy2(KSBAK, KSCONF)
        os.unlink(KSBAK)
        shutil.rmtree(CACHEDIR, ignore_errors = True)

#    def testCommonSection(self):
#        self.assertEqual(self.configmgr.common['test'], 'test')

    def testCreateSection(self):
        #self.assertEqual(self.configmgr.create['local_pkgs_path'], '/opt/cache')
        self.assertEqual(self.configmgr.create['pkgmgr'], 'yum')

#    def testChrootSection(self):
#        self.assertEqual(self.configmgr.chroot['test2'], 'test2')

#    def testConvertSection(self):
#        self.assertEqual(self.configmgr.convert['test3'], 'test3')

    def testKickstartConfig(self):
        cachedir = self.configmgr.create['cachedir']
        repomd = [{'baseurl': 'file://%s' % REPOURI ,
             'cachedir': '%s' % cachedir,
             'comps': None,
             'name': 'test',
             'patterns': None,
             'primary': '%s/test/primary.sqlite' % cachedir,
             'proxies': None,
             'repokey': None,
             'repomd': '%s/test/repomd.xml' % cachedir}]
        self.configmgr._ksconf = KSCONF
        self.assertTrue(isinstance(self.configmgr.create['ks'], KickstartParser))
        #self.assertEqual(self.configmgr.create['name'], 'test')
        #self.assertDictEqual(repomd[0], self.configmgr.create['repomd'][0])
        self.assertEqual(repomd[0], self.configmgr.create['repomd'][0])
        self.assertEqual(self.configmgr.create['arch'], 'i686')

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