Ryan Harper
2006-Aug-14 16:56 UTC
[Xen-devel] [PATCH 1/3] xm-test: have getVcpuInfo return more info
Currently, getVcpuInfo in XmTestLib returns only a list of vcpu to cpu mapping. This patch changes getVcpuInfo to return a list of dictionaries which represent each value in the xm vcpu-list output of a domain. This patch also: -adds vcpu_to_cpu function which behaves like previous getVcpuInfo -modifies the users of getVcpuInfo(vcpu-pin,vcpu-disable) -fixes vcpu-pin to wait for all vcpus to be online prior to disabling -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 ryanh@us.ibm.com diffstat output: lib/XmTestLib/Xm.py | 30 +++++++++++++++++++----- tests/vcpu-disable/01_vcpu-disable_basic_pos.py | 16 +++++++++++- tests/vcpu-pin/01_vcpu-pin_basic_pos.py | 4 +-- 3 files changed, 40 insertions(+), 10 deletions(-) Signed-off-by: Ryan Harper <ryanh@us.ibm.com> --- diff -r f328519053f5 tools/xm-test/lib/XmTestLib/Xm.py --- a/tools/xm-test/lib/XmTestLib/Xm.py Mon Aug 14 10:58:02 2006 +0100 +++ b/tools/xm-test/lib/XmTestLib/Xm.py Sat Aug 12 08:22:45 2006 -0500 @@ -170,16 +170,34 @@ def getVcpuInfo(domain): lines = output.split("\n") - vcpus = {} - + vcpus = [] for line in lines[1:]: cols = re.split(" +", line) + info = {} + info[''domain''] = cols[0] + info[''id''] = cols[1] + info[''vcpu''] = cols[2] if cols[3] == ''-'': - vcpus[int(cols[2])] = None + info[''cpu''] = None else: - vcpus[int(cols[2])] = int(cols[3]) + info[''cpu''] = cols[3] + info[''state''] = cols[4] + info[''time''] = cols[5] + info[''affinity''] = cols[6] + vcpus.append(info) return vcpus + +def vcpu_to_cpu(domain): + + vcpuinfo = getVcpuInfo(domain) + vcpus = {} + + for info in vcpuinfo: + vcpus[int(info[''vcpu''])] = info[''cpu''] + + return vcpus + def getInfo(key): @@ -240,6 +258,6 @@ if __name__ == "__main__": print "Domain-0 CPU: " + cpu print "Domain-0 state: " + state - v = getVcpuInfo("Domain-0") + v = vcpu_to_cpu("Domain-0") for key in v.keys(): - print "VCPU%i is on CPU %i" % (key, v[key]) + print "VCPU%i is on CPU %s" % (key, v[key]) diff -r f328519053f5 tools/xm-test/tests/vcpu-disable/01_vcpu-disable_basic_pos.py --- a/tools/xm-test/tests/vcpu-disable/01_vcpu-disable_basic_pos.py Mon Aug 14 10:58:02 2006 +0100 +++ b/tools/xm-test/tests/vcpu-disable/01_vcpu-disable_basic_pos.py Sat Aug 12 09:20:55 2006 -0500 @@ -49,6 +49,18 @@ except DomainError, e: print e.extra FAIL(str(e)) +# wait for both vcpus to come up +vcpus_up = 0 +start = int(time.time()) +print "waiting for all VCPUS to come up" +while vcpus_up != 2: + vcpus_up = len(filter(lambda x: x is not None, vcpu_to_cpu(domain.getName()))) + # 20 second timeout + if int(time.time()) >= start+20: + FAIL("Failed to bring all VCPUS online for test"); + time.sleep(1) + + # Disable VCPU 1 cmd = "xm vcpu-set %s 1" % domain.getName() status, output = safecmd(cmd) @@ -57,7 +69,7 @@ if check_status and status != 0: # Wait for the change to become active for i in [1,2,3,4,5,6,7,8,9,10]: - domUvcpu1 = getVcpuInfo(domain.getName())[1] + domUvcpu1 = vcpu_to_cpu(domain.getName())[1] status, output = traceCommand("xm vcpu-list") if domUvcpu1 is None: break @@ -74,7 +86,7 @@ if check_status and status != 0: FAIL("\"%s\" returned invalid %i != 0" %(cmd,status)) for i in [1,2,3,4,5,6,7,8,9,10]: - domUvcpu1 = getVcpuInfo(domain.getName())[1] + domUvcpu1 = vcpu_to_cpu(domain.getName())[1] if domUvcpu1 is not None: break time.sleep(1) diff -r f328519053f5 tools/xm-test/tests/vcpu-pin/01_vcpu-pin_basic_pos.py --- a/tools/xm-test/tests/vcpu-pin/01_vcpu-pin_basic_pos.py Mon Aug 14 10:58:02 2006 +0100 +++ b/tools/xm-test/tests/vcpu-pin/01_vcpu-pin_basic_pos.py Sat Aug 12 08:22:45 2006 -0500 @@ -32,7 +32,7 @@ if status != 0: if status != 0: FAIL("xm vcpu-pin returned invalid %i != 0" % status) -cpu = getVcpuInfo(domain.getName())[0] +cpu = int(vcpu_to_cpu(domain.getName())[0]) if cpu != 0: FAIL("failed to switch VCPU 0 to CPU 0") @@ -42,7 +42,7 @@ if status != 0: if status != 0: FAIL("xm vcpu-pin returned invalid %i != 0" % status) -cpu = getVcpuInfo(domain.getName())[0] +cpu = int(vcpu_to_cpu(domain.getName())[0]) if cpu != 1: FAIL("failed to switch VCPU 0 to CPU 1") _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel