Adam Litke has uploaded a new change for review. Change subject: HostKSM: Gracefully handle ksmd pid lookup failure ......................................................................
HostKSM: Gracefully handle ksmd pid lookup failure In case the pid of ksmd cannot be found we currently fail with a ValueError exception. Check the pidof return code before trying to convert the output to an int. If the pid cannot be found, then report 0 for get_ksmd_jiffies(). Change-Id: Iccd14ee44f4f7d8d9107e692c9faa27e7c487790 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1152182 Signed-off-by: Adam Litke <ali...@redhat.com> --- M mom/Collectors/HostKSM.py 1 file changed, 14 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/78/34378/1 diff --git a/mom/Collectors/HostKSM.py b/mom/Collectors/HostKSM.py index ee3a3a7..8b291f5 100644 --- a/mom/Collectors/HostKSM.py +++ b/mom/Collectors/HostKSM.py @@ -41,13 +41,21 @@ def __init__(self, properties): self.open_files() self.interval = properties['interval'] - self.pid = int(Popen(['pidof', 'ksmd'], stdout=PIPE).communicate()[0]) + self.pid = self._get_ksmd_pid() self.last_jiff = self.get_ksmd_jiffies() def __del__(self): for datum in self.sysfs_keys: if datum in self.files and self.files[datum] is not None: self.files[datum].close() + + def _get_ksmd_pid(self): + proc = Popen(['pidof', 'ksmd'], stdout=PIPE) + out = proc.communicate()[0] + if proc.returncode == 0: + return int(out) + else: + return -1 def open_files(self): self.files = {} @@ -59,8 +67,11 @@ raise FatalError("HostKSM: open %s failed: %s" % (name, msg)) def get_ksmd_jiffies(self): - return sum(map(int, file('/proc/%s/stat' % self.pid) \ - .read().split()[13:15])) + if self.pid == -1: + return 0 + else: + return sum(map(int, file('/proc/%s/stat' % self.pid) \ + .read().split()[13:15])) def get_ksmd_cpu_usage(self): """ -- To view, visit http://gerrit.ovirt.org/34378 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iccd14ee44f4f7d8d9107e692c9faa27e7c487790 Gerrit-PatchSet: 1 Gerrit-Project: mom Gerrit-Branch: master Gerrit-Owner: Adam Litke <ali...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches