From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 6/9] [RFC] KVM test: add utility functions start_windows_service() and stop_windows_service() Date: Thu, 15 Jul 2010 18:57:35 +0300 Message-ID: <1279209458-19590-6-git-send-email-mgoldish@redhat.com> References: <1279209458-19590-1-git-send-email-mgoldish@redhat.com> <1279209458-19590-2-git-send-email-mgoldish@redhat.com> <1279209458-19590-3-git-send-email-mgoldish@redhat.com> <1279209458-19590-4-git-send-email-mgoldish@redhat.com> <1279209458-19590-5-git-send-email-mgoldish@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: In-Reply-To: <1279209458-19590-5-git-send-email-mgoldish@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org 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 --- 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) + + +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