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
):
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")
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")
39 self
.assertEqual(stringToVersion("Fedora Core 3"), FC3
)
40 self
.assertEqual(stringToVersion("FC3"), FC3
)
42 self
.assertEqual(stringToVersion("Fedora Core 4"), FC4
)
43 self
.assertEqual(stringToVersion("FC4"), FC4
)
45 self
.assertEqual(stringToVersion("Fedora Core 5"), FC5
)
46 self
.assertEqual(stringToVersion("FC5"), FC5
)
48 self
.assertEqual(stringToVersion("Fedora Core 6"), FC6
)
49 self
.assertEqual(stringToVersion("FC6"), FC6
)
51 self
.assertEqual(stringToVersion("Fedora Core 7"), F7
)
52 self
.assertEqual(stringToVersion("Fedora 7"), F7
)
53 self
.assertEqual(stringToVersion("F7"), F7
)
55 self
.assertEqual(stringToVersion("Fedora Core 8"), F8
)
56 self
.assertEqual(stringToVersion("Fedora 8"), F8
)
57 self
.assertEqual(stringToVersion("F8"), F8
)
59 self
.assertEqual(stringToVersion("Fedora Core 9"), F9
)
60 self
.assertEqual(stringToVersion("Fedora 9"), F9
)
61 self
.assertEqual(stringToVersion("F9"), F9
)
63 self
.assertEqual(stringToVersion("Fedora Core 10"), F10
)
64 self
.assertEqual(stringToVersion("Fedora 10"), F10
)
65 self
.assertEqual(stringToVersion("F10"), F10
)
67 self
.assertEqual(stringToVersion("Fedora 11"), F11
)
68 self
.assertEqual(stringToVersion("F11"), F11
)
70 self
.assertEqual(stringToVersion("Fedora 12"), F12
)
71 self
.assertEqual(stringToVersion("F12"), F12
)
73 self
.assertEqual(stringToVersion("Fedora 13"), F13
)
74 self
.assertEqual(stringToVersion("F13"), F13
)
76 self
.assertEqual(stringToVersion("Fedora 14"), F14
)
77 self
.assertEqual(stringToVersion("F14"), F14
)
79 self
.assertEqual(stringToVersion("Fedora 15"), F15
)
80 self
.assertEqual(stringToVersion("F15"), F15
)
82 self
.assertEqual(stringToVersion("Fedora 16"), F16
)
83 self
.assertEqual(stringToVersion("F16"), F16
)
85 self
.assertEqual(stringToVersion("Fedora 17"), F17
)
86 self
.assertEqual(stringToVersion("F17"), F17
)
88 self
.assertEqual(stringToVersion("Fedora 18"), F18
)
89 self
.assertEqual(stringToVersion("F18"), F18
)
91 self
.assertEqual(stringToVersion("Fedora 19"), F19
)
92 self
.assertEqual(stringToVersion("F19"), F19
)
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
)
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
)
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
)
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
)
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
):
143 # Make sure DEVEL is the highest version, but RHEL versions aren't
146 for (ver_str
,ver_num
) in versionMap
.items():
147 if ver_str
.startswith("RHEL"):
150 highest
= max(ver_num
, highest
)
151 self
.assertEqual(highest
, DEVEL
)
154 self
.assertEqual(versionToString(FC3
), "FC3")
155 self
.assertEqual(versionToString(FC4
), "FC4")
156 self
.assertEqual(versionToString(FC5
), "FC5")
157 self
.assertEqual(versionToString(FC6
), "FC6")
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")
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
):
186 # Test that everything in version.versionMap has a handler, except
188 for (name
, vers
) in versionMap
.iteritems():
192 self
.assertEqual(returnClassForVersion(vers
).version
, vers
)
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
):
207 def write_ks_cfg(buf
):
208 (fd
, name
) = tempfile
.mkstemp(prefix
="ks-", suffix
=".cfg", dir="/tmp")
213 # no version specified
215 # This is a sample kickstart file
219 ks_cfg
= write_ks_cfg(ks_cfg
)
220 self
.assertEqual(versionFromFile(ks_cfg
), DEVEL
)
223 # proper format ... DEVEL
225 # This is a sample kickstart file
230 ks_cfg
= write_ks_cfg(ks_cfg
)
231 self
.assertEqual(versionFromFile(ks_cfg
), DEVEL
)
234 # proper format ... RHEL3
236 # This is a sample kickstart file
241 ks_cfg
= write_ks_cfg(ks_cfg
)
242 self
.assertEqual(versionFromFile(ks_cfg
), RHEL3
)
245 # improper format ... fallback to DEVEL
247 # This is a sample kickstart file
252 ks_cfg
= write_ks_cfg(ks_cfg
)
253 self
.assertEqual(versionFromFile(ks_cfg
), DEVEL
)
256 # unknown version specified ... raise exception
258 # This is a sample kickstart file
263 ks_cfg
= write_ks_cfg(ks_cfg
)
264 self
.assertRaises(KickstartVersionError
, versionFromFile
, ks_cfg
)
267 if __name__
== "__main__":