Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

dmcache cannot handle situation where lvmcache is not configured #115

Closed
happz opened this Issue Sep 21, 2016 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

happz commented Sep 21, 2016

Without having any LVM cache set up command pcp dmcache leads to a traceback:

[root@foo ~]# pcp dmcache
Traceback (most recent call last):
  File "/usr/libexec/pcp/bin/pcp-dmcache", line 166, in <module>
    manager.run()
  File "/usr/lib64/python2.7/site-packages/pcp/pmcc.py", line 639, in run
    self._printer.report(self)
  File "/usr/libexec/pcp/bin/pcp-dmcache", line 137, in report
    max_lv = max_lv_length(group)
  File "/usr/libexec/pcp/bin/pcp-dmcache", line 82, in max_lv_length
    return len(max(lv_names, key=len))
ValueError: max() arg is an empty sequence
[root@foo ~]# 

Running pminfo -f dmcache reports (correctly) no values for dmcache metrics. The issue lies in formatting code, method max_lv_length expects there are always some data for dmcache available, and does not handle situation there are no data for key dmcache.cache.used. Very direct patch leads to a correct output (header + repeating lines of "No values available") but maybe a more sophisticated patch would be more appropriate.

diff --git a/src/pcp/dmcache/pcp-dmcache.py b/src/pcp/dmcache/pcp-dmcache.py
index a606eb1..ac243ca 100755
--- a/src/pcp/dmcache/pcp-dmcache.py
+++ b/src/pcp/dmcache/pcp-dmcache.py
@@ -78,6 +78,8 @@ def cache_dict(group, metric):
 def max_lv_length(group):
     """ look at the observation group and return the max length of all the lvnames """
     cache_used = cache_dict(group, 'dmcache.cache.used')
+    if not cache_used:
+        return 0
     lv_names = cache_used.keys()
     return len(max(lv_names, key=len))

goodwinos added a commit that referenced this issue Sep 26, 2016

dmcache: dmcache cannot handle situation where lvmcache is not config…
…ured

Improved error handling in dmcache when the underlying PMDA is not configured.
#115
Author:    Miloš Prchlík <mprchlik@redhat.com>
Contributor

goodwinos commented Sep 26, 2016

thanks, pulled this in for 3.11.5. There is still an issue if the 'dm' PMDA is not ./Install'd, but when it is this patch improves the error handling.

@goodwinos goodwinos closed this Sep 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment