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 18:09:37 +0800 Message-ID: <20091014100937.GC2497@aFu.nay.redhat.com> References: <1254042696-16487-1-git-send-email-yzhou@redhat.com> <6ac58f4f0910131329v43e95b92v37933b13c60f323f@mail.gmail.com> <20091014025425.GA2497@aFu.nay.redhat.com> <6ac58f4f0910140258w2615e866t97c2f887b79267f8@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: autotest@test.kernel.org, kvm@vger.kernel.org To: Lucas Meneghel Rodrigues Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40138 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753574AbZJNKKF (ORCPT ); Wed, 14 Oct 2009 06:10:05 -0400 Content-Disposition: inline In-Reply-To: <6ac58f4f0910140258w2615e866t97c2f887b79267f8@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Oct 14, 2009 at 06:58:01AM -0300, Lucas Meneghel Rodrigues wrot= e: > On Tue, Oct 13, 2009 at 11:54 PM, Yolkfull Chow wr= ote: > > On Tue, Oct 13, 2009 at 05:29:40PM -0300, Lucas Meneghel Rodrigues = wrote: > >> Hi Yolkfull and Chen: > >> > >> Thanks for your test! I have some comments and doubts to clear, mo= st > >> of them are about content of the messages delivered for the user a= nd > >> some other details. > >> > >> On Sun, Sep 27, 2009 at 6:11 AM, Yolkfull Chow = wrote: > >> > For this case, Ken Cao wrote the linux part previously and I did= extensive > >> > 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/test= s/kvm/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/powe= r/state > >> > + =A0 =A0 =A0 =A0test_s4_cmd =3D "cd /tmp/;nohup tcpdump -q -t i= p host 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/ura= ndom 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 /hibe= rnate on > >> > + =A0 =A0 =A0 =A0 =A0 =A0test_s4_cmd =3D start /B ping -n 3000 l= ocalhost > >> > + =A0 =A0 =A0 =A0 =A0 =A0check_s4_cmd =3D tasklist | find /I "pi= ng" > >> > + =A0 =A0 =A0 =A0 =A0 =A0set_s4_cmd =3D rundll32.exe PowrProf.dl= l, 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/k= vm/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 OSe= s. > >> > + > >> > + =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("ma= in_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...") > >> > >> Yes, generally X starts a bit later than the SSH service, so I > >> understand the time being here, however: > >> > >> =A0* 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 i= s > >> 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, therefor= e 30s > > 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 some= thing > > like: > > > > def wait_services_up(services_list): > > =A0 =A0... > > > > and for this case: > > > > wait_services_up(["Xorg"]) for Linux and > > wait_services_up(["explore.exe"]) for Windows. >=20 > Ok, sounds good to me! >=20 > >> =A0* 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 functi= ons > >> to stablish as well as possible when all services of a host are fu= lly > >> booted up. Stated this way, it looks simple, but it's not. > >> > >> 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 t= he > >> '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 confiden= tly) > >> that a windows/linux guest is booted up. > >> > >> > + =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 te= stcase. > >> > + =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 back= ground" % 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,susp= end failed") > >> > + =A0 =A0logging.info("VM suspended successfully.") > >> > + > >> > + =A0 =A0logging.info("VM suspended to disk. sleep 10 seconds to= have a break...") > >> > + =A0 =A0time.sleep(10) > >> > + > >> > + =A0 =A0# Start vm, and check whether the program is still runn= ing > >> > + =A0 =A0logging.info("Restart VM now...") > >> > + > >> > + =A0 =A0if not vm.create(): > >> > + =A0 =A0 =A0 =A0raise error.TestError("failed to start the vm a= gain.") > >> > + =A0 =A0if not vm.is_alive(): > >> > + =A0 =A0 =A0 =A0raise error.TestError("VM seems to be dead; Tes= t requires 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) > >> > >> My doubt here is if by issuing a get_command_status we are actuall= y > >> 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 com= mand > >> 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 confi= g file, > > it's 'ps' for Linux guests and 'tasklist' for Windows OSes. > > > > The reason I used a second session(session2) is that for Windows gu= est, > > 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 > Yes, I was just plain mistaken, somewhat my brain ignored the > check_s4_cmd... it looks very good to me, sorry :) That's no problem.=20 And I saw that you had sent the new patch.=20 Thanks very much for help improving this test. :) Best Regards, >=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 l= et > >> me know if you think it's OK. > >> > >> {{{ > >> 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 =A0 Suspend 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 =A0 vm =3D kvm_test_utils.get_living_vm(env, params.get("main_= vm")) > >> =A0 =A0 session =3D kvm_test_utils.wait_for_login(vm) > >> > >> =A0 =A0 logging.info("Checking whether VM supports S4") > >> =A0 =A0 status =3D session.get_command_status(params.get("check_s4= _support_cmd")) > >> =A0 =A0 if status is None: > >> =A0 =A0 =A0 =A0 logging.error("Failed to check if host supports S4= ") > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0^^^^ =3D> "guest" > >> =A0 =A0 elif status !=3D 0: > >> =A0 =A0 =A0 =A0 raise error.TestFail("Guest does not support S4") > >> > >> =A0 =A0 logging.info("Wait until all guest services are fully star= ted") > >> =A0 =A0 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 ava= ilable, > > we send patch to fix this problem at that time. > > What do you think? >=20 > Sounds like a plan! Commited as: >=20 > http://autotest.kernel.org/changeset/3843