adapt/improve memory leak tests
Change-Id: I0437c9e4a499d1882f2150cf9fdf93e3a1226b2b
diff --git a/libraries/onu_utilities.robot b/libraries/onu_utilities.robot
index 620c463..48a6a93 100755
--- a/libraries/onu_utilities.robot
+++ b/libraries/onu_utilities.robot
@@ -28,7 +28,7 @@
... ELSE Append To List ${onu_sn_list} ${onu_sn}
FOR ${sn} IN @{onu_sn_list}
${device_id}= Get Device ID From SN ${sn}
- ${output}= Catenate ${output} ONU Serial Number: ${sn} ONU Device ID: ${device_id}\r\n
+ ${output}= Catenate ${output}ONU Serial Number: ${sn} ONU Device ID: ${device_id}\r\n
END
Log ${output}
Run Keyword If ${print2console} Log ${output} console=yes
diff --git a/libraries/utility.py b/libraries/utility.py
index 78bbc86..6093a63 100755
--- a/libraries/utility.py
+++ b/libraries/utility.py
@@ -143,7 +143,7 @@
"""
Query Prometheus and generate instantaneous memory consumptions for given pods under test
:param address: string The address of the Prometheus instance to query
- :container: string The pod name
+ :param container: string The pod name
:param namespace: string The pod namespace
:return: memory consumtion value
"""
@@ -158,3 +158,28 @@
return container_cpu[0]["value"][1]
else:
return -1
+
+def get_memory_consumptions_range(address, container, namespace="default", start=0, end=0):
+ """
+ Query Prometheus and generate instantaneous memory consumptions for given pods under test
+ :param address: string The address of the Prometheus instance to query
+ :param container: string The pod name
+ :param namespace: string The pod namespace
+ :param start: integer The range start time (epoch)
+ :param end: integer The range end time
+ :return: memory consumtion value
+ """
+ container_mem_query = ('sort_desc(container_memory_working_set_bytes{namespace="%s",container="%s"})' %
+ (namespace, container))
+ mem_params = {
+ "query": container_mem_query,
+ "start":start,
+ "end":end,
+ "step":'1m',
+ }
+ r = requests.get("http://%s/api/v1/query_range" % address, mem_params)
+ container_cpu = r.json()["data"]["result"]
+ if len(container_cpu) > 0:
+ return container_cpu[0]["values"]
+ else:
+ return -1