Define sulfur version
[integration/test.git] / csit / libraries / RestPerfClient.robot
1 *** Settings ***
2 Documentation     RestPerfClient handling singleton resource.
3 ...
4 ...               Copyright (c) 2016,2017 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 ...
11 ...               This singleton manages RestPerfClient invocation, tracks the log file
12 ...               produced by the invocation, allows the test suite to easily search this
13 ...               log file and collect it once done.
14 ...
15 ...               TODO: RemoteBash.robot contains logic which could be reused here.
16 ...
17 ...               TODO: Currently only one RestPerfClient invocation running at a time is
18 ...               supported. Support for multiple concurrently running RestPerfClient
19 ...               invocations might be needed for example when performance testing cluster
20 ...               nodes. However no such suites are planned for now.
21 ...
22 ...               FIXME: There may be suites which want to use this Resource without
23 ...               NetconfKeywords, in which case NexusKeywords will not be initialized
24 ...               and Setup_Restperfclient will fail. Fixing this problem will require
25 ...               updating NexusKeywords initialization (which may break other suites)
26 ...               and currently all suites using this use also NetconfKeywords so this
27 ...               was postponed. Workaround for the problem: Initialize NexusKeywords
28 ...               manually before initializing this resource.
29 Library           DateTime
30 Library           SSHLibrary
31 Resource          ${CURDIR}/NexusKeywords.robot
32 Resource          ${CURDIR}/SetupUtils.robot
33 Resource          ${CURDIR}/SSHKeywords.robot
34 Resource          ${CURDIR}/Utils.robot
35 Resource          ${CURDIR}/RemoteBash.robot
36
37 *** Variables ***
38 ${RestPerfClient__restperfclientlog}    ${EMPTY}
39
40 *** Keywords ***
41 Setup_Restperfclient
42     [Arguments]    ${build_version}=${EMPTY}    ${build_location}=${EMPTY}
43     [Documentation]    Deploy RestPerfClient and determine the Java command to use to call it.
44     ...    Open a SSH connection through which the RestPerfClient will be
45     ...    invoked, deploy RestPerfClient and the data files it needs to do
46     ...    its work and initialize the internal state for the remaining
47     ...    keywords.
48     ${connection}=    SSHKeywords.Open_Connection_To_Tools_System
49     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient}    ${connection}
50     SSHLibrary.Put_File    ${CURDIR}/../variables/netconf/RestPerfClient/request1.json
51     ${filename}=    Run Keyword If    '${IS_KARAF_APPL}' == 'False'    Set Variable    ${RESTPERF_FILENAME}
52     ...    ELSE    NexusKeywords.Deploy_Test_Tool    netconf    netconf-testtool    rest-perf-client
53     ${prefix}=    NexusKeywords.Compose_Full_Java_Command    -Xmx4G -jar ${filename}
54     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix}    ${prefix}
55
56 RestPerfClient__Kill
57     RemoteBash.Write_Bare_Ctrl_C
58     SSHLibrary.Set_Client_Configuration    timeout=5
59     SSHLibrary.Read_Until_Prompt
60
61 Restperfclient__Wait_For_Finish
62     SSHLibrary.Write    ${Empty}
63     ${stdout}=    SSHLibrary.Read_Until_Prompt
64
65 Restperfclient__Invoke_With_Timeout
66     [Arguments]    ${timeout}    ${command}
67     ${stdout}=    SSHLibrary.Read
68     BuiltIn.Log    ${stdout}
69     ${cmd}=    BuiltIn.Set_Variable    ${command} 2>&1 | tee ${RestPerfClient__restperfclientlog}
70     SSHLibrary.Write    ${cmd}
71     SSHLibrary.Set_Client_Configuration    timeout=120
72     BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    1s    Restperfclient__Wait_For_Finish
73     Execute_Command_Passes    cat ${RestPerfClient__restperfclientlog}
74
75 Invoke_Restperfclient
76     [Arguments]    ${timeout}    ${url}    ${testcase}=${EMPTY}    ${ip}=${ODL_SYSTEM_IP}    ${port}=${RESTCONFPORT}    ${count}=${REQUEST_COUNT}
77     ...    ${async}=false    ${user}=${ODL_RESTCONF_USER}    ${password}=${ODL_RESTCONF_PASSWORD}
78     [Documentation]    Invoke RestPerfClient on the specified URL with the specified timeout.
79     ...    Assemble the RestPerfClient invocation commad, setup the specified
80     ...    timeout for the SSH connection, invoke the assembled command and
81     ...    then check that RestPerfClient finished its run correctly.
82     ${restperfclient_running}=    Set_Variable    False
83     ${logname}=    Utils.Get_Log_File_Name    restperfclient    ${testcase}
84     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${logname}
85     ${options}=    BuiltIn.Set_Variable    --ip ${ip} --port ${port} --edits ${count}
86     ${options}=    BuiltIn.Set_Variable    ${options} --edit-content request1.json --async-requests ${async}
87     ${options}=    BuiltIn.Set_Variable    ${options} --auth ${user} ${password}
88     ${timeout_in_minutes}=    Utils.Convert_To_Minutes    ${timeout}
89     ${options}=    BuiltIn.Set_Variable    ${options} --timeout ${timeout_in_minutes} --destination ${url}
90     ${command}=    BuiltIn.Set_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix} ${options}
91     BuiltIn.Log    Running restperfclient: ${command}
92     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
93     ${keyword_timeout}=    DateTime.Add_Time_To_Time    ${timeout}    2m    result_format=compact
94     SetupUtils.Set_Known_Bug_Id    5413
95     ${restperfclient_running}=    Set_Variable    True
96     Restperfclient__Invoke_With_Timeout    ${keyword_timeout}    ${command}
97     ${restperfclient_running}=    Set_Variable    False
98     SetupUtils.Set_Unknown_Bug_Id
99     ${result}=    Grep_Restperfclient_Log    FINISHED. Execution time:
100     BuiltIn.Should_Not_Be_Equal    '${result}'    ''
101     [Teardown]    BuiltIn.Run_Keyword_If    ${restperfclient_running}    BuiltIn.Run_Keyword_And_Ignore_Error    RestPerfClient__Kill
102
103 Grep_Restperfclient_Log
104     [Arguments]    ${pattern}
105     [Documentation]    Search for the specified string in the log file produced by latest invocation of RestPerfClient
106     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
107     ${result}=    SSHLibrary.Execute_Command    grep '${pattern}' ${RestPerfClient__restperfclientlog}
108     [Return]    ${result}
109
110 Collect_From_Restperfclient
111     [Documentation]    Collect useful data produced by restperfclient
112     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
113     SSHLibrary.Get_File    ${RestPerfClient__restperfclientlog}
114     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${EMPTY}
115
116 Teardown_Restperfclient
117     [Documentation]    Free resources allocated during the RestPerfClient setup
118     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
119     SSHLibrary.Close_Connection