From patchwork Tue Oct 26 16:49:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 283092 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9QHjP74003920 for ; Tue, 26 Oct 2010 17:45:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760058Ab0JZRpW (ORCPT ); Tue, 26 Oct 2010 13:45:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52014 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755473Ab0JZRpW (ORCPT ); Tue, 26 Oct 2010 13:45:22 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9QHjJEY025136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Oct 2010 13:45:21 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9QGnoDJ001702; Tue, 26 Oct 2010 12:49:50 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o9QGnjvG022482; Tue, 26 Oct 2010 12:49:49 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 3/5] KVM test: add utility functions start_windows_service() and stop_windows_service() Date: Tue, 26 Oct 2010 18:49:42 +0200 Message-Id: <1288111784-10188-3-git-send-email-mgoldish@redhat.com> In-Reply-To: <1288111784-10188-2-git-send-email-mgoldish@redhat.com> References: <1288111784-10188-1-git-send-email-mgoldish@redhat.com> <1288111784-10188-2-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 26 Oct 2010 17:45:26 +0000 (UTC) diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py index c5f44b4..8d287b2 100644 --- a/client/tests/kvm/kvm_test_utils.py +++ b/client/tests/kvm/kvm_test_utils.py @@ -241,6 +241,52 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp", return dest_vm +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: 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: 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