qa_network.py 2.81 KB
Newer Older
Helga Velroyen's avatar
Helga Velroyen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#
#

# Copyright (C) 2013 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


"""QA tests for networks.

"""

import qa_config
Hrvoje Ribicic's avatar
Hrvoje Ribicic committed
27
import qa_tags
Helga Velroyen's avatar
Helga Velroyen committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
import qa_utils

from qa_utils import AssertCommand


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

  @param count: Number of networks to get
  @rtype: integer

  """
  return qa_utils.GetNonexistentEntityNames(count, "networks", "network")


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

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

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


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


Helga Velroyen's avatar
Helga Velroyen committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
def TestNetworkConnect():
  """gnt-network connect/disconnect"""
  (group1, ) = qa_utils.GetNonexistentGroups(1)
  (network1, ) = GetNonexistentNetworks(1)

  default_mode = "bridged"
  default_link = "xen-br0"
  nicparams = qa_config.get("default-nicparams")
  if nicparams:
    mode = nicparams.get("mode", default_mode)
    link = nicparams.get("link", default_link)
  else:
    mode = default_mode
    link = default_link

83 84
  nicparams = "mode=%s,link=%s" % (mode, link)

Helga Velroyen's avatar
Helga Velroyen committed
85 86 87
  AssertCommand(["gnt-group", "add", group1])
  AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1])

88 89
  AssertCommand(["gnt-network", "connect", "--nic-parameters", nicparams,
                network1, group1])
Helga Velroyen's avatar
Helga Velroyen committed
90 91 92 93
  AssertCommand(["gnt-network", "disconnect", network1, group1])

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