From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yolkfull Chow Subject: Re: [Autotest] [PATCH 1/2] Adds a test to verify resources inside a VM Date: Wed, 2 Dec 2009 10:21:50 +0800 Message-ID: <20091202022150.GA2111@aFu.nay.redhat.com> References: <20091129072015.GA2445@aFu.nay.redhat.com> <20091129104057.GA5363@aFu.nay.redhat.com> <6ac58f4f0912010556g6ffa996aq2b5d24240ee943f@mail.gmail.com> Reply-To: Yolkfull Chow Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: sudhir kumar , Autotest mailing list , Lucas Meneghel Rodrigues , kvm-devel To: Lucas Meneghel Rodrigues Return-path: Received: from mx1.redhat.com ([209.132.183.28]:34830 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753731AbZLBCVw (ORCPT ); Tue, 1 Dec 2009 21:21:52 -0500 Content-Disposition: inline In-Reply-To: <6ac58f4f0912010556g6ffa996aq2b5d24240ee943f@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Dec 01, 2009 at 11:56:43AM -0200, Lucas Meneghel Rodrigues wrot= e: > Hi Sudhir and Yolkfull: >=20 > Thanks for your work on this test! Since Yolkfull's test matches > Sudhir's test functionality and extends it, I will go with it. Some > points: >=20 > * A failure on checking a given resource shouldn't prevent us from > testing other resources. Hence, instead of TestFail() exceptions, > let's replace it by an increase on a failure counter defined in the > beginning of the test. > * In order to make it more clear what the test does, let's change th= e > name to check_physical_resources > * At least for the user messages, it's preferrable to use "Assigned > to VM" and "Reported by OS" instead of "expected" and "actual". >=20 > I have implemented the suggestions and tested it, works quite well. A > patch was sent to the mailing list a couple of minutes ago, please le= t > me know what you guys think. Looks good for me. Thanks Lucas for improving this test.=20 Sudhir, what do you think about this? :) Cheers, Yolkfull >=20 > Cheers, >=20 > On Sun, Nov 29, 2009 at 8:40 AM, Yolkfull Chow wro= te: > > On Sun, Nov 29, 2009 at 02:22:40PM +0530, sudhir kumar wrote: > >> On Sun, Nov 29, 2009 at 12:50 PM, Yolkfull Chow = wrote: > >> > 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= and 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/f= ailure > >> >> + > >> >> + =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("m= ain_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 ex= pected > >> >> 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_v= cpus) > >> >> + =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 /pr= oc/cpuinfo|grep processor") > >> > > >> > We'd better here not hard code the command that getting CPU coun= t. As KVM supports not > >> > only Linux & Windows, but also others say Unix/BSD. > >> > A recommended method could be define it in config file for diffe= rent 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 = have > >> to be different for each type of OS ie windows linux etc. > >> > >> > > >> > - @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 su= ggest 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 /pr= oc/meminfo") > >> > > >> > For catching memory size of Linux guests, I prefer command 'dmid= ecode' 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.spli= t()[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 fo= r systeminfo > >> >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("systemi= nfo", 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 memp= hysical' 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 limitati= ons that it can > > only be executed within TELNET session or Windows command prompt. B= ut it'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 ca= se to verify > >> > them together. > >> Yeah, I just gave a first try for such a test. We need to test all= the > >> emulated hardware. > >> > > >> > I had wrote such test couples of days before. I also ran it seve= ral times. > >> > Please comment on it when I post it here later. Thanks, > >> Sure. Please post them. I am happy to see them getting merged. > >> > >> Thanks a lot for your comments!! > >> Sudhir > >> > >> > > >> >> + > >> >> + =A0 =A0else: > >> >> + =A0 =A0 =A0 =A0raise error.TestFail("Till date this test is s= upported 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(c= pu =3D '%s' memory =3D'%s' MB" > >> >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 % (real_vcpus= , real_mem_mb, exp_vcpus, exp_mem_mb)) > >> >> + > >> >> + =A0 =A0session.close() > >> >> > >> >> > >> >> > >> >> > >> >> Sending the patch as an attachment too. Please review and provi= de your comments. > >> >> -- > >> >> Sudhir Kumar > >> > > >> >> This patch adds a test for verifying whether the number of cpus= and 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/f= ailure > >> >> + > >> >> + =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("m= ain_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 ex= pected 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_v= cpus) > >> >> + =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 /pr= oc/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 /pr= oc/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.spli= t()[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 fo= r systeminfo > >> >> + =A0 =A0 =A0 =A0output =3D session.get_command_output("systemi= nfo", 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 s= upported 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(c= pu =3D '%s' memory =3D'%s' MB" > >> >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 % (real_vcpus= , real_mem_mb, exp_vcpus, exp_mem_mb)) > >> >> + > >> >> + =A0 =A0session.close() > >> > > >> > > >> > >> > >> > >> -- > >> Sudhir Kumar > > _______________________________________________ > > Autotest mailing list > > Autotest@test.kernel.org > > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > > >=20 >=20 >=20 > --=20 > Lucas