From 7ca6a5911744e68df509d1bcf509884310f3b765 Mon Sep 17 00:00:00 2001 From: lbeles Date: Fri, 24 Feb 2017 14:25:24 +0100 Subject: [PATCH] Add flow table metrics test for Elastic Search TSDR Change-Id: I8dc51a59e327d82f4533b4e17a9806edab7f71de Signed-off-by: lbeles --- csit/libraries/TsdrUtils.robot | 37 ++++++++ csit/libraries/UtilLibrary.py | 36 +++++++ .../tsdr-elasticsearch-datastore.txt | 3 + .../Elasticsearch/030_FlowTableMetrics.robot | 93 +++++++++++++++++++ .../scripts/elasticsearch-startup.sh | 28 ++++++ .../tsdr-elasticsearch-datastore.txt | 2 + 6 files changed, 199 insertions(+) create mode 100644 csit/scriptplans/tsdr-elasticsearch-datastore.txt create mode 100644 csit/suites/tsdr/Elasticsearch/030_FlowTableMetrics.robot create mode 100755 csit/suites/tsdr/Elasticsearch/scripts/elasticsearch-startup.sh create mode 100644 csit/testplans/tsdr-elasticsearch-datastore.txt diff --git a/csit/libraries/TsdrUtils.robot b/csit/libraries/TsdrUtils.robot index b37f54095c..398e767d86 100644 --- a/csit/libraries/TsdrUtils.robot +++ b/csit/libraries/TsdrUtils.robot @@ -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} diff --git a/csit/libraries/UtilLibrary.py b/csit/libraries/UtilLibrary.py index 1b2ead89ba..e244c33495 100644 --- a/csit/libraries/UtilLibrary.py +++ b/csit/libraries/UtilLibrary.py @@ -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 index 0000000000..5b77fea3de --- /dev/null +++ b/csit/scriptplans/tsdr-elasticsearch-datastore.txt @@ -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 index 0000000000..a617512291 --- /dev/null +++ b/csit/suites/tsdr/Elasticsearch/030_FlowTableMetrics.robot @@ -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 index 0000000000..e6ee6d6027 --- /dev/null +++ b/csit/suites/tsdr/Elasticsearch/scripts/elasticsearch-startup.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Installation of Elasticsearch. +cat > ${WORKSPACE}/elasticsearch.sh <