From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yolkfull Chow Subject: Re: [PATCH 1/2] Adds a test to verify resources inside a VM Date: Sun, 29 Nov 2009 18:40:57 +0800 Message-ID: <20091129104057.GA5363@aFu.nay.redhat.com> References: <20091129072015.GA2445@aFu.nay.redhat.com> Reply-To: Yolkfull Chow Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm-devel , Autotest mailing list , Lucas Meneghel Rodrigues , Michael Goldish To: sudhir kumar Return-path: Received: from mx1.redhat.com ([209.132.183.28]:59406 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752138AbZK2Kk7 (ORCPT ); Sun, 29 Nov 2009 05:40:59 -0500 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Sun, Nov 29, 2009 at 02:22:40PM +0530, sudhir kumar wrote: > On Sun, Nov 29, 2009 at 12:50 PM, Yolkfull Chow wr= ote: > > On Wed, Nov 25, 2009 at 11:35:02AM +0530, sudhir kumar wrote: > >> This patch adds a test for verifying whether the number of cpus an= d amount > >> of memory as seen inside a guest is same as allocated to it on the= qemu > >> command line. > > > > Hello Sudhir, > > > > Please see embedded comments as below: > > > >> > >> Signed-off-by: Sudhir Kumar > >> > >> Index: kvm/tests/verify_resources.py > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >> --- /dev/null > >> +++ kvm/tests/verify_resources.py > >> @@ -0,0 +1,74 @@ > >> +import logging, time > >> +from autotest_lib.client.common_lib import error > >> +import kvm_subprocess, kvm_test_utils, kvm_utils > >> + > >> +""" > >> +Test to verify if the guest has the equal amount of resources > >> +as allocated through the qemu command line > >> + > >> +@Copyright: 2009 IBM Corporation > >> +@author: Sudhir Kumar > >> + > >> +""" > >> + > >> +def run_verify_resources(test, params, env): > >> + =A0 =A0""" > >> + =A0 =A0KVM test for verifying VM resources(#vcpu, memory): > >> + =A0 =A01) Get resources from the VM parameters > >> + =A0 =A02) Log into the guest > >> + =A0 =A03) Get actual resources, compare and report the pass/fail= ure > >> + > >> + =A0 =A0@param test: kvm test object > >> + =A0 =A0@param params: Dictionary with the test parameters > >> + =A0 =A0@param env: Dictionary with test environment. > >> + =A0 =A0""" > >> + =A0 =A0vm =3D kvm_test_utils.get_living_vm(env, params.get("main= _vm")) > >> + > >> + =A0 =A0# Get info about vcpu and memory from dictionary > >> + =A0 =A0exp_vcpus =3D int(params.get("smp")) > >> + =A0 =A0exp_mem_mb =3D long(params.get("mem")) > >> + =A0 =A0real_vcpus =3D 0 > >> + =A0 =A0real_mem_kb =3D 0 > >> + =A0 =A0real_mem_mb =3D 0 > >> + =A0 =A0# Some memory is used by bios and all, so lower the expec= ted > >> value say by 5% > >> + =A0 =A0exp_mem_mb =3D long(exp_mem_mb * 0.95) > >> + =A0 =A0logging.info("The guest should have vcpus: %s" % exp_vcpu= s) > >> + =A0 =A0logging.info("The guest should have min mem: %s MB" % exp= _mem_mb) > >> + > >> + =A0 =A0session =3D kvm_test_utils.wait_for_login(vm) > >> + > >> + =A0 =A0# Get info about vcpu and memory from within guest > >> + =A0 =A0if params.get("guest_os_type") =3D=3D "Linux": > >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("cat /proc/= cpuinfo|grep processor") > > > > We'd better here not hard code the command that getting CPU count. = As KVM supports not > > only Linux & Windows, but also others say Unix/BSD. > > A recommended method could be define it in config file for differen= t platforms: > I agree. The only concern that made me doing it inside test is the > increasing size and complexity of the config file. I am fine with > passing the command from the config file but still the code paths hav= e > to be different for each type of OS ie windows linux etc. >=20 > > > > - @Linux: > > =A0 =A0verify_resources: > > =A0 =A0 =A0 =A0count_cpu_cmd =3D grep processor /proc/cpuinfo > > > > - @Windows: > > =A0 =A0verify_resources: > > =A0 =A0 =A0 =A0count_cpu_cmd =3D systeminfo (here I would not sugge= st we use 'systeminfo' > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0for catching M$ guest's memory size) > > > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'processor' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0real_vcpus =3D real_vcpus + 1 > >> + > >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("cat /proc/= meminfo") > > > > For catching memory size of Linux guests, I prefer command 'dmideco= de' which can > > catch memory size exactly in MB. > I think we can use both here. To my knowledge dmidecode will test the > BIOS code of kvm and hence we can include both the methods? > > > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'MemTotal' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0real_mem_kb =3D long(line.split()= [1]) > >> + =A0 =A0 =A0 =A0real_mem_mb =3D real_mem_kb / 1024 > >> + > >> + =A0 =A0elif params.get("guest_os_type") =3D=3D "Windows": > >> + =A0 =A0 =A0 =A0# Windows takes long time to display output for s= ysteminfo > >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("systeminfo= ", timeout =3D > >> 150, internal_timeout =3D 50) > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'Processor' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0real_vcpus =3D int(line.split()[1= ]) > >> + > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'Total Physical Memory' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 real_mem_mb =3D long("".join("%s" % = k for k in > >> line.split()[3].split(','))) > > > > So many slice and split operations can easy results in problems. > > To catch memory of Windows guests, I recommend we use 'wmic memphys= ical' which > > can dump memory size in KB exactly. > Is the command available for all windows OSes? If yes we can > definitely use the command. Yes it's available for all Windows OSes although with some limitations = that it can only be executed within TELNET session or Windows command prompt. But i= t's fixed now.:) Cheers, > > > > > > Meanwhile, we also need to verify guest's NICs' count and their(its= ) model, > > hard disk(s)'s count & model etc. Therefore I think we need a case = to verify > > them together. > Yeah, I just gave a first try for such a test. We need to test all th= e > emulated hardware. > > > > I had wrote such test couples of days before. I also ran it several= times. > > Please comment on it when I post it here later. Thanks, > Sure. Please post them. I am happy to see them getting merged. >=20 > Thanks a lot for your comments!! > Sudhir >=20 > > > >> + > >> + =A0 =A0else: > >> + =A0 =A0 =A0 =A0raise error.TestFail("Till date this test is supp= orted only > >> for Linux and Windows") > >> + > >> + =A0 =A0logging.info("The guest has cpus: %s" % real_vcpus) > >> + =A0 =A0logging.info("The guest has mem: %s MB" % real_mem_mb) > >> + =A0 =A0if exp_vcpus !=3D real_vcpus or real_mem_mb < exp_mem_mb: > >> + =A0 =A0 =A0 =A0raise error.TestFail("Actual resources(cpu =3D'%s= ' memory =3D'%s' MB) " > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0"differ from Allocated resources(cpu = =3D '%s' memory =3D'%s' MB" > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 % (real_vcpus, r= eal_mem_mb, exp_vcpus, exp_mem_mb)) > >> + > >> + =A0 =A0session.close() > >> > >> > >> > >> > >> Sending the patch as an attachment too. Please review and provide = your comments. > >> -- > >> Sudhir Kumar > > > >> This patch adds a test for verifying whether the number of cpus an= d amount > >> of memory as seen inside a guest is same as allocated to it on the= qemu > >> command line. > >> > >> Signed-off-by: Sudhir Kumar > >> > >> Index: kvm/tests/verify_resources.py > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >> --- /dev/null > >> +++ kvm/tests/verify_resources.py > >> @@ -0,0 +1,74 @@ > >> +import logging, time > >> +from autotest_lib.client.common_lib import error > >> +import kvm_subprocess, kvm_test_utils, kvm_utils > >> + > >> +""" > >> +Test to verify if the guest has the equal amount of resources > >> +as allocated through the qemu command line > >> + > >> +@Copyright: 2009 IBM Corporation > >> +@author: Sudhir Kumar > >> + > >> +""" > >> + > >> +def run_verify_resources(test, params, env): > >> + =A0 =A0""" > >> + =A0 =A0KVM test for verifying VM resources(#vcpu, memory): > >> + =A0 =A01) Get resources from the VM parameters > >> + =A0 =A02) Log into the guest > >> + =A0 =A03) Get actual resources, compare and report the pass/fail= ure > >> + > >> + =A0 =A0@param test: kvm test object > >> + =A0 =A0@param params: Dictionary with the test parameters > >> + =A0 =A0@param env: Dictionary with test environment. > >> + =A0 =A0""" > >> + =A0 =A0vm =3D kvm_test_utils.get_living_vm(env, params.get("main= _vm")) > >> + > >> + =A0 =A0# Get info about vcpu and memory from dictionary > >> + =A0 =A0exp_vcpus =3D int(params.get("smp")) > >> + =A0 =A0exp_mem_mb =3D long(params.get("mem")) > >> + =A0 =A0real_vcpus =3D 0 > >> + =A0 =A0real_mem_kb =3D 0 > >> + =A0 =A0real_mem_mb =3D 0 > >> + =A0 =A0# Some memory is used by bios and all, so lower the expec= ted value say by 5% > >> + =A0 =A0exp_mem_mb =3D long(exp_mem_mb * 0.95) > >> + =A0 =A0logging.info("The guest should have vcpus: %s" % exp_vcpu= s) > >> + =A0 =A0logging.info("The guest should have min mem: %s MB" % exp= _mem_mb) > >> + > >> + =A0 =A0session =3D kvm_test_utils.wait_for_login(vm) > >> + > >> + =A0 =A0# Get info about vcpu and memory from within guest > >> + =A0 =A0if params.get("guest_os_type") =3D=3D "Linux": > >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("cat /proc/= cpuinfo|grep processor") > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'processor' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0real_vcpus =3D real_vcpus + 1 > >> + > >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("cat /proc/= meminfo") > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'MemTotal' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0real_mem_kb =3D long(line.split()= [1]) > >> + =A0 =A0 =A0 =A0real_mem_mb =3D real_mem_kb / 1024 > >> + > >> + =A0 =A0elif params.get("guest_os_type") =3D=3D "Windows": > >> + =A0 =A0 =A0 =A0# Windows takes long time to display output for s= ysteminfo > >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("systeminfo= ", timeout =3D 150, internal_timeout =3D 50) > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'Processor' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0real_vcpus =3D int(line.split()[1= ]) > >> + > >> + =A0 =A0 =A0 =A0for line in output.split('\n'): > >> + =A0 =A0 =A0 =A0 =A0 =A0if 'Total Physical Memory' in line: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 real_mem_mb =3D long("".join("%s" % = k for k in line.split()[3].split(','))) > >> + > >> + =A0 =A0else: > >> + =A0 =A0 =A0 =A0raise error.TestFail("Till date this test is supp= orted only for Linux and Windows") > >> + > >> + =A0 =A0logging.info("The guest has cpus: %s" % real_vcpus) > >> + =A0 =A0logging.info("The guest has mem: %s MB" % real_mem_mb) > >> + =A0 =A0if exp_vcpus !=3D real_vcpus or real_mem_mb < exp_mem_mb: > >> + =A0 =A0 =A0 =A0raise error.TestFail("Actual resources(cpu =3D'%s= ' memory =3D'%s' MB) " > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0"differ from Allocated resources(cpu = =3D '%s' memory =3D'%s' MB" > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 % (real_vcpus, r= eal_mem_mb, exp_vcpus, exp_mem_mb)) > >> + > >> + =A0 =A0session.close() > > > > >=20 >=20 >=20 > --=20 > Sudhir Kumar