Fix F18/F19 cdrom methods
[pykickstart.git] / tests / version.py
blob9459df11756e26494a1cad1810a86f13cd36855b
1 import unittest, shlex
2 import warnings
3 import tempfile
4 from tests.baseclass import *
6 from pykickstart.version import *
7 from pykickstart.errors import *
8 from pykickstart.commands.vnc import *
9 #from pykickstart.base import *
10 #from pykickstart.options import *
12 def getClassName(cls):
13 return cls().__class__.__name__
15 class StringToVersion_TestCase(CommandTest):
16 def runTest(self):
18 # fail - no version specified
19 self.assertRaises(KickstartVersionError, stringToVersion, "RHEL")
20 self.assertRaises(KickstartVersionError, stringToVersion, "Red Hat Enterprise Linux")
21 self.assertRaises(KickstartVersionError, stringToVersion, "Fedora")
22 self.assertRaises(KickstartVersionError, stringToVersion, "F")
23 self.assertRaises(KickstartVersionError, stringToVersion, "FC")
25 # fail - too old
26 self.assertRaises(KickstartVersionError, stringToVersion, "Fedora Core 1")
27 self.assertRaises(KickstartVersionError, stringToVersion, "Fedora Core 2")
29 # fail - incorrect syntax
30 self.assertRaises(KickstartVersionError, stringToVersion, "FC7")
31 self.assertRaises(KickstartVersionError, stringToVersion, "FC8")
32 self.assertRaises(KickstartVersionError, stringToVersion, "FC9")
33 self.assertRaises(KickstartVersionError, stringToVersion, "FC10")
34 self.assertRaises(KickstartVersionError, stringToVersion, "FC11")
35 self.assertRaises(KickstartVersionError, stringToVersion, "F1111")
36 self.assertRaises(KickstartVersionError, stringToVersion, "F 11")
38 # pass - FC3
39 self.assertEqual(stringToVersion("Fedora Core 3"), FC3)
40 self.assertEqual(stringToVersion("FC3"), FC3)
41 # pass - FC4
42 self.assertEqual(stringToVersion("Fedora Core 4"), FC4)
43 self.assertEqual(stringToVersion("FC4"), FC4)
44 # pass - FC5
45 self.assertEqual(stringToVersion("Fedora Core 5"), FC5)
46 self.assertEqual(stringToVersion("FC5"), FC5)
47 # pass - FC6
48 self.assertEqual(stringToVersion("Fedora Core 6"), FC6)
49 self.assertEqual(stringToVersion("FC6"), FC6)
50 # pass - F7
51 self.assertEqual(stringToVersion("Fedora Core 7"), F7)
52 self.assertEqual(stringToVersion("Fedora 7"), F7)
53 self.assertEqual(stringToVersion("F7"), F7)
54 # pass - F8
55 self.assertEqual(stringToVersion("Fedora Core 8"), F8)
56 self.assertEqual(stringToVersion("Fedora 8"), F8)
57 self.assertEqual(stringToVersion("F8"), F8)
58 # pass - F9
59 self.assertEqual(stringToVersion("Fedora Core 9"), F9)
60 self.assertEqual(stringToVersion("Fedora 9"), F9)
61 self.assertEqual(stringToVersion("F9"), F9)
62 # pass - F10
63 self.assertEqual(stringToVersion("Fedora Core 10"), F10)
64 self.assertEqual(stringToVersion("Fedora 10"), F10)
65 self.assertEqual(stringToVersion("F10"), F10)
66 # pass - F11
67 self.assertEqual(stringToVersion("Fedora 11"), F11)
68 self.assertEqual(stringToVersion("F11"), F11)
69 # pass - F12
70 self.assertEqual(stringToVersion("Fedora 12"), F12)
71 self.assertEqual(stringToVersion("F12"), F12)
72 # pass - F13
73 self.assertEqual(stringToVersion("Fedora 13"), F13)
74 self.assertEqual(stringToVersion("F13"), F13)
75 # pass - F14
76 self.assertEqual(stringToVersion("Fedora 14"), F14)
77 self.assertEqual(stringToVersion("F14"), F14)
78 # pass - F15
79 self.assertEqual(stringToVersion("Fedora 15"), F15)
80 self.assertEqual(stringToVersion("F15"), F15)
81 # pass - F16
82 self.assertEqual(stringToVersion("Fedora 16"), F16)
83 self.assertEqual(stringToVersion("F16"), F16)
84 # pass - F17
85 self.assertEqual(stringToVersion("Fedora 17"), F17)
86 self.assertEqual(stringToVersion("F17"), F17)
87 # pass - F18
88 self.assertEqual(stringToVersion("Fedora 18"), F18)
89 self.assertEqual(stringToVersion("F18"), F18)
90 # pass - F19
91 self.assertEqual(stringToVersion("Fedora 19"), F19)
92 self.assertEqual(stringToVersion("F19"), F19)
94 # pass - RHEL3
95 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 3"), RHEL3)
96 self.assertEqual(stringToVersion("Red Hat Enterprise Linux AS 3"), RHEL3)
97 self.assertEqual(stringToVersion("Red Hat Enterprise Linux ES 3"), RHEL3)
98 self.assertEqual(stringToVersion("Red Hat Enterprise Linux WS 3"), RHEL3)
99 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Desktop 3"), RHEL3)
100 self.assertEqual(stringToVersion("RHEL3"), RHEL3)
102 # pass - RHEL4
103 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 4"), RHEL4)
104 self.assertEqual(stringToVersion("Red Hat Enterprise Linux AS 4"), RHEL4)
105 self.assertEqual(stringToVersion("Red Hat Enterprise Linux ES 4"), RHEL4)
106 self.assertEqual(stringToVersion("Red Hat Enterprise Linux WS 4"), RHEL4)
107 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Desktop 4"), RHEL4)
108 self.assertEqual(stringToVersion("RHEL4"), RHEL4)
110 # pass - RHEL5
111 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 5"), RHEL5)
112 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Client 5"), RHEL5)
113 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Server 5"), RHEL5)
114 for MINOR in range(1,10):
115 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 5.%s" % MINOR), RHEL5)
116 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Client 5.%s" % MINOR), RHEL5)
117 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Server 5.%s" % MINOR), RHEL5)
118 self.assertEqual(stringToVersion("RHEL5"), RHEL5)
120 # pass - RHEL6
121 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 6"), RHEL6)
122 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Client 6"), RHEL6)
123 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Server 6"), RHEL6)
124 for MINOR in range(1,10):
125 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 6.%s" % MINOR), RHEL6)
126 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Client 6.%s" % MINOR), RHEL6)
127 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Server 6.%s" % MINOR), RHEL6)
128 self.assertEqual(stringToVersion("RHEL6"), RHEL6)
130 # pass - RHEL7
131 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 7"), RHEL7)
132 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Client 7"), RHEL7)
133 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Server 7"), RHEL7)
134 for MINOR in range(1,10):
135 self.assertEqual(stringToVersion("Red Hat Enterprise Linux 7.%s" % MINOR), RHEL7)
136 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Client 7.%s" % MINOR), RHEL7)
137 self.assertEqual(stringToVersion("Red Hat Enterprise Linux Server 7.%s" % MINOR), RHEL7)
138 self.assertEqual(stringToVersion("RHEL7"), RHEL7)
140 class VersionToString_TestCase(CommandTest):
141 def runTest(self):
143 # Make sure DEVEL is the highest version, but RHEL versions aren't
144 # counted as devel.
145 highest = 0
146 for (ver_str,ver_num) in versionMap.items():
147 if ver_str.startswith("RHEL"):
148 continue
150 highest = max(ver_num, highest)
151 self.assertEqual(highest, DEVEL)
153 # FC series
154 self.assertEqual(versionToString(FC3), "FC3")
155 self.assertEqual(versionToString(FC4), "FC4")
156 self.assertEqual(versionToString(FC5), "FC5")
157 self.assertEqual(versionToString(FC6), "FC6")
158 # F series
159 self.assertEqual(versionToString(F7), "F7")
160 self.assertEqual(versionToString(F8), "F8")
161 self.assertEqual(versionToString(F9), "F9")
162 self.assertEqual(versionToString(F10), "F10")
163 self.assertEqual(versionToString(F10, skipDevel=True), "F10")
164 self.assertEqual(versionToString(F10, skipDevel=False), "F10")
165 self.assertEqual(versionToString(F11, skipDevel=True), "F11")
166 self.assertEqual(versionToString(F11, skipDevel=False), "F11")
167 self.assertEqual(versionToString(F12, skipDevel=True), "F12")
168 self.assertEqual(versionToString(F13, skipDevel=True), "F13")
169 self.assertEqual(versionToString(F14, skipDevel=True), "F14")
170 self.assertEqual(versionToString(F15, skipDevel=True), "F15")
171 self.assertEqual(versionToString(F16, skipDevel=True), "F16")
172 self.assertEqual(versionToString(F17, skipDevel=True), "F17")
173 self.assertEqual(versionToString(F18, skipDevel=True), "F18")
174 self.assertEqual(versionToString(F19, skipDevel=True), "F19")
175 self.assertEqual(versionToString(F19, skipDevel=False), "DEVEL")
176 # RHEL series
177 self.assertEqual(versionToString(RHEL3), "RHEL3")
178 self.assertEqual(versionToString(RHEL4), "RHEL4")
179 self.assertEqual(versionToString(RHEL5), "RHEL5")
180 self.assertEqual(versionToString(RHEL6), "RHEL6")
181 self.assertEqual(versionToString(RHEL7), "RHEL7")
183 class returnClassForVersion_TestCase(CommandTest):
184 def runTest(self):
186 # Test that everything in version.versionMap has a handler, except
187 # for DEVEL.
188 for (name, vers) in versionMap.iteritems():
189 if name == "DEVEL":
190 continue
192 self.assertEqual(returnClassForVersion(vers).version, vers)
194 # Load the handlers
195 import pykickstart.handlers
196 for module in loadModules(pykickstart.handlers.__path__[0], cls_pattern="Handler", skip_list=["control"]):
197 if module.__name__.endswith("Handler") and module.__name__ not in ["BaseHandler"]:
198 # What is the version of the handler?
199 vers = module.__name__.replace("Handler","")
200 self.assertTrue(versionMap.has_key(vers))
201 # Ensure that returnClassForVersion returns what we expect
202 self.assertEqual(getClassName(returnClassForVersion(versionMap[vers])), getClassName(module))
204 class versionFromFile_TestCase(CommandTest):
205 def runTest(self):
207 def write_ks_cfg(buf):
208 (fd, name) = tempfile.mkstemp(prefix="ks-", suffix=".cfg", dir="/tmp")
209 os.write(fd, buf)
210 os.close(fd)
211 return name
213 # no version specified
214 ks_cfg = '''
215 # This is a sample kickstart file
216 rootpw testing123
217 cdrom
219 ks_cfg = write_ks_cfg(ks_cfg)
220 self.assertEqual(versionFromFile(ks_cfg), DEVEL)
221 os.unlink(ks_cfg)
223 # proper format ... DEVEL
224 ks_cfg = '''
225 # This is a sample kickstart file
226 #version=DEVEL
227 rootpw testing123
228 cdrom
230 ks_cfg = write_ks_cfg(ks_cfg)
231 self.assertEqual(versionFromFile(ks_cfg), DEVEL)
232 os.unlink(ks_cfg)
234 # proper format ... RHEL3
235 ks_cfg = '''
236 # This is a sample kickstart file
237 #version=RHEL3
238 rootpw testing123
239 cdrom
241 ks_cfg = write_ks_cfg(ks_cfg)
242 self.assertEqual(versionFromFile(ks_cfg), RHEL3)
243 os.unlink(ks_cfg)
245 # improper format ... fallback to DEVEL
246 ks_cfg = '''
247 # This is a sample kickstart file
248 # version: FC3
249 rootpw testing123
250 cdrom
252 ks_cfg = write_ks_cfg(ks_cfg)
253 self.assertEqual(versionFromFile(ks_cfg), DEVEL)
254 os.unlink(ks_cfg)
256 # unknown version specified ... raise exception
257 ks_cfg = '''
258 # This is a sample kickstart file
259 #version=RHEL5000
260 rootpw testing123
261 cdrom
263 ks_cfg = write_ks_cfg(ks_cfg)
264 self.assertRaises(KickstartVersionError, versionFromFile, ks_cfg)
265 os.unlink(ks_cfg)
267 if __name__ == "__main__":
268 unittest.main()