Skip to contentSkip to conversation

KVM test: Memory ballooning test for KVM guest

PATCH In review pradeep 3 participants 11 messages Feb 11, 2010 – Apr 16, 2010 KVM

lore
Share & tools
lore

pradeep

author
#0 lore raw

PATCH 1/1 KVM test: Memory ballooning test for KVM guest

Hi

This path tests Memory ballooning functionality of a KVM guest.

Create a guest. Boot the guest with "-balloon virtio"

Try to increase/decrease the memory from qemu monitor and verify the changes.

Please find the attached patch.

Thanks
Pradeep

---

client/tests/kvm/tests/balloon_check.py +0 -63
diff -uprN a/client/tests/kvm/tests/balloon_check.py b/client/tests/kvm/tests/balloon_check.py
@@ -1,63 +0,0 @@
-import re, string, logging
-from autotest_lib.client.common_lib import error
-import kvm_test_utils, kvm_utils
-
-def run_balloon_check(test, params, env):
-    """
-    Check Memory ballooning:
-    1) Boot a guest
-    2) Increase and decrease the memory of guest using balloon command from monitor
-    3) check memory info
-
-    @param test: kvm test object
-    @param params: Dictionary with the test parameters
-    @param env: Dictionary with test environment.
-    """
-    
-    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
-    session = kvm_test_utils.wait_for_login(vm)
-    fail = 0
-    
-    # Check memory size
-    ogging.info("Memory size check")
-    expected_mem = int(params.get("mem"))
-    actual_mem = vm.get_memory_size()
-    if actual_mem != expected_mem:
-        logging.error("Memory size mismatch:")
-        logging.error("    Assigned to VM: %s" % expected_mem)
-        logging.error("    Reported by OS: %s" % actual_mem)
-    
-    #check info balloon command
-    o, str = vm.send_monitor_cmd("info balloon")
-    if o != 0:
-        logging.error("qemu monitor command failed:")
-    s =int(re.findall("\d+",str)[0])
-    if s != actual_mem:
-        logging.error("qemu monitor command failed: info balloon")
-        raise error.TestFail("Memory ballooning failed while decreasing memory")
-
-    #Reduce memory to 80% of actual memory
-    new_mem = int (0.8 * actual_mem)
-    vm.send_monitor_cmd(" balloon %s " % new_mem)
-    o, str = vm.send_monitor_cmd("info balloon")
-    if o != 0:
-        logging.error("qemu monitor command failed:")
-    s = int(re.findall("\d+",str)[0])
-    if s != new_mem:
-        logging.error(" memory ballooning failed ")
-        fail = 1
-
-    # increase memory to actual size 
-    vm.send_monitor_cmd(" balloon %s " % new_mem )
-    o,str = vm.send_monitor_cmd("info balloon")
-    if o != 0:
-        logging.error("qemu monitor command failed:")
-    s = int(re.findall("\d+",str)[0])
-    if s != actual_mem:
-        logging.error("Memory ballooning failed while increasing memory")
-        fail = 1
-    
-    #Checking for test result
-    if fail != 0:
-        raise error.TestFail("Memory ballooning test failed ")
-    session.close()
client/tests/kvm/tests_base.cfg.sample +18 -28

196 lines not on this page · raw message

---

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

#1 lore raw
Quoted 12 lines · pradeep

Hi

This path tests Memory ballooning functionality of a KVM guest.

Create a guest. Boot the guest with "-balloon virtio"

Try to increase/decrease the memory from qemu monitor and verify the changes.

Quoted 5 lines

Please find the attached patch.

Thanks
Pradeep

Hi Pradeep:

Thanks for your patch! See my comments below:

client/tests/kvm/tests/balloon_check.py

Quoted 6 lines

plain text document attachment (patch)

---
diff -uprN a/client/tests/kvm/tests/balloon_check.py b/client/tests/kvm/tests/balloon_check.py

client/tests/kvm/tests/balloon_check.py +0 -0

This patch is a reversed patch, in actuality it should be adding the test instead of removing it. You might want to work your patches from now on using git, git branch, git rebase, git format-patch and git send-email, they will save you a lot of trouble. Here is the git URL for the autotest git svn mirror:

git clone git://github.com/ehabkost/autotest.git

Quoted 13 lines
client/tests/kvm/tests/balloon_check.py +0 -12
@@ -1,63 +0,0 @@
-import re, string, logging
-from autotest_lib.client.common_lib import error
-import kvm_test_utils, kvm_utils
-
-def run_balloon_check(test, params, env):
-    """
-    Check Memory ballooning:
-    1) Boot a guest
-    2) Increase and decrease the memory of guest using balloon command from monitor
-    3) check memory info
-
-    @param test: kvm test object

client/tests/kvm/tests/balloon_check.py line 22

Quoted 10 lines
client/tests/kvm/tests/balloon_check.py +0 -10
-    @param params: Dictionary with the test parameters
-    @param env: Dictionary with test environment.
-    """
-    
-    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
-    session = kvm_test_utils.wait_for_login(vm)
-    fail = 0
-    
-    # Check memory size
-    ogging.info("Memory size check")

There's a typo above, should be 'logging';

client/tests/kvm/tests/balloon_check.py line 34

Quoted 12 lines
client/tests/kvm/tests/balloon_check.py +0 -12
-    expected_mem = int(params.get("mem"))
-    actual_mem = vm.get_memory_size()
-    if actual_mem != expected_mem:
-        logging.error("Memory size mismatch:")
-        logging.error("    Assigned to VM: %s" % expected_mem)
-        logging.error("    Reported by OS: %s" % actual_mem)
-    
-    #check info balloon command
-    o, str = vm.send_monitor_cmd("info balloon")
-    if o != 0:
-        logging.error("qemu monitor command failed:")
-    s =int(re.findall("\d+",str)[0])

