221d9d3d9535a9aeb271ab16b3a427b82c37fa58
[integration/test.git] / csit / suites / controller / benchmark / dsbenchmark.robot
1 *** Settings ***
2 Documentation     MD-SAL Data Store benchmarking.
3 ...
4 ...               Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...               This test suite uses the odl-dsbenchmark-impl feature controlled
11 ...               via dsbenchmark.py tool for testing the MD-SAL Data Store performance.
12 ...               (see the 'https://wiki.opendaylight.org/view/Controller_Core_Functionality_Tutorials:Tutorials:Data_Store_Benchmarking_and_Data_Access_Patterns')
13 ...
14 ...               Based on values in test suite variables it triggers required numbers of
15 ...               warm-up and measured test runs: odl-dsbenchmark-impl module generates
16 ...               (towards MD-SAL Data Store) specified structure, type and number of operations.
17 ...               The test suite performs checks for start-up and test execution timeouts
18 ...               (Start Measurement, Wait For Results) and basic checks for test runs results
19 ...               (Check Results). Finally it provides total numbers per operation structure and type
20 ...               (by default in the perf_per_struct.csv, perf_per_ops.csv files)
21 ...               suitable for plotting in system test environment. See also the
22 ...               'https://wiki.opendaylight.org/view/CrossProject:Integration_Group:System_Test:Step_by_Step_Guide#Optional_-_Plot_a_graph_from_your_job'
23 ...               Included totals can be filtered using the FILTER parameter (RegExp).
24 ...               Because of the way how graphs are drawn, it is recomended to keep
25 ...               all test suite variables unchanged as defined for the 1st build.
26 ...               Parameters WARMUPS, RUNS and accordingly the TIMEOUT value can be changed
27 ...               for each build if needed. Parameter UNITS defines time units returned
28 ...               by odl-dsbenchmark-impl module. The dsbenchmark.py tool always returns
29 ...               values in miliseconds.
30 ...
31 ...               When running this robot suite always use --exclude tag for distinguish
32 ...               the run for 3node setup: need a benchmark for leader and follow (--exclude singlenode_setup)
33 ...               the run for 1node setup: no followr present (--exclude clustered_setup)
34 Suite Setup       Setup_Everything
35 Suite Teardown    Teardown_Everything
36 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
37 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
38 Library           OperatingSystem
39 Library           SSHLibrary    timeout=10s
40 Library           RequestsLibrary
41 Variables         ${CURDIR}/../../../variables/Variables.py
42 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
43 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
44 Resource          ${CURDIR}/../../../libraries/Utils.robot
45 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
46
47 *** Variables ***
48 ${ODL_LOG_LEVEL}    info
49 ${TX_TYPE}        {TX-CHAINING,SIMPLE-TX}
50 ${OP_TYPE}        {PUT,READ,MERGE,DELETE}
51 ${TOTAL_OPS}      100000
52 ${OPS_PER_TX}     100000
53 ${INNER_OPS}      100000
54 ${WARMUPS}        4
55 ${RUNS}           8
56 ${TIMEOUT}        3h
57 ${FILTER}         EXEC
58 ${UNITS}          microseconds
59 ${tool}           dsbenchmark.py
60 ${tool_args}      ${EMPTY}
61 ${tool_startup_timeout}    10s
62 ${tool_log_name}    dsbenchmark.log
63 ${tool_output_name}    test.csv
64 ${tool_results1_name}    perf_per_struct.csv
65 ${tool_results2_name}    perf_per_ops.csv
66
67 *** Test Cases ***
68 Measure_Both_Datastores_For_One_Node_Odl_Setup
69     [Tags]    critical    singlenode_setup
70     [Template]    Measuring_Template
71     leader    {CONFIG,OPERATIONAL}    both_lead_    60s
72
73 Measure_Config_Leader
74     [Tags]    critical    clustered_setup
75     [Template]    Measuring_Template
76     leader    CONFIG    conf_lead_
77
78 Measure_Operational_Leader
79     [Tags]    critical    clustered_setup
80     [Template]    Measuring_Template
81     leader    OPERATIONAL    op_lead_
82
83 Measure_Config_Follwer
84     [Tags]    critical    clustered_setup
85     [Template]    Measuring_Template
86     follower    CONFIG    conf_fol_
87
88 Measure_Operational_Follower
89     [Tags]    critical    clustered_setup
90     [Template]    Measuring_Template
91     follower    OPERATIONAL    op_fol_
92
93 Merge_Csvs_Together
94     [Documentation]    Merge created csvs into given file necause plot plugin cannot have more
95     ...    source files for one graph.
96     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
97     Merge_Csv    perf_per_ops.csv
98     Merge_Csv    perf_per_struct.csv
99
100 *** Keywords ***
101 Setup_Everything
102     [Documentation]    Setup imported resources, SSH-login to mininet machine,
103     ...    create HTTP session, put Python tool to mininet machine.
104     SetupUtils.Setup_Utils_For_Setup_And_Teardown
105     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
106     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
107     Utils.Flexible_Mininet_Login
108     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/mdsal_benchmark/${tool}
109     SSHKeywords.Virtual_Env_Create
110     SSHKeywords.Virtual_Env_Install_Package    requests
111     ClusterManagement.Run_Karaf_Command_On_List_Or_All    log:set ${ODL_LOG_LEVEL}
112
113 Teardown_Everything
114     [Documentation]    Cleaning-up
115     SSHKeywords.Virtual_Env_Delete
116     SSHLibrary.Close_All_Connections
117
118 Start_Benchmark_Tool
119     [Arguments]    ${tested_datastore}    ${tested_node_ip}    ${retry}=${EMPTY}
120     [Documentation]    Start the benchmark tool. Check that it has been running at least for ${tool_startup_timeout} period.
121     ...    If the script exits early, retry once after \${retry} if specified.
122     ${command}=    BuiltIn.Set_Variable    python ${tool} --host ${tested_node_ip} --port ${RESTCONFPORT} --warmup ${WARMUPS} --runs ${RUNS} --total ${TOTAL_OPS} --inner ${INNER_OPS} --txtype ${TX_TYPE} --ops ${OPS_PER_TX} --optype ${OP_TYPE} --plot ${FILTER} --units ${UNITS} --datastore ${tested_datastore} ${tool_args} &> ${tool_log_name}
123     BuiltIn.Log    ${command}
124     SSHKeywords.Virtual_Env_Activate_On_Current_Session
125     ${output}=    SSHLibrary.Write    ${command}
126     ${status}    ${message}=    BuiltIn.Run Keyword And Ignore Error    Write Until Expected Output    ${EMPTY}    ${TOOLS_SYSTEM_PROMPT}    ${tool_startup_timeout}
127     ...    1s
128     BuiltIn.Log    ${status}
129     BuiltIn.Log    ${message}
130     BuiltIn.Return From Keyword If    "${status}" != "PASS"
131     BuiltIn.Run Keyword If    """${retry}""" == ""    BuiltIn.Fail    Benchmark tool is not running.
132     BuiltIn.Comment    An ugly hack for Carbon -all- jobs being slow to finish booting. FIXME: Use WUKS and open a Bug.
133     BuiltIn.Sleep    ${retry}
134     ${output}=    SSHLibrary.Write    ${command}
135     ${status}    ${message}=    BuiltIn.Run Keyword And Ignore Error    Write Until Expected Output    ${EMPTY}    ${TOOLS_SYSTEM_PROMPT}    ${tool_startup_timeout}
136     ...    1s
137     BuiltIn.Log    ${status}
138     BuiltIn.Log    ${message}
139     BuiltIn.Run Keyword If    "${status}" == "PASS"    BuiltIn.Fail    Benchmark tool is not running.
140
141 Wait_Until_Benchmark_Tool_Finish
142     [Arguments]    ${timeout}
143     [Documentation]    Wait until the benchmark tool is finished. Fail in case of test timeout (${timeout}).
144     ...    In order to prevent SSH session from closing due to inactivity, newline is sent every check.
145     BuiltIn.Wait Until Keyword Succeeds    ${timeout}    30s    BuiltIn.Run Keywords    SSHLibrary.Write    ${EMPTY}
146     ...    AND    SSHLibrary.Read Until Prompt
147
148 Stop_Benchmark_Tool
149     [Documentation]    Stop the benchmark tool. Fail if still running.
150     SSHLibrary.Read
151     Utils.Write_Bare_Ctrl_C
152     SSHLibrary.Read Until Prompt
153     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session
154
155 Get_Log_File
156     [Arguments]    ${file_name}
157     [Documentation]    Return and log content of the provided file.
158     ${output_log}=    SSHLibrary.Execute_Command    cat ${file_name}
159     BuiltIn.Log    ${output_log}
160     [Return]    ${output_log}
161
162 Store_File_To_Robot
163     [Arguments]    ${file_name}    ${file_prefix}
164     [Documentation]    Store the provided file from the MININET to the ROBOT machine.
165     ${output_log}=    SSHLibrary.Execute_Command    cat ${file_name}
166     BuiltIn.Log    ${output_log}
167     OperatingSystem.Create_File    ${file_prefix}${file_name}    ${output_log}
168
169 Collect Logs
170     [Documentation]    Collect logs and detailed results for debugging
171     ${files}=    SSHLibrary.List Files In Directory    .
172     ${tool_log}=    Get_Log_File    ${tool_log_name}
173     ${tool_output}=    Get_Log_File    ${tool_output_name}
174     ${tool_results1}=    Get_Log_File    ${tool_results1_name}
175     ${tool_results2}=    Get_Log_File    ${tool_results2_name}
176
177 Check Results
178     [Documentation]    Check outputs for expected content. Fail in case of unexpected content.
179     ${tool_log}=    Get_Log_File    ${tool_log_name}
180     BuiltIn.Should Contain    ${tool_log}    Total execution time:
181     BuiltIn.Should Not Contain    ${tool_log}    status: NOK
182
183 Set_Node_Ip_For_Benchmark
184     [Arguments]    ${state}    ${tested_ds}    ${file_prefix}
185     [Documentation]    Returns the node ip which should be tested
186     BuiltIn.Return From Keyword If    ${NUM_ODL_SYSTEM}==1    ${ODL_SYSTEM_1_IP}
187     ${shard_type}=    BuiltIn.Set_Variable_If    "${tested_ds}"=="CONFIG"    config    operational
188     ${leader}    ${followers}=    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_type=${shard_type}
189     BuiltIn.Return From Keyword If    "${state}"=="leader"    ${ODL_SYSTEM_${leader}_IP}
190     BuiltIn.Return From Keyword    ${ODL_SYSTEM_@{followers}[0]_IP}
191
192 Measuring_Template
193     [Arguments]    ${state}    ${tested_ds}    ${file_prefix}    ${retry}=${EMPTY}
194     [Documentation]    Keywork which will cover a whole banchmark.
195     ...    If ${file_prefix} is ${Empty} we have 1 node odl.
196     ${odl_node_ip}=    Set_Node_Ip_For_Benchmark    ${state}    ${tested_ds}    ${file_prefix}
197     Start_Benchmark_Tool    ${tested_ds}    ${odl_node_ip}    ${retry}
198     Wait_Until_Benchmark_Tool_Finish    ${TIMEOUT}
199     SSHLibrary.File Should Exist    ${tool_results1_name}
200     SSHLibrary.File Should Exist    ${tool_results2_name}
201     Check Results
202     Store_File_To_Robot    ${tool_results1_name}    ${file_prefix}
203     Store_File_To_Robot    ${tool_results2_name}    ${file_prefix}
204     [Teardown]    Stop_Measurement_And_Save_Logs
205
206 Stop_Measurement_And_Save_Logs
207     Stop_Benchmark_Tool
208     Collect Logs
209
210 Merge_Csv
211     [Arguments]    ${final_file}
212     [Documentation]    Creates ${final_file} csv file from existing files in the current directory
213     ${final_columns}=    BuiltIn.Set_Variable    ${Empty}
214     ${final_values}=    BuiltIn.Set_variable    ${Empty}
215     @{csv_files}=    OperatingSystem.List_Files_In_Directory    .    *${final_file}
216     Collections.Sort_List    ${csv_files}
217     : FOR    ${file}    IN    @{csv_files}
218     \    BuiltIn.Log_To_Console    ${file}
219     \    ${csv_content}=    OperatingSystem.GetFile    ${file}
220     \    ${column_names}=    Get_Column_Names    ${file}    ${csv_content}
221     \    ${column_values}=    String.Get_Line    ${csv_content}    1
222     \    ${final_columns}=    BuiltIn.Set_Variable_If    "${final_columns}"=="${Empty}"    ${column_names}    ${final_columns},${column_names}
223     \    ${final_values}=    BuiltIn.Set_Variable_If    "${final_values}"=="${Empty}"    ${column_values}    ${final_values},${column_values}
224     ${content}=    BuiltIn.Catenate    SEPARATOR=${\n}    ${final_columns}    ${final_values}
225     OperatingSystem.Create_File    ${final_file}    ${content}
226
227 Get_Column_Names
228     [Arguments]    ${file_name}    ${file_content}
229     [Documentation]    Returns the first line of the given csv file. It is modified if the file name
230     ...    indicates that it is the file from the shard follower.
231     ${column_names}=    String.Get_Line    ${file_content}    0
232     BuiltIn.Return_From_Keyword_If    "_fol_" not in "${file_name}"    ${column_names}
233     # now we have followers and FOL_ will be prepended to the column names
234     @{columns}    String.Split_String    ${column_names}    ,
235     ${final_columns}    BuiltIn.Set_Variable    ${Empty}
236     : FOR    ${column}    IN    @{columns}
237     \    ${final_columns}    BuiltIn.Set_Variable_If    "${final_columns}"=="${Empty}"    FOL_${column}    ${final_columns},FOL_${column}
238     BuiltIn.Return_From_Keyword    ${final_columns}