From: Yolkfull Chow Subject: Re: [Autotest] [PATCH] Add a kvm test guest_s4 which supports both Linux and Windows platform Date: Wed, 14 Oct 2009 10:54:25 +0800 Message-ID: <20091014025425.GA2497@aFu.nay.redhat.com> References: <1254042696-16487-1-git-send-email-yzhou@redhat.com> <6ac58f4f0910131329v43e95b92v37933b13c60f323f@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: "Cao, Chen" , kvm@vger.kernel.org, autotest@test.kernel.org To: Lucas Meneghel Rodrigues Return-path: Received: from mx1.redhat.com ([209.132.183.28]:9864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754304AbZJNCyx (ORCPT ); Tue, 13 Oct 2009 22:54:53 -0400 Content-Disposition: inline In-Reply-To: <6ac58f4f0910131329v43e95b92v37933b13c60f323f@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Oct 13, 2009 at 05:29:40PM -0300, Lucas Meneghel Rodrigues wrot= e: > Hi Yolkfull and Chen: >=20 > Thanks for your test! I have some comments and doubts to clear, most > of them are about content of the messages delivered for the user and > some other details. >=20 > On Sun, Sep 27, 2009 at 6:11 AM, Yolkfull Chow wro= te: > > For this case, Ken Cao wrote the linux part previously and I did ex= tensive > > modifications on Windows platform support. > > > > Signed-off-by: Ken Cao > > Signed-off-by: Yolkfull Chow > > --- > > =A0client/tests/kvm/kvm_tests.cfg.sample | =A0 14 +++++++ > > =A0client/tests/kvm/tests/guest_s4.py =A0 =A0| =A0 66 +++++++++++++= ++++++++++++++++++++ > > =A02 files changed, 80 insertions(+), 0 deletions(-) > > =A0create mode 100644 client/tests/kvm/tests/guest_s4.py > > > > diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/k= vm/kvm_tests.cfg.sample > > index 285a38f..f9ecb61 100644 > > --- a/client/tests/kvm/kvm_tests.cfg.sample > > +++ b/client/tests/kvm/kvm_tests.cfg.sample > > @@ -94,6 +94,14 @@ variants: > > =A0 =A0 - linux_s3: =A0 =A0 install setup > > =A0 =A0 =A0 =A0 type =3D linux_s3 > > > > + =A0 =A0- guest_s4: > > + =A0 =A0 =A0 =A0type =3D guest_s4 > > + =A0 =A0 =A0 =A0check_s4_support_cmd =3D grep -q disk /sys/power/s= tate > > + =A0 =A0 =A0 =A0test_s4_cmd =3D "cd /tmp/;nohup tcpdump -q -t ip h= ost localhost" > > + =A0 =A0 =A0 =A0check_s4_cmd =3D pgrep tcpdump > > + =A0 =A0 =A0 =A0set_s4_cmd =3D echo disk > /sys/power/state > > + =A0 =A0 =A0 =A0kill_test_s4_cmd =3D pkill tcpdump > > + > > =A0 =A0 - timedrift: =A0 =A0install setup > > =A0 =A0 =A0 =A0 type =3D timedrift > > =A0 =A0 =A0 =A0 extra_params +=3D " -rtc-td-hack" > > @@ -382,6 +390,12 @@ variants: > > =A0 =A0 =A0 =A0 =A0 =A0 # Alternative host load: > > =A0 =A0 =A0 =A0 =A0 =A0 #host_load_command =3D "dd if=3D/dev/urando= m of=3D/dev/null" > > =A0 =A0 =A0 =A0 =A0 =A0 host_load_instances =3D 8 > > + =A0 =A0 =A0 =A0guest_s4: > > + =A0 =A0 =A0 =A0 =A0 =A0check_s4_support_cmd =3D powercfg /hiberna= te on > > + =A0 =A0 =A0 =A0 =A0 =A0test_s4_cmd =3D start /B ping -n 3000 loca= lhost > > + =A0 =A0 =A0 =A0 =A0 =A0check_s4_cmd =3D tasklist | find /I "ping" > > + =A0 =A0 =A0 =A0 =A0 =A0set_s4_cmd =3D rundll32.exe PowrProf.dll, = SetSuspendState > > + =A0 =A0 =A0 =A0 =A0 =A0kill_test_s4_cmd =3D taskkill /IM ping.exe= /F > > > > =A0 =A0 =A0 =A0 variants: > > =A0 =A0 =A0 =A0 =A0 =A0 - Win2000: > > diff --git a/client/tests/kvm/tests/guest_s4.py b/client/tests/kvm/= tests/guest_s4.py > > new file mode 100644 > > index 0000000..5d8fbdf > > --- /dev/null > > +++ b/client/tests/kvm/tests/guest_s4.py > > @@ -0,0 +1,66 @@ > > +import logging, time > > +from autotest_lib.client.common_lib import error > > +import kvm_test_utils, kvm_utils > > + > > + > > +def run_guest_s4(test, params, env): > > + =A0 =A0""" > > + =A0 =A0Suspend guest to disk,supports both Linux & Windows OSes. > > + > > + =A0 =A0@param test: kvm test object. > > + =A0 =A0@param params: Dictionary with test parameters. > > + =A0 =A0@param env: Dictionary with the test environment. > > + =A0 =A0""" > > + =A0 =A0vm =3D kvm_test_utils.get_living_vm(env, params.get("main_= vm")) > > + =A0 =A0session =3D kvm_test_utils.wait_for_login(vm) > > + > > + =A0 =A0logging.info("Checking whether VM supports S4") > > + =A0 =A0status =3D session.get_command_status(params.get("check_s4= _support_cmd")) > > + =A0 =A0if status is None: > > + =A0 =A0 =A0 =A0logging.error("Failed to check if S4 exists") > > + =A0 =A0elif status !=3D 0: > > + =A0 =A0 =A0 =A0raise error.TestFail("Guest does not support S4") > > + > > + =A0 =A0logging.info("Waiting for a while for X to start...") >=20 > Yes, generally X starts a bit later than the SSH service, so I > understand the time being here, however: >=20 > * In fact we are waiting for all services of the guest to be up and > functional, so depending on the level of load, I don't think 10s is > gonna make it. So I suggest something >=3D 30s Yeah,reasonable, we did ignore the circumstance with workload. But as you metioned,it can depend on different level of workload, therefore 30= s may be not enough as well. Your idea that write a utility function waiting for some services up is good I think, thus it could be somethin= g like: def wait_services_up(services_list): ... and for this case: wait_services_up(["Xorg"]) for Linux and wait_services_up(["explore.exe"]) for Windows. > * It's also true that just wait for a given time and hope that it > will be OK kinda sucks, so ideally we need to write utility functions > to stablish as well as possible when all services of a host are fully > booted up. Stated this way, it looks simple, but it's not. >=20 > Autotest experience suggests that there's no real sane way to > determine when a linux box is booted up, but we can take a > semi-rational approach and verify if all services for the current run > level have the status up or a similar approach. For windows, I was > talking to Yaniv Kaul and it seems that processing the output of the > 'sc query' command might give what we want. Bottom line, I'd like to > add a TODO item, and write a function to stablish (fairly confidently= ) > that a windows/linux guest is booted up. >=20 > > + =A0 =A0time.sleep(10) > > + > > + =A0 =A0# Start up a program(tcpdump for linux OS & ping for M$ OS= ), as a flag. > > + =A0 =A0# If the program died after suspend, then fails this testc= ase. > > + =A0 =A0test_s4_cmd =3D params.get("test_s4_cmd") > > + =A0 =A0session.sendline(test_s4_cmd) > > + > > + =A0 =A0# Get the second session to start S4 > > + =A0 =A0session2 =3D kvm_test_utils.wait_for_login(vm) > > + > > + =A0 =A0check_s4_cmd =3D params.get("check_s4_cmd") > > + =A0 =A0if session2.get_command_status(check_s4_cmd): > > + =A0 =A0 =A0 =A0raise error.TestError("Failed to launch %s backgro= und" % test_s4_cmd) > > + =A0 =A0logging.info("Launched command background in guest: %s" % = test_s4_cmd) > > + > > + =A0 =A0# Implement S4 > > + =A0 =A0logging.info("Start suspend to disk now...") > > + =A0 =A0session2.sendline(params.get("set_s4_cmd")) > > + > > + =A0 =A0if not kvm_utils.wait_for(vm.is_dead, 360, 30, 2): > > + =A0 =A0 =A0 =A0raise error.TestFail("VM refuse to go down,suspend= failed") > > + =A0 =A0logging.info("VM suspended successfully.") > > + > > + =A0 =A0logging.info("VM suspended to disk. sleep 10 seconds to ha= ve a break...") > > + =A0 =A0time.sleep(10) > > + > > + =A0 =A0# Start vm, and check whether the program is still running > > + =A0 =A0logging.info("Restart VM now...") > > + > > + =A0 =A0if not vm.create(): > > + =A0 =A0 =A0 =A0raise error.TestError("failed to start the vm agai= n.") > > + =A0 =A0if not vm.is_alive(): > > + =A0 =A0 =A0 =A0raise error.TestError("VM seems to be dead; Test r= equires a live VM.") > > + > > + =A0 =A0# Check whether test command still alive > > + =A0 =A0if session2.get_command_status(check_s4_cmd): > > + =A0 =A0 =A0 =A0raise error.TestFail("%s died, indicating that S4 = failed" % test_s4_cmd) >=20 > My doubt here is if by issuing a get_command_status we are actually > checking if the first command issued is alive. I am under the > impression that this will only create a new process with the same > command line, and hence, we are not checking if the background comman= d > is alive... Perhaps check if the command is alive using ps/windows > task manager or something? We did. As we can see the value of variable 'check_s4_cmd' in config fi= le, it's 'ps' for Linux guests and 'tasklist' for Windows OSes. The reason I used a second session(session2) is that for Windows guest, after executing some command background, it will persistently print output which will result in get_command_status timeout. Let me know whether this answers your questions. ;-) >=20 > About the wording of some messages, I have here a suggestion (full > code that I had edited, see below), please take a look at it and let > me know if you think it's OK. >=20 > {{{ > import logging, time > from autotest_lib.client.common_lib import error > import kvm_test_utils, kvm_utils >=20 >=20 > def run_guest_s4(test, params, env): > """ > Suspend guest to disk,supports both Linux & Windows OSes. >=20 > @param test: kvm test object. > @param params: Dictionary with test parameters. > @param env: Dictionary with the test environment. > """ > vm =3D kvm_test_utils.get_living_vm(env, params.get("main_vm")) > session =3D kvm_test_utils.wait_for_login(vm) >=20 > logging.info("Checking whether VM supports S4") > status =3D session.get_command_status(params.get("check_s4_suppor= t_cmd")) > if status is None: > logging.error("Failed to check if host supports S4") ^^^^ =3D> "guest" > elif status !=3D 0: > raise error.TestFail("Guest does not support S4") >=20 > logging.info("Wait until all guest services are fully started") > time.sleep(30) =3D=3D> time.sleep(params.get("services_up_timeout")) ?? Anyway, in my opinion, we could now leave the time as configurable in config file. And after wait_services_up() utility functions are availab= le, we send patch to fix this problem at that time. What do you think? >=20 > # Start up a program (tcpdump for linux & ping for Windows), as a= flag. > # If the program died after suspend, then fails this testcase. > test_s4_cmd =3D params.get("test_s4_cmd") > session.sendline(test_s4_cmd) >=20 > # Get the second session to start S4 > session2 =3D kvm_test_utils.wait_for_login(vm) >=20 > check_s4_cmd =3D params.get("check_s4_cmd") > if session2.get_command_status(check_s4_cmd): > raise error.TestError("Failed to launch '%s' as a background = process" % > test_s4_cmd) > logging.info("Launched background command in guest: %s" % test_s4= _cmd) >=20 > # Suspend to disk > logging.info("Start suspend to disk now...") > session2.sendline(params.get("set_s4_cmd")) >=20 > if not kvm_utils.wait_for(vm.is_dead, 360, 30, 2): > raise error.TestFail("VM refuses to go down. Suspend failed") > logging.info("VM suspended successfully. Wait before booting it a= gain.") > time.sleep(10) >=20 > # Start vm, and check whether the program is still running > logging.info("Start suspended VM...") >=20 > if not vm.create(): > raise error.TestError("Failed to start the VM after suspend t= o disk") > if not vm.is_alive(): > raise error.TestError("VM seems to be dead after it was suspe= nded") >=20 > # Check whether test command still alive > logging.info("Checking if background command returned") > if session2.get_command_status(check_s4_cmd): > raise error.TestFail("Command %s failed. S4 failed" % test_s4= _cmd) >=20 > logging.info("VM resumed after S4") > session2.sendline(params.get("kill_test_s4_cmd")) > session.close() > session2.close() >=20 > }}} >=20 > So I am waiting your comments before I can apply this patch. Thanks very much for imporving this test. :) >=20 > Thanks! >=20 > Lucas