Remove code for genius
[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
30 Library             DateTime
31 Library             SSHLibrary
32 Resource            ${CURDIR}/NexusKeywords.robot
33 Resource            ${CURDIR}/SetupUtils.robot
34 Resource            ${CURDIR}/SSHKeywords.robot
35 Resource            ${CURDIR}/Utils.robot
36 Resource            ${CURDIR}/RemoteBash.robot
37
38
39 *** Variables ***
40 ${RestPerfClient__restperfclientlog}    ${EMPTY}
41
42
43 *** Keywords ***
44 Setup_Restperfclient
45     [Documentation]    Deploy RestPerfClient and determine the Java command to use to call it.
46     ...    Open a SSH connection through which the RestPerfClient will be
47     ...    invoked, deploy RestPerfClient and the data files it needs to do
48     ...    its work and initialize the internal state for the remaining
49     ...    keywords.
50     [Arguments]    ${build_version}=${EMPTY}    ${build_location}=${EMPTY}
51     ${connection}=    SSHKeywords.Open_Connection_To_Tools_System
52     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient}    ${connection}
53     SSHLibrary.Put_File    ${CURDIR}/../variables/netconf/RestPerfClient/request1.json
54     IF    '${IS_KARAF_APPL}' == 'False'
55         ${filename}=    Set Variable    ${RESTPERF_FILENAME}
56     ELSE
57         ${filename}=    NexusKeywords.Deploy_Test_Tool    netconf    netconf-testtool    rest-perf-client
58     END
59     ${prefix}=    NexusKeywords.Compose_Full_Java_Command    -Xmx4G -jar ${filename}
60     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix}    ${prefix}
61
62 RestPerfClient__Kill
63     RemoteBash.Write_Bare_Ctrl_C
64     SSHLibrary.Set_Client_Configuration    timeout=5
65     SSHLibrary.Read_Until_Prompt
66
67 Restperfclient__Wait_For_Finish
68     SSHLibrary.Write    ${Empty}
69     ${stdout}=    SSHLibrary.Read_Until_Prompt
70
71 Restperfclient__Invoke_With_Timeout
72     [Arguments]    ${timeout}    ${command}
73     ${stdout}=    SSHLibrary.Read
74     BuiltIn.Log    ${stdout}
75     ${cmd}=    BuiltIn.Set_Variable    ${command} 2>&1 | tee ${RestPerfClient__restperfclientlog}
76     SSHLibrary.Write    ${cmd}
77     SSHLibrary.Set_Client_Configuration    timeout=120
78     BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    1s    Restperfclient__Wait_For_Finish
79     Execute_Command_Passes    cat ${RestPerfClient__restperfclientlog}
80
81 Invoke_Restperfclient
82     [Documentation]    Invoke RestPerfClient on the specified URL with the specified timeout.
83     ...    Assemble the RestPerfClient invocation commad, setup the specified
84     ...    timeout for the SSH connection, invoke the assembled command and
85     ...    then check that RestPerfClient finished its run correctly.
86     [Arguments]    ${timeout}    ${url}    ${testcase}=${EMPTY}    ${ip}=${ODL_SYSTEM_IP}    ${port}=${RESTCONFPORT}    ${count}=${REQUEST_COUNT}
87     ...    ${async}=false    ${user}=${ODL_RESTCONF_USER}    ${password}=${ODL_RESTCONF_PASSWORD}
88     ${restperfclient_running}=    Set_Variable    False
89     ${logname}=    Utils.Get_Log_File_Name    restperfclient    ${testcase}
90     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${logname}
91     ${options}=    BuiltIn.Set_Variable    --ip ${ip} --port ${port} --edits ${count}
92     ${options}=    BuiltIn.Set_Variable    ${options} --edit-content request1.json --async-requests ${async}
93     ${options}=    BuiltIn.Set_Variable    ${options} --auth ${user} ${password}
94     ${timeout_in_minutes}=    Utils.Convert_To_Minutes    ${timeout}
95     ${options}=    BuiltIn.Set_Variable    ${options} --timeout ${timeout_in_minutes} --destination ${url}
96     ${command}=    BuiltIn.Set_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix} ${options}
97     BuiltIn.Log    Running restperfclient: ${command}
98     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
99     ${keyword_timeout}=    DateTime.Add_Time_To_Time    ${timeout}    2m    result_format=compact
100     SetupUtils.Set_Known_Bug_Id    5413
101     ${restperfclient_running}=    Set_Variable    True
102     Restperfclient__Invoke_With_Timeout    ${keyword_timeout}    ${command}
103     ${restperfclient_running}=    Set_Variable    False
104     SetupUtils.Set_Unknown_Bug_Id
105     ${result}=    Grep_Restperfclient_Log    FINISHED. Execution time:
106     BuiltIn.Should_Not_Be_Equal    '${result}'    ''
107     [Teardown]    BuiltIn.Run_Keyword_If    ${restperfclient_running}    BuiltIn.Run_Keyword_And_Ignore_Error    RestPerfClient__Kill
108
109 Grep_Restperfclient_Log
110     [Documentation]    Search for the specified string in the log file produced by latest invocation of RestPerfClient
111     [Arguments]    ${pattern}
112     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
113     ${result}=    SSHLibrary.Execute_Command    grep '${pattern}' ${RestPerfClient__restperfclientlog}
114     RETURN    ${result}
115
116 Collect_From_Restperfclient
117     [Documentation]    Collect useful data produced by restperfclient
118     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
119     SSHLibrary.Get_File    ${RestPerfClient__restperfclientlog}
120     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${EMPTY}
121
122 Teardown_Restperfclient
123     [Documentation]    Free resources allocated during the RestPerfClient setup
124     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
125     SSHLibrary.Close_Connection