697f72f50b2760df28d25058608de5558809d8fa
[integration/test.git] / csit / libraries / RestPerfClient.robot
1 *** Settings ***
2 Documentation     RestPerfClient handling singleton resource.
3 ...
4 ...               Copyright (c) 2016 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 singleton manages RestPerfClient invocation, tracks the log file
11 ...               produced by the invocation, allows the test suite to easily search this
12 ...               log file and collect it once done.
13 ...
14 ...               TODO: Currently only one RestPerfClient invocation running at a time is
15 ...               supported. Support for multiple concurrently running RestPerfClient
16 ...               invocations might be needed for example when performance testing cluster
17 ...               nodes. However no such suites are planned for now.
18 ...
19 ...               FIXME: There may be suites which want to use this Resource without
20 ...               NetconfKeywords, in which case NexusKeywords will not be initialized
21 ...               and Setup_Restperfclient will fail. Fixing this problem will require
22 ...               updating NexusKeywords initialization (which may break other suites)
23 ...               and currently all suites using this use also NetconfKeywords so this
24 ...               was postponed. Workaround for the problem: Initialize NexusKeywords
25 ...               manually before initializing this resource.
26 Library           SSHLibrary
27 Resource          ${CURDIR}/NexusKeywords.robot
28 Resource          ${CURDIR}/SSHKeywords.robot
29 Resource          ${CURDIR}/Utils.robot
30
31 *** Variables ***
32 ${RestPerfClient__restperfclientlog}    ${EMPTY}
33
34 *** Keywords ***
35 Setup_Restperfclient
36     [Documentation]    Deploy RestPerfClient and determine the Java command to use to call it.
37     ...    Open a SSH connection through which the RestPerfClient will be
38     ...    invoked, deploy RestPerfClient and the data files it needs to do
39     ...    its work and initialize the internal state for the remaining
40     ...    keywords.
41     ${connection}=    SSHKeywords.Open_Connection_To_Tools_System
42     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient}    ${connection}
43     SSHLibrary.Put_File    ${CURDIR}/../variables/netconf/RestPerfClient/request1.json
44     ${filename}=    NexusKeywords.Deploy_Test_Tool    netconf    netconf-testtool    rest-perf-client
45     ${prefix}=    NexusKeywords.Compose_Full_Java_Command    -Xmx1G -XX:MaxPermSize=256M -jar ${filename}
46     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix}    ${prefix}
47
48 Invoke_Restperfclient
49     [Arguments]    ${timeout}    ${url}    ${testcase}=${EMPTY}    ${ip}=${ODL_SYSTEM_IP}    ${port}=${RESTCONFPORT}    ${count}=${REQUEST_COUNT}
50     ...    ${async}=false    ${user}=${ODL_RESTCONF_USER}    ${password}=${ODL_RESTCONF_PASSWORD}
51     [Documentation]    Invoke RestPerfClient on the specified URL with the specified timeout.
52     ...    Assemble the RestPerfClient invocation commad, setup the specified
53     ...    timeout for the SSH connection, invoke the assembled command and
54     ...    then check that RestPerfClient finished its run correctly.
55     ${logname}=    Utils.Get_Log_File_Name    restperfclient    ${testcase}
56     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${logname}
57     ${options}=    BuiltIn.Set_Variable    --ip ${ip} --port ${port} --edits ${count}
58     ${options}=    BuiltIn.Set_Variable    ${options} --edit-content request1.json --async-requests ${async}
59     ${options}=    BuiltIn.Set_Variable    ${options} --auth ${user} ${password}
60     ${timeout_in_minutes}=    Utils.Convert_To_Minutes    ${timeout}
61     ${options}=    BuiltIn.Set_Variable    ${options} --timeout ${timeout_in_minutes} --destination ${url}
62     ${command}=    BuiltIn.Set_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix} ${options}
63     BuiltIn.Log    Running restperfclient: ${command}
64     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
65     SSHLibrary.Set_Client_Configuration    timeout=${timeout}
66     Set_Known_Bug_Id    5413
67     Execute_Command_Passes    ${command} >${RestPerfClient__restperfclientlog} 2>&1
68     Set_Unknown_Bug_Id
69     ${result}=    Grep_Restperfclient_Log    FINISHED. Execution time:
70     BuiltIn.Should_Not_Be_Equal    '${result}'    ''
71
72 Grep_Restperfclient_Log
73     [Arguments]    ${pattern}
74     [Documentation]    Search for the specified string in the log file produced by latest invocation of RestPerfClient
75     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
76     ${result}=    SSHLibrary.Execute_Command    grep '${pattern}' ${RestPerfClient__restperfclientlog}
77     [Return]    ${result}
78
79 Get_Current_Log_Name
80     [Return]    ${RestPerfClient__restperfclientlog}
81
82 Collect_From_Restperfclient
83     [Documentation]    Collect useful data produced by restperfclient
84     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
85     SSHLibrary.Get_File    ${RestPerfClient__restperfclientlog}
86     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${EMPTY}
87
88 Teardown_Restperfclient
89     [Documentation]    Free resources allocated during the RestPerfClient setup
90     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
91     SSHLibrary.Close_Connection