Commit ea7693c1 authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Network QA



This adds a script for the QA of 'gnt-network'. So far it
covers adding/removing and connecting/disconnecting networks.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 9928c63e
......@@ -37,6 +37,7 @@ import qa_env
import qa_error
import qa_group
import qa_instance
import qa_network
import qa_node
import qa_os
import qa_job
......@@ -324,6 +325,14 @@ def RunGroupListTests():
RunTestIf("group-list", qa_group.TestGroupListFields)
def RunNetworkTests():
"""Run tests for network management.
"""
RunTestIf("network", qa_network.TestNetworkAddRemove)
RunTestIf("network", qa_network.TestNetworkConnect)
def RunGroupRwTests():
"""Run tests for adding/removing/renaming groups.
......@@ -478,6 +487,7 @@ def RunQa():
RunCommonNodeTests()
RunGroupListTests()
RunGroupRwTests()
RunNetworkTests()
# The master shouldn't be readded or put offline; "delay" needs a non-master
# node to test
......
......@@ -84,6 +84,14 @@
]
},
"networks": {
"inexistent-networks": [
"network1",
"network2",
"network3"
]
},
"tests": {
"# Whether tests are enabled or disabled by default": null,
"default": true,
......@@ -118,6 +126,8 @@
"group-list": true,
"group-rwops": true,
"network": false,
"node-list": true,
"node-info": true,
"node-volumes": true,
......
#
#
# 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
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])
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
AssertCommand(["gnt-group", "add", group1])
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1])
AssertCommand(["gnt-network", "connect", network1, mode, link, group1])
AssertCommand(["gnt-network", "disconnect", network1, group1])
AssertCommand(["gnt-group", "remove", group1])
AssertCommand(["gnt-network", "remove", network1])
......@@ -653,17 +653,40 @@ def GetNonexistentGroups(count):
"""Gets group names which shouldn't exist on the cluster.
@param count: Number of groups to get
@rtype: list
@rtype: integer
"""
groups = qa_config.get("groups", {})
return GetNonexistentEntityNames(count, "groups", "group")
default = ["group1", "group2", "group3"]
def GetNonexistentEntityNames(count, name_config, name_prefix):
"""Gets entity names which shouldn't exist on the cluster.
The actualy names can refer to arbitrary entities (for example
groups, networks).
@param count: Number of names to get
@rtype: integer
@param name_config: name of the leaf in the config containing
this entity's configuration, including a 'inexistent-'
element
@rtype: string
@param name_prefix: prefix of the entity's names, used to compose
the default values; for example for groups, the prefix is
'group' and the generated names are then group1, group2, ...
@rtype: string
"""
entities = qa_config.get(name_config, {})
default = [name_prefix + str(i) for i in range(count)]
assert count <= len(default)
candidates = groups.get("inexistent-groups", default)[:count]
name_config_inexistent = "inexistent-" + name_config
candidates = entities.get(name_config_inexistent, default)[:count]
if len(candidates) < count:
raise Exception("At least %s non-existent groups are needed" % count)
raise Exception("At least %s non-existent %s are needed" %
(count, name_config))
return candidates
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment