Replace prometheus host and port by URL and infer it from OSM_HOSTNAME

Change-Id: Iff647f8c61ad3891ff995f4d458ce93e0a0d9ac6
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/robot-systest/lib/prometheus_lib.resource b/robot-systest/lib/prometheus_lib.resource
index be3c120..4ad3028 100644
--- a/robot-systest/lib/prometheus_lib.resource
+++ b/robot-systest/lib/prometheus_lib.resource
@@ -34,13 +34,18 @@
 Set Testsuite Prometheus Variables
     [Documentation]   Set Testsuite Prometheus Variables to be used in subsequent test cases
 
-    IF   ${PROMETHEUS_HOST} == 'UNKNOWN'
+    IF   '${PROMETHEUS_HOST}' == 'UNKNOWN'
         ${local_prometheus_host}=   Get Environment Variable   OSM_HOSTNAME
+        IF   '${local_prometheus_host}'.startswith('nbi.')
+            ${local_prometheus_host}=   Replace String   ${local_prometheus_host}   nbi.   prometheus.
+        END
         Set Suite Variable   ${PROMETHEUS_HOST}   ${local_prometheus_host}
-        Set Suite Variable   ${PROMETHEUS_HOST}   9091
+        Set Suite Variable   ${PROMETHEUS_PORT}   80
     END
+    Set Suite Variable   ${PROMETHEUS_URL}   http://${PROMETHEUS_HOST}:${PROMETHEUS_PORT}
     Log   ${PROMETHEUS_PORT}
     Log   ${PROMETHEUS_HOST}
+    Log   ${PROMETHEUS_URL}
     Log   ${PROMETHEUS_USER}
     Log   ${PROMETHEUS_PASSWORD}
 
@@ -49,16 +54,22 @@
     ...                 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}   ${prometheus_password}   \${metric}
-    ...                     \${metric}=   Get Metric   \${prometheus_ip}   \${prometheus_port}   ${prometheus_password}   \${metric}   \${param1}=\${value1}   \${param2}=\${value2}
-    [Arguments]   ${prometheus_ip}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}   ${metric}   @{filter_parameters}
+    ...                     \${metric}=   Get Metric   \${prometheus_url}   ${prometheus_password}   \${metric}
+    ...                     \${metric}=   Get Metric   \${prometheus_url}   ${prometheus_password}   \${metric}   \${param1}=\${value1}   \${param2}=\${value2}
+    [Arguments]   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}   ${metric}   @{filter_parameters}
+    Log   ${prometheus_url}
+    Log   ${prometheus_user}
+    Log   ${prometheus_password}
+    Log   ${metric}
+    Log   ${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
         Log   ${match},${param_name},${param_value}
         ${filter}=   Catenate   SEPARATOR=   ${filter}   ${param_name}="${param_value}",
     END
-    ${resp}=   Execute Prometheus Instant Query   ${prometheus_ip}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}   query=${metric}{${filter}}
+    ${resp}=   Execute Prometheus Instant Query   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}   query=${metric}{${filter}}
+    Log   ${resp}
     ${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
@@ -68,10 +79,14 @@
 Execute Prometheus Instant Query
     [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}   ${prometheus_user}   ${prometheus_password}   ${querystring}
+    ...                 The requested URL is the next: \${prometheus_url}/api/v1/query?\${querystring}
+    [Arguments]   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}   ${querystring}
+    Log   ${prometheus_url}
+    Log   ${prometheus_user}
+    Log   ${prometheus_password}
+    Log   ${querystring}
     ${auth}=   IF   '${prometheus_password}' != '${EMPTY}'   Create List   ${prometheus_user}   ${prometheus_password}   ELSE   Set Variable   None
-    Create Session   prometheus   http://${prometheus_ip}:${prometheus_port}   timeout=${TIMEOUT}   max_retries=${MAX_RETRIES}   verify=false   auth=${auth}
+    Create Session   prometheus   ${prometheus_url}   timeout=${TIMEOUT}   max_retries=${MAX_RETRIES}   verify=false   auth=${auth}
     ${resp}=   GET On Session   prometheus   /api/v1/query?${querystring}   timeout=${TIMEOUT}
     Status Should Be   200   ${resp}
     RETURN   ${resp.json()}
diff --git a/robot-systest/lib/sdnc_lib.resource b/robot-systest/lib/sdnc_lib.resource
index c9cd8c7..3f04e53 100644
--- a/robot-systest/lib/sdnc_lib.resource
+++ b/robot-systest/lib/sdnc_lib.resource
@@ -79,8 +79,8 @@
 
 Check For SDNC Status
     [Documentation]   Check in a loop if the value of the metric osm_sdnc_status in Prometheus for the SDN controller is 1 (reachable).
-    [Arguments]   ${sdnc_id}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
-    Wait Until Keyword Succeeds   ${SDNC_STATUS_MAX_WAIT_TIME}   ${SDNC_STATUS_POL_TIME}   Check If SDNC Is Available   ${sdnc_id}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
+    [Arguments]   ${sdnc_id}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
+    Wait Until Keyword Succeeds   ${SDNC_STATUS_MAX_WAIT_TIME}   ${SDNC_STATUS_POL_TIME}   Check If SDNC Is Available   ${sdnc_id}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
 
 Get SDNC ID
     [Documentation]   Check if an SDN controller identified by name exists in OSM, and return the id.
@@ -92,6 +92,6 @@
 
 Check If SDNC Is Available
     [Documentation]   Check if the value of the metric osm_sdnc_status in Prometheus for the SDN controller is 1 (reachable).
-    [Arguments]   ${sdnc_id}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
-    ${metric}=   Get Metric   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}   osm_sdnc_status   sdnc_id=${sdnc_id}
+    [Arguments]   ${sdnc_id}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
+    ${metric}=   Get Metric   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}   osm_sdnc_status   sdnc_id=${sdnc_id}
     Should Be Equal As Integers   ${metric}   1   msg=SDNC '${sdnc_id}' is not active   values=false
diff --git a/robot-systest/lib/vim_lib.resource b/robot-systest/lib/vim_lib.resource
index e46f632..4688bf9 100644
--- a/robot-systest/lib/vim_lib.resource
+++ b/robot-systest/lib/vim_lib.resource
@@ -73,15 +73,15 @@
 
 Check For VIM Target Metric
     [Documentation]   Check in a loop if the metric of osm_vim_status is present in Prometheus for the VIM account in OSM.
-    [Arguments]   ${vim_name}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
+    [Arguments]   ${vim_name}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
     ${vim_account_id}=   Get VIM Target ID   ${vim_name}
-    Wait Until Keyword Succeeds   ${VIM_STATUS_MAX_WAIT_TIME}   ${VIM_STATUS_POL_TIME}   Check If VIM Target Has Metric   ${vim_account_id}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
+    Wait Until Keyword Succeeds   ${VIM_STATUS_MAX_WAIT_TIME}   ${VIM_STATUS_POL_TIME}   Check If VIM Target Has Metric   ${vim_account_id}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
 
 Check For VIM Target Status
     [Documentation]   Check in a loop if the value of the metric osm_vim_status in Prometheus for the VIM account is 1 (reachable).
-    [Arguments]   ${vim_name}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
+    [Arguments]   ${vim_name}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
     ${vim_account_id}=   Get VIM Target ID   ${vim_name}
-    Wait Until Keyword Succeeds   ${VIM_STATUS_MAX_WAIT_TIME}   ${VIM_STATUS_POL_TIME}   Check If VIM Target Is Available   ${vim_account_id}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
+    Wait Until Keyword Succeeds   ${VIM_STATUS_MAX_WAIT_TIME}   ${VIM_STATUS_POL_TIME}   Check If VIM Target Is Available   ${vim_account_id}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
 
 Get VIM Target ID
     [Documentation]   Get from OSM the VIM account id associated to the VIM account name passed as parameter.
@@ -105,12 +105,16 @@
 
 Check If VIM Target Is Available
     [Documentation]   Check if the value of the metric osm_vim_status in Prometheus for the VIM account is 1 (reachable).
-    [Arguments]   ${vim_account_id}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
-    ${metric}=   Get Metric   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}   osm_vim_status   vim_account_id=${vim_account_id}
+    [Arguments]   ${vim_account_id}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
+    Log   ${prometheus_url}
+    Log   ${prometheus_user}
+    Log   ${prometheus_password}
+    Log   ${vim_account_id}
+    ${metric}=   Get Metric   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}   osm_vim_status   vim_account_id=${vim_account_id}
     Should Be Equal As Integers   ${metric}   1   msg=VIM Target '${vim_account_id}' is not active   values=false
 
 Check If VIM Target Has Metric
     [Documentation]   Check if the metric of osm_vim_status is present in Prometheus for the VIM account in OSM.
-    [Arguments]   ${vim_account_id}   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}
-    ${metric}=   Get Metric   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}   osm_vim_status   vim_account_id=${vim_account_id}
+    [Arguments]   ${vim_account_id}   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}
+    ${metric}=   Get Metric   ${prometheus_url}   ${prometheus_user}   ${prometheus_password}   osm_vim_status   vim_account_id=${vim_account_id}
     Should Be True   ${metric} <2   msg=VIM Target '${vim_account_id}' has no metric