public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: Michael Goldish <mgoldish@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: Re: [KVM-AUTOTEST PATCH 6/9] [RFC] KVM test: add utility functions start_windows_service() and stop_windows_service()
Date: Thu, 5 Aug 2010 08:38:55 +0800	[thread overview]
Message-ID: <20100805003855.GA2916@z> (raw)
In-Reply-To: <1279209458-19590-6-git-send-email-mgoldish@redhat.com>

On Thu, Jul 15, 2010 at 06:57:35PM +0300, Michael Goldish wrote:
> These utilities use sc to stop and start windows services.  They're used by whql_submission
> and whql_client_install to stop or restart wttsvc on the client machine.
> 
> Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> ---
>  client/tests/kvm/kvm_test_utils.py |   46 ++++++++++++++++++++++++++++++++++++
>  1 files changed, 46 insertions(+), 0 deletions(-)
> 
> diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
> index 53c11ae..9fd3a74 100644
> --- a/client/tests/kvm/kvm_test_utils.py
> +++ b/client/tests/kvm/kvm_test_utils.py
> @@ -242,6 +242,52 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
>          raise
>  
>  
> +def stop_windows_service(session, service, timeout=120):
> +    """
> +    Stop a Windows service using sc.
> +    If the service is already stopped or is not installed, do nothing.
> +
> +    @param service: The name of the service
> +    @param timeout: Time duration to wait for service to stop
> +    @raise: error.TestError is raised if the service can't be stopped
> +    """
> +    end_time = time.time() + timeout
> +    while time.time() < end_time:
> +        o = session.get_command_output("sc stop %s" % service, timeout=60)
> +        # FAILED 1060 means the service isn't installed.
> +        # FAILED 1062 means the service hasn't been started.
> +        if re.search(r"\bFAILED (1060|1062)\b", o, re.I):
> +            break
> +        time.sleep(1)
> +    else:
> +        raise error.TestError("Could not stop service '%s'" % service)

Hi Michael, 

How about combine those two function together ? we can also use it do other setup.

   def setup_windows_service(session, service, action, timeout=120):
       ...
       # FAILED 1060 means the service isn't installed.
       # FAILED 1062 means the service hasn't been started.
       # FAILED 1056 means the service is already running.
       dict = {
       #"$action" : ["$fail_str", "$break_str"]
       "stop": ["", "(1060|1062)"],
       "start": ["1060", "1056"],
       ...
       ...
       }

       end_time = time.time() + timeout
       while time.time() < end_time:
           o = session.get_command_output("sc %s %s" % service, action, timeout=60)
           if re.search(r"\bFAILED %s\b" % dict[action][0], o, re.I):
               raise error.TestError("..... %s, %s" % (action, dict[action][0]))
           if re.search(r"\bFAILED %s\b" % dict[action][1], o, re.I):
               break
           ...
           ...
           time.sleep(1)
       else:
           raise error.TestError("Could not %s service '%s'" % (action, service))


> +def start_windows_service(session, service, timeout=120):
> +    """
> +    Start a Windows service using sc.
> +    If the service is already running, do nothing.
> +    If the service isn't installed, fail.
> +
> +    @param service: The name of the service
> +    @param timeout: Time duration to wait for service to start
> +    @raise: error.TestError is raised if the service can't be started
> +    """
> +    end_time = time.time() + timeout
> +    while time.time() < end_time:
> +        o = session.get_command_output("sc start %s" % service, timeout=60)
> +        # FAILED 1060 means the service isn't installed.
> +        if re.search(r"\bFAILED 1060\b", o, re.I):
> +            raise error.TestError("Could not start service '%s' "
> +                                  "(service not installed)" % service)
> +        # FAILED 1056 means the service is already running.
> +        if re.search(r"\bFAILED 1056\b", o, re.I):
> +            break
> +        time.sleep(1)
> +    else:
> +        raise error.TestError("Could not start service '%s'" % service)
> +
> +
>  def get_time(session, time_command, time_filter_re, time_format):
>      """
>      Return the host time and guest time.  If the guest time cannot be fetched
> -- 
> 1.5.4.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2010-08-05  0:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-15 15:57 [KVM-AUTOTEST PATCH 1/9] KVM test: kvm_vm.py: make -drive index optional for both images and cdrom ISOs Michael Goldish
2010-07-15 15:57 ` [KVM-AUTOTEST PATCH 2/9] KVM test: allow definition of multiple cdroms Michael Goldish
2010-07-15 15:57   ` [KVM-AUTOTEST PATCH 3/9] KVM test: rss_file_transfer.py: add convenience functions upload() and download() Michael Goldish
2010-07-15 15:57     ` [KVM-AUTOTEST PATCH 4/9] [RFC] KVM test: DTM automation program for WHQL tests Michael Goldish
2010-07-15 15:57       ` [KVM-AUTOTEST PATCH 5/9] [RFC] KVM test: DTM machine deletion tool " Michael Goldish
2010-07-15 15:57         ` [KVM-AUTOTEST PATCH 6/9] [RFC] KVM test: add utility functions start_windows_service() and stop_windows_service() Michael Goldish
2010-07-15 15:57           ` [KVM-AUTOTEST PATCH 7/9] [RFC] KVM test: add whql_submission test Michael Goldish
2010-07-15 15:57             ` [KVM-AUTOTEST PATCH 8/9] [RFC] KVM test: add whql_client_install test Michael Goldish
2010-07-15 15:57               ` [KVM-AUTOTEST PATCH 9/9] [RFC] KVM test: add WHQL test definitions to tests_base.cfg.sample Michael Goldish
2010-08-05  0:38           ` Amos Kong [this message]
2010-08-05 13:32             ` [KVM-AUTOTEST PATCH 6/9] [RFC] KVM test: add utility functions start_windows_service() and stop_windows_service() Michael Goldish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100805003855.GA2916@z \
    --to=akong@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mgoldish@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox