Statistics
| Branch: | Tag: | Revision:

root / qa / qa_network.py @ a4c589d2

History | View | Annotate | Download (2.7 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 qa_utils import AssertCommand
31

    
32

    
33
def GetNonexistentNetworks(count):
34
  """Gets network names which shouldn't exist on the cluster.
35

36
  @param count: Number of networks to get
37
  @rtype: integer
38

39
  """
40
  return qa_utils.GetNonexistentEntityNames(count, "networks", "network")
41

    
42

    
43
def TestNetworkAddRemove():
44
  """gnt-network add/remove"""
45
  (network1, network2) = GetNonexistentNetworks(2)
46

    
47
  # Add some networks of different sizes.
48
  # Note: Using RFC5737 addresses.
49
  AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/30", network1])
50
  AssertCommand(["gnt-network", "add", "--network", "198.51.100.0/24",
51
                 network2])
52
  # Try to add a network with an existing name.
53
  AssertCommand(["gnt-network", "add", "--network", "203.0.133.0/24", network2],
54
                fail=True)
55

    
56
  AssertCommand(["gnt-network", "remove", network1])
57
  AssertCommand(["gnt-network", "remove", network2])
58

    
59

    
60
def TestNetworkTags():
61
  """gnt-network tags"""
62
  (network, ) = GetNonexistentNetworks(1)
63
  AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/30", network])
64
  qa_tags.TestNetworkTags(network)
65
  AssertCommand(["gnt-network", "remove", network])
66

    
67

    
68
def TestNetworkConnect():
69
  """gnt-network connect/disconnect"""
70
  (group1, ) = qa_utils.GetNonexistentGroups(1)
71
  (network1, ) = GetNonexistentNetworks(1)
72

    
73
  default_mode = "bridged"
74
  default_link = "xen-br0"
75
  nicparams = qa_config.get("default-nicparams")
76
  if nicparams:
77
    mode = nicparams.get("mode", default_mode)
78
    link = nicparams.get("link", default_link)
79
  else:
80
    mode = default_mode
81
    link = default_link
82

    
83
  AssertCommand(["gnt-group", "add", group1])
84
  AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1])
85

    
86
  AssertCommand(["gnt-network", "connect", network1, mode, link, group1])
87
  AssertCommand(["gnt-network", "disconnect", network1, group1])
88

    
89
  AssertCommand(["gnt-group", "remove", group1])
90
  AssertCommand(["gnt-network", "remove", network1])