| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | # Copyright (C) International Business Machines Corp., 2005 |
|---|
| 4 | # Author: Woody Marvel <marvel@us.ibm.com> |
|---|
| 5 | ## |
|---|
| 6 | ## Description: |
|---|
| 7 | ## Tests that verify mem-set output and return code |
|---|
| 8 | ## 1) Test for xm mem-set |
|---|
| 9 | ## create domain, |
|---|
| 10 | ## verify domain and ls output, |
|---|
| 11 | ## mem-set in dom0, |
|---|
| 12 | ## verify with xm list memory change external, |
|---|
| 13 | ## verify with xm list memory change internal, |
|---|
| 14 | ## |
|---|
| 15 | ## Author: Woody Marvel marvel@us.ibm.com |
|---|
| 16 | ## |
|---|
| 17 | |
|---|
| 18 | import sys |
|---|
| 19 | import re |
|---|
| 20 | import time |
|---|
| 21 | from XmTestLib import * |
|---|
| 22 | |
|---|
| 23 | if ENABLE_HVM_SUPPORT: |
|---|
| 24 | SKIP("Mem-set not supported for HVM domains") |
|---|
| 25 | |
|---|
| 26 | # Create a domain (default XmTestDomain, with our ramdisk) |
|---|
| 27 | domain = XmTestDomain() |
|---|
| 28 | |
|---|
| 29 | # Start it |
|---|
| 30 | try: |
|---|
| 31 | console = domain.start() |
|---|
| 32 | except DomainError, e: |
|---|
| 33 | if verbose: |
|---|
| 34 | print "Failed to create test domain because:" |
|---|
| 35 | print e.extra |
|---|
| 36 | FAIL(str(e)) |
|---|
| 37 | |
|---|
| 38 | try: |
|---|
| 39 | # Make sure it's up an running before we continue |
|---|
| 40 | console.runCmd("ls") |
|---|
| 41 | except ConsoleError, e: |
|---|
| 42 | FAIL(str(e)) |
|---|
| 43 | |
|---|
| 44 | try: |
|---|
| 45 | run = console.runCmd("cat /proc/xen/balloon | grep Current"); |
|---|
| 46 | except ConsoleError, e: |
|---|
| 47 | FAIL(str(e)) |
|---|
| 48 | |
|---|
| 49 | match = re.match("[^0-9]+([0-9]+)", run["output"]) |
|---|
| 50 | if not match: |
|---|
| 51 | FAIL("Invalid domU meminfo line") |
|---|
| 52 | |
|---|
| 53 | origmem = int(match.group(1)) / 1024 |
|---|
| 54 | newmem = origmem - 1 |
|---|
| 55 | |
|---|
| 56 | # set mem-set for less than default |
|---|
| 57 | cmd = "xm mem-set %s %i" % (domain.getName(), newmem) |
|---|
| 58 | status, output = traceCommand(cmd) |
|---|
| 59 | if status != 0: |
|---|
| 60 | if verbose: |
|---|
| 61 | print "mem-set failed:" |
|---|
| 62 | print output |
|---|
| 63 | FAIL("cmd %s returned invalid %i != 0" % (cmd, status)) |
|---|
| 64 | |
|---|
| 65 | for i in [1,2,3,4,5,6,7,8,9,10]: |
|---|
| 66 | mem = getDomMem(domain.getName()) |
|---|
| 67 | if mem == newmem: |
|---|
| 68 | break |
|---|
| 69 | time.sleep(1) |
|---|
| 70 | |
|---|
| 71 | # verify memory set externally |
|---|
| 72 | mem = getDomMem(domain.getName()) |
|---|
| 73 | if not mem: |
|---|
| 74 | FAIL("Failed to get memory amount for domain %s" % domain.getName()) |
|---|
| 75 | elif mem != newmem: |
|---|
| 76 | FAIL("Dom0 failed to verify %i MB; got %i MB" % newmem,mem) |
|---|
| 77 | |
|---|
| 78 | # verify memory set internally |
|---|
| 79 | try: |
|---|
| 80 | run = console.runCmd("cat /proc/xen/balloon | grep Current") |
|---|
| 81 | except ConsoleError, e: |
|---|
| 82 | FAIL(str(e)) |
|---|
| 83 | |
|---|
| 84 | # Check the output of 'cat /proc/xen/balloon' |
|---|
| 85 | m = re.match("^Current allocation:\s+(\d+)\skB", run["output"]) |
|---|
| 86 | if not m: |
|---|
| 87 | FAIL("The DomU command 'cat /proc/xen/balloon' failed.") |
|---|
| 88 | |
|---|
| 89 | domUmem = int(m.group(1)) / 1024 |
|---|
| 90 | |
|---|
| 91 | if domUmem != newmem: |
|---|
| 92 | FAIL("DomU reported incorrect memory amount: %i MB" % (domUmem)) |
|---|
| 93 | |
|---|
| 94 | # quiesce everything |
|---|
| 95 | # Close the console |
|---|
| 96 | domain.closeConsole() |
|---|
| 97 | |
|---|
| 98 | # Stop the domain (nice shutdown) |
|---|
| 99 | domain.stop() |
|---|