Please fix the spacing on the attribution statement

client/tests/kvm/tests/balloon_check.py line 40

Quoted 6 lines
client/tests/kvm/tests/balloon_check.py +0 -6
-    if s != actual_mem:
-        logging.error("qemu monitor command failed: info balloon")
-        raise error.TestFail("Memory ballooning failed while decreasing memory")
-
-    #Reduce memory to 80% of actual memory
-    new_mem = int (0.8 * actual_mem)

Maybe it's a nice idea to choose a random number between, let's say, 0.8 and 0.95, so we can run some iterations and see how the guest behaves.

client/tests/kvm/tests/balloon_check.py line 41

Quoted 1 line
client/tests/kvm/tests/balloon_check.py +0 -1
-    vm.send_monitor_cmd(" balloon %s " % new_mem)

Why the spacing between the quotes and the baloon string?

client/tests/kvm/tests/balloon_check.py line 33

Quoted 3 lines
client/tests/kvm/tests/balloon_check.py +0 -3
-    o, str = vm.send_monitor_cmd("info balloon")
-    if o != 0:
-        logging.error("qemu monitor command failed:")

We need to specify which qemu monitor command failed above. Also, you could use more desctiptive names for the variables, such as (status, output).

client/tests/kvm/tests/balloon_check.py line 48

Quoted 4 lines
client/tests/kvm/tests/balloon_check.py +0 -4
-    s = int(re.findall("\d+",str)[0])
-    if s != new_mem:
-        logging.error(" memory ballooning failed ")
-        fail = 1

It makes more sense to increase the failure counter throughout the test

fail += 1

client/tests/kvm/tests/balloon_check.py line 50

Quoted 1 line
client/tests/kvm/tests/balloon_check.py +0 -1
-    # increase memory to actual size

In the comment above, original size is more descriptive.

client/tests/kvm/tests/balloon_check.py line 51

Quoted 2 lines
client/tests/kvm/tests/balloon_check.py +0 -1
-    vm.send_monitor_cmd(" balloon %s " % new_mem )

The above monitor command should replace %s by actual_mem.

client/tests/kvm/tests/balloon_check.py line 54

Quoted 3 lines
client/tests/kvm/tests/balloon_check.py +0 -3
-    o,str = vm.send_monitor_cmd("info balloon")
-    if o != 0:
-        logging.error("qemu monitor command failed:")

In the above we also want to increase the failure counter, no?

Quoted 13 lines
client/tests/kvm/tests/balloon_check.py +0 -9
-    s = int(re.findall("\d+",str)[0])
-    if s != actual_mem:
-        logging.error("Memory ballooning failed while increasing memory")
-        fail = 1
-    
-    #Checking for test result
-    if fail != 0:
-        raise error.TestFail("Memory ballooning test failed ")
-    session.close()

diff -uprN a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample

client/tests/kvm/tests_base.cfg.sample variants: · line 163

Quoted 6 lines
client/tests/kvm/tests_base.cfg.sample +0 -3
@@ -158,10 +158,6 @@ variants:
                 drift_threshold = 10
                 drift_threshold_single = 3
 
-    - balloon_check:  install setup unattended_install
-        type = balloon_check
-        extra_params += "-balloon virtio"

In the above attribution, be sure to allways put a whitespace ' ' before the flags:

extra_params += " -balloon virtio"

Quoted 106 lines
client/tests/kvm/tests_base.cfg.sample +6 -12
     - stress_boot:  install setup unattended_install
         type = stress_boot
         max_vms = 5    
@@ -320,7 +316,7 @@ variants:
 
                 variants:
                     - 8.32:
-                        no setup balloon_check
+                        no setup
                         image_name = fc8-32
                         cdrom = linux/Fedora-8-i386-DVD.iso
                         md5sum = dd6c79fddfff36d409d02242e7b10189
@@ -331,7 +327,7 @@ variants:
                             unattended_file = unattended/Fedora-8.ks
 
                     - 8.64:
-                        no setup balloon_check
+                        no setup
                         image_name = fc8-64
                         cdrom = linux/Fedora-8-x86_64-DVD.iso
                         md5sum = 2cb231a86709dec413425fd2f8bf5295
@@ -342,7 +338,6 @@ variants:
                             unattended_file = unattended/Fedora-8.ks
 
                     - 9.32:
-                        no balloon_check
                         image_name = fc9-32
                         cdrom = linux/Fedora-9-i386-DVD.iso
                         md5sum = 72601f685ea8c808c303353d8bf4d307
@@ -353,7 +348,6 @@ variants:
                             unattended_file = unattended/Fedora-9.ks
 
                     - 9.64:
-                        no balloon_check
                         image_name = fc9-64
                         cdrom = linux/Fedora-9-x86_64-DVD.iso
                         md5sum = 05b2ebeed273ec54d6f9ed3d61ea4c96
@@ -364,7 +358,6 @@ variants:
                             unattended_file = unattended/Fedora-9.ks
 
                     - 10.32:
-                        no balloon_check
                         image_name = fc10-32
                         cdrom = linux/Fedora-10-i386-DVD.iso
                         md5sum = 27e581edb392728c4a07d00d3fc5ced0
@@ -373,7 +366,6 @@ variants:
                             unattended_file = unattended/Fedora-10.ks
 
                     - 10.64:
-                        no balloon_check
                         image_name = fc10-64
                         cdrom = linux/Fedora-10-x86_64-DVD.iso
                         sha1sum = f1e5ae7db6a1ba227de7294c4112385922388648
@@ -382,7 +374,6 @@ variants:
                             unattended_file = unattended/Fedora-10.ks
 
                     - 11.32:
-                        no balloon_check
                         image_name = fc11-32
                         cdrom = linux/Fedora-11-i386-DVD.iso
                         md5sum = e3b1e2d1ba42aa4705fa5f41771b3927
@@ -393,7 +384,6 @@ variants:
                             unattended_file = unattended/Fedora-11.ks
 
                     - 11.64:
-                        no balloon_check 
                         image_name = fc11-64
                         cdrom = linux/Fedora-11-x86_64-DVD.iso
                         md5sum = 9d419844adeb93120215fe7505c9bce8
@@ -418,7 +408,7 @@ variants:
                             unattended_file = unattended/Fedora-12.ks
 
             - DSL-4.2.5:
-                no setup dbench bonnie linux_s3 balloon_check 
+                no setup dbench bonnie linux_s3
                 image_name = dsl-4.2.5
                 install:
                     steps = DSL-4.2.5.steps
@@ -427,7 +417,7 @@ variants:
                     md5sum_1m = 527f2481bd25310f2e3a6e5345ff3d12
 
             - Mandriva-One-2007:
-                only install 
+                only install
                 image_name = mandriva-one-2007
                 steps = Mandriva-One-2007-32.steps
                 cdrom = linux/mandriva-one-2007-i386.iso
@@ -435,7 +425,7 @@ variants:
                 md5sum_1m = dc7865a75db665efc86d59bca7c1fe07
 
             - openSUSE-11.0.32:
-                no setup dbench bonnie balloon_check
+                no setup dbench bonnie
                 image_name = openSUSE-11.0-32
                 install:
                     steps = openSUSE-11.0-32.steps
@@ -444,7 +434,7 @@ variants:
                     md5sum_1m = c720b30557af758e69de450409516369
 
             - openSUSE-11.1.32:
-                no setup dbench bonnie balloon_check
+                no setup dbench bonnie
                 image_name = openSUSE-11.1-32
                 install:
                     steps = openSUSE-11.1-32-and-64.steps

client/tests/kvm/tests_base.cfg.sample variants: · line 449

Quoted 8 lines
client/tests/kvm/tests_base.cfg.sample +1 -1
@@ -453,7 +443,7 @@ variants:
                     md5sum_1m = b70217417468389083429f81ba7ce2bd
 
             - openSUSE-11.1.64:
-                no setup dbench bonnie balloon_check
+                no setup dbench bonnie
                 image_name = openSUSE-11.1-64
                 install:
                     steps = openSUSE-11.1-32-and-64.steps

Are you sure openSUSE 11.x does not support virtio-balooning? I was under the impression it had a pretty recent kernel on it.

Quoted 100 lines
client/tests/kvm/tests_base.cfg.sample +11 -12
@@ -506,7 +496,7 @@ variants:
 
                 variants:
                     - 3.9.i386:
-                        no setup autotest linux_s3 balloon_check
+                        no setup autotest linux_s3
                         image_name = rhel3-32
                         mem_chk_cmd = dmidecode | awk -F: '/Maximum Capacity/ {print $2}'
                         cdrom = linux/RHEL-3.9-i386-DVD.iso
@@ -518,7 +508,7 @@ variants:
                             unattended_file = unattended/RHEL-3-series.ks
 
                     - 3.9.x86_64:
-                        no setup autotest linux_s3 balloon_check
+                        no setup autotest linux_s3
                         image_name = rhel3-64
                         mem_chk_cmd = dmidecode | awk -F: '/Maximum Capacity/ {print $2}'
                         cdrom = linux/RHEL-3.9-x86_64-DVD.iso
@@ -530,7 +520,7 @@ variants:
                             unattended_file = unattended/RHEL-3-series.ks
 
                     - 4.7.i386:
-                        no setup autotest balloon_check
+                        no setup autotest
                         image_name = rhel4-32
                         cdrom=linux/RHEL-4.7-i386-DVD.iso
                         md5sum=ee5092653732a88ddbaf8eef2484c500
@@ -541,7 +531,7 @@ variants:
                             unattended_file = unattended/RHEL-4-series.ks
 
                     - 4.7.x86_64:
-                        no setup autotest balloon_check
+                        no setup autotest
                         image_name = rhel4-64
                         cdrom=linux/RHEL-4.7-x86_64-DVD.iso
                         md5sum=ea9dae16dd86f7d94092d0e672333292
@@ -552,7 +542,7 @@ variants:
                             unattended_file = unattended/RHEL-4-series.ks
 
                     - 4.8.i386:
-                        no setup autotest balloon_check
+                        no setup autotest
                         image_name = rhel4-32
                         cdrom = linux/RHEL-4.8-i386-DVD.iso
                         md5sum = b024f0af5079539d3ef51f71fed0b194
@@ -561,7 +551,7 @@ variants:
                             unattended_file = unattended/RHEL-4-series.ks
 
                     - 4.8.x86_64:
-                        no setup autotest balloon_check
+                        no setup autotest
                         image_name = rhel4-64
                         cdrom = linux/RHEL-4.8-x86_64-DVD.iso
                         md5sum = 696bc877b0200cc942626673fcc3fc09
@@ -570,7 +560,7 @@ variants:
                             unattended_file = unattended/RHEL-4-series.ks
 
                     - 5.3.i386:
-                        no setup balloon_check
+                        no setup
                         image_name = rhel5-32
                         cdrom=linux/RHEL-5.3-i386-DVD.iso
                         md5sum=371c62851611fd32ead440df6f24a296
@@ -581,7 +571,7 @@ variants:
                             unattended_file = unattended/RHEL-5-series.ks
 
                     - 5.3.x86_64:
-                        no setup balloon_check
+                        no setup
                         image_name = rhel5-64
                         cdrom=linux/RHEL-5.3-x86_64-DVD.iso
                         md5sum=c5ed6b284410f4d8212cafc78fd7a8c5
@@ -592,7 +582,7 @@ variants:
                             unattended_file = unattended/RHEL-5-series.ks
 
                     - 5.4.i386:
-                        no setup balloon_check
+                        no setup
                         image_name = rhel5-32
                         cdrom = linux/RHEL-5.4-i386-DVD.iso
                         md5sum = 7a12ec6599527e4f3d1790b51eadbfed
@@ -601,7 +591,7 @@ variants:
                             unattended_file = unattended/RHEL-5-series.ks
 
                     - 5.4.x86_64:
-                        no setup balloon_check
+                        no setup
                         image_name = rhel5-64
                         cdrom = linux/RHEL-5.4-x86_64-DVD.iso
                         md5sum = 04fe3c10202402d7b389528d2bad0210
@@ -611,7 +601,7 @@ variants:
 
     # Windows section
     - @Windows:
-        no autotest linux_s3 vlan_tag balloon_check
+        no autotest linux_s3 vlan_tag
         shutdown_command = shutdown /s /t 0
         reboot_command = shutdown /r /t 0
         status_test_command = echo %errorlevel%
---
author
#2 lore raw

Hi Lucas

Thanks for your comments.
Please find the patch, with suggested changes.

Thanks
Pradeep

---

client/tests/kvm/tests/balloon_check.py +47 -0
diff -uprN autotest-old/client/tests/kvm/tests/balloon_check.py autotest/client/tests/kvm/tests/balloon_check.py
@@ -0,0 +1,47 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
+    2) Increase and decrease the memory of guest using balloon command from monitor
+    3) check memory info
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+    
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+    fail = 0
+    
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        logging.error("Memory size mismatch:")
+        logging.error("Assigned to VM: %s" % expected_mem)
+        logging.error("Reported by OS: %s" % actual_mem)
+    
+    #change memory to random size between 60% to 95% of actual memory
+    percent = random.uniform(0.6, 0.95)
+    new_mem = int(percent*expected_mem)
+    vm.send_monitor_cmd("balloon %s" %new_mem)
+    time.sleep(20)
+    status, output = vm.send_monitor_cmd("info balloon")
+    if status != 0:
+        logging.error("qemu monitor command failed: info balloon")
+
+    balloon_cmd_mem = int(re.findall("\d+",output)[0])
+    if balloon_cmd_mem != new_mem:
+        logging.error("memory ballooning failed while changing memory to %s" %balloon_cmd_mem)  
+	fail += 1
+
+    #Checking for test result
+    if fail != 0:
+        raise error.TestFail("Memory ballooning test failed ")
+    session.close()
client/tests/kvm/tests_base.cfg.sample +4 -0
diff -uprN autotest-old/client/tests/kvm/tests_base.cfg.sample autotest/client/tests/kvm/tests_base.cfg.sample
@@ -185,6 +185,10 @@ variants:
                 drift_threshold = 10
                 drift_threshold_single = 3
 
+    - balloon_check:  install setup unattended_install boot
+        type = balloon_check
+        extra_params += " -balloon virtio"
+
     - stress_boot:  install setup unattended_install
         type = stress_boot
         max_vms = 5    

---

#3 lore raw
Quoted 29 lines · pradeep

Hi Lucas

Thanks for your comments.
Please find the patch, with suggested changes.

Thanks
Pradeep

---
diff -uprN autotest-old/client/tests/kvm/tests/balloon_check.py autotest/client/tests/kvm/tests/balloon_check.py
--- autotest-old/client/tests/kvm/tests/balloon_check.py        1969-12-31 19:00:00.000000000 -0500
+++ autotest/client/tests/kvm/tests/balloon_check.py    2010-04-09 12:33:34.000000000 -0400

client/tests/kvm/tests/balloon_check.py +9 -0
@@ -0,0 +1,47 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
+    2) Increase and decrease the memory of guest using balloon command from
Quoted 1 line

monitor

Better replace this description by "Change the guest memory between X and Y values"
Also instead of using 0.6 and 0.95 below, better use two variables and take their value from config file. This will give the user a flexibility to narrow or widen the ballooning range.

Quoted 14 lines

+    3) check memory info

client/tests/kvm/tests/balloon_check.py +13 -0
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+    fail = 0
+
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))

client/tests/kvm/tests/balloon_check.py line 33

Quoted 10 lines
client/tests/kvm/tests/balloon_check.py +10 -0
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        logging.error("Memory size mismatch:")
+        logging.error("Assigned to VM: %s" % expected_mem)
+        logging.error("Reported by OS: %s" % actual_mem)
+
+    #change memory to random size between 60% to 95% of actual memory
+    percent = random.uniform(0.6, 0.95)
+    new_mem = int(percent*expected_mem)
+    vm.send_monitor_cmd("balloon %s" %new_mem)

You may want to check if the command passed/failed. Older versions might not support ballooning.

Quoted 1 line

+    time.sleep(20)

why 20 second sleep and why the magic number?

Quoted 1 line

+    status, output = vm.send_monitor_cmd("info balloon")

You might want to put this check before changing the memory.

Quoted 4 lines

+    if status != 0:
+        logging.error("qemu monitor command failed: info balloon") +
+    balloon_cmd_mem = int(re.findall("\d+",output)[0])

A better variable name I can think of is "ballooned_mem"

Quoted 7 lines

+    if balloon_cmd_mem != new_mem:
+        logging.error("memory ballooning failed while changing memory to %s" %balloon_cmd_mem)
+       fail += 1
+
+    #Checking for test result
+    if fail != 0:

In case you are running multiple iterations and the 2nd iteration fails you will always miss this condition.

Quoted 12 lines

+        raise error.TestFail("Memory ballooning test failed ")
+    session.close()
diff -uprN autotest-old/client/tests/kvm/tests_base.cfg.sample autotest/client/tests/kvm/tests_base.cfg.sample
--- autotest-old/client/tests/kvm/tests_base.cfg.sample 2010-04-09 12:32:50.000000000 -0400
+++ autotest/client/tests/kvm/tests_base.cfg.sample     2010-04-09 12:53:27.000000000 -0400

(quoted diff) +0 -0
@@ -185,6 +185,10 @@ variants:

                drift_threshold = 10
                drift_threshold_single = 3

Quoted 8 lines

+    - balloon_check:  install setup unattended_install boot
+        type = balloon_check
+        extra_params += " -balloon virtio"
+
    - stress_boot:  install setup unattended_install type = stress_boot
        max_vms = 5
---

Rest all looks good!!!!

Quoted 7 lines

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Signature · 2 lines
Regards
Sudhir Kumar
author
#4 lore raw
Quoted 29 lines · sudhir kumar
Quoted 27 lines · pradeep

Hi Lucas

Thanks for your comments.
Please find the patch, with suggested changes.

Thanks
Pradeep

---
diff -uprN autotest-old/client/tests/kvm/tests/balloon_check.py autotest/client/tests/kvm/tests/balloon_check.py
--- autotest-old/client/tests/kvm/tests/balloon_check.py 1969-12-31
19:00:00.000000000 -0500
+++ autotest/client/tests/kvm/tests/balloon_check.py 2010-04-09
12:33:34.000000000 -0400

client/tests/kvm/tests/balloon_check.py +8 -0
@@ -0,0 +1,47 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
Quoted 9 lines
Quoted 3 lines
(quoted diff) +1 -0
+    2) Increase and decrease the memory of guest using balloon command from

monitor

Better replace this description by "Change the guest memory between X and Y values"
Also instead of using 0.6 and 0.95 below, better use two variables and take their value from config file. This will give the user a flexibility to narrow or widen the ballooning range.

Thanks for your suggestions. I dont think, user should need flexibility here.
If ballooning doest work for one set of value, it will not work for any other.
And here, we are choosing between 60 to 95% of actual values, which is reasonable.

Quoted 21 lines
Quoted 21 lines
client/tests/kvm/tests/balloon_check.py +20 -0
+    3) check memory info
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+    fail = 0
+
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        logging.error("Memory size mismatch:")
+        logging.error("Assigned to VM: %s" % expected_mem)
+        logging.error("Reported by OS: %s" % actual_mem)
+
Quoted 9 lines

client/tests/kvm/tests/balloon_check.py line 33

Quoted 5 lines
client/tests/kvm/tests/balloon_check.py +4 -0
+    #change memory to random size between 60% to 95% of actual memory
+    percent = random.uniform(0.6, 0.95)
+    new_mem = int(percent*expected_mem)
+    vm.send_monitor_cmd("balloon %s" %new_mem)

You may want to check if the command passed/failed. Older versions might not support ballooning.

sure, i will make changes here.

Quoted 5 lines
Quoted 3 lines

+ time.sleep(20)

why 20 second sleep and why the magic number?

As soon as balloon command is passed, it takes some time for memory ballooing.
If we check "info balloon" as soon as we run ballooning, it will give weird values.
I just choose it as, 20sec and its not huge time from testing perspective.

Quoted 6 lines
Quoted 3 lines

+ status, output = vm.send_monitor_cmd("info balloon")

You might want to put this check before changing the memory.

sure, will make changes here too.

Quoted 7 lines

client/tests/kvm/tests/balloon_check.py line 39

Quoted 5 lines
client/tests/kvm/tests/balloon_check.py +4 -0
+    if status != 0:
+        logging.error("qemu monitor command failed: info balloon")
+
+    balloon_cmd_mem = int(re.findall("\d+",output)[0])

A better variable name I can think of is "ballooned_mem"

will change it...

Quoted 49 lines

client/tests/kvm/tests/balloon_check.py line 45

