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
|
#!/usr/bin/python
# Copyright (C) International Business Machines Corp., 2005
# Author: Woody Marvel <marvel@us.ibm.com>
##
## Description:
## Tests that verify mem-set output and return code
## 1) Test for xm mem-set
## create domain,
## verify domain and ls output,
## mem-set in dom0,
## verify with xm list memory change external,
## verify with xm list memory change internal,
##
## Author: Woody Marvel marvel@us.ibm.com
##
import sys
import re
import time
from XmTestLib import *
if ENABLE_HVM_SUPPORT:
SKIP("Mem-set not supported for HVM domains")
# Create a domain (default XmTestDomain, with our ramdisk)
domain = XmTestDomain()
# Start it
try:
console = domain.start()
except DomainError, e:
if verbose:
print "Failed to create test domain because:"
print e.extra
FAIL(str(e))
try:
# Make sure it's up an running before we continue
console.runCmd("ls")
except ConsoleError, e:
FAIL(str(e))
try:
run = console.runCmd("cat /proc/xen/balloon | grep Current");
except ConsoleError, e:
FAIL(str(e))
match = re.match("[^0-9]+([0-9]+)", run["output"])
if not match:
FAIL("Invalid domU meminfo line")
origmem = int(match.group(1)) / 1024
newmem = origmem - 1
# set mem-set for less than default
cmd = "xm mem-set %s %i" % (domain.getName(), newmem)
status, output = traceCommand(cmd)
if status != 0:
if verbose:
print "mem-set failed:"
print output
FAIL("cmd %s returned invalid %i != 0" % (cmd, status))
for i in [1,2,3,4,5,6,7,8,9,10]:
mem = getDomMem(domain.getName())
if mem == newmem:
break
time.sleep(1)
# verify memory set externally
mem = getDomMem(domain.getName())
if not mem:
FAIL("Failed to get memory amount for domain %s" % domain.getName())
elif mem != newmem:
FAIL("Dom0 failed to verify %i MB; got %i MB" % newmem,mem)
# verify memory set internally
try:
run = console.runCmd("cat /proc/xen/balloon | grep Current")
except ConsoleError, e:
FAIL(str(e))
# Check the output of 'cat /proc/xen/balloon'
m = re.match("^Current allocation:\s+(\d+)\skB", run["output"])
if not m:
FAIL("The DomU command 'cat /proc/xen/balloon' failed.")
domUmem = int(m.group(1)) / 1024
if domUmem != newmem:
FAIL("DomU reported incorrect memory amount: %i MB" % (domUmem))
# quiesce everything
# Close the console
domain.closeConsole()
# Stop the domain (nice shutdown)
domain.stop()
|