root / qa / qa_network.py @ 33c730a2
History | View | Annotate | Download (2.5 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2013 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""QA tests for networks.
|
23 |
|
24 |
"""
|
25 |
|
26 |
import qa_config |
27 |
import qa_utils |
28 |
|
29 |
from qa_utils import AssertCommand |
30 |
|
31 |
|
32 |
def GetNonexistentNetworks(count): |
33 |
"""Gets network names which shouldn't exist on the cluster.
|
34 |
|
35 |
@param count: Number of networks to get
|
36 |
@rtype: integer
|
37 |
|
38 |
"""
|
39 |
return qa_utils.GetNonexistentEntityNames(count, "networks", "network") |
40 |
|
41 |
|
42 |
def TestNetworkAddRemove(): |
43 |
"""gnt-network add/remove"""
|
44 |
(network1, network2) = GetNonexistentNetworks(2)
|
45 |
|
46 |
# Add some networks of different sizes.
|
47 |
# 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", |
50 |
network2]) |
51 |
# Try to add a network with an existing name.
|
52 |
AssertCommand(["gnt-network", "add", "--network", "203.0.133.0/24", network2], |
53 |
fail=True)
|
54 |
|
55 |
AssertCommand(["gnt-network", "remove", network1]) |
56 |
AssertCommand(["gnt-network", "remove", network2]) |
57 |
|
58 |
|
59 |
def TestNetworkConnect(): |
60 |
"""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 |
73 |
|
74 |
AssertCommand(["gnt-group", "add", group1]) |
75 |
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1]) |
76 |
|
77 |
AssertCommand(["gnt-network", "connect", network1, mode, link, group1]) |
78 |
AssertCommand(["gnt-network", "disconnect", network1, group1]) |
79 |
|
80 |
AssertCommand(["gnt-group", "remove", group1]) |
81 |
AssertCommand(["gnt-network", "remove", network1]) |