From patchwork Fri Apr 16 22:23:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 93243 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3GMO5QM012253 for ; Fri, 16 Apr 2010 22:24:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932648Ab0DPWYD (ORCPT ); Fri, 16 Apr 2010 18:24:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6289 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932635Ab0DPWYA (ORCPT ); Fri, 16 Apr 2010 18:24:00 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3GMNuee004468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 16 Apr 2010 18:23:56 -0400 Received: from localhost.localdomain (vpn-8-42.rdu.redhat.com [10.11.8.42]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3GMNqeN031017; Fri, 16 Apr 2010 18:23:52 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, mgoldish@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH] [RFC] KVM test: Create a remote session cleaning thread Date: Fri, 16 Apr 2010 19:23:49 -0300 Message-Id: <1271456629-13314-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 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 (demeter.kernel.org [140.211.167.41]); Fri, 16 Apr 2010 22:24:05 +0000 (UTC) diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 50db65c..707565d 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -13,7 +13,8 @@ except ImportError: _screendump_thread = None _screendump_thread_termination_event = None - +_session_cleaning_thread = None +_session_cleaning_thread_termination_event = None def preprocess_image(test, params): """ @@ -267,6 +268,14 @@ def preprocess(test, params, env): args=(test, params, env)) _screendump_thread.start() + # Start the session cleaning thread + logging.debug("Starting remote session cleaning thread") + global _session_cleaning_thread, _session_cleaning_thread_termination_event + _session_cleaning_thread_termination_event = threading.Event() + _session_cleaning_thread = threading.Thread(target=_clean_remote_sessions, + args=(test, params, env)) + _session_cleaning_thread.start() + def postprocess(test, params, env): """ @@ -442,3 +451,25 @@ def _take_screendumps(test, params, env): if _screendump_thread_termination_event.isSet(): break _screendump_thread_termination_event.wait(delay) + + +def _clean_remote_sessions(test, params, env): + """ + Some remote shell servers such as SSH can be very slow on giving up of a + connection, which is fair. However, if the VM is known to be dead, we + can speed up this process reaping the remote sessions stablished to it. + + @param test: KVM test object. + @param params: Dictionary with test parameters. + @param env: KVM test environment. + """ + global _session_cleaning_termination_event + delay = float(params.get("session_cleaning_delay", 30)) + while True: + for vm in kvm_utils.env_get_all_vms(env): + if vm.is_dead(): + for session in vm.get_remote_session_list(): + session.close() + if _session_cleaning_thread_termination_event.isSet(): + break + _session_cleaning_thread_termination_event.wait(delay) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 047505a..82ef3cf 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -115,6 +115,7 @@ class VM: self.root_dir = root_dir self.address_cache = address_cache self.pci_assignable = None + self.remote_session_list = [] # Find available monitor filename while True: @@ -749,6 +750,10 @@ class VM: return self.process.get_pid() + def get_remote_session_list(self): + return self.remote_session_list + + def get_shared_meminfo(self): """ Returns the VM's shared memory information. @@ -802,6 +807,8 @@ class VM: if session: session.set_status_test_command(self.params.get("status_test_" "command", "")) + self.remote_session_list.append(session) + return session