Quoted 9 lines
(quoted diff) +2 -0
+    if balloon_cmd_mem != new_mem:
+        logging.error("memory ballooning failed while changing memory to

%s" %balloon_cmd_mem)

client/tests/kvm/tests/balloon_check.py +4 -0
+       fail += 1
+
+    #Checking for test result
+    if fail != 0:

In case you are running multiple iterations and the 2nd iteration fails you will always miss this condition.

Quoted 11 lines
client/tests/kvm/tests/balloon_check.py +2 -0
+        raise error.TestFail("Memory ballooning test failed ")
+    session.close()

diff -uprN autotest-old/client/tests/kvm/tests_base.cfg.sample autotest/client/tests/kvm/tests_base.cfg.sample
--- autotest-old/client/tests/kvm/tests_base.cfg.sample 2010-04-09 12:32:50.000000000 -0400
+++ autotest/client/tests/kvm/tests_base.cfg.sample 2010-04-09
12:53:27.000000000 -0400

client/tests/kvm/tests_base.cfg.sample +0 -0
@@ -185,6 +185,10 @@ variants:
                drift_threshold = 10

client/tests/kvm/tests_base.cfg.sample variants:

Quoted 10 lines
client/tests/kvm/tests_base.cfg.sample +4 -1
                drift_threshold_single = 3
 
+    - balloon_check:  install setup unattended_install boot
+        type = balloon_check
+        extra_params += " -balloon virtio"
+
    - stress_boot:  install setup unattended_install
        type = stress_boot
        max_vms = 5
---

Rest all looks good!!!!

Quoted 7 lines

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

author
#5 lore raw

Lucas

Any comments??

--sp

Quoted 180 lines · pradeep
Quoted 31 lines · sudhir kumar
Quoted 28 lines · pradeep

Hi Lucas

Thanks for your comments.
Please find the patch, with suggested changes.

Thanks
Pradeep

---
diff -uprN autotest-old/client/tests/kvm/tests/balloon_check.py autotest/client/tests/kvm/tests/balloon_check.py
--- autotest-old/client/tests/kvm/tests/balloon_check.py 1969-12-31
19:00:00.000000000 -0500
+++ autotest/client/tests/kvm/tests/balloon_check.py 2010-04-09
12:33:34.000000000 -0400

client/tests/kvm/tests/balloon_check.py +9 -0
@@ -0,0 +1,47 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
+    2) Increase and decrease the memory of guest using balloon command from
Quoted 10 lines
Quoted 3 lines

monitor

Better replace this description by "Change the guest memory between X and Y values"
Also instead of using 0.6 and 0.95 below, better use two variables and take their value from config file. This will give the user a flexibility to narrow or widen the ballooning range.

Thanks for your suggestions. I dont think, user should need flexibility here. If ballooning doest work for one set of value, it will not work for any other. And here, we are choosing between 60 to 95% of actual values, which is reasonable.

Quoted 22 lines
Quoted 22 lines
client/tests/kvm/tests/balloon_check.py +20 -0
+    3) check memory info
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+    fail = 0
+
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        logging.error("Memory size mismatch:")
+        logging.error("Assigned to VM: %s" % expected_mem)
+        logging.error("Reported by OS: %s" % actual_mem)
+
Quoted 10 lines

client/tests/kvm/tests/balloon_check.py line 33

Quoted 6 lines
client/tests/kvm/tests/balloon_check.py +4 -0
+    #change memory to random size between 60% to 95% of actual memory
+    percent = random.uniform(0.6, 0.95)
+    new_mem = int(percent*expected_mem)
+    vm.send_monitor_cmd("balloon %s" %new_mem)

You may want to check if the command passed/failed. Older versions might not support ballooning.

sure, i will make changes here.

Quoted 8 lines
Quoted 5 lines

+ time.sleep(20)

why 20 second sleep and why the magic number?

As soon as balloon command is passed, it takes some time for memory ballooing. If we check "info balloon" as soon as we run ballooning, it will give weird values. I just choose it as, 20sec and its not huge time from testing perspective.

Quoted 9 lines
Quoted 5 lines

+ status, output = vm.send_monitor_cmd("info balloon")

You might want to put this check before changing the memory.

sure, will make changes here too.

Quoted 9 lines

client/tests/kvm/tests/balloon_check.py line 39

Quoted 6 lines
client/tests/kvm/tests/balloon_check.py +4 -0
+    if status != 0:
+        logging.error("qemu monitor command failed: info balloon")
+
+    balloon_cmd_mem = int(re.findall("\d+",output)[0])

A better variable name I can think of is "ballooned_mem"

will change it...

Quoted 31 lines

client/tests/kvm/tests/balloon_check.py line 45

Quoted 11 lines
(quoted diff) +2 -0
+    if balloon_cmd_mem != new_mem:
+        logging.error("memory ballooning failed while changing memory to

%s" %balloon_cmd_mem)

client/tests/kvm/tests/balloon_check.py +4 -0
+       fail += 1
+
+    #Checking for test result
+    if fail != 0:

In case you are running multiple iterations and the 2nd iteration fails you will always miss this condition.

Quoted 12 lines
client/tests/kvm/tests/balloon_check.py +2 -0
+        raise error.TestFail("Memory ballooning test failed ")
+    session.close()

diff -uprN autotest-old/client/tests/kvm/tests_base.cfg.sample autotest/client/tests/kvm/tests_base.cfg.sample
--- autotest-old/client/tests/kvm/tests_base.cfg.sample 2010-04-09 12:32:50.000000000 -0400
+++ autotest/client/tests/kvm/tests_base.cfg.sample 2010-04-09
12:53:27.000000000 -0400

client/tests/kvm/tests_base.cfg.sample +0 -0
@@ -185,6 +185,10 @@ variants:
                drift_threshold = 10
                drift_threshold_single = 3
 
Quoted 24 lines

client/tests/kvm/tests_base.cfg.sample variants:

Quoted 10 lines
client/tests/kvm/tests_base.cfg.sample +4 -1
+    - balloon_check:  install setup unattended_install boot
+        type = balloon_check
+        extra_params += " -balloon virtio"
+
    - stress_boot:  install setup unattended_install
        type = stress_boot
        max_vms = 5
---

Rest all looks good!!!!

Quoted 8 lines

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

#6 lore raw
Quoted 4 lines · pradeep

Lucas

Any comments??

No pradeep, Sudhir's comments are very reasonable, please implement the changes he suggested and re-send the patch, I am going to do some testing on it on my local systems and then commit it upstream when done with testing.

Quoted 196 lines

--sp

Quoted 180 lines · pradeep
Quoted 31 lines · sudhir kumar
Quoted 28 lines · pradeep

Hi Lucas

Thanks for your comments.
Please find the patch, with suggested changes.

Thanks
Pradeep

---
diff -uprN autotest-old/client/tests/kvm/tests/balloon_check.py autotest/client/tests/kvm/tests/balloon_check.py
--- autotest-old/client/tests/kvm/tests/balloon_check.py        1969-12-31 19:00:00.000000000 -0500
+++ autotest/client/tests/kvm/tests/balloon_check.py    2010-04-09 12:33:34.000000000 -0400

client/tests/kvm/tests/balloon_check.py +9 -0
@@ -0,0 +1,47 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
+    2) Increase and decrease the memory of guest using balloon command from
Quoted 10 lines
Quoted 3 lines

monitor

Better replace this description by "Change the guest memory between X and Y values"
Also instead of using 0.6 and 0.95 below, better use two variables and take their value from config file. This will give the user a flexibility to narrow or widen the ballooning range.

Thanks for your suggestions. I dont  think, user should need flexibility here.
If ballooning doest work for one set of value, it will not work for any other.
And here, we are choosing between 60 to 95% of actual values, which is reasonable.

Quoted 22 lines
Quoted 22 lines

+    3) check memory info

client/tests/kvm/tests/balloon_check.py +19 -0
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+    fail = 0
+
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        logging.error("Memory size mismatch:")
+        logging.error("Assigned to VM: %s" % expected_mem)
+        logging.error("Reported by OS: %s" % actual_mem)
+
Quoted 10 lines
Quoted 6 lines

+    #change memory to random size between 60% to 95% of actual memory
+    percent = random.uniform(0.6, 0.95)
+    new_mem = int(percent*expected_mem)
+    vm.send_monitor_cmd("balloon %s" %new_mem)

You may want to check if the command passed/failed. Older versions might not support ballooning.

sure,  i will make changes here.

Quoted 8 lines
Quoted 5 lines

+    time.sleep(20)

why 20 second sleep and why the magic number?

As soon as balloon command is passed, it takes some time for memory ballooing.
If we check "info balloon" as soon as we run ballooning, it will give weird values.
I just choose it as, 20sec and its not huge time from testing perspective.

Quoted 9 lines
Quoted 5 lines

+    status, output = vm.send_monitor_cmd("info balloon")

You might want to put this check before changing the memory.

sure, will make changes here too.

Quoted 9 lines
Quoted 6 lines

+    if status != 0:
+        logging.error("qemu monitor command failed: info balloon") +
+    balloon_cmd_mem = int(re.findall("\d+",output)[0])

A better variable name I can think of is "ballooned_mem"

will  change it...

Quoted 31 lines
Quoted 11 lines

+    if balloon_cmd_mem != new_mem:
+        logging.error("memory ballooning failed while changing memory to %s" %balloon_cmd_mem)
+       fail += 1
+
+    #Checking for test result
+    if fail != 0:

In case you are running multiple iterations and the 2nd iteration fails you will always miss this condition.

Quoted 12 lines

+        raise error.TestFail("Memory ballooning test failed ")
+    session.close()
diff -uprN autotest-old/client/tests/kvm/tests_base.cfg.sample autotest/client/tests/kvm/tests_base.cfg.sample
--- autotest-old/client/tests/kvm/tests_base.cfg.sample 2010-04-09 12:32:50.000000000 -0400
+++ autotest/client/tests/kvm/tests_base.cfg.sample     2010-04-09 12:53:27.000000000 -0400

(quoted diff) +0 -0
@@ -185,6 +185,10 @@ variants:

                drift_threshold = 10
                drift_threshold_single = 3

Quoted 24 lines
Quoted 10 lines

+    - balloon_check:  install setup unattended_install boot
+        type = balloon_check
+        extra_params += " -balloon virtio"
+
    - stress_boot:  install setup unattended_install type = stress_boot
        max_vms = 5
---

Rest all looks good!!!!

Quoted 8 lines

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Quoted 5 lines

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Signature · 1 line
Lucas
#7 lore raw
In reply to pradeep
Quoted 40 lines · pradeep
Quoted 29 lines · sudhir kumar
Quoted 27 lines · pradeep

Hi Lucas

Thanks for your comments.
Please find the patch, with suggested changes.

Thanks
Pradeep

---
diff -uprN autotest-old/client/tests/kvm/tests/balloon_check.py autotest/client/tests/kvm/tests/balloon_check.py
--- autotest-old/client/tests/kvm/tests/balloon_check.py        1969-12-31 19:00:00.000000000 -0500
+++ autotest/client/tests/kvm/tests/balloon_check.py    2010-04-09 12:33:34.000000000 -0400

client/tests/kvm/tests/balloon_check.py +8 -0
@@ -0,0 +1,47 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
Quoted 9 lines
Quoted 3 lines
(quoted diff) +1 -0
+    2) Increase and decrease the memory of guest using balloon command from

monitor

Better replace this description by "Change the guest memory between X and Y values"
Also instead of using 0.6 and 0.95 below, better use two variables and take their value from config file. This will give the user a flexibility to narrow or widen the ballooning range.

