Making ssh key configurable in all tests. ${SSH_KEY} variable placed in variables...
[integration/test.git] / test / csit / libraries / TsdrUtils.txt
1 *** Settings ***\r
2 Library           OperatingSystem\r
3 Resource          Utils.txt\r
4 \r
5 *** Variables ***\r
6 ${HBASE_CLIENT}    /tmp/Hbase/hbase-0.94.15/bin\r
7 ${final}          ${EMPTY}\r
8 \r
9 *** Keywords ***\r
10 Start Tsdr Suite\r
11     [Arguments]    ${switch}=ovsk\r
12     [Documentation]    TSDR specific setup/cleanup work that can be done safely before any system\r
13     ...    is run.\r
14     Clean Mininet System\r
15     ${mininet_conn_id1}=    Open Connection    ${MININET}    prompt=${LINUX_PROMPT}    timeout=30s\r
16     Set Suite Variable    ${mininet_conn_id1}\r
17     Login With Public Key    ${MININET_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any\r
18     Execute Command    sudo ovs-vsctl set-manager ptcp:6644\r
19     ${start}=    Set Variable    sudo mn --controller=remote,ip=${CONTROLLER} --topo=linear,3 --switch ${switch},protocols=OpenFlow13\r
20     Log    ${start}\r
21     Write    ${start}\r
22     Read Until    mininet>\r
23 \r
24 Stop Tsdr Suite\r
25     [Documentation]    Cleanup/Shutdown work that should be done at the completion of all\r
26     ...    tests\r
27     Switch Connection    ${mininet_conn_id1}\r
28     Read\r
29     Write    exit\r
30     Read Until    ${LINUX_PROMPT}\r
31     Close Connection\r
32 \r
33 Initialize the HBase for TSDR\r
34     [Documentation]    Install and initialize the tsdr tables on HBase Server\r
35     ${hbase_server}=    Run Command On Remote System    ${CONTROLLER}    export JAVA_HOME=/usr && ${HBASE_CLIENT}/start-hbase.sh    ${MININET_USER}    ${LINUX_PROMPT}    120\r
36     Log    ${hbase_server}\r
37     ${hbase_process}=    Run Command On Remote System    ${CONTROLLER}    ps -ef | grep HMaster\r
38     Log    ${hbase_process}\r
39 \r
40 Stop the HBase Server\r
41     [Documentation]    Stop the HBase server\r
42     ${hbase_server}=    Run Command On Remote System    ${CONTROLLER}    export JAVA_HOME=/usr && ${HBASE_CLIENT}/stop-hbase.sh    ${MININET_USER}    ${LINUX_PROMPT}    90\r
43     Log    ${hbase_server}\r
44 \r
45 Configure the Queue on Switch\r
46     [Arguments]    ${queue_interface}    ${user}=${MININET_USER}    ${prompt}=${LINUX_PROMPT}    ${prompt_timeout}=120s\r
47     [Documentation]    Configure the 2 queues on specified openvswitch interface\r
48     Log    Configure the queue on ${queue_interface}\r
49     ${output}=    Run Command On Remote System    ${MININET}    sudo ovs-vsctl set port ${queue_interface} qos=@newqos -- --id=@newqos create qos type=linux-htb other-config:max-rate=200000000 queues=0=@q0,1=@q1,2=@q2 -- --id=@q0 create queue other-config:min-rate=100000 other-config:max-rate=200000 -- --id=@q1 create queue other-config:min-rate=10001 other-config:max-rate=300000 -- --id=@q2 create queue other-config:min-rate=300001 other-config:max-rate=200000000    ${MININET_USER}    ${LINUX_PROMPT}    90\r
50     Log    ${output}\r
51 \r
52 Query the Data from HBaseClient\r
53     [Arguments]    ${query}    ${remote}=${CONTROLLER}    ${user}=${MININET_USER}    ${prompt}=${LINUX_PROMPT}    ${prompt_timeout}=120s\r
54     [Documentation]    Execute the HBase Query and return the result\r
55     Log    Attempting to execute ${query} on ${remote} via HbaseClient\r
56     ${conn_id}=    Open Connection    ${remote}    prompt=${prompt}    timeout=${prompt_timeout}\r
57     Login With Public Key    ${user}    ${USER_HOME}/.ssh/${SSH_KEY}    any\r
58     Write    export JAVA_HOME=/usr\r
59     Write    ${HBASE_CLIENT}/hbase shell\r
60     Read Until    hbase(main):001:0>\r
61     Write    ${query}\r
62     ${output}=    Read Until    hbase(main):\r
63     Write    exit\r
64     LOG    ${output}\r
65     Comment    ${output}=    Read Until    ${prompt}\r
66     Close Connection\r
67     [Return]    ${output}\r
68 \r
69 Verify the Metric is Collected?\r
70     [Arguments]    ${tsdr_cmd}    ${metric}    ${remote}=${CONTROLLER}    ${user}=${MININET_USER}    ${prompt}=${LINUX_PROMPT}    ${prompt_timeout}=120s\r
71     [Documentation]    Verify the ${tsdr_cmd} output contains ${metric}\r
72     ${output}=    Issue Command On Karaf Console    ${tsdr_cmd}    ${CONTROLLER}    ${KARAF_SHELL_PORT}    ${prompt_timeout}\r
73     Should Contain    ${output}    ${metric}\r
74 \r
75 Prepare HBase Filter\r
76     [Arguments]    ${left_str}    ${right_str}    ${connector}\r
77     [Documentation]    Prepare the Hbase Filter from Tsdr List output\r
78     ${left_str}=    Remove Space on String    ${left_str}\r
79     ${right_str}=    Remove Space on String    ${right_str}    1\r
80     ${x}=    Run Keyword If    '${left_str}' == 'MetricID'    Catenate    ${SPACE}    _    ELSE IF\r
81     ...    '${left_str}' == 'ObjectKeys'    Catenate    ${right_str}    _    ELSE IF    '${left_str}' == 'TimeStamp'\r
82     ...    Get Epoch Time    ${right_str}    ELSE    Catenate    ${SPACE}\r
83     [Return]    ${x}\r
84 \r
85 Create the Hbase table row\r
86     [Arguments]    ${tsdr_line}    ${metrics}\r
87     [Documentation]    Create the Hbase table row from tsdr:list\r
88     @{words}=    Split String    ${tsdr_line}    |\r
89     : FOR    ${li}    IN    @{words}\r
90     \    ${key}=    Fetch From Left    ${li}    =\r
91     \    ${value}=    Fetch From Right    ${li}    =\r
92     \    ${each_value}=    Prepare HBase Filter    ${key}    ${value}    _\r
93     \    ${final}=    Concatenate the String    ${final}    ${each_value}\r
94     ${query}=    Concatenate the String    ${metrics}    ${final}\r
95     ${query}=    Remove Space on String    ${query}\r
96     [Return]    ${query}\r
97 \r
98 Query Metrics on H2 Datastore\r
99     [Arguments]    ${category}    ${attribute}    ${nodeid}=openflow:1\r
100     [Documentation]    Generate the JDBC query for H2 Datastore\r
101     ${h2_query}=    Concatenate the String    jdbc:query metric "select * from Metric where MetricCategory=    '${category}' and\r
102     ${h2_query}=    Concatenate the String    ${h2_query}    MetricName = '${attribute}' and NODEID = '${nodeid}' order by ID desc limit 5"\r
103     ${output}=    Issue Command On Karaf Console    ${h2_query}    ${CONTROLLER}    ${KARAF_SHELL_PORT}    30\r
104     [Return]    ${output}\r
105 \r
106 Generate HBase Query\r
107     [Arguments]    ${table}    ${filter}\r
108     [Documentation]    Scan the Hbase Table with Filter\r
109     ${hbase_query}=    Concatenate the String    scan    '${table}'\r
110     ${hbase_query}=    Concatenate the String    ${hbase_query}    ,{ FILTER =>\"(RowFilter(=,\r
111     ${hbase_query}=    Concatenate the String    ${hbase_query}    'regexstring:${filter}*\'))\",LIMIT=>10}\r
112     [Return]    ${hbase_query}\r
113 \r
114 Get Metrics Value\r
115     [Arguments]    ${tsdr_line}\r
116     [Documentation]    Get Metric Value from tsdr:list\r
117     ${value}=    Fetch From Right    ${tsdr_line}    |\r
118     ${value}=    Replace String    ${value}    MetricValue    value\r
119     ${value}=    Replace String    ${value}    [m    ${EMPTY}\r
120     ${value}=    Replace String    ${value}    =    \=\r
121     ${value}=    Remove Space on String    ${value}\r
122     ${value}=    Convert to String    ${value}\r
123     [Return]    ${value}\r
124 \r
125 Verify the Metrics Attributes on Hbase Client\r
126     [Arguments]    ${attribute}    ${rowfilter}    ${table}=PortStats\r
127     [Documentation]    Verification on Metrics attributes on Hbase Client\r
128     ${pattern}=    Concatenate the String    ${attribute}    _\r
129     ${pattern}=    Concatenate the String    ${pattern}    ${rowfilter}\r
130     ${pattern}=    Remove Space on String    ${pattern}\r
131     ${query}=    Generate HBase Query    ${table}    ${pattern}\r
132     ${out}=    Query the Data from HBaseClient    ${query}\r
133     Should Match Regexp    ${out}    (?mui)${attribute}\r