Add flow table metrics test for Elastic Search TSDR 50/52250/12
authorlbeles <lbeles@frinx.io>
Fri, 24 Feb 2017 13:25:24 +0000 (14:25 +0100)
committerJamo Luhrsen <jluhrsen@redhat.com>
Thu, 13 Apr 2017 22:47:37 +0000 (22:47 +0000)
Change-Id: I8dc51a59e327d82f4533b4e17a9806edab7f71de
Signed-off-by: lbeles <lbeles@frinx.io>
csit/libraries/TsdrUtils.robot
csit/libraries/UtilLibrary.py
csit/scriptplans/tsdr-elasticsearch-datastore.txt [new file with mode: 0644]
csit/suites/tsdr/Elasticsearch/030_FlowTableMetrics.robot [new file with mode: 0644]
csit/suites/tsdr/Elasticsearch/scripts/elasticsearch-startup.sh [new file with mode: 0755]
csit/testplans/tsdr-elasticsearch-datastore.txt [new file with mode: 0644]

index b37f54095c347825fe170ef2a6b09077adc90fe0..398e767d86838625871c478ca4eced4963aaaebd 100644 (file)
@@ -655,3 +655,40 @@ Collect Data from SNMP Agent
     \    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}
     [Return]    ${SNMP_ENTRY}    ${SNMP_VALUES}
+
+Retrieve Value From Elasticsearch
+    [Arguments]    ${data_category}    ${metric_name}    ${node_id}    ${rk_node_id}
+    [Documentation]    Retrieve the last record of Elastic Search from index TSDR. Query is done by data category, metricname and node ID
+    Create Session    session    http://${ODL_SYSTEM_IP}:${ELASTICPORT}    auth=${AUTH}    headers=${HEADERS_QUERY}
+    ${els_query}=    create_query_string_search    ${data_category}    ${metric_name}    ${node_id}    ${rk_node_id}
+    ${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}
+    ${result}=    extract_metric_value_search    ${json}
+    [Teardown]    Delete All Sessions
+    [Return]    ${result}
+
+Check Available values from Elasticsearch
+    [Arguments]    ${data_category}    ${number_items}
+    [Documentation]    Check whether data were sent to Elastic Search. We retrieve all data by data category and then compare its count
+    Create Session    session    http://${ODL_SYSTEM_IP}:${ELASTICPORT}    auth=${AUTH}    headers=${HEADERS_QUERY}
+    ${els_query}=    create_query_string_count    ${data_category}
+    ${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}
+    ${result}=    extract_metric_value_count    ${json}
+    Log To Console    Elasticsearch: Check number of elements
+    Should Be True    ${result} > ${number_items}
+    [Teardown]    Delete All Sessions
+
+Clear Elasticsearch Datastore
+    [Documentation]    Clear Elastic Search Datastore
+    Create Session    session    http://${ODL_SYSTEM_IP}:${ELASTICPORT}    auth=${AUTH}    headers=${HEADERS_QUERY}
+    ${resp}=    RequestsLibrary.Delete_Request    session    tsdr
+    Should Be Equal As Strings    ${resp.status_code}    200
+    [Teardown]    Delete All Sessions
+    [Return]    ${resp.status_code}
index 1b2ead89baf977a2572d098467f3ca8da430a188..e244c334956332de5fd624dc749c52ffe16e8654 100644 (file)
@@ -4,6 +4,7 @@ from SSHLibrary import SSHLibrary
 import robot
 import time
 import re
+import json
 import warnings
 
 
@@ -304,6 +305,41 @@ def flush_iptables(controllers, username, password):
     return flush_result
 
 
+def build_elastic_search_JSON_request(query_String):
+    data = {'from': '0',
+            'size': '1',
+            'sort': [{'TimeStamp': {'order': 'desc'}}],
+            'query': {'query_string': {'query': query_String}}}
+    return json.dumps(data)
+
+
+def create_query_string_search(data_category, metric_name, node_id, rk_node_id):
+    query = 'TSDRDataCategory:'
+    query += data_category
+    query += ' AND MetricName:'
+    query += metric_name
+    query += ' AND NodeID:\"'
+    query += node_id
+    query += '\" AND RecordKeys.KeyValue:\"'
+    query += rk_node_id
+    query += '\" AND RecordKeys.KeyName:Node AND RecordKeys.KeyValue:0 AND RecordKeys.KeyName:Table'
+    return query
+
+
+def create_query_string_count(data_category):
+    query = 'TSDRDataCategory:'
+    query += data_category
+    return query
+
+
+def extract_metric_value_search(response):
+    return str(response['hits']['hits'][0]['_source']['MetricValue'])
+
+
+def extract_metric_value_count(response):
+    return int(response['hits']['total'])
+
+
 #
 # main invoked
 if __name__ != "__main__":
