ia64/xen-unstable

changeset 7997:1d754a4ad350

xm-test: add tests for network-attach command

Signed-off-by: Murillo Fernandes Bernardes <mfb@br.ibm.com>
author root@localhost.localdomain
date Wed Nov 23 12:32:44 2005 +0100 (2005-11-23)
parents 092ac41ec8bd
children 6d9ea03c1baa
files tools/xm-test/configure.ac tools/xm-test/tests/Makefile.am tools/xm-test/tests/network-attach/01_network_attach_pos.py tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py tools/xm-test/tests/network-attach/Makefile.am tools/xm-test/tests/network-attach/network_utils.py
line diff
     1.1 --- a/tools/xm-test/configure.ac	Wed Nov 23 12:31:55 2005 +0100
     1.2 +++ b/tools/xm-test/configure.ac	Wed Nov 23 12:32:44 2005 +0100
     1.3 @@ -50,6 +50,7 @@ AC_CONFIG_FILES([
     1.4      tests/memmax/Makefile
     1.5      tests/memset/Makefile
     1.6      tests/migrate/Makefile
     1.7 +    tests/network-attach/Makefile
     1.8      tests/pause/Makefile
     1.9      tests/reboot/Makefile
    1.10      tests/restore/Makefile
     2.1 --- a/tools/xm-test/tests/Makefile.am	Wed Nov 23 12:31:55 2005 +0100
     2.2 +++ b/tools/xm-test/tests/Makefile.am	Wed Nov 23 12:32:44 2005 +0100
     2.3 @@ -13,6 +13,7 @@ SUBDIRS = 	               	\
     2.4  		list		\
     2.5  		memmax		\
     2.6  		memset		\
     2.7 +		network-attach	\
     2.8  		pause		\
     2.9  		reboot 		\
    2.10  		sedf		\
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/xm-test/tests/network-attach/01_network_attach_pos.py	Wed Nov 23 12:32:44 2005 +0100
     3.3 @@ -0,0 +1,48 @@
     3.4 +#!/usr/bin/python
     3.5 +
     3.6 +# Copyright (C) International Business Machines Corp., 2005
     3.7 +# Author: Murillo F. Bernardes <mfb@br.ibm.com>
     3.8 +
     3.9 +import sys
    3.10 +
    3.11 +from XmTestLib import *
    3.12 +from network_utils import *
    3.13 +
    3.14 +# Create a domain (default XmTestDomain, with our ramdisk)
    3.15 +domain = XmTestDomain()
    3.16 +
    3.17 +try:
    3.18 +    domain.start()
    3.19 +except DomainError, e:
    3.20 +    if verbose:
    3.21 +        print "Failed to create test domain because:"
    3.22 +        print e.extra
    3.23 +    FAIL(str(e))
    3.24 +
    3.25 +# Attach a console to it
    3.26 +try:
    3.27 +    console = XmConsole(domain.getName(), historySaveCmds=True)
    3.28 +except ConsoleError, e:
    3.29 +    FAIL(str(e))
    3.30 +
    3.31 +try:
    3.32 +    # Activate the console
    3.33 +    console.sendInput("input")
    3.34 +    # Run 'ls'
    3.35 +    run = console.runCmd("ls")
    3.36 +except ConsoleError, e:
    3.37 +    saveLog(console.getHistory())
    3.38 +    FAIL(str(e))
    3.39 +    
    3.40 +## Real test
    3.41 +status, msg = network_attach(domain.getName(), console)
    3.42 +if status:
    3.43 +    FAIL(msg)
    3.44 +
    3.45 +
    3.46 +##
    3.47 +# Close the console
    3.48 +console.closeConsole()
    3.49 +
    3.50 +# Stop the domain (nice shutdown)
    3.51 +domain.stop()
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py	Wed Nov 23 12:32:44 2005 +0100
     4.3 @@ -0,0 +1,54 @@
     4.4 +#!/usr/bin/python
     4.5 +
     4.6 +# Copyright (C) International Business Machines Corp., 2005
     4.7 +# Author: Murillo F. Bernardes <mfb@br.ibm.com>
     4.8 +
     4.9 +import sys
    4.10 +import re
    4.11 +import time
    4.12 +
    4.13 +from XmTestLib import *
    4.14 +from network_utils import *
    4.15 +
    4.16 +# Create a domain (default XmTestDomain, with our ramdisk)
    4.17 +domain = XmTestDomain()
    4.18 +
    4.19 +try:
    4.20 +    domain.start()
    4.21 +except DomainError, e:
    4.22 +    if verbose:
    4.23 +        print "Failed to create test domain because:"
    4.24 +        print e.extra
    4.25 +    FAIL(str(e))
    4.26 +
    4.27 +# Attach a console to it
    4.28 +try:
    4.29 +    console = XmConsole(domain.getName(), historySaveCmds=True)
    4.30 +except ConsoleError, e:
    4.31 +    FAIL(str(e))
    4.32 +
    4.33 +try:
    4.34 +    # Activate the console
    4.35 +    console.sendInput("input")
    4.36 +    # Run 'ls'
    4.37 +    run = console.runCmd("ls")
    4.38 +except ConsoleError, e:
    4.39 +    saveLog(console.getHistory())
    4.40 +    FAIL(str(e))
    4.41 +
    4.42 +## Real test - attach and detach
    4.43 +status, msg = network_attach(domain.getName(), console)
    4.44 +if status:
    4.45 +    FAIL(msg)
    4.46 +
    4.47 +status, msg = network_detach(domain.getName(), console)
    4.48 +if status:
    4.49 +    FAIL(msg)
    4.50 +
    4.51 +
    4.52 +
    4.53 +# Close the console
    4.54 +console.closeConsole()
    4.55 +
    4.56 +# Stop the domain (nice shutdown)
    4.57 +domain.stop()
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py	Wed Nov 23 12:32:44 2005 +0100
     5.3 @@ -0,0 +1,54 @@
     5.4 +#!/usr/bin/python
     5.5 +
     5.6 +# Copyright (C) International Business Machines Corp., 2005
     5.7 +# Author: Murillo F. Bernardes <mfb@br.ibm.com>
     5.8 +
     5.9 +import sys
    5.10 +import re
    5.11 +import time
    5.12 +
    5.13 +from XmTestLib import *
    5.14 +from network_utils import *
    5.15 +
    5.16 +# Create a domain (default XmTestDomain, with our ramdisk)
    5.17 +domain = XmTestDomain()
    5.18 +
    5.19 +try:
    5.20 +    domain.start()
    5.21 +except DomainError, e:
    5.22 +    if verbose:
    5.23 +        print "Failed to create test domain because:"
    5.24 +        print e.extra
    5.25 +    FAIL(str(e))
    5.26 +
    5.27 +# Attach a console to it
    5.28 +try:
    5.29 +    console = XmConsole(domain.getName(), historySaveCmds=True)
    5.30 +except ConsoleError, e:
    5.31 +    FAIL(str(e))
    5.32 +
    5.33 +try:
    5.34 +    # Activate the console
    5.35 +    console.sendInput("input")
    5.36 +    # Run 'ls'
    5.37 +    run = console.runCmd("ls")
    5.38 +except ConsoleError, e:
    5.39 +    saveLog(console.getHistory())
    5.40 +    FAIL(str(e))
    5.41 +    
    5.42 +for i in range(10):
    5.43 +    print "Attaching %d device" % i 
    5.44 +    status, msg = network_attach(domain.getName(), console)
    5.45 +    if status:
    5.46 +        FAIL(msg)
    5.47 +    
    5.48 +    print "Detaching %d device" % i 
    5.49 +    status, msg = network_detach(domain.getName(), console, i)
    5.50 +    if status:
    5.51 +        FAIL(msg)
    5.52 +
    5.53 +# Close the console
    5.54 +console.closeConsole()
    5.55 +
    5.56 +# Stop the domain (nice shutdown)
    5.57 +domain.stop()
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py	Wed Nov 23 12:32:44 2005 +0100
     6.3 @@ -0,0 +1,17 @@
     6.4 +#!/usr/bin/python
     6.5 +
     6.6 +# Copyright (C) International Business Machines Corp., 2005
     6.7 +# Author: Murillo F. Bernardes <mfb@br.ibm.com>
     6.8 +
     6.9 +from XmTestLib import *
    6.10 +
    6.11 +status, output = traceCommand("xm network-attach NOT-EXIST")
    6.12 +
    6.13 +eyecatcher = "Error"
    6.14 +where = output.find(eyecatcher)
    6.15 +if status == 0:
    6.16 +	FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
    6.17 +elif where == -1:
    6.18 +	FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
    6.19 +	
    6.20 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/xm-test/tests/network-attach/Makefile.am	Wed Nov 23 12:32:44 2005 +0100
     7.3 @@ -0,0 +1,24 @@
     7.4 +
     7.5 +SUBDIRS =
     7.6 +
     7.7 +TESTS = 01_network_attach_pos.test \
     7.8 +	02_network_attach_detach_pos.test \
     7.9 +	03_network_attach_detach_multiple_pos.test  \
    7.10 +	04_network_attach_baddomain_neg.test
    7.11 +
    7.12 +DISABLED = 
    7.13 +
    7.14 +EXTRA_DIST = $(TESTS) $(XFAIL_TESTS) network_utils.py
    7.15 +
    7.16 +TESTS_ENVIRONMENT=@TENV@
    7.17 +
    7.18 +%.test: %.py
    7.19 +	cp $< $@
    7.20 +	chmod +x $@
    7.21 +
    7.22 +clean-local: am_config_clean-local
    7.23 +
    7.24 +am_config_clean-local:
    7.25 +	rm -f *test
    7.26 +	rm -f *log
    7.27 +	rm -f *~
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/xm-test/tests/network-attach/network_utils.py	Wed Nov 23 12:32:44 2005 +0100
     8.3 @@ -0,0 +1,37 @@
     8.4 +#!/usr/bin/python
     8.5 +
     8.6 +# Copyright (C) International Business Machines Corp., 2005
     8.7 +# Author: Murillo F. Bernardes <mfb@br.ibm.com>
     8.8 +
     8.9 +from XmTestLib import *
    8.10 +
    8.11 +def count_eth(console):
    8.12 +    try:
    8.13 +        run = console.runCmd("ifconfig -a | grep eth")
    8.14 +    except ConsoleError, e:
    8.15 +        FAIL(str(e))
    8.16 +    return = len(run['output'].splitlines())
    8.17 +
    8.18 +def network_attach(domain_name, console):
    8.19 +    eths_before = count_eth(console)
    8.20 +    status, output = traceCommand("xm network-attach %s" % domain_name)
    8.21 +    if status != 0:
    8.22 +        return -1, "xm network-attach returned invalid %i != 0" % status
    8.23 +
    8.24 +    eths_after = count_eth(console)
    8.25 +    if (eths_after != (eths_before+1)):
    8.26 +        return -2, "Network device is not actually connected to domU"
    8.27 +
    8.28 +    return 0, None 
    8.29 +
    8.30 +def network_detach(domain_name, console, num=0):
    8.31 +    eths_before = count_eth(console)
    8.32 +    status, output = traceCommand("xm network-detach %s %d" % (domain_name, num))
    8.33 +    if status != 0:
    8.34 +        return -1, "xm network-attach returned invalid %i != 0" % status
    8.35 +
    8.36 +    eths_after = count_eth(console)
    8.37 +    if eths_after != (eths_before-1):
    8.38 +    	return -2, "Network device was not actually disconnected from domU"
    8.39 +
    8.40 +    return 0, None