Statistics
| Branch: | Tag: | Revision:

root / qa / qa_network.py @ 82ce55fa

History | View | Annotate | Download (2.8 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 ganeti import query
30

    
31
from qa_utils import AssertCommand
32

    
33

    
34
def TestNetworkList():
35
  """gnt-network list"""
36
  qa_utils.GenericQueryTest("gnt-network", query.NETWORK_FIELDS.keys())
37

    
38

    
39
def TestNetworkListFields():
40
  """gnt-network list-fields"""
41
  qa_utils.GenericQueryFieldsTest("gnt-network", query.NETWORK_FIELDS.keys())
42

    
43

    
44
def GetNonexistentNetworks(count):
45
  """Gets network names which shouldn't exist on the cluster.
46

47
  @param count: Number of networks to get
48
  @rtype: integer
49

50
  """
51
  return qa_utils.GetNonexistentEntityNames(count, "networks", "network")
52

    
53

    
54
def TestNetworkAddRemove():
55
  """gnt-network add/remove"""
56
  (network1, network2) = GetNonexistentNetworks(2)
57

    
58
  # Add some networks of different sizes.
59
  # Note: Using RFC5737 addresses.
60
  AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/30", network1])
61
  AssertCommand(["gnt-network", "add", "--network", "198.51.100.0/24",
62
                 network2])
63
  # Try to add a network with an existing name.
64
  AssertCommand(["gnt-network", "add", "--network", "203.0.133.0/24", network2],
65
                fail=True)
66

    
67
  TestNetworkList()
68
  TestNetworkListFields()
69

    
70
  AssertCommand(["gnt-network", "remove", network1])
71
  AssertCommand(["gnt-network", "remove", network2])
72

    
73
  TestNetworkList()
74

    
75

    
76
def TestNetworkConnect():
77
  """gnt-network connect/disconnect"""
78
  (group1, ) = qa_utils.GetNonexistentGroups(1)
79
  (network1, ) = GetNonexistentNetworks(1)
80

    
81
  default_mode = "bridged"
82
  default_link = "xen-br0"
83
  nicparams = qa_config.get("default-nicparams")
84
  if nicparams:
85
    mode = nicparams.get("mode", default_mode)
86
    link = nicparams.get("link", default_link)
87
  else:
88
    mode = default_mode
89
    link = default_link
90

    
91
  AssertCommand(["gnt-group", "add", group1])
92
  AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1])
93

    
94
  AssertCommand(["gnt-network", "connect", network1, mode, link, group1])
95

    
96
  TestNetworkList()
97

    
98
  AssertCommand(["gnt-network", "disconnect", network1, group1])
99

    
100
  AssertCommand(["gnt-group", "remove", group1])
101
  AssertCommand(["gnt-network", "remove", network1])