Add TopologyNetconfNodes.py library
[integration/test.git] / csit / libraries / TsdrUtils.robot
index 398e767d86838625871c478ca4eced4963aaaebd..9c3604e85372ff6bd3c92d95028db61a74740c84 100644 (file)
@@ -8,7 +8,6 @@ Library           DateTime
 Resource          Utils.robot
 Variables         ../variables/Variables.py
 Library           json
-Library           HttpLibrary.HTTP
 Library           Process
 
 *** Variables ***
@@ -171,11 +170,12 @@ Create the Hbase table row
     [Arguments]    ${tsdr_line}    ${metrics}
     [Documentation]    Create the Hbase table row from tsdr:list
     @{words}=    Split String    ${tsdr_line}    |
-    : FOR    ${li}    IN    @{words}
-    \    ${key}=    Fetch From Left    ${li}    =
-    \    ${value}=    Fetch From Right    ${li}    =
-    \    ${each_value}=    Prepare HBase Filter    ${key}    ${value}    _
-    \    ${final}=    Concatenate the String    ${final}    ${each_value}
+    FOR    ${li}    IN    @{words}
+        ${key}=    Fetch From Left    ${li}    =
+        ${value}=    Fetch From Right    ${li}    =
+        ${each_value}=    Prepare HBase Filter    ${key}    ${value}    _
+        ${final}=    Concatenate the String    ${final}    ${each_value}
+    END
     ${query}=    Concatenate the String    ${metrics}    ${final}
     ${query}=    Remove Space on String    ${query}
     [Return]    ${query}
@@ -374,7 +374,7 @@ Get Stats XML
     [Documentation]    Parse the xml output and returns it.
     ${sid}=    RequestsLibrary.Create_Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    headers=${SEND_ACCEPT_XML_HEADERS}    auth=${AUTH}
     ${resp}=    RequestsLibrary.Get Request    session    ${query}    headers=${SEND_ACCEPT_XML_HEADERS}
-    ${resp_xml}=    Parse XML    ${resp.content}
+    ${resp_xml}=    Parse XML    ${resp.text}
     ${id1}=    Get Element Text    ${resp_xml}    ${xpath}
     Delete All Sessions
     [Return]    ${id1}
@@ -384,7 +384,7 @@ Return all XML matches
     [Documentation]    Returns all the values from xpath
     ${sid}=    RequestsLibrary.Create_Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    headers=${SEND_ACCEPT_XML_HEADERS}    auth=${AUTH}
     ${resp}=    RequestsLibrary.Get Request    session    ${query}    headers=${SEND_ACCEPT_XML_HEADERS}
-    ${resp_xml}=    Parse XML    ${resp.content}
+    ${resp_xml}=    Parse XML    ${resp.text}
     @{id1}=    Get Elements Texts    ${resp_xml}    ${xpath}
     Delete All Sessions
     [Return]    @{id1}
@@ -424,11 +424,12 @@ Verify the Metrics Syslog on Cassandra Client
 Iterating over metricpath
     [Documentation]    Used to traverse over metricpath file and traverse over metricpath file and get the keys
     @{mp_lines}=    Read File and Return Split Lines    ${CASSANDRA_DB_PATH}${metric_path}
-    : FOR    ${line}    IN    @{mp_lines}
-    \    @{split_line}=    Split String    ${line}    ${SPACE}
-    \    ${keya}=    Get From List    ${split_line}    1
-    \    ${keyb}=    Get From List    ${split_line}    2
-    \    Iterating over metricval    ${keya}    ${keyb}
+    FOR    ${line}    IN    @{mp_lines}
+        @{split_line}=    Split String    ${line}    ${SPACE}
+        ${keya}=    Get From List    ${split_line}    1
+        ${keyb}=    Get From List    ${split_line}    2
+        Iterating over metricval    ${keya}    ${keyb}
+    END
 
 Iterating over metricval
     [Arguments]    ${keya}    ${keyb}
@@ -465,7 +466,7 @@ Generate TSDR Query
     [Documentation]    Issues TSDR Query and returns the list
     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_QUERY}
     ${resp}=    RequestsLibrary.Get Request    session    /tsdr/metrics/query?tsdrkey="[NID=${NID}][DC=${DC}][MN=${MN}][RK=${RK}]"&from=${from}&until=${until}    headers=${HEADERS_QUERY}
