2 # Radek Vykydal <rvykydal@redhat.com>
4 # Copyright 2013 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.
21 from tests
.baseclass
import *
23 from pykickstart
.errors
import *
24 from pykickstart
.commands
.network
import *
26 class F20_TestCase(CommandTest
):
33 cmd
= "network --device team0 --bootproto static --ip=10.34.102.222 --netmask=255.255.255.0 --gateway=10.34.102.254 --nameserver=10.34.39.2 --teamslaves=\"p3p1'{\\\"prio\\\": -10, \\\"sticky\\\": true}',p3p2'{\\\"prio\\\": 100}'\" --teamconfig=\"{\\\"runner\\\": {\\\"name\\\": \\\"activebackup\\\"}}\" --activate"
34 self
.assert_parse(cmd
)
36 cmd
= "network --device team0 --bootproto dhcp --teamslaves=p3p1,p3p2 --teamconfig=\"{\\\"runner\\\": {\\\"name\\\": \\\"roundrobin\\\"}}\" --activate"
37 self
.assert_parse(cmd
)
40 # --teamslaves="<DEV1>['<CONFIG1>'],<DEV2>['<CONFIG2>'],..."
41 # CONFIGX is json with " escaped to \"
43 teamslaves_strings
= [
45 r
"eth1,eth2'{\"prio
\": 100}'",
46 r"eth1'{\"prio
\": -10, \"sticky
\": true
}',eth2",
47 r"eth1'{\"prio
\": -10, \"sticky
\": true
}',eth2'{\"prio
\": 100}'",
49 r"eth1,eth2'{\"prio
\": 100}',eth3",
53 [('eth1
',""), ('eth2
',"")],
54 [('eth1
',""), ('eth2
','{"prio": 100}')],
55 [('eth1
','{"prio": -10, "sticky": true
}'), ('eth2
',"")],
56 [('eth1
','{"prio": -10, "sticky": true
}'), ('eth2
','{"prio": 100}')],
57 [('eth1
',""), ('eth2
',""), ('eth3
',"")],
58 [('eth1
',""), ('eth2
','{"prio": 100}'), ('eth3
',"")],
61 for string, value in zip(teamslaves_strings, teamslaves_values):
62 network_data = self.assert_parse("network --device team0 --bootproto=dhcp --teamslaves=\"%s\"" % string)
63 self.assertEquals(network_data.teamslaves, value)
65 for value in teamslaves_values:
66 nd = self.assert_parse("network --device team0 --bootproto=dhcp")
69 nd2 = self.assert_parse(s)
70 self.assertEquals(value, nd2.teamslaves)
72 class RHEL7_TestCase(F20_TestCase):
74 F20_TestCase.runTest(self)
75 # there needs to be a vlan id after a dot & only one dot is allowed
76 self.assert_parse_error("network --interfacename=abc.", KickstartValueError)
77 self.assert_parse_error("network --interfacename=abc.def", KickstartValueError)
78 self.assert_parse_error("network --interfacename=abc..", KickstartValueError)
79 self.assert_parse_error("network --interfacename=abc.123.456", KickstartValueError)
80 # 'vlan
' can't be followed by a
'.'
81 self
.assert_parse_error("network --interfacename=vlan.123", KickstartValueError
)
82 self
.assert_parse_error("network --interfacename=vlan.", KickstartValueError
)
83 self
.assert_parse_error("network --interfacename=vlan..", KickstartValueError
)
84 self
.assert_parse_error("network --interfacename=vlan.abc", KickstartValueError
)
85 self
.assert_parse("network --interfacename=abc.123")
87 # if the device name begins with 'vlan', vlan id needs to follow
88 self
.assert_parse_error("network --interfacename=vlan", KickstartValueError
)
89 self
.assert_parse_error("network --interfacename=vlanabcd", KickstartValueError
)
90 # a valid vlan id needs to directly follow the 'vlan' prefix
91 self
.assert_parse_error("network --interfacename=vlanabcd123", KickstartValueError
)
92 self
.assert_parse_error("network --interfacename=vlanabcd123zxy", KickstartValueError
)
93 self
.assert_parse_error("network --interfacename=vlan123zxy", KickstartValueError
)
94 self
.assert_parse("network --interfacename=vlan123")
96 # vlan ids go from 0 to 4095
97 self
.assert_parse("network --interfacename=vlan0")
98 self
.assert_parse("network --interfacename=vlan4095")
99 self
.assert_parse("network --interfacename=abc.0")
100 self
.assert_parse("network --interfacename=abc.4095")
101 self
.assert_parse_error("network --interfacename=vlan9001", KickstartValueError
)
102 self
.assert_parse_error("network --interfacename=abc.9001", KickstartValueError
)
104 if __name__
== "__main__":