Quoted 6 lines

Thanks for your suggestions. I dont  think, user should need flexibility here.
If ballooning doest work for one set of value, it will not work for any other.
And here, we are choosing between 60 to 95% of actual values, which is reasonable.

Sorry for not having commented on this before. Yes, a reasonable, hardcoded range is completely OK to me. Did you tested and verified that this range is safe for guest testing? I mean, a memory set too low might trigger OOM killer on VMs, so I was wondering if 60% isn't too low...

Signature · 1 line
Lucas
author
#8 lore raw

Hi Lucas

Please ignore my earlier patch
Find the correct patch with the suggested changes.

--SP

client/tests/kvm/tests/balloon_check.py +51 -0
diff -purN autotest/client/tests/kvm/tests/balloon_check.py autotest-new/client/tests/kvm/tests/balloon_check.py
@@ -0,0 +1,51 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
+    2) Change the memory between 60% to 95% of memory of guest using ballooning 
+    3) check memory info
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+    
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+    fail = 0
+    
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        logging.error("Memory size mismatch:")
+        logging.error("    Assigned to VM: %s" % expected_mem)
+        logging.error("    Reported by OS: %s" % actual_mem)
+    
+    
+    #Check if info balloon works or not.
+    status, output = vm.send_monitor_cmd("info balloon")
+    if status != 0:
+        logging.error("qemu monitor command failed: info balloon")
+        fail += 1
+ 
+    #Reduce memory to random size between 60% to 95% of actual memory
+    percent = random.uniform(0.6, 0.95)
+    new_mem = int(percent*actual_mem)
+    vm.send_monitor_cmd("balloon %s" % new_mem)
+    time.sleep(20)
+    status, output = vm.send_monitor_cmd("info balloon")
+    ballooned_mem = int(re.findall("\d+",output)[0])
+    if ballooned_mem != new_mem:
+        logging.error("memory ballooning failed while changing memory from %s to %s" %actual_mem %new_mem)  
+        fail += 1
+    
+    #Checking for test result
+    if fail != 0:
+        raise error.TestFail("Memory ballooning test failed ")
+    session.close()
client/tests/kvm/tests_base.cfg.sample +4 -0
diff -purN autotest/client/tests/kvm/tests_base.cfg.sample autotest-new/client/tests/kvm/tests_base.cfg.sample
@@ -171,6 +171,10 @@ variants:
                 drift_threshold = 10
                 drift_threshold_single = 3
 
+    - balloon_check:  install setup unattended_install
+        type = balloon_check
+        extra_params += "-balloon virtio"
+
     - stress_boot:  install setup unattended_install
         type = stress_boot
         max_vms = 5    
#9 lore raw
Quoted 4 lines · pradeep

Hi Lucas

Please ignore my earlier patch
Find the correct patch with the suggested changes.

Hi Pradeep, I was reading the test once again while trying it myself, some other ideas came to me. I spent some time hacking the test and sent an updated patch with changes. Please let me know what you think, if you are OK with them I'll commit it.

Quoted 74 lines

--SP

plain text document attachment (patch)
diff -purN autotest/client/tests/kvm/tests/balloon_check.py autotest-new/client/tests/kvm/tests/balloon_check.py

client/tests/kvm/tests/balloon_check.py +51 -0
@@ -0,0 +1,51 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+    """
+    Check Memory ballooning:
+    1) Boot a guest
+    2) Change the memory between 60% to 95% of memory of guest using ballooning 
+    3) check memory info
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+    
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+    fail = 0
+    
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        logging.error("Memory size mismatch:")
+        logging.error("    Assigned to VM: %s" % expected_mem)
+        logging.error("    Reported by OS: %s" % actual_mem)
+    
+    
+    #Check if info balloon works or not.
+    status, output = vm.send_monitor_cmd("info balloon")
+    if status != 0:
+        logging.error("qemu monitor command failed: info balloon")
+        fail += 1
+ 
+    #Reduce memory to random size between 60% to 95% of actual memory
+    percent = random.uniform(0.6, 0.95)
+    new_mem = int(percent*actual_mem)
+    vm.send_monitor_cmd("balloon %s" % new_mem)
+    time.sleep(20)
+    status, output = vm.send_monitor_cmd("info balloon")
+    ballooned_mem = int(re.findall("\d+",output)[0])
+    if ballooned_mem != new_mem:
+        logging.error("memory ballooning failed while changing memory from %s to %s" %actual_mem %new_mem)  
+        fail += 1
+    
+    #Checking for test result
+    if fail != 0:
+        raise error.TestFail("Memory ballooning test failed ")
+    session.close()

diff -purN autotest/client/tests/kvm/tests_base.cfg.sample autotest-new/client/tests/kvm/tests_base.cfg.sample

client/tests/kvm/tests_base.cfg.sample +4 -0
@@ -171,6 +171,10 @@ variants:
                 drift_threshold = 10
                 drift_threshold_single = 3
 
+    - balloon_check:  install setup unattended_install
+        type = balloon_check
+        extra_params += "-balloon virtio"
+
     - stress_boot:  install setup unattended_install
         type = stress_boot
         max_vms = 5    
author
#10 lore raw
Quoted 8 lines · Lucas Meneghel Rodrigues

Hi Pradeep, I was reading the test once again while trying it myself, some other ideas came to me. I spent some time hacking the test and sent an updated patch with changes. Please let me know what you think, if you are OK with them I'll commit it.

Hi Lucas

Patch looks fine to me. Thanks for your code changes.

--SP