diff --git a/csit/scriptplans/tsdr-elasticsearch-datastore.txt b/csit/scriptplans/tsdr-elasticsearch-datastore.txt
new file mode 100644 (file)
index 0000000..5b77fea
--- /dev/null
@@ -0,0 +1,3 @@
+# Place the scripts in run order:
+integration/test/csit/suites/tsdr/Elasticsearch/scripts/elasticsearch-startup.sh
+
diff --git a/csit/suites/tsdr/Elasticsearch/030_FlowTableMetrics.robot b/csit/suites/tsdr/Elasticsearch/030_FlowTableMetrics.robot
new file mode 100644 (file)
index 0000000..a617512
--- /dev/null
@@ -0,0 +1,93 @@
+*** Settings ***
+Documentation     Test suite for ElasticSearch DataStore PortStats Verification
+Suite Teardown    Stop Tsdr Suite
+Library           SSHLibrary
+Library           Collections
+Library           String
+Library           RequestsLibrary
+Library           ../../../libraries/Common.py
+Resource          ../../../libraries/KarafKeywords.robot
+Resource          ../../../libraries/TsdrUtils.robot
+Resource          ../../../variables/Variables.robot
+
+*** Variables ***
+@{tsdr_pl}
+@{tsdr_af}
+@{tsdr_pm}
+${packetlookup}    flow-table-statistics/packets-looked-up
+${activeflows}    flow-table-statistics/active-flows
+${packetmatched}    flow-table-statistics/packets-matched
+@{openflow_packetlookup}
+@{openflow_activeflows}
+@{openflow_packetmatched}
+
+*** Test Cases ***
+Verification of TSDR ElasticSearch Feature Installation
+    [Documentation]    Install and Verify the Elastic Search Features
+    COMMENT    Install a Feature    odl-tsdr-elasticsearch    ${ODL_SYSTEM_IP}    ${KARAF_SHELL_PORT}    60
+    Install a Feature    odl-tsdr-elasticsearch    ${ODL_SYSTEM_IP}    ${KARAF_SHELL_PORT}    60
+    Install a Feature    odl-tsdr-openflow-statistics-collector    ${ODL_SYSTEM_IP}    ${KARAF_SHELL_PORT}    260
+    COMMENT    Wait Until Keyword Succeeds    24x    10 sec    Check Karaf Log Has Messages    tsdr.openflow
+    Verify Feature Is Installed    odl-tsdr-elasticsearch
+    Verify Feature Is Installed    odl-tsdr-openflow-statistics-collector
+    Start Tsdr Suite
+    Ping All Hosts
+    Clear Elasticsearch Datastore
+    Wait Until Keyword Succeeds    30x    1 sec    Check Available values from Elasticsearch    FLOWTABLESTATS    4571
+
+Comparing Flow Table Metrics
+    [Documentation]    Comparing Flow table values between Elasticsearch and openflow plugin.
+    Getting all Tables from Openflow Plugin
+    Getting all Tables from ElasticSearch datastore
+    Should Be Equal As Strings    ${tsdr_pl}    ${openflow_packetlookup}
+    Should Be Equal As Strings    ${tsdr_af}    ${openflow_activeflows}
+    Should Be Equal As Strings    ${tsdr_pm}    ${openflow_packetmatched}
+
+*** Keywords ***
+Getting all Tables from Openflow Plugin
+    [Documentation]    Getting Flow Table Stats Values from Openflow plugin
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:1/table/0/    ${packetlookup}
+    Append To List    ${openflow_packetlookup}    ${ret}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:2/table/0/    ${packetlookup}
+    Append To List    ${openflow_packetlookup}    ${ret}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:3/table/0/    ${packetlookup}
+    Append To List    ${openflow_packetlookup}    ${ret}
+    Set Suite Variable    @{openflow_packetlookup}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:1/table/0/    ${activeflows}
+    Append To List    ${openflow_activeflows}    ${ret}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:2/table/0/    ${activeflows}
+    Append To List    ${openflow_activeflows}    ${ret}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:3/table/0/    ${activeflows}
+    Append To List    ${openflow_activeflows}    ${ret}
+    Set Suite Variable    @{openflow_activeflows}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:1/table/0/    ${packetmatched}
+    Append To List    ${openflow_packetmatched}    ${ret}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:2/table/0/    ${packetmatched}
+    Append To List    ${openflow_packetmatched}    ${ret}
+    ${ret}=    Get Stats XML    ${OPERATIONAL_NODES_API}/node/openflow:3/table/0/    ${packetmatched}
+    Append To List    ${openflow_packetmatched}    ${ret}
+    Set Suite Variable    @{openflow_packetmatched}
+
+Getting all Tables from ElasticSearch datastore
+    [Documentation]    Getting Flow Table Stats Values from ELK plugin
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    PacketLookup    openflow:1    openflow:1
+    Append To List    ${tsdr_pl}    ${ret}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    PacketLookup    openflow:2    openflow:2
+    Append To List    ${tsdr_pl}    ${ret}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    PacketLookup    openflow:3    openflow:3
+    Append To List    ${tsdr_pl}    ${ret}
+    Set Suite Variable    @{tsdr_pl}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    ActiveFlows    openflow:1    openflow:1
+    Append To List    ${tsdr_af}    ${ret}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    ActiveFlows    openflow:2    openflow:2
+    Append To List    ${tsdr_af}    ${ret}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    ActiveFlows    openflow:3    openflow:3
+    Append To List    ${tsdr_af}    ${ret}
+    Set Suite Variable    @{tsdr_af}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    PacketMatch    openflow:1    openflow:1
+    Append To List    ${tsdr_pm}    ${ret}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    PacketMatch    openflow:2    openflow:2
+    Append To List    ${tsdr_pm}    ${ret}
+    ${ret}=    Retrieve Value From Elasticsearch    FLOWTABLESTATS    PacketMatch    openflow:3    openflow:3
+    Append To List    ${tsdr_pm}    ${ret}
+    Set Suite Variable    @{tsdr_pm}
diff --git a/csit/suites/tsdr/Elasticsearch/scripts/elasticsearch-startup.sh b/csit/suites/tsdr/Elasticsearch/scripts/elasticsearch-startup.sh
new file mode 100755 (executable)
index 0000000..e6ee6d6
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Installation of Elasticsearch.
+cat > ${WORKSPACE}/elasticsearch.sh <<EOF
+EL_PATH=/tmp/elasticsearch/elasticsearch-1.7.5
+LOG_FILE=\$EL_PATH/logs/elasticsearch.log
+
+echo "Start the Elasticsearch Server"
+export JAVA_HOME=/usr
+
+rm \$LOG_FILE
+cd \$EL_PATH/bin
+
+sudo \$EL_PATH/bin/elasticsearch -d
+echo "Check status of the Elasticsearch Server"
+
+sleep 2
+while : ;do
+    [[ -f "\$LOG_FILE" ]] && grep -q "started" "\$LOG_FILE" && echo "Elastic search has been started" && break
+done
+less \$LOG_FILE | grep started
+
+EOF
+
+echo "Copy the Elasticsearch startup script to ${ODL_SYSTEM_IP}"
+scp ${WORKSPACE}/elasticsearch.sh ${ODL_SYSTEM_IP}:/tmp
+ssh ${ODL_SYSTEM_IP} 'bash /tmp/elasticsearch.sh'
+ssh ${ODL_SYSTEM_IP} 'ps -ef | grep elasticsearch'
diff --git a/csit/testplans/tsdr-elasticsearch-datastore.txt b/csit/testplans/tsdr-elasticsearch-datastore.txt
new file mode 100644 (file)
index 0000000..f569d80
--- /dev/null
@@ -0,0 +1,2 @@
+# Place the suites in run order:
+integration/test/csit/suites/tsdr/Elasticsearch