From: Lucas Meneghel Rodrigues Subject: [PATCH] Client profilers: kvm_stat: Make absence of kvm_stat non-fatal Date: Fri, 15 Jul 2011 18:08:43 -0300 Message-ID: <1310764123-22161-1-git-send-email-lmr@redhat.com> Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues To: autotest@test.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:43206 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752419Ab1GOVIt (ORCPT ); Fri, 15 Jul 2011 17:08:49 -0400 Sender: kvm-owner@vger.kernel.org List-ID: The client side kvm test is the first (and so far, probably the only) user of the kvm_stat profiler. If no kvm_stat is found, an exception is thrown, stopping the entire kvm autotest job. This is somewhat annoying, since it introduces a point of failure for non core functionality. So, following the model of graceful degradation, if kvm_stat is not present, just print error messages, so users know what is missing. They can always either disable the profiler on the config file or install kvm_stat. Signed-off-by: Lucas Meneghel Rodrigues --- client/profilers/kvm_stat/kvm_stat.py | 53 +++++++++++++++++++++----------- 1 files changed, 35 insertions(+), 18 deletions(-) diff --git a/client/profilers/kvm_stat/kvm_stat.py b/client/profilers/kvm_stat/kvm_stat.py index 59d6ff6..d201fb0 100644 --- a/client/profilers/kvm_stat/kvm_stat.py +++ b/client/profilers/kvm_stat/kvm_stat.py @@ -6,7 +6,7 @@ will try to mount it so it's possible to proceed. @copyright: Red Hat 2010 @author: Lucas Meneghel Rodrigues (lmr@redhat.com) """ -import time, os, subprocess, commands +import time, os, subprocess, commands, logging from autotest_lib.client.bin import utils, profiler, os_dep from autotest_lib.client.common_lib import error @@ -21,15 +21,27 @@ class kvm_stat(profiler.profiler): """ Gets path of kvm_stat and verifies if debugfs needs to be mounted. """ - self.stat_path = os_dep.command('kvm_stat') + self.is_enabled = False + + kvm_stat_installed = False try: - utils.system_output("%s --batch" % self.stat_path) - except error.CmdError, e: - if 'debugfs' in str(e): - utils.system('mount -t debugfs debugfs /sys/kernel/debug') - else: - raise error.AutotestError('kvm_stat failed due to an ' - 'unknown reason: %s' % str(e)) + self.stat_path = os_dep.command('kvm_stat') + kvm_stat_installed = True + except ValueError: + logging.error('Command kvm_stat not present') + + if kvm_stat_installed: + try: + utils.run("%s --batch" % self.stat_path) + self.is_enabled = True + except error.CmdError, e: + if 'debugfs' in str(e): + try: + utils.run('mount -t debugfs debugfs /sys/kernel/debug') + except error.CmdError, e: + logging.error('Failed to mount debugfs:\n%s', str(e)) + else: + logging.error('Failed to execute kvm_stat:\n%s', str(e)) def start(self, test): @@ -38,11 +50,15 @@ class kvm_stat(profiler.profiler): @param test: Autotest test on which this profiler will operate on. """ - cmd = "%s -l" % self.stat_path - logfile = open(os.path.join(test.profdir, "kvm_stat"), 'w') - p = subprocess.Popen(cmd, shell=True, stdout=logfile, - stderr=subprocess.STDOUT) - self.pid = p.pid + if self.is_enabled: + cmd = "%s -l" % self.stat_path + logfile = open(os.path.join(test.profdir, "kvm_stat"), 'w') + p = subprocess.Popen(cmd, shell=True, stdout=logfile, + stderr=subprocess.STDOUT) + self.pid = p.pid + else: + logging.error('Asked for kvm_stat profiler, but kvm_stat not ' + 'present') def stop(self, test): @@ -51,10 +67,11 @@ class kvm_stat(profiler.profiler): @param test: Autotest test on which this profiler will operate on. """ - try: - os.kill(self.pid, 15) - except OSError: - pass + if self.is_enabled: + try: + os.kill(self.pid, 15) + except OSError: + pass def report(self, test): -- 1.7.6