2 # James Laska <jlaska@redhat.com>
4 # Copyright 2009 Red Hat, Inc.
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
22 from tests
.baseclass
import *
24 from pykickstart
.errors
import *
25 from pykickstart
.commands
.dmraid
import *
27 class FC3_TestCase(CommandTest
):
30 def __init__(self
, *kargs
, **kwargs
):
31 CommandTest
.__init
__(self
, *kargs
, **kwargs
)
32 self
.validLevels
= ["RAID0", "RAID1", "RAID5", "RAID6"]
33 self
.minorBasedDevice
= True
36 if "--bytes-per-inode" in self
.optionList
:
37 self
.bytesPerInode
= " --bytes-per-inode=4096"
39 self
.bytesPerInode
= ""
43 for level
in self
.validLevels
:
44 self
.assert_parse("raid / --device=md0 --level=%s%s raid.01" % (level
, self
.bytesPerInode
), \
45 "raid / --device=0 --level=%s%s raid.01\n" % (level
, self
.bytesPerInode
))
48 self
.assert_parse("raid / --device=md0 --level=0%s raid.01" % (self
.bytesPerInode
), \
49 "raid / --device=0 --level=RAID0%s raid.01\n" % (self
.bytesPerInode
))
51 self
.assert_parse("raid / --device=0 --level=1%s raid.01 raid.02 raid.03" % (self
.bytesPerInode
), \
52 "raid / --device=0 --level=RAID1%s raid.01 raid.02 raid.03\n" % (self
.bytesPerInode
))
53 # device=2, level=RAID1
54 self
.assert_parse("raid / --device=md0 --level=RAID1%s raid.01 raid.02 raid.03" % (self
.bytesPerInode
), \
55 "raid / --device=0 --level=RAID1%s raid.01 raid.02 raid.03\n" % (self
.bytesPerInode
))
57 self
.assert_parse("raid / --device=md2 --level=5 --spares=0%s raid.01 raid.02 raid.03" % (self
.bytesPerInode
), \
58 "raid / --device=2 --level=RAID5%s raid.01 raid.02 raid.03\n" % (self
.bytesPerInode
))
60 self
.assert_parse("raid / --device=md2 --level=5 --spares=2%s raid.01 raid.02 raid.03" % (self
.bytesPerInode
), \
61 "raid / --device=2 --level=RAID5 --spares=2%s raid.01 raid.02 raid.03\n" % (self
.bytesPerInode
))
64 self
.assert_parse("raid / --device=md0 --fstype=ASDF --level=6%s raid.01 raid.02" % (self
.bytesPerInode
), \
65 "raid / --device=0 --fstype=\"ASDF\" --level=RAID6%s raid.01 raid.02\n" % (self
.bytesPerInode
))
67 self
.assert_parse("raid / --device=md0 --level=6 --useexisting%s" % (self
.bytesPerInode
), \
68 "raid / --device=0 --level=RAID6 --useexisting%s\n" % (self
.bytesPerInode
))
71 self
.assert_parse("raid / --device=md0 --level=6 --noformat --useexisting%s" % (self
.bytesPerInode
), \
72 "raid / --device=0 --level=RAID6 --noformat --useexisting%s\n" % (self
.bytesPerInode
))
75 # no mountpoint or options
76 self
.assert_parse_error("raid", KickstartValueError
)
77 # no mountpoint or options ... just partitions
78 self
.assert_parse_error("raid part.01 part.01", KickstartValueError
)
80 self
.assert_parse_error("raid --level=0 --device=md0", KickstartValueError
)
82 self
.assert_parse_error("raid /", KickstartValueError
)
84 self
.assert_parse_error("raid / --level=0", KickstartValueError
)
86 self
.assert_parse_error("raid / --device=md0", KickstartValueError
)
87 # No raid members defined
88 self
.assert_parse_error("raid / --level=0 --device=md0", KickstartValueError
)
89 # Both raid members and useexisting given
90 self
.assert_parse_error("raid / --level=0 --device=md0 --useexisting raid.01 raid.02", KickstartValueError
)
92 if self
.minorBasedDevice
:
93 # Invalid device string - device=asdf0 (--device=(md)?<minor>)
94 self
.assert_parse_error("raid / --device=asdf0 --level=RAID1 raid.01 raid.02 raid.03", ValueError)
97 self
.assert_parse("raid / --device=root --level=RAID1 raid.01 raid.02 raid.03",
98 "raid / --device=root --level=RAID1 raid.01 raid.02 raid.03\n")
100 class FC4_TestCase(FC3_TestCase
):
103 FC3_TestCase
.runTest(self
)
107 self
.assert_parse("raid / --device=md0 --fstype=\"ext3\" --level=6 --fsoptions \"these=are,options\"%s raid.01 raid.02" % (self
.bytesPerInode
), \
108 "raid / --device=0 --fstype=\"ext3\" --level=RAID6 --fsoptions=\"these=are,options\"%s raid.01 raid.02\n" % (self
.bytesPerInode
))
110 class FC5_TestCase(FC4_TestCase
):
113 FC4_TestCase
.runTest(self
)
117 self
.assert_parse("raid / --device=md0 --fstype=\"ext2\" --level=RAID0%s raid.01 raid.02" % (self
.bytesPerInode
,), \
118 "raid / --device=0 --fstype=\"ext2\" --level=RAID0%s raid.01 raid.02\n" % (self
.bytesPerInode
,))
120 if "--encrypted" in self
.optionList
:
123 self
.assert_parse("raid / --device=md0 --fstype=\"ext3\" --level=1%s --encrypted raid.01 raid.02" % (self
.bytesPerInode
), \
124 "raid / --device=0 --fstype=\"ext3\" --level=RAID1%s --encrypted raid.01 raid.02\n" % (self
.bytesPerInode
))
126 # FIXME - should this fail since no --encrypted?
127 self
.assert_parse("raid / --device=md0 --fstype=\"ext3\" --level=1%s --passphrase=asdf raid.01 raid.02" % (self
.bytesPerInode
), \
128 "raid / --device=0 --fstype=\"ext3\" --level=RAID1%s raid.01 raid.02\n" % (self
.bytesPerInode
))
130 # encrypted w/ passphrase
131 self
.assert_parse("raid / --device=md0 --fstype=\"ext3\" --level=1%s --encrypted --passphrase=asdf raid.01 raid.02" % (self
.bytesPerInode
), \
132 "raid / --device=0 --fstype=\"ext3\" --level=RAID1%s --encrypted --passphrase=\"asdf\" raid.01 raid.02\n" % (self
.bytesPerInode
))
135 # --encrypted=<value>
136 self
.assert_parse_error("raid / --device=md0 --level=1 --encrypted=1", KickstartParseError
)
138 class RHEL5_TestCase(FC5_TestCase
):
139 def __init__(self
, *kargs
, **kwargs
):
140 FC5_TestCase
.__init
__(self
, *kargs
, **kwargs
)
141 self
.validLevels
.append("RAID10")
143 F7_TestCase
= RHEL5_TestCase
145 class F9_TestCase(F7_TestCase
):
149 F7_TestCase
.runTest(self
)
152 self
.assert_parse("raid / --device=md0 --fstype=\"ext3\" --level=1 --fsprofile=ASDF raid.01 raid.02", \
153 "raid / --device=0 --fstype=\"ext3\" --level=RAID1 --fsprofile=\"ASDF\" raid.01 raid.02\n")
156 self
.assert_deprecated("raid", "--bytes-per-inode")
158 class F12_TestCase(F9_TestCase
):
162 F9_TestCase
.runTest(self
)
165 self
.assert_parse("raid / --device=md0 --escrowcert=\"http://x/y\" --level=1 raid.01 raid.02",
166 "raid / --device=0 --level=RAID1 raid.01 raid.02\n")
167 self
.assert_parse("raid / --device=md0 --encrypted --backuppassphrase --level=1 raid.01 raid.02",
168 "raid / --device=0 --level=RAID1 --encrypted raid.01 raid.02\n")
169 self
.assert_parse("raid / --device=md0 --encrypted --escrowcert=\"http://x/y\" --level=1 raid.01 raid.02",
170 "raid / --device=0 --level=RAID1 --encrypted --escrowcert=\"http://x/y\" raid.01 raid.02\n")
171 self
.assert_parse("raid / --device=md0 --encrypted --escrowcert=\"http://x/y\" --backuppassphrase --level=1 raid.01 raid.02",
172 "raid / --device=0 --level=RAID1 --encrypted --escrowcert=\"http://x/y\" --backuppassphrase raid.01 raid.02\n")
173 self
.assert_parse("raid / --device=md0 --encrypted --escrowcert=http://x/y --level=1 raid.01 raid.02",
174 "raid / --device=0 --level=RAID1 --encrypted --escrowcert=\"http://x/y\" raid.01 raid.02\n")
177 self
.assert_parse_error("raid / --device=md0 --level=1 raid.01 raid.02 -escrowcert")
178 self
.assert_parse_error("raid / --device=md0 --escrowcert --backuppassphrase --level=1 raid.01 raid.02")
179 self
.assert_parse_error("raid / --device=md0 --encrypted --escrowcert --backuppassphrase --level=1 raid.01 raid.02")
180 self
.assert_parse_error("raid / --device=md0 --backuppassphrase=False --level=1 raid.01 raid.02")
181 self
.assert_parse_error("raid / --device=md0 --backuppassphrase=True --level=1 raid.01 raid.02")
183 class F13_TestCase(F12_TestCase
):
184 def __init__(self
, *kargs
, **kwargs
):
185 F12_TestCase
.__init
__(self
, *kargs
, **kwargs
)
186 self
.validLevels
.append("RAID4")
188 class RHEL6_TestCase(F13_TestCase
):
190 F13_TestCase
.runTest(self
)
192 self
.assert_parse("raid / --device=md0 --level=1 --encrypted --cipher=3-rot13 raid.01 raid.02",
193 "raid / --device=0 --level=RAID1 --encrypted --cipher=\"3-rot13\" raid.01 raid.02\n")
194 # Allowed here, but anaconda should complain. Note how we throw out
195 # cipher from the output if there's no --encrypted.
196 self
.assert_parse("raid / --device=md0 --level=1 --cipher=3-rot13 raid.01 raid.02",
197 "raid / --device=0 --level=RAID1 raid.01 raid.02\n")
199 self
.assert_parse_error("raid / --cipher --device=md0 --level=1 raid.01 raid.02")
201 class F14_TestCase(F13_TestCase
):
203 F13_TestCase
.runTest(self
)
204 self
.assert_removed("raid", "bytes-per-inode")
206 class F15_TestCase(F14_TestCase
):
208 F14_TestCase
.runTest(self
)
211 self
.assert_parse("raid / --device=md0 --label=ROOT --level=1 raid.01 raid.02",
212 "raid / --device=0 --level=RAID1 --label=ROOT raid.01 raid.02\n")
214 class F18_TestCase(F15_TestCase
):
216 F15_TestCase
.runTest(self
)
218 self
.assert_parse("raid / --device=md0 --level=1 --encrypted --cipher=3-rot13 raid.01 raid.02",
219 "raid / --device=0 --level=RAID1 --encrypted --cipher=\"3-rot13\" raid.01 raid.02\n")
220 # Allowed here, but anaconda should complain. Note how we throw out
221 # cipher from the output if there's no --encrypted.
222 self
.assert_parse("raid / --device=md0 --level=1 --cipher=3-rot13 raid.01 raid.02",
223 "raid / --device=0 --level=RAID1 raid.01 raid.02\n")
225 self
.assert_parse_error("raid / --cipher --device=md0 --level=1 raid.01 raid.02")
227 class F19_TestCase(F18_TestCase
):
228 def __init__(self
, *kargs
, **kwargs
):
229 F18_TestCase
.__init
__(self
, *kargs
, **kwargs
)
230 self
.minorBasedDevice
= False
232 if __name__
== "__main__":