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