Locally built mic-bootstrap using gbs cannot be used in mic.
[tools/mic.git] / tests / test_configmgr.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import shutil
6 import StringIO
7 import unittest
8
9 from mic import conf, msger
10 from pykickstart.parser import KickstartParser
11
12 CWD = os.path.dirname(__file__) or '.'
13 SITECONF = os.path.join(CWD, 'configmgr_fixtures', 'mic.conf')
14 KSCONF = os.path.join(CWD, 'configmgr_fixtures', 'test.ks')
15 KSBAK = os.path.join(CWD, 'configmgr_fixtures', 'test.ks.bak')
16 REPOURI = os.path.join(CWD, 'configmgr_fixtures', 'packages')
17 CACHEDIR = os.path.join(CWD, 'configmgr_fixtures', 'cache')
18
19 def suite():
20     return unittest.makeSuite(ConfigMgrTest)
21
22 class ConfigMgrTest(unittest.TestCase):
23
24     def setUp(self):
25         self.configmgr = conf.ConfigMgr(siteconf=SITECONF)
26         shutil.copy2(KSCONF, KSBAK)
27         with open(KSCONF, 'r') as f:
28             content = f.read()
29         content = content.replace('$$$$$$', "file://" + REPOURI)
30         with open(KSCONF, 'w') as f:
31             f.write(content)
32         if not os.path.exists(CACHEDIR):
33             os.makedirs(CACHEDIR)
34         self.configmgr.create['cachedir'] = CACHEDIR
35         self.level = msger.get_loglevel()
36         msger.set_loglevel('RAWTEXT')
37
38     def tearDown(self):
39         msger.set_loglevel(self.level)
40         shutil.copy2(KSBAK, KSCONF)
41         os.unlink(KSBAK)
42         shutil.rmtree(CACHEDIR, ignore_errors = True)
43
44 #    def testCommonSection(self):
45 #        self.assertEqual(self.configmgr.common['test'], 'test')
46
47     def testCreateSection(self):
48         #self.assertEqual(self.configmgr.create['local_pkgs_path'], '/opt/cache')
49         self.assertEqual(self.configmgr.create['pkgmgr'], 'yum')
50
51 #    def testChrootSection(self):
52 #        self.assertEqual(self.configmgr.chroot['test2'], 'test2')
53
54 #    def testConvertSection(self):
55 #        self.assertEqual(self.configmgr.convert['test3'], 'test3')
56
57     def testKickstartConfig(self):
58         cachedir = self.configmgr.create['cachedir']
59         repomd = [{'baseurl': 'file://%s' % REPOURI ,
60              'cachedir': '%s' % cachedir,
61              'comps': None,
62              'name': 'test',
63              'patterns': None,
64              'primary': '%s/test/primary.sqlite' % cachedir,
65              'proxies': None,
66              'repokey': None,
67              'repomd': '%s/test/repomd.xml' % cachedir,
68              'priority': None}]
69         self.configmgr._ksconf = KSCONF
70         self.assertTrue(isinstance(self.configmgr.create['ks'], KickstartParser))
71         #self.assertEqual(self.configmgr.create['name'], 'test')
72         #self.assertDictEqual(repomd[0], self.configmgr.create['repomd'][0])
73         self.assertEqual(repomd[0], self.configmgr.create['repomd'][0])
74         self.assertEqual(self.configmgr.create['arch'], 'i686')
75
76 if __name__ == "__main__":
77     unittest.main()