From 21cdf90f7acb1303742e6e5249a7d317c2f4bcfe Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Thu, 26 Apr 2007 15:48:09 +0100 Subject: [XM-TEST] Move network_utils.py to lib directory signed-off-by: Tom Wilkie --- tools/xm-test/lib/XmTestLib/network_utils.py | 60 ++++++++++++++++++++++ .../tests/network-attach/01_network_attach_pos.py | 2 +- .../network-attach/02_network_attach_detach_pos.py | 2 +- .../03_network_attach_detach_multiple_pos.py | 2 +- .../xm-test/tests/network-attach/network_utils.py | 56 -------------------- 5 files changed, 63 insertions(+), 59 deletions(-) create mode 100644 tools/xm-test/lib/XmTestLib/network_utils.py delete mode 100644 tools/xm-test/tests/network-attach/network_utils.py (limited to 'tools/xm-test') diff --git a/tools/xm-test/lib/XmTestLib/network_utils.py b/tools/xm-test/lib/XmTestLib/network_utils.py new file mode 100644 index 0000000000..5c06f2f042 --- /dev/null +++ b/tools/xm-test/lib/XmTestLib/network_utils.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +# Copyright (C) International Business Machines Corp., 2005 +# Author: Murillo F. Bernardes + +from XmTestLib import * + +def count_eth(console): + try: + run = console.runCmd("ifconfig -a | grep eth") + except ConsoleError, e: + FAIL(str(e)) + return len(run['output'].splitlines()) + +def get_state(domain_name, number): + s, o = traceCommand("xm network-list %s | awk '/^%d/ {print $5}'" % + (domain_name, number)) + print o + + if s != 0: + FAIL("network-list failed") + if o == "": + return 0 + else: + return int(o) + +def network_attach(domain_name, console, bridge=None): + eths_before = count_eth(console) + if bridge: + status, output = traceCommand("xm network-attach %s bridge=%s" + % (domain_name, bridge)) + else: + status, output = traceCommand("xm network-attach %s" % domain_name) + if status != 0: + return -1, "xm network-attach returned invalid %i != 0" % status + + eths_after = count_eth(console) + if (eths_after != (eths_before+1)): + return -2, "Network device is not actually connected to domU" + + return 0, None + +def network_detach(domain_name, console, num=0): + eths_before = count_eth(console) + status, output = traceCommand("xm network-detach %s %d" % (domain_name, num)) + if status != 0: + return -1, "xm network-detach returned invalid %i != 0" % status + + for i in range(10): + if get_state(domain_name, num) == 0: + break + time.sleep(1) + else: + FAIL("network-detach failed: device did not disappear") + + eths_after = count_eth(console) + if eths_after != (eths_before-1): + return -2, "Network device was not actually disconnected from domU" + + return 0, None diff --git a/tools/xm-test/tests/network-attach/01_network_attach_pos.py b/tools/xm-test/tests/network-attach/01_network_attach_pos.py index f8e7f1a748..d6fdabbaa9 100644 --- a/tools/xm-test/tests/network-attach/01_network_attach_pos.py +++ b/tools/xm-test/tests/network-attach/01_network_attach_pos.py @@ -6,7 +6,7 @@ import sys from XmTestLib import * -from network_utils import * +from XmTestLib.network_utils import * if ENABLE_HVM_SUPPORT: SKIP("Network-attach not supported for HVM domains") diff --git a/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py b/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py index c985957dd9..43b8e20113 100644 --- a/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py +++ b/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py @@ -8,7 +8,7 @@ import re import time from XmTestLib import * -from network_utils import * +from XmTestLib.network_utils import * if ENABLE_HVM_SUPPORT: SKIP("Network-attach not supported for HVM domains") diff --git a/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py b/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py index b3e49e4c0e..a0066d92f0 100644 --- a/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py +++ b/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py @@ -8,7 +8,7 @@ import re import time from XmTestLib import * -from network_utils import * +from XmTestLib.network_utils import * if ENABLE_HVM_SUPPORT: SKIP("Network-attach not supported for HVM domains") diff --git a/tools/xm-test/tests/network-attach/network_utils.py b/tools/xm-test/tests/network-attach/network_utils.py deleted file mode 100644 index 0d1c2a726b..0000000000 --- a/tools/xm-test/tests/network-attach/network_utils.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python - -# Copyright (C) International Business Machines Corp., 2005 -# Author: Murillo F. Bernardes - -from XmTestLib import * - -def count_eth(console): - try: - run = console.runCmd("ifconfig -a | grep eth") - except ConsoleError, e: - FAIL(str(e)) - return len(run['output'].splitlines()) - -def get_state(domain_name, number): - s, o = traceCommand("xm network-list %s | awk '/^%d/ {print $5}'" % - (domain_name, number)) - print o - - if s != 0: - FAIL("network-list failed") - if o == "": - return 0 - else: - return int(o) - -def network_attach(domain_name, console): - eths_before = count_eth(console) - status, output = traceCommand("xm network-attach %s" % domain_name) - if status != 0: - return -1, "xm network-attach returned invalid %i != 0" % status - - eths_after = count_eth(console) - if (eths_after != (eths_before+1)): - return -2, "Network device is not actually connected to domU" - - return 0, None - -def network_detach(domain_name, console, num=0): - eths_before = count_eth(console) - status, output = traceCommand("xm network-detach %s %d" % (domain_name, num)) - if status != 0: - return -1, "xm network-detach returned invalid %i != 0" % status - - for i in range(10): - if get_state(domain_name, num) == 0: - break - time.sleep(1) - else: - FAIL("network-detach failed: device did not disappear") - - eths_after = count_eth(console) - if eths_after != (eths_before-1): - return -2, "Network device was not actually disconnected from domU" - - return 0, None -- cgit v1.2.3