Revision 16eb7455 qa/qa_network.py
b/qa/qa_network.py | ||
---|---|---|
29 | 29 |
from qa_utils import AssertCommand |
30 | 30 |
|
31 | 31 |
|
32 |
def GetNonexistentNetworks(count): |
|
33 |
"""Gets network names which shouldn't exist on the cluster. |
|
32 |
TEST_NET_1 = "192.0.2.0/24" |
|
33 |
TEST_NET_2 = "198.51.100.0/24" |
|
34 |
TEST_NET_3 = "203.0.113.0/24" |
|
34 | 35 |
|
35 |
@param count: Number of networks to get |
|
36 |
@rtype: integer |
|
36 |
TEST_NET6_1 = "2001:648:2ffc:1201::/64" |
|
37 |
GW_IN_NET6_1 = "2001:648:2ffc:1201::1" |
|
38 |
IP_IN_NET6_1 = "2001:648:2ffc:1201::81" |
|
37 | 39 |
|
38 |
""" |
|
39 |
return qa_utils.GetNonexistentEntityNames(count, "networks", "network") |
|
40 |
TEST_NET6_2 = "2002:648:2c:101::/64" |
|
41 |
GW_IN_NET6_2 = "2002:648:2c:101::1" |
|
42 |
IP_IN_NET6_2 = "2002:648:2c:101::54" |
|
43 |
|
|
44 |
GW_IN_NET_1 = "192.0.2.1" |
|
45 |
GW2_IN_NET_1 = "192.0.2.100" |
|
46 |
GW_IN_NET_2 = "198.51.100.1" |
|
47 |
GW_IN_NET_3 = "203.0.113.1" |
|
48 |
IP_IN_NET_1 = "192.0.2.50" |
|
49 |
IP2_IN_NET_1 = "192.0.2.70" |
|
50 |
IP_IN_NET_2 = "198.51.100.82" |
|
51 |
IP_IN_NET_3 = "203.0.113.118" |
|
52 |
|
|
53 |
def GetNicParams(): |
|
54 |
default_mode = "bridged" |
|
55 |
default_link = "br0" |
|
56 |
nicparams = qa_config.get("default-nicparams") |
|
57 |
if nicparams: |
|
58 |
mode = nicparams.get("mode", default_mode) |
|
59 |
link = nicparams.get("link", default_link) |
|
60 |
else: |
|
61 |
mode = default_mode |
|
62 |
link = default_link |
|
63 |
|
|
64 |
return mode, link |
|
65 |
|
|
66 |
|
|
67 |
def GetNetOption(idx=-1, action=None, mac=None, ip=None, network=None, |
|
68 |
mode=None, link=None): |
|
69 |
net = "%d:" % idx |
|
70 |
if action: |
|
71 |
net += action |
|
72 |
if mac: |
|
73 |
net += ",mac=" + mac |
|
74 |
if ip: |
|
75 |
net += ",ip=" + ip |
|
76 |
if network: |
|
77 |
net += ",network=" + network |
|
78 |
if mode: |
|
79 |
net += ",mode=" + mode |
|
80 |
if link: |
|
81 |
net += ",link=" + link |
|
82 |
|
|
83 |
return net.replace(":,", ":") |
|
84 |
|
|
85 |
|
|
86 |
def RemoveInstance(instance): |
|
87 |
name = instance["name"] |
|
88 |
AssertCommand(["gnt-instance", "remove", "-f", name]) |
|
89 |
qa_config.ReleaseInstance(instance) |
|
90 |
|
|
91 |
|
|
92 |
def LaunchInstance(instance, mac=None, ip=None, network=None, |
|
93 |
mode=None, link=None, fail=False): |
|
94 |
|
|
95 |
name = instance["name"] |
|
96 |
net = GetNetOption(0, None, mac, ip, network, mode, link) |
|
97 |
AssertCommand(["gnt-instance", "add", "-o", "debootstrap+default", |
|
98 |
"-t", "file", "--disk", "0:size=1G", "--net", net, |
|
99 |
"--no-name-check", "--no-ip-check", "--no-install", name], |
|
100 |
fail=fail) |
|
101 |
|
|
102 |
|
|
103 |
def ModifyInstance(instance, idx=-1, action="add", mac=None, |
|
104 |
ip=None, network=None, mode=None, link=None, fail=False): |
|
105 |
|
|
106 |
name = instance["name"] |
|
107 |
net = GetNetOption(idx, action, mac, ip, network, mode, link) |
|
108 |
AssertCommand(["gnt-instance", "modify", "--net", net, name], fail=fail) |
|
40 | 109 |
|
41 | 110 |
|
42 | 111 |
def TestNetworkAddRemove(): |
43 | 112 |
"""gnt-network add/remove""" |
44 |
(network1, network2) = GetNonexistentNetworks(2)
|
|
113 |
(network1, network2, network3, ) = qa_utils.GetNonexistentNetworks(3)
|
|
45 | 114 |
|
46 |
# Add some networks of different sizes. |
|
47 | 115 |
# Note: Using RFC5737 addresses. |
48 |
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/30", network1]) |
|
49 |
AssertCommand(["gnt-network", "add", "--network", "198.51.100.0/24", |
|
116 |
# Add a network without subnet |
|
117 |
# TODO: make this fail=False once abstract networks are implemented |
|
118 |
AssertCommand(["gnt-network", "add", network1], fail=True) |
|
119 |
# remove non-existing network |
|
120 |
AssertCommand(["gnt-network", "remove", network1], fail=True) |
|
121 |
|
|
122 |
# Check wrong opcode parameters |
|
123 |
# wrone cidr notation |
|
124 |
AssertCommand(["gnt-network", "add", "--network", "xxxxx", network1], |
|
125 |
fail=True) |
|
126 |
# gateway outside the network |
|
127 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, |
|
128 |
"--gateway", GW_IN_NET_2, network1], |
|
129 |
fail=True) |
|
130 |
# v6 gateway but not network |
|
131 |
#AssertCommand(["gnt-network", "add", "--gateway6", IP_IN_NET6_1, network1], |
|
132 |
# fail=False) |
|
133 |
# gateway but not network |
|
134 |
#AssertCommand(["gnt-network", "add", "--gateway", IP_IN_NET_1, network1], |
|
135 |
# fail=False) |
|
136 |
# wrong mac prefix |
|
137 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, |
|
138 |
"--mac-prefix", "xxxxxx", network1], |
|
139 |
fail=True) |
|
140 |
|
|
141 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, |
|
142 |
"--gateway", GW_IN_NET_1, "--mac-prefix", "aa:bb:cc", |
|
143 |
"--add-reserved-ips", IP_IN_NET_1, |
|
144 |
"--network6", TEST_NET6_1, |
|
145 |
"--gateway6", GW_IN_NET6_1, network1]) |
|
146 |
|
|
147 |
# TODO: add a network that contains the nodes' IPs |
|
148 |
# This should reserve them |
|
149 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_2, |
|
50 | 150 |
network2]) |
151 |
|
|
152 |
# This does not reserve master/node IPs |
|
153 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_3, |
|
154 |
"--no-conflicts-check", network3]) |
|
155 |
|
|
51 | 156 |
# Try to add a network with an existing name. |
52 |
AssertCommand(["gnt-network", "add", "--network", "203.0.133.0/24", network2],
|
|
157 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, network2],
|
|
53 | 158 |
fail=True) |
54 | 159 |
|
55 | 160 |
AssertCommand(["gnt-network", "remove", network1]) |
56 | 161 |
AssertCommand(["gnt-network", "remove", network2]) |
162 |
AssertCommand(["gnt-network", "remove", network3]) |
|
163 |
|
|
164 |
|
|
165 |
def TestNetworkSetParams(): |
|
166 |
"""gnt-network modify""" |
|
167 |
(network1, ) = qa_utils.GetNonexistentNetworks(1) |
|
168 |
|
|
169 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, |
|
170 |
"--gateway", GW_IN_NET_1, "--mac-prefix", "aa:bb:cc", |
|
171 |
"--add-reserved-ips", IP_IN_NET_1, |
|
172 |
"--network6", TEST_NET6_1, |
|
173 |
"--gateway6", GW_IN_NET6_1, network1]) |
|
174 |
|
|
175 |
# Cannot modify subnet |
|
176 |
AssertCommand(["gnt-network", "modify", "--network", TEST_NET_2, |
|
177 |
network1], fail=True) |
|
178 |
|
|
179 |
# Gateway outside network |
|
180 |
AssertCommand(["gnt-network", "modify", "--gateway", IP_IN_NET_2, |
|
181 |
network1], fail=True) |
|
182 |
|
|
183 |
# Gateway with reserved ips |
|
184 |
AssertCommand(["gnt-network", "modify", "--gateway", GW2_IN_NET_1, |
|
185 |
"--add-reserved-ips", IP2_IN_NET_1, |
|
186 |
network1], fail=True) |
|
187 |
|
|
188 |
# Edit all |
|
189 |
# TODO: test reserved ips |
|
190 |
AssertCommand(["gnt-network", "modify", "--gateway", GW2_IN_NET_1, |
|
191 |
"--network6", TEST_NET6_2, |
|
192 |
"--gateway6", GW_IN_NET6_2, |
|
193 |
network1]) |
|
194 |
|
|
195 |
# reset everything |
|
196 |
AssertCommand(["gnt-network", "modify", "--gateway", "none", |
|
197 |
"--network6", "none", "--gateway6", "none", |
|
198 |
"--mac-prefix", "none", |
|
199 |
network1]) |
|
200 |
|
|
201 |
AssertCommand(["gnt-network", "remove", network1]) |
|
57 | 202 |
|
58 | 203 |
|
59 | 204 |
def TestNetworkConnect(): |
60 | 205 |
"""gnt-network connect/disconnect""" |
61 |
(group1, ) = qa_utils.GetNonexistentGroups(1) |
|
62 |
(network1, ) = GetNonexistentNetworks(1) |
|
63 |
|
|
64 |
default_mode = "bridged" |
|
65 |
default_link = "xen-br0" |
|
66 |
nicparams = qa_config.get("default-nicparams") |
|
67 |
if nicparams: |
|
68 |
mode = nicparams.get("mode", default_mode) |
|
69 |
link = nicparams.get("link", default_link) |
|
70 |
else: |
|
71 |
mode = default_mode |
|
72 |
link = default_link |
|
206 |
(group1, group2, ) = qa_utils.GetNonexistentGroups(2) |
|
207 |
(network1, network2, ) = qa_utils.GetNonexistentNetworks(2) |
|
208 |
defmode, deflink = GetNicParams() |
|
73 | 209 |
|
74 | 210 |
AssertCommand(["gnt-group", "add", group1]) |
75 |
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1]) |
|
211 |
AssertCommand(["gnt-group", "add", group2]) |
|
212 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, network1]) |
|
213 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_2, network2]) |
|
214 |
|
|
215 |
AssertCommand(["gnt-network", "connect", network1, |
|
216 |
defmode, deflink, group1]) |
|
217 |
# This should produce a warning for group1 |
|
218 |
AssertCommand(["gnt-network", "connect", network1, defmode, deflink]) |
|
219 |
# Network still connected |
|
220 |
AssertCommand(["gnt-network", "remove", network1], fail=True) |
|
221 |
|
|
222 |
instance1 = qa_config.AcquireInstance() |
|
223 |
# Add instance inside the network |
|
224 |
LaunchInstance(instance1, ip="pool", network=network1) |
|
225 |
# Conflicting IP, at least one instance belongs to the network |
|
226 |
AssertCommand(["gnt-network", "disconnect", network1], fail=True) |
|
227 |
RemoveInstance(instance1) |
|
76 | 228 |
|
77 |
AssertCommand(["gnt-network", "connect", network1, mode, link, group1]) |
|
78 |
AssertCommand(["gnt-network", "disconnect", network1, group1]) |
|
229 |
AssertCommand(["gnt-network", "disconnect", network1]) |
|
230 |
# This should only produce a warning. |
|
231 |
AssertCommand(["gnt-network", "disconnect", network1]) |
|
232 |
|
|
233 |
instance1 = qa_config.AcquireInstance() |
|
234 |
# TODO: add conflicting image. |
|
235 |
LaunchInstance(instance1, ip=IP_IN_NET_2) |
|
236 |
# Conflicting IPs |
|
237 |
AssertCommand(["gnt-network", "connect", network2, defmode, deflink], |
|
238 |
fail=True) |
|
239 |
AssertCommand(["gnt-network", "connect", "--no-conflicts-check", |
|
240 |
network2, defmode, deflink]) |
|
241 |
AssertCommand(["gnt-network", "disconnect", network2]) |
|
79 | 242 |
|
243 |
RemoveInstance(instance1) |
|
80 | 244 |
AssertCommand(["gnt-group", "remove", group1]) |
245 |
AssertCommand(["gnt-group", "remove", group2]) |
|
81 | 246 |
AssertCommand(["gnt-network", "remove", network1]) |
247 |
AssertCommand(["gnt-network", "remove", network2]) |
|
248 |
|
|
249 |
|
|
250 |
def TestInstanceAddAndNetAdd(): |
|
251 |
""" gnt-istance add / gnt-instance modify --net -1:add """ |
|
252 |
(network1, network2) = qa_utils.GetNonexistentNetworks(2) |
|
253 |
defmode, deflink = GetNicParams() |
|
254 |
|
|
255 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, |
|
256 |
"--gateway", GW_IN_NET_1, "--mac-prefix", "aa:bb:cc", |
|
257 |
"--add-reserved-ips", IP_IN_NET_1, |
|
258 |
"--network6", TEST_NET6_1, |
|
259 |
"--gateway6", GW_IN_NET6_1, network1]) |
|
260 |
AssertCommand(["gnt-network", "connect", network1, defmode, deflink]) |
|
261 |
|
|
262 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_2, network2]) |
|
263 |
AssertCommand(["gnt-network", "connect", network2, "routed", "rt5000"]) |
|
264 |
|
|
265 |
|
|
266 |
# (mac, ip, network, mode, link) |
|
267 |
success_cases = [ |
|
268 |
(None, None, None, None, None), # random mac and default nicparams |
|
269 |
("generate", IP_IN_NET_3, None, "routed", "rt5000"), # given params |
|
270 |
(None, "pool", network1, None, None), # first IP in network given |
|
271 |
# TODO: include this use case with --no-conflicts-check |
|
272 |
# just add an extra field in Launch|ModifyInstance |
|
273 |
#(None, "192.168.1.6", None, None, None), # IP but no net |
|
274 |
(None, None, network1, None, None) # nicparams/mac inherited by network |
|
275 |
] |
|
276 |
|
|
277 |
for (mac, ip, network, mode, link) in success_cases: |
|
278 |
instance1 = qa_config.AcquireInstance() |
|
279 |
LaunchInstance(instance1, mac, ip, network, mode, link) |
|
280 |
ModifyInstance(instance1, idx=-1, action="add", mac=mac, |
|
281 |
ip=ip, network=network, mode=mode, link=link) |
|
282 |
ModifyInstance(instance1, idx=1, action="remove") |
|
283 |
RemoveInstance(instance1) |
|
284 |
|
|
285 |
fail_cases = [ |
|
286 |
(None, None, None, "lala", None), |
|
287 |
(None, "lala", None, None, None), |
|
288 |
(None, None, "lala", None, None), |
|
289 |
(None, IP_IN_NET_2, None, None, None), # conflicting IP |
|
290 |
(None, None, None, "routed", None), # routed with no IP |
|
291 |
(None, "pool", network1, "routed", None), # nicparams along with network |
|
292 |
(None, "pool", network1, None, deflink) |
|
293 |
] |
|
294 |
|
|
295 |
instance1 = qa_config.AcquireInstance() |
|
296 |
instance2 = qa_config.AcquireInstance() |
|
297 |
LaunchInstance(instance2) |
|
298 |
for (mac, ip, network, mode, link) in fail_cases: |
|
299 |
LaunchInstance(instance1, mac=mac, ip=ip, network=network, |
|
300 |
mode=mode, link=link, fail=True) |
|
301 |
ModifyInstance(instance2, idx=-1, action="add", mac=mac, |
|
302 |
ip=ip, network=network, mode=mode, link=link, fail=True) |
|
303 |
ModifyInstance(instance2, idx=0, action="modify", mac=mac, |
|
304 |
ip=ip, network=network, mode=mode, link=link, fail=True) |
|
305 |
|
|
306 |
RemoveInstance(instance2) |
|
307 |
AssertCommand(["gnt-network", "disconnect", network1]) |
|
308 |
AssertCommand(["gnt-network", "remove", network1]) |
|
309 |
AssertCommand(["gnt-network", "disconnect", network2]) |
|
310 |
AssertCommand(["gnt-network", "remove", network2]) |
|
311 |
|
|
312 |
|
|
313 |
def TestInstanceNetMod(): |
|
314 |
""" gnt-istance modify --net 0:modify """ |
|
315 |
(network1, network2) = qa_utils.GetNonexistentNetworks(2) |
|
316 |
defmode, deflink = GetNicParams() |
|
317 |
|
|
318 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_1, |
|
319 |
"--gateway", GW_IN_NET_1, "--mac-prefix", "aa:bb:cc", |
|
320 |
"--add-reserved-ips", IP_IN_NET_1, |
|
321 |
"--network6", TEST_NET6_1, |
|
322 |
"--gateway6", GW_IN_NET6_1, network1]) |
|
323 |
AssertCommand(["gnt-network", "connect", network1, defmode, deflink]) |
|
324 |
|
|
325 |
success_cases = [ |
|
326 |
("generate", IP_IN_NET_3, None, "routed", "rt5000"), # given params |
|
327 |
(None, "pool", network1, None, None), # first IP in network given |
|
328 |
(None, "none", "none", None, None), # random mac and default nicparams |
|
329 |
(None, IP2_IN_NET_1, network1, None, None), # IP inside network |
|
330 |
#TODO: include this use case with --no-conflickts-check |
|
331 |
#(None, IP2_IN_NET_1, None, None, None), # IP but no net |
|
332 |
(None, None, network1, None, None) # nicparams/mac inherited by network |
|
333 |
] |
|
334 |
|
|
335 |
instance1 = qa_config.AcquireInstance() |
|
336 |
LaunchInstance(instance1) |
|
337 |
for (mac, ip, network, mode, link) in success_cases: |
|
338 |
ModifyInstance(instance1, idx=0, action="modify", mac=mac, |
|
339 |
ip=ip, network=network, mode=mode, link=link) |
|
340 |
# reset to defaults |
|
341 |
ModifyInstance(instance1, idx=0, action="modify", mac="generate", |
|
342 |
ip="none", network="none", mode=defmode, link=deflink) |
|
343 |
|
|
344 |
AssertCommand(["gnt-network", "add", "--network", TEST_NET_2, network2]) |
|
345 |
AssertCommand(["gnt-network", "connect", network2, "routed", "rt5000"]) |
|
346 |
# put instance inside network1 |
|
347 |
ModifyInstance(instance1, idx=0, action="modify", ip="pool", network=network1) |
|
348 |
# move instance to network2 |
|
349 |
ModifyInstance(instance1, idx=0, action="modify", ip="pool", network=network2) |
|
350 |
|
|
351 |
RemoveInstance(instance1) |
|
352 |
AssertCommand(["gnt-network", "disconnect", network1]) |
|
353 |
AssertCommand(["gnt-network", "remove", network1]) |
|
354 |
AssertCommand(["gnt-network", "disconnect", network2]) |
|
355 |
AssertCommand(["gnt-network", "remove", network2]) |
Also available in: Unified diff