direct-io.hg

changeset 8299:a22ad856d199

Single domU, ping loopback and the local eth0.

Signed-off-by: Jim Dykman <dykman@us.ibm.com>
author emellor@leeni.uk.xensource.com
date Fri Dec 09 10:40:00 2005 +0000 (2005-12-09)
parents 06b7f33e954c
children 9d812d5470e8
files tools/xm-test/lib/XmTestLib/Network.py tools/xm-test/tests/network/02_network_local_ping_pos.py tools/xm-test/tests/network/Makefile.am
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/xm-test/lib/XmTestLib/Network.py	Fri Dec 09 10:40:00 2005 +0000
     1.3 @@ -0,0 +1,79 @@
     1.4 +#!/usr/bin/python
     1.5 +"""
     1.6 + Network.py - Common utilities for network tests
     1.7 +
     1.8 + Copyright (C) International Business Machines Corp., 2005
     1.9 + Author: Jim Dykman <dykman@us.ibm.com>
    1.10 +
    1.11 + This program is free software; you can redistribute it and/or modify
    1.12 + it under the terms of the GNU General Public License as published by
    1.13 + the Free Software Foundation; under version 2 of the License.
    1.14 +
    1.15 + This program is distributed in the hope that it will be useful,
    1.16 + but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 + GNU General Public License for more details.
    1.19 +
    1.20 + You should have received a copy of the GNU General Public License
    1.21 + along with this program; if not, write to the Free Software
    1.22 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.23 +
    1.24 +"""
    1.25 +import sys;
    1.26 +import os;
    1.27 +import atexit;
    1.28 +
    1.29 +from Test import *
    1.30 +from Xm import *
    1.31 +
    1.32 +class NetworkError(Exception):
    1.33 +    def __init__(self, msg):
    1.34 +        self.errMsg = msg
    1.35 +
    1.36 +    def __str__(self):
    1.37 +        return str(self.errMsg)
    1.38 +
    1.39 +def undo_dom0_alias(eth, ip):
    1.40 +    traceCommand("ip addr del " + ip + " dev " + eth)
    1.41 +
    1.42 +class XmNetwork:
    1.43 +
    1.44 +    def __init__(self):
    1.45 +        # Check for existing zeroconf address. We are using the zeroconf 
    1.46 +        # address range as static IP addresses.... if someone is using 
    1.47 +        # real zeroconf addresses, then we're going to skip tests to 
    1.48 +        # avoid interfering with them.
    1.49 +        rc, out = traceCommand(
    1.50 +                  "ip addr show |grep \"inet 169.254\" | grep -v vif")
    1.51 +
    1.52 +        if rc == 0:
    1.53 +            SKIP("Zeroconf address found: " + out)
    1.54 +
    1.55 +    def calc_ip_address(self, dom, interface):
    1.56 +        # Generate an IP address from the dom# and eth#:
    1.57 +        #      169.254.(eth#+153).(dom#+10)
    1.58 +        ethnum = int(interface[len("eth"):])
    1.59 +        domnum = int(dom[len("dom"):])
    1.60 +        return "169.254."+ str(ethnum+153) + "." + str(domnum+10)
    1.61 +
    1.62 +    def ip(self, dom, interface, todomname=None, toeth=None):
    1.63 +        newip = self.calc_ip_address(dom, interface)
    1.64 +
    1.65 +        # If the testcase is going to talk to dom0, we need to add an 
    1.66 +        # IP address in the proper subnet
    1.67 +        if dom == "dom0":
    1.68 +            # The domain's vif is a convenient place to add to
    1.69 +            vifname = "vif" + str(domid(todomname)) + "." + toeth[3:]
    1.70 +
    1.71 +            # register the exit handler FIRST, just in case
    1.72 +            atexit.register(undo_dom0_alias, vifname, newip)
    1.73 +
    1.74 +            # add the alias
    1.75 +            status, output = traceCommand("ip addr add " + newip + 
    1.76 +                                              " dev " + vifname)
    1.77 +            if status:
    1.78 +                SKIP("\"ip addr add\" failed")
    1.79 +        return newip
    1.80 +
    1.81 +    def mask(self, dom, interface):
    1.82 +        return "255.255.255.0"
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/xm-test/tests/network/02_network_local_ping_pos.py	Fri Dec 09 10:40:00 2005 +0000
     2.3 @@ -0,0 +1,84 @@
     2.4 +#!/usr/bin/python
     2.5 +
     2.6 +# Copyright (C) International Business Machines Corp., 2005
     2.7 +# Author:  <dykman@us.ibm.com>
     2.8 +
     2.9 +# Ping tests on local interfaces.
    2.10 +#  - creates a single guest domain
    2.11 +#  - sets up a single NIC
    2.12 +#  - conducts ping tests to the local loopback and IP address.
    2.13 +
    2.14 +# ping -c 1 -s $size 127.0.0.1
    2.15 +# ping -c 1 -s $size $local_IP 
    2.16 +#   where $size = 1, 48, 64, 512, 1440, 1500, 1505, 
    2.17 +#                 4096, 4192, 32767, 65507, 65508
    2.18 +
    2.19 +pingsizes = [ 1, 48, 64, 512, 1440, 1500, 1505, 4096, 4192, 
    2.20 +              32767, 65507 ]
    2.21 +
    2.22 +
    2.23 +
    2.24 +from XmTestLib import *
    2.25 +rc = 0
    2.26 +
    2.27 +Net = XmNetwork()
    2.28 +
    2.29 +# read an IP address from the config
    2.30 +ip   = Net.ip("dom1", "eth0")
    2.31 +mask = Net.mask("dom1", "eth0")
    2.32 +
    2.33 +# Fire up a guest domain w/1 nic
    2.34 +domain = XmTestDomain(extraOpts={ 'nics' : 1 })
    2.35 +try:
    2.36 +    domain.configSetVar('vif', " [ 'ip=" + ip + "' ]")
    2.37 +    domain.start()
    2.38 +except DomainError, e:
    2.39 +    if verbose:
    2.40 +        print "Failed to create test domain because:"
    2.41 +        print e.extra
    2.42 +    FAIL(str(e))
    2.43 +
    2.44 +
    2.45 +# Attach a console
    2.46 +try:
    2.47 +    console = XmConsole(domain.getName(), historySaveCmds=True)
    2.48 +except ConsoleError, e:
    2.49 +    FAIL(str(e))
    2.50 +
    2.51 +try:
    2.52 +    # Activate the console
    2.53 +    console.sendInput("bhs")
    2.54 +
    2.55 +    # Bring up the "lo" interface.
    2.56 +    console.runCmd("ifconfig lo up")
    2.57 +
    2.58 +    console.runCmd("ifconfig eth0 inet "+ip+" netmask "+mask+" up")
    2.59 +
    2.60 +    # First the loopback pings
    2.61 +    lofails=""
    2.62 +    for size in pingsizes:
    2.63 +        out = console.runCmd("ping -q -c 1 -s " + str(size) + " 127.0.0.1")
    2.64 +        if out["return"]:
    2.65 +            lofails += " " + str(size)
    2.66 +
    2.67 +    # Next comes eth0
    2.68 +    eth0fails=""
    2.69 +    for size in pingsizes:
    2.70 +        out = console.runCmd("ping -q -c 1 -s " + str(size) + " " + ip)
    2.71 +        if out["return"]:
    2.72 +            eth0fails += " " + str(size) 
    2.73 +except ConsoleError, e:
    2.74 +        FAIL(str(e))
    2.75 +except NetworkError, e:
    2.76 +        FAIL(str(e))
    2.77 +
    2.78 +
    2.79 +# Tally up failures
    2.80 +failures=""
    2.81 +if len(lofails):
    2.82 +        failures += "ping loopback failed for size" + lofails + ". "
    2.83 +if len(eth0fails):
    2.84 +        failures += "ping eth0 failed for size" + eth0fails + "."
    2.85 +if len(failures):
    2.86 +    FAIL(failures)
    2.87 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/xm-test/tests/network/Makefile.am	Fri Dec 09 10:40:00 2005 +0000
     3.3 @@ -0,0 +1,29 @@
     3.4 +
     3.5 +SUBDIRS =
     3.6 +
     3.7 +TESTS = \
     3.8 +	02_network_local_ping_pos.test		\
     3.9 +	05_network_dom0_ping_pos.test		\
    3.10 +	11_network_domU_ping_pos.test
    3.11 +
    3.12 +
    3.13 +
    3.14 +XFAIL_TESTS = 				\
    3.15 +	02_network_local_ping_pos.test		\
    3.16 +	05_network_dom0_ping_pos.test		\
    3.17 +	11_network_domU_ping_pos.test
    3.18 +
    3.19 +EXTRA_DIST = $(TESTS) $(XFAIL_TESTS)
    3.20 +
    3.21 +TESTS_ENVIRONMENT=@TENV@
    3.22 +
    3.23 +%.test: %.py
    3.24 +	cp $< $@
    3.25 +	chmod +x $@
    3.26 +
    3.27 +clean-local: am_config_clean-local
    3.28 +
    3.29 +am_config_clean-local:
    3.30 +	rm -f *test
    3.31 +	rm -f *log
    3.32 +	rm -f *~