From: Lukas Doktor Subject: [PATCH 1/2] cgroup: cgroup_common.py bugfixies and modifications Date: Thu, 22 Sep 2011 18:29:45 +0200 Message-ID: <1316708986-12045-2-git-send-email-ldoktor@redhat.com> References: <1316708986-12045-1-git-send-email-ldoktor@redhat.com> To: autotest@test.kernel.org, kvm@vger.kernel.org, kvm-autotest@redhat.com, akong@redhat.com, lmr@redhat.com, ldoktor@redhat.com, jzupka@redhat.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:53217 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752247Ab1IVQaA (ORCPT ); Thu, 22 Sep 2011 12:30:00 -0400 In-Reply-To: <1316708986-12045-1-git-send-email-ldoktor@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: [FIX] incorrect prop/dir variable usage [MOD] Use __del__() instead of cleanup - Simplifies the code with small drawback (failures can't be handled. Anyway, they are not critical and were never handled before...) Signed-off-by: Lukas Doktor --- client/tests/cgroup/cgroup_common.py | 41 +++++++++++++++++++++++++++++----- 1 files changed, 35 insertions(+), 6 deletions(-) diff --git a/client/tests/cgroup/cgroup_common.py b/client/tests/cgroup/cgroup_common.py index 836a23e..2a95c76 100755 --- a/client/tests/cgroup/cgroup_common.py +++ b/client/tests/cgroup/cgroup_common.py @@ -25,8 +25,20 @@ class Cgroup(object): self.module = module self._client = _client self.root = None + self.cgroups = [] + def __del__(self): + """ + Destructor + """ + self.cgroups.sort(reverse=True) + for pwd in self.cgroups[:]: + for task in self.get_property("tasks", pwd): + if task: + self.set_root_cgroup(int(task)) + self.rm_cgroup(pwd) + def initialize(self, modules): """ Initializes object for use. @@ -57,6 +69,7 @@ class Cgroup(object): except Exception, inst: logging.error("cg.mk_cgroup(): %s" , inst) return None + self.cgroups.append(pwd) return pwd @@ -70,6 +83,10 @@ class Cgroup(object): """ try: os.rmdir(pwd) + self.cgroups.remove(pwd) + except ValueError: + logging.warn("cg.rm_cgroup(): Removed cgroup which wasn't created" + "using this Cgroup") except Exception, inst: if not supress: logging.error("cg.rm_cgroup(): %s" , inst) @@ -329,6 +346,22 @@ class CgroupModules(object): self.modules.append([]) self.mountdir = mkdtemp(prefix='cgroup-') + '/' + def __del__(self): + """ + Unmount all cgroups and remove the mountdir + """ + for i in range(len(self.modules[0])): + if self.modules[2][i]: + try: + os.system('umount %s -l' % self.modules[1][i]) + except: + logging.warn("CGM: Couldn't unmount %s directory" + % self.modules[1][i]) + try: + os.system('rm -rf %s' % self.mountdir) + except: + logging.warn("CGM: Couldn't remove the %s directory" + % self.mountdir) def init(self, _modules): """ @@ -376,13 +409,9 @@ class CgroupModules(object): def cleanup(self): """ - Unmount all cgroups and remove the mountdir. + Kept for compatibility """ - for i in range(len(self.modules[0])): - if self.modules[2][i]: - utils.system('umount %s -l' % self.modules[1][i], - ignore_status=True) - shutil.rmtree(self.mountdir) + pass def get_pwd(self, module): -- 1.7.6