summaryrefslogtreecommitdiffstats
path: root/cns-libs
diff options
context:
space:
mode:
authornigoyal <nigoyal@redhat.com>2018-09-24 15:46:16 +0530
committernigoyal <nigoyal@redhat.com>2018-11-06 18:09:30 +0530
commitb910e0ccc647691d64b68fd363cc6976afbd493b (patch)
tree7193df67f3a288ce45fbaeae65cc33836b336c01 /cns-libs
parent93da51ec026a3ffe4cd501aa6b5660252c454175 (diff)
test cases for heketi metrics
CNS-1243 - Heketi_metrics_generate CNS-1244 - Heketi_metrics_validating_VolumeCount_on_creation CNS-1245 - Heketi_metrics_validating_VolumeCount_on_deletion CNS-1262 - Heketi-metrics_validating_heketi_pod failure Change-Id: Idb863d1ceaf555dfc2a9cff863b97cda65a816f6 Signed-off-by: nigoyal <nigoyal@redhat.com>
Diffstat (limited to 'cns-libs')
-rw-r--r--cns-libs/cnslibs/common/heketi_ops.py29
-rw-r--r--cns-libs/cnslibs/common/utils.py26
-rw-r--r--cns-libs/setup.py3
3 files changed, 57 insertions, 1 deletions
diff --git a/cns-libs/cnslibs/common/heketi_ops.py b/cns-libs/cnslibs/common/heketi_ops.py
index fea574da..534017ff 100644
--- a/cns-libs/cnslibs/common/heketi_ops.py
+++ b/cns-libs/cnslibs/common/heketi_ops.py
@@ -15,6 +15,7 @@ except ImportError:
g.log.error("Please install python-client for heketi and re-run the test")
from cnslibs.common import exceptions, podcmd
+from cnslibs.common.utils import parse_prometheus_data
HEKETI_SSH_KEY = "/etc/heketi/heketi_key"
HEKETI_CONFIG_FILE = "/etc/heketi/heketi.json"
@@ -2388,3 +2389,31 @@ def match_heketi_and_gluster_block_volumes(
assert sorted(gluster_vol_block_list) == heketi_block_volumes, (
"Gluster and Heketi Block volume list match failed")
+
+
+def get_heketi_metrics(heketi_client_node, heketi_server_url,
+ prometheus_format=False):
+ ''' Execute curl command to get metrics output
+
+ Args:
+ - heketi_client_node (str) : Node where we want to run our commands.
+ - heketi_server_url (str) : This is a heketi server url
+ - prometheus_format (bool) : control the format of output
+ by default it is False, So it will parse prometheus format into
+ python dict. If we need prometheus format we have to set it True.
+ Returns:
+ Metrics output: if successful
+ Raises:
+ err: if fails to run command
+
+ '''
+
+ cmd = "curl %s/metrics" % heketi_server_url
+ ret, out, err = g.run(heketi_client_node, cmd)
+ if ret != 0:
+ msg = "failed to get Heketi metrics with following error: %s" % err
+ g.log.error(msg)
+ raise AssertionError(msg)
+ if prometheus_format:
+ return out.strip()
+ return parse_prometheus_data(out)
diff --git a/cns-libs/cnslibs/common/utils.py b/cns-libs/cnslibs/common/utils.py
index 7d1f6d6f..9aa38ff9 100644
--- a/cns-libs/cnslibs/common/utils.py
+++ b/cns-libs/cnslibs/common/utils.py
@@ -10,6 +10,7 @@ import string
from glusto.core import Glusto as g
+from prometheus_client.parser import text_string_to_metric_families
ONE_GB_BYTES = 1073741824.0
@@ -49,3 +50,28 @@ def get_device_size(host, device_name):
def get_random_str(size=14):
chars = string.ascii_lowercase + string.digits
return ''.join(random.choice(chars) for _ in range(size))
+
+
+def parse_prometheus_data(text):
+ """Parse prometheus-formatted text to the python objects
+
+ Args:
+ text (str): prometheus-formatted data
+
+ Returns:
+ dict: parsed data as python dictionary
+ """
+ metrics = {}
+ for family in text_string_to_metric_families(text):
+ for sample in family.samples:
+ key, data, val = (sample.name, sample.labels, sample.value)
+ if data.keys():
+ data['value'] = val
+ if key in metrics.keys():
+ metrics[key].append(data)
+ else:
+ metrics[key] = [data]
+ else:
+ metrics[key] = val
+
+ return metrics
diff --git a/cns-libs/setup.py b/cns-libs/setup.py
index 42f1fd83..bb3803a9 100644
--- a/cns-libs/setup.py
+++ b/cns-libs/setup.py
@@ -22,7 +22,8 @@ setup(
'Programming Language :: Python :: 2.7'
'Topic :: Software Development :: Testing'
],
- install_requires=['glusto', 'ddt', 'mock', 'rtyaml', 'jsondiff', 'six'],
+ install_requires=['glusto', 'ddt', 'mock', 'rtyaml', 'jsondiff', 'six',
+ 'prometheus_client>=0.4.2'],
dependency_links=[
'http://github.com/loadtheaccumulator/glusto/tarball/master#egg=glusto'
],