-    @{convert}=    Parse Json    ${resp.content}
+    @{convert}=    Parse Json    ${resp.text}
     Delete All Sessions
     [Return]    @{convert}
 
@@ -475,10 +476,10 @@ Generate TSDR NBI
     [Documentation]    Issues TSDR Query and returns the list
     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_QUERY}
     ${resp}=    RequestsLibrary.Get Request    session    /tsdr/nbi/render?target="[NID=${NID}][DC=${DC}][MN=${MN}][RK=${RK}]"&from=${from}&until=${until}&maxDataPoints=${datapts}    headers=${HEADERS_QUERY}
-    @{convert}=    Parse Json    ${resp.content}
+    @{convert}=    Parse Json    ${resp.text}
     ${dict_convert}=    Convert To Dictionary    @{convert}
     @{dict}=    Get Dictionary Values    ${dict_convert}
-    @{datapoints_list}=    Convert to List    @{dict}[0]
+    ${datapoints_list}=    Convert to List    ${dict}[0]
     Delete All Sessions
     [Return]    @{datapoints_list}
 
@@ -564,14 +565,16 @@ Evaluate Datasets Length
 Evaluate Datasets Value
     [Arguments]    ${tsdr_lines}    ${query_output}    ${nbi_output}    ${TYPE}
     [Documentation]    Compare the outputs returned from all Data Stores
-    FOR    ${q_item}    ${t_item}    ${n_item}    IN ZIP    ${query_output}    ${tsdr_lines}
+    FOR    ${q_item}    ${t_item}    ${n_item}    IN ZIP    ${query_output}    ${tsdr_lines}
     ...    ${nbi_output}
-    \    ${query_row}=    Extract Row Values from TSDR Query    ${q_item}    ${t_item}    ${n_item}    ${TYPE}
-    : FOR    ${found_line}    IN    @{matching_list}
-    \    @{split_line}=    Split String    ${found_line}    |
-    \    ${hex_name}=    Get From List    ${split_line}    2
-    \    ${if_desc}=    Decode Bytes To String    ${hex_name}    HEX
-    \    Append To List    ${ifdesc_list}    ${if_desc}
+        ${query_row}=    Extract Row Values from TSDR Query    ${q_item}    ${t_item}    ${n_item}    ${TYPE}
+    END
+    FOR    ${found_line}    IN    @{matching_list}
+        @{split_line}=    Split String    ${found_line}    |
+        ${hex_name}=    Get From List    ${split_line}    2
+        ${if_desc}=    Decode Bytes To String    ${hex_name}    HEX
+        Append To List    ${ifdesc_list}    ${if_desc}
+    END
     [Return]    @{ifdesc_list}
 
 Write SNMP config
@@ -597,63 +600,64 @@ Collect Data from SNMP Agent
     ${snmpagentcreate_json}=    json.dumps    ${snmpagentcreate}
     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_QUERY}
     ${resp}=    RequestsLibrary.Post Request    session    /restconf/operations/snmp:get-interfaces    data=${snmpagentcreate_json}
-    ${convert}=    To Json    ${resp.content}
+    ${convert}=    To Json    ${resp.text}
     @{dict1}=    Get Dictionary Keys    ${convert}
     ${dict1_0}=    Get From List    ${dict1}    0
     ${dict1_val}=    Get From Dictionary    ${convert}    ${dict1_0}
     @{ifEntry}=    Get From Dictionary    ${dict1_val}    ifEntry
     @{SNMP_ENTRY}=    Create List
     @{SNMP_VALUES}=    Create List
