Reformat Robot files to follow best practices
[osm/tests.git] / robot-systest / lib / prometheus_lib.robot
index e133c2a..c76b560 100644 (file)
@@ -11,7 +11,7 @@
 #   limitations under the License.
 
 *** Settings ***
-Documentation     Library to obtain metrics from Prometheus.
+Documentation   Library to obtain metrics from Prometheus.
 
 Library   String
 Library   Collections
@@ -19,42 +19,42 @@ Library   RequestsLibrary
 
 
 *** Variables ***
-${timeout}  30
-${max_retries}  1
+${timeout}   30
+${max_retries}   1
 
 
 *** Keywords ***
 Get Metric
-    [Documentation]     Get the instant value of a metric from Prometheus using multiple filter parameters.
+    [Documentation]   Get the instant value of a metric from Prometheus using multiple filter parameters.
     ...                 The filter parameters are given to this function in key=value format (one argument per key/value pair).
     ...                 Fails if the metric is not found or has multiple values.
     ...                 Examples of execution:
-    ...                     \${metric}=  Get Metric  \${prometheus_ip}  \${prometheus_port}  \${metric}
-    ...                     \${metric}=  Get Metric  \${prometheus_ip}  \${prometheus_port}  \${metric}  \${param1}=\${value1}  \${param2}=\${value2}
+    ...                     \${metric}=   Get Metric   \${prometheus_ip}   \${prometheus_port}   \${metric}
+    ...                     \${metric}=   Get Metric   \${prometheus_ip}   \${prometheus_port}   \${metric}   \${param1}=\${value1}   \${param2}=\${value2}
 
-    [Arguments]  ${prometheus_ip}  ${prometheus_port}  ${metric}  @{filter_parameters}
+    [Arguments]   ${prometheus_ip}   ${prometheus_port}   ${metric}   @{filter_parameters}
 
-    ${filter}=  Set Variable  ${EMPTY}
-    FOR  ${param}  IN  @{filter_parameters}
-        ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in filter parameters
-        ${filter}=  Catenate  SEPARATOR=  ${filter}  ${param_name}="${param_value}",
+    ${filter}=   Set Variable   ${EMPTY}
+    FOR   ${param}   IN   @{filter_parameters}
+        ${match}   ${param_name}   ${param_value} =   Should Match Regexp   ${param}   (.+)=(.+)   msg=Syntax error in filter parameters
+        ${filter}=   Catenate   SEPARATOR=   ${filter}   ${param_name}="${param_value}",
     END
-    ${resp}=  Execute Prometheus Instant Query  ${prometheus_host}  ${prometheus_port}  query=${metric}{${filter}}
-    ${result_list}=  Convert To List  ${resp["data"]["result"]}
-    ${results}=  Get Length  ${result_list}
-    Should Not Be Equal As Numbers  0  ${results}  msg=Metric ${metric} not found  values=false
-    Should Be Equal As Integers  1  ${results}  msg=Metric ${metric} with multiple values  values=false
-    [Return]  ${result_list[0]["value"][1]}
+    ${resp}=   Execute Prometheus Instant Query   ${prometheus_host}   ${prometheus_port}   query=${metric}{${filter}}
+    ${result_list}=   Convert To List   ${resp["data"]["result"]}
+    ${results}=   Get Length   ${result_list}
+    Should Not Be Equal As Numbers   0   ${results}   msg=Metric ${metric} not found   values=false
+    Should Be Equal As Integers   1   ${results}   msg=Metric ${metric} with multiple values   values=false
+    [Return]   ${result_list[0]["value"][1]}
 
 
 Execute Prometheus Instant Query
-    [Documentation]     Execute a Prometheus Instant Query using HTTP API.
+    [Documentation]   Execute a Prometheus Instant Query using HTTP API.
     ...                 Return an inline json with the result of the query.
     ...                 The requested URL is the next: http://\${prometheus_ip}:\${prometheus_port}/api/v1/query?\${querystring}
 
-    [Arguments]  ${prometheus_ip}  ${prometheus_port}  ${querystring}
+    [Arguments]   ${prometheus_ip}   ${prometheus_port}   ${querystring}
 
-    Create Session  prometheus  http://${prometheus_ip}:${prometheus_port}  timeout=${timeout}  max_retries=${max_retries}
-    ${resp}=  GET On Session  prometheus  /api/v1/query?${querystring}  timeout=${timeout}
-    Status Should Be  200  ${resp}
-    [Return]  ${resp.json()}
+    Create Session   prometheus   http://${prometheus_ip}:${prometheus_port}   timeout=${timeout}   max_retries=${max_retries}
+    ${resp}=   GET On Session   prometheus   /api/v1/query?${querystring}   timeout=${timeout}
+    Status Should Be   200   ${resp}
+    [Return]   ${resp.json()}