Revision ea7693c1

b/qa/ganeti-qa.py
37 37
import qa_error
38 38
import qa_group
39 39
import qa_instance
40
import qa_network
40 41
import qa_node
41 42
import qa_os
42 43
import qa_job
......
324 325
  RunTestIf("group-list", qa_group.TestGroupListFields)
325 326

  
326 327

  
328
def RunNetworkTests():
329
  """Run tests for network management.
330

  
331
  """
332
  RunTestIf("network", qa_network.TestNetworkAddRemove)
333
  RunTestIf("network", qa_network.TestNetworkConnect)
334

  
335

  
327 336
def RunGroupRwTests():
328 337
  """Run tests for adding/removing/renaming groups.
329 338

  
......
478 487
  RunCommonNodeTests()
479 488
  RunGroupListTests()
480 489
  RunGroupRwTests()
490
  RunNetworkTests()
481 491

  
482 492
  # The master shouldn't be readded or put offline; "delay" needs a non-master
483 493
  # node to test
b/qa/qa-sample.json
84 84
    ]
85 85
  },
86 86

  
87
  "networks": {
88
    "inexistent-networks": [
89
      "network1",
90
      "network2",
91
      "network3"
92
    ]
93
  },
94

  
87 95
  "tests": {
88 96
    "# Whether tests are enabled or disabled by default": null,
89 97
    "default": true,
......
118 126
    "group-list": true,
119 127
    "group-rwops": true,
120 128

  
129
    "network": false,
130

  
121 131
    "node-list": true,
122 132
    "node-info": true,
123 133
    "node-volumes": true,
b/qa/qa_network.py
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])
b/qa/qa_utils.py
653 653
  """Gets group names which shouldn't exist on the cluster.
654 654

  
655 655
  @param count: Number of groups to get
656
  @rtype: list
656
  @rtype: integer
657 657

  
658 658
  """
659
  groups = qa_config.get("groups", {})
659
  return GetNonexistentEntityNames(count, "groups", "group")
660 660

  
661
  default = ["group1", "group2", "group3"]
661

  
662
def GetNonexistentEntityNames(count, name_config, name_prefix):
663
  """Gets entity names which shouldn't exist on the cluster.
664

  
665
  The actualy names can refer to arbitrary entities (for example
666
  groups, networks).
667

  
668
  @param count: Number of names to get
669
  @rtype: integer
670
  @param name_config: name of the leaf in the config containing
671
    this entity's configuration, including a 'inexistent-'
672
    element
673
  @rtype: string
674
  @param name_prefix: prefix of the entity's names, used to compose
675
    the default values; for example for groups, the prefix is
676
    'group' and the generated names are then group1, group2, ...
677
  @rtype: string
678

  
679
  """
680
  entities = qa_config.get(name_config, {})
681

  
682
  default = [name_prefix + str(i) for i in range(count)]
662 683
  assert count <= len(default)
663 684

  
664
  candidates = groups.get("inexistent-groups", default)[:count]
685
  name_config_inexistent = "inexistent-" + name_config
686
  candidates = entities.get(name_config_inexistent, default)[:count]
665 687

  
666 688
  if len(candidates) < count:
667
    raise Exception("At least %s non-existent groups are needed" % count)
689
    raise Exception("At least %s non-existent %s are needed" %
690
                    (count, name_config))
668 691

  
669 692
  return candidates

Also available in: Unified diff