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