root / qa / qa_network.py @ a07ae57f
History | View | Annotate | Download (3.1 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_tags |
28 |
import qa_utils |
29 |
|
30 |
from ganeti import query |
31 |
|
32 |
from qa_utils import AssertCommand |
33 |
|
34 |
|
35 |
def TestNetworkList(): |
36 |
"""gnt-network list"""
|
37 |
qa_utils.GenericQueryTest("gnt-network", query.NETWORK_FIELDS.keys())
|
38 |
|
39 |
|
40 |
def TestNetworkListFields(): |
41 |
"""gnt-network list-fields"""
|
42 |
qa_utils.GenericQueryFieldsTest("gnt-network", query.NETWORK_FIELDS.keys())
|
43 |
|
44 |
|
45 |
def GetNonexistentNetworks(count): |
46 |
"""Gets network names which shouldn't exist on the cluster.
|
47 |
|
48 |
@param count: Number of networks to get
|
49 |
@rtype: integer
|
50 |
|
51 |
"""
|
52 |
return qa_utils.GetNonexistentEntityNames(count, "networks", "network") |
53 |
|
54 |
|
55 |
def TestNetworkAddRemove(): |
56 |
"""gnt-network add/remove"""
|
57 |
(network1, network2) = GetNonexistentNetworks(2)
|
58 |
|
59 |
# Add some networks of different sizes.
|
60 |
# Note: Using RFC5737 addresses.
|
61 |
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/30", network1]) |
62 |
AssertCommand(["gnt-network", "add", "--network", "198.51.100.0/24", |
63 |
network2]) |
64 |
# Try to add a network with an existing name.
|
65 |
AssertCommand(["gnt-network", "add", "--network", "203.0.133.0/24", network2], |
66 |
fail=True)
|
67 |
|
68 |
TestNetworkList() |
69 |
TestNetworkListFields() |
70 |
|
71 |
AssertCommand(["gnt-network", "remove", network1]) |
72 |
AssertCommand(["gnt-network", "remove", network2]) |
73 |
|
74 |
TestNetworkList() |
75 |
|
76 |
|
77 |
def TestNetworkTags(): |
78 |
"""gnt-network tags"""
|
79 |
(network, ) = GetNonexistentNetworks(1)
|
80 |
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/30", network]) |
81 |
qa_tags.TestNetworkTags(network) |
82 |
AssertCommand(["gnt-network", "remove", network]) |
83 |
|
84 |
|
85 |
def TestNetworkConnect(): |
86 |
"""gnt-network connect/disconnect"""
|
87 |
(group1, ) = qa_utils.GetNonexistentGroups(1)
|
88 |
(network1, ) = GetNonexistentNetworks(1)
|
89 |
|
90 |
default_mode = "bridged"
|
91 |
default_link = "xen-br0"
|
92 |
nicparams = qa_config.get("default-nicparams")
|
93 |
if nicparams:
|
94 |
mode = nicparams.get("mode", default_mode)
|
95 |
link = nicparams.get("link", default_link)
|
96 |
else:
|
97 |
mode = default_mode |
98 |
link = default_link |
99 |
|
100 |
AssertCommand(["gnt-group", "add", group1]) |
101 |
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1]) |
102 |
|
103 |
AssertCommand(["gnt-network", "connect", network1, mode, link, group1]) |
104 |
|
105 |
TestNetworkList() |
106 |
|
107 |
AssertCommand(["gnt-network", "disconnect", network1, group1]) |
108 |
|
109 |
AssertCommand(["gnt-group", "remove", group1]) |
110 |
AssertCommand(["gnt-network", "remove", network1]) |