-    : FOR    ${int}    IN    @{ifEntry}
-    \    ${ifindex}=    Get From Dictionary    ${int}    ifIndex
-    \    ${ifOutDiscards}=    Get From Dictionary    ${int}    ifOutDiscards
-    \    ${ifInDiscards}=    Get From Dictionary    ${int}    ifInDiscards
-    \    ${ifType}=    Get From Dictionary    ${int}    ifType
-    \    ${ifInOctets}=    Get From Dictionary    ${int}    ifInOctets
-    \    ${ifSpeed}=    Get From Dictionary    ${int}    ifSpeed
-    \    ${ifOutQLen}=    Get From Dictionary    ${int}    ifOutQLen
-    \    ${ifOutErrors}=    Get From Dictionary    ${int}    ifOutErrors
-    \    ${ifPhysAddress}=    Get From Dictionary    ${int}    ifPhysAddress
-    \    ${ifInUcastPkts}=    Get From Dictionary    ${int}    ifInUcastPkts
-    \    ${ifOutNUcastPkts}=    Get From Dictionary    ${int}    ifOutNUcastPkts
-    \    ${ifInErrors}=    Get From Dictionary    ${int}    ifInErrors
-    \    ${ifOutOctets}=    Get From Dictionary    ${int}    ifOutOctets
-    \    ${ifAdminStatus1}=    Get From Dictionary    ${int}    ifAdminStatus
-    \    ${ifAdminStatus}=    Get From Dictionary    ${OPER_STATUS}    ${ifAdminStatus1}
-    \    ${ifInUnknownProtos}=    Get From Dictionary    ${int}    ifInUnknownProtos
-    \    ${ifOutUcastPkts}=    Get From Dictionary    ${int}    ifOutUcastPkts
-    \    ${ifInNUcastPkts}=    Get From Dictionary    ${int}    ifInNUcastPkts
-    \    ${ifMtu}=    Get From Dictionary    ${int}    ifMtu
-    \    ${ifOperStatus1}=    Get From Dictionary    ${int}    ifOperStatus
-    \    ${ifOperStatus}=    Get From Dictionary    ${OPER_STATUS}    ${ifOperStatus1}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutDiscards | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutDiscards
-    \    Append To List    ${SNMP_VALUES}    ${ifOutDiscards}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInDiscards | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInDiscards
-    \    Append To List    ${SNMP_VALUES}    ${ifInDiscards}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInOctets | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInOctets
-    \    Append To List    ${SNMP_VALUES}    ${ifInOctets}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutQLen | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutQLen
-    \    Append To List    ${SNMP_VALUES}    ${ifOutQLen}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutErrors | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutErrors
-    \    Append To List    ${SNMP_VALUES}    ${ifOutErrors}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInUcastPkts
-    \    Append To List    ${SNMP_VALUES}    ${ifInUcastPkts}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutNUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutNUcastPkts
-    \    Append To List    ${SNMP_VALUES}    ${ifOutNUcastPkts}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInErrors | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInErrors
-    \    Append To List    ${SNMP_VALUES}    ${ifInErrors}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutOctets | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutOctets
-    \    Append To List    ${SNMP_VALUES}    ${ifOutOctets}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfAdminStatus | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfAdminStatus
-    \    Append To List    ${SNMP_VALUES}    ${ifAdminStatus}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInUnknownProtos | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInUnknownProtos
-    \    Append To List    ${SNMP_VALUES}    ${ifInUnknownProtos}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutUcastPkts
-    \    Append To List    ${SNMP_VALUES}    ${ifOutUcastPkts}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInNUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInNUcastPkts
-    \    Append To List    ${SNMP_VALUES}    ${ifInNUcastPkts}
-    \    Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOperStatus | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOperStatus
-    \    Append To List    ${SNMP_VALUES}    ${ifOperStatus}
+    FOR    ${int}    IN    @{ifEntry}
+        ${ifindex}=    Get From Dictionary    ${int}    ifIndex
+        ${ifOutDiscards}=    Get From Dictionary    ${int}    ifOutDiscards
+        ${ifInDiscards}=    Get From Dictionary    ${int}    ifInDiscards
+        ${ifType}=    Get From Dictionary    ${int}    ifType
+        ${ifInOctets}=    Get From Dictionary    ${int}    ifInOctets
+        ${ifSpeed}=    Get From Dictionary    ${int}    ifSpeed
+        ${ifOutQLen}=    Get From Dictionary    ${int}    ifOutQLen
+        ${ifOutErrors}=    Get From Dictionary    ${int}    ifOutErrors
+        ${ifPhysAddress}=    Get From Dictionary    ${int}    ifPhysAddress
+        ${ifInUcastPkts}=    Get From Dictionary    ${int}    ifInUcastPkts
+        ${ifOutNUcastPkts}=    Get From Dictionary    ${int}    ifOutNUcastPkts
+        ${ifInErrors}=    Get From Dictionary    ${int}    ifInErrors
+        ${ifOutOctets}=    Get From Dictionary    ${int}    ifOutOctets
+        ${ifAdminStatus1}=    Get From Dictionary    ${int}    ifAdminStatus
+        ${ifAdminStatus}=    Get From Dictionary    ${OPER_STATUS}    ${ifAdminStatus1}
+        ${ifInUnknownProtos}=    Get From Dictionary    ${int}    ifInUnknownProtos
+        ${ifOutUcastPkts}=    Get From Dictionary    ${int}    ifOutUcastPkts
+        ${ifInNUcastPkts}=    Get From Dictionary    ${int}    ifInNUcastPkts
+        ${ifMtu}=    Get From Dictionary    ${int}    ifMtu
+        ${ifOperStatus1}=    Get From Dictionary    ${int}    ifOperStatus
+        ${ifOperStatus}=    Get From Dictionary    ${OPER_STATUS}    ${ifOperStatus1}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutDiscards | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutDiscards
+        Append To List    ${SNMP_VALUES}    ${ifOutDiscards}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInDiscards | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInDiscards
+        Append To List    ${SNMP_VALUES}    ${ifInDiscards}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInOctets | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInOctets
+        Append To List    ${SNMP_VALUES}    ${ifInOctets}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutQLen | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutQLen
+        Append To List    ${SNMP_VALUES}    ${ifOutQLen}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutErrors | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutErrors
+        Append To List    ${SNMP_VALUES}    ${ifOutErrors}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInUcastPkts
+        Append To List    ${SNMP_VALUES}    ${ifInUcastPkts}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutNUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutNUcastPkts
+        Append To List    ${SNMP_VALUES}    ${ifOutNUcastPkts}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInErrors | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInErrors
+        Append To List    ${SNMP_VALUES}    ${ifInErrors}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutOctets | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutOctets
+        Append To List    ${SNMP_VALUES}    ${ifOutOctets}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfAdminStatus | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfAdminStatus
+        Append To List    ${SNMP_VALUES}    ${ifAdminStatus}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInUnknownProtos | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInUnknownProtos
+        Append To List    ${SNMP_VALUES}    ${ifInUnknownProtos}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOutUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOutUcastPkts
+        Append To List    ${SNMP_VALUES}    ${ifOutUcastPkts}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfInNUcastPkts | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfInNUcastPkts
+        Append To List    ${SNMP_VALUES}    ${ifInNUcastPkts}
+        Append To List    ${SNMP_ENTRY}    grep NID=${SNMP_IP} | grep DC=SNMPINTERFACES | grep MN=IfOperStatus | grep RK=ifIndex:${ifindex},ifName:Iso88023Csmacd,SnmpMetric:IfOperStatus
+        Append To List    ${SNMP_VALUES}    ${ifOperStatus}
+    END
     [Return]    ${SNMP_ENTRY}    ${SNMP_VALUES}
 
 Retrieve Value From Elasticsearch
@@ -664,8 +668,8 @@ Retrieve Value From Elasticsearch
     ${els_JSON_request}=    build_elastic_search_JSON_request    ${els_query}
     ${resp}=    RequestsLibrary.Post_Request    session    _search?pretty    data=${els_JSON_request}
     Should Be Equal As Strings    ${resp.status_code}    200
-    @{convert}=    Parse Json    ${resp.content}
-    ${json}=    RequestsLibrary.To Json    ${resp.content}
+    @{convert}=    Parse Json    ${resp.text}
+    ${json}=    RequestsLibrary.To Json    ${resp.text}
     ${result}=    extract_metric_value_search    ${json}
     [Teardown]    Delete All Sessions
     [Return]    ${result}
@@ -678,8 +682,8 @@ Check Available values from Elasticsearch
     ${els_JSON_request}=    build_elastic_search_JSON_request    ${els_query}
     ${resp}=    RequestsLibrary.Post_Request    session    _search?pretty    data=${els_JSON_request}
     Should Be Equal As Strings    ${resp.status_code}    200
-    @{convert}=    Parse Json    ${resp.content}
-    ${json}=    RequestsLibrary.To Json    ${resp.content}
+    @{convert}=    Parse Json    ${resp.text}
+    ${json}=    RequestsLibrary.To Json    ${resp.text}
     ${result}=    extract_metric_value_count    ${json}
     Log To Console    Elasticsearch: Check number of elements
     Should Be True    ${result} > ${number_items}