aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xm-test/tests/cpupool/03_cpupool_domain.py
blob: dcff944dac1f7eccee6fe771c15d833bc8e53049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python

import sys
import re
import time

from XmTestLib import *
from pools import *


checkRequirements()

#
# create Pool-1 with 1 CPU and start a VM
#
createStdPool()
name = "TestDomPool-1"
domain = XmTestDomain(extraConfig={'pool' : 'Pool-1'}, name=name)
try:
    domain.start(noConsole=True)
except DomainError, ex:
    FAIL(str(e))

cmd = "xm list --pool=Pool-1"
status, output = traceCommand(cmd)
if status != 0:
    FAIL("%s failed, rc %s" % (cmd,status))
if not re.search(name, output):
    FAIL("%s; missing '%s' in Pool-1" % (cmd,name))

domain.stop()
waitForDomain(name)
destroyPool("Pool-1", True)



#
# create Pool-1 with 1 CPU, add a second CPU
# start a VM (with vpcu=3) add a third CPU
# remove 2 CPUs from pool
# create Pool-1 with 1 CPU and start a VM
#
pool_names = ['Pool-1', 'Pool-2']
createStdPool({'name' : pool_names[0], 'cpus' : '"1"'})
name = "TestDomPool-1"
cmd = "xm pool-cpu-add Pool-1 2"
status, output = traceCommand(cmd)
if status != 0:
    FAIL("%s failed, rc %s" % (cmd,status))

domain = XmTestDomain(extraConfig={ 'pool' : 'Pool-1'}, name=name)
try:
    domain.start(noConsole=True)
except DomainError, ex:
    FAIL(str(e))

cmd = "xm pool-cpu-add Pool-1 3"
status, output = traceCommand(cmd)
if status != 0:
    FAIL("%s failed, rc %s" % (cmd,status))

cmd = "xm pool-cpu-remove Pool-1 2"
status, output = traceCommand(cmd)
if status != 0:
    FAIL("%s failed, rc %s" % (cmd,status))
cmd = "xm pool-cpu-remove Pool-1 3"

status, output = traceCommand(cmd)
if status != 0:
    FAIL("%s failed, rc %s" % (cmd,status))


createStdPool({'name' : pool_names[1]})
name2 = "TestDomPool-2"
domain2 = XmTestDomain(extraConfig={ 'pool' : 'Pool-2'}, name=name2)
try:
    domain2.start(noConsole=True)
except DomainError, ex:
    FAIL(str(e))

domain2.stop()
domain.stop()

waitForDomain(name)
waitForDomain(name2)

for pool in pool_names:
    destroyPool(pool, True)



#
# Create 2 pools with 1 cpu per pool.
# Create three domains in each pool, with 1,2,3 VCPUs
# Switch a thrid cpu between the pools.
#
pool_names = ['Pool-1', 'Pool-2']
domains = {}
cpu=3

for pool in pool_names:
    createStdPool({'name' : pool})
    for dom_nr in range(3):
        name = "TestDom%s-%s" % (pool, dom_nr)
        domains[name] = XmTestDomain(extraConfig={'pool' : pool},
            name=name)
        try:
            domains[name].start(noConsole=True)
        except DomainError, ex:
            FAIL(str(ex))

cmd_add_1 = "xm pool-cpu-add Pool-1 %s" % cpu
cmd_rem_1 = "xm pool-cpu-remove Pool-1 %s" % cpu
cmd_add_2 = "xm pool-cpu-add Pool-2 %s" % cpu
cmd_rem_2 = "xm pool-cpu-remove Pool-2 %s" % cpu

for i in range(25):
    traceCommand(cmd_add_1)
    traceCommand(cmd_rem_1)
    traceCommand(cmd_add_2)
    traceCommand(cmd_rem_2)

destroyAllDomUs()
for pool in pool_names:
    destroyPool(pool, True)