3
# Copyright (C) International Business Machines Corp., 2005
4
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
6
from XmTestLib import *
8
def count_eth(console):
10
run = console.runCmd("ifconfig -a | grep eth")
11
except ConsoleError, e:
13
return len(run['output'].splitlines())
15
def get_state(domain_name, number):
16
s, o = traceCommand("xm network-list %s | awk '/^%d/ {print $5}'" %
17
(domain_name, number))
21
FAIL("network-list failed")
27
def network_attach(domain_name, console, bridge=None):
28
eths_before = count_eth(console)
30
status, output = traceCommand("xm network-attach %s bridge=%s"
31
% (domain_name, bridge))
33
status, output = traceCommand("xm network-attach %s" % domain_name)
35
return -1, "xm network-attach returned invalid %i != 0" % status
37
eths_after = count_eth(console)
38
if (eths_after != (eths_before+1)):
39
return -2, "Network device is not actually connected to domU"
43
def network_detach(domain_name, console, num=0):
44
eths_before = count_eth(console)
45
status, output = traceCommand("xm network-detach %s %d" % (domain_name, num))
47
return -1, "xm network-detach returned invalid %i != 0" % status
50
if get_state(domain_name, num) == 0:
54
FAIL("network-detach failed: device did not disappear")
56
eths_after = count_eth(console)
57
if eths_after != (eths_before-1):
58
return -2, "Network device was not actually disconnected from domU"