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