source: trunk/packages/xen-3.1/xen-3.1/tools/xm-test/tests/enforce_dom0_cpus/01_enforce_dom0_cpus_basic_pos.py @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

  • Property svn:mime-type set to text/script
File size: 4.2 KB
Line 
1#!/usr/bin/python
2
3# Copyright (C) International Business Machines Corp., 2005
4# Authors: Dan Smith <danms@us.ibm.com>
5#          Ryan Harper <ryanh@us.ibm.com>
6
7# 1) Make sure we have a multi cpu system and dom0 has at
8#    least 2 vcpus online.
9# 2) clone standard config (/etc/xen/xend-config.sxp)
10# 3) modify clone with enforce_dom0_cpus=X
11# 4) restart xend with modified config
12# 5) check /proc/cpuinfo for cpu count
13# 6) check xm info 'VCPUs' field to see that only 'enforce_dom0_cpus'
14#    number of cpus are online in dom0
15# 7) Restore initial dom0 vcpu state
16# 8) Restart xend with default config
17
18import sys
19import re
20import time
21import os
22
23# what value should dom0_cpus enforce?
24enforce_dom0_cpus=1
25
26from XmTestLib import *
27
28check_status = 1
29max_tries = 10
30
31def reset_vcpu_count():
32    status, output = traceCommand("xm vcpu-set 0 %s"%(dom0_online_vcpus))
33    if status != 0:
34        print "WARNING!!! Unable to set vcpus back to %s, please set manually"\
35            %(dom0_online_vcpus)
36
37# 1) Make sure we have a multi cpu system and dom0 has at least 2 vcpus online.
38
39if smpConcurrencyLevel() <= 1:
40    print "*** NOTE: This machine does not have more than one physical"
41    print "          or logical cpu.  The vcpu-disable test cannot be run!"
42    SKIP("Host not capable of running test")
43
44# count number of online vcpus in dom0
45dom0_online_vcpus = int(getDomInfo("Domain-0", "VCPUs"))
46if dom0_online_vcpus <= 1:
47    print "*** NOTE: DOM0 needs at least 2 VCPUs online to run this test"
48    print "          Please enable additional vcpus if possible via xm vcpu-set"
49    SKIP("Host state not capable of running test")
50   
51# 2) clone standard config (/etc/xen/xend-config.sxp)
52# 3) modify clone with enforce_dom0_cpus=1
53old_config="/etc/xen/xend-config.sxp"
54new_config ="/tmp/xend-config.sxp"
55cmd = "sed -e 's,dom0-cpus 0,dom0-cpus %s,' %s > %s" % (enforce_dom0_cpus,
56                                                        old_config,
57                                                        new_config)
58status, output = traceCommand(cmd)
59if check_status and status != 0:
60    FAIL("\"%s\" returned invalid %i != 0" %(cmd,status))
61
62
63# 4) restart xend with new config
64os.putenv("XEND_CONFIG", "/tmp/xend-config.sxp")
65status = restartXend()
66os.unsetenv("XEND_CONFIG")
67if check_status and status != 0:
68    ns, no = restartXend()
69    if ns != 0:
70        FAIL("Restarting xend isn't working: something is WAY broken")
71    else:
72        FAIL("\"%s\" returned invalid %i != 0" %(cmd,status))
73
74# 5) check /proc/cpuinfo for cpu count
75
76# It takes some time for the CPU count to change, on multi-proc systems, so check the number of procs in a loop for 30 seconds.
77#Sleep inside the loop for a second each time.
78timeout = 30
79starttime = time.time()
80while timeout + starttime > time.time():
81# Check /proc/cpuinfo
82    cmd = "grep \"^processor\" /proc/cpuinfo | wc -l"
83    status, output = traceCommand(cmd)
84    if check_status and status != 0:
85        reset_vcpu_count()
86        restartXend()
87        FAIL("\"%s\" returned invalid %i != 0" %(cmd,status))
88# Has it succeeded? If so, we can leave the loop
89    if output == str(enforce_dom0_cpus):
90        break
91# Sleep for 1 second before trying again
92    time.sleep(1)
93if output != str(enforce_dom0_cpus):
94    reset_vcpu_count()
95    restartXend()
96    FAIL("/proc/cpuinfo says xend didn't enforce dom0_cpus (%s != %s)"%(output,
97                                                             enforce_dom0_cpus))
98
99# 6) count number of online cpus and see that it matches enforce value
100num_online = int(getDomInfo("Domain-0", "VCPUs"))
101if num_online != enforce_dom0_cpus:
102    reset_vcpu_count()
103    restartXend()
104    FAIL("xm says xend didn't enforce dom0_cpus (%s != %s)" %(num_online,
105                                                             enforce_dom0_cpus))
106
107# 7) restore dead processors
108reset_vcpu_count()
109
110# check restore worked
111# Since this also takes time, we will do it in a loop with a 30 second timeout.
112timeout=30
113starttime=time.time()
114while timeout + starttime > time.time():
115    num_online = int(getDomInfo("Domain-0", "VCPUs"))
116    if num_online == dom0_online_vcpus:
117        break
118    time.sleep(1)
119if num_online != dom0_online_vcpus:
120    restartXend()
121    FAIL("failed to restore dom0's VCPUs")
122
123
124# 8) Restart xend with default config
125restartXend()
126
Note: See TracBrowser for help on using the repository browser.