Add missing reference to SetupUtils
[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}/SetupUtils.robot
29 Resource          ${CURDIR}/SSHKeywords.robot
30 Resource          ${CURDIR}/Utils.robot
31
32 *** Variables ***
33 ${RestPerfClient__restperfclientlog}    ${EMPTY}
34
35 *** Keywords ***
36 Setup_Restperfclient
37     [Documentation]    Deploy RestPerfClient and determine the Java command to use to call it.
38     ...    Open a SSH connection through which the RestPerfClient will be
39     ...    invoked, deploy RestPerfClient and the data files it needs to do
40     ...    its work and initialize the internal state for the remaining
41     ...    keywords.
42     ${connection}=    SSHKeywords.Open_Connection_To_Tools_System
43     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient}    ${connection}
44     SSHLibrary.Put_File    ${CURDIR}/../variables/netconf/RestPerfClient/request1.json
45     ${filename}=    NexusKeywords.Deploy_Test_Tool    netconf    netconf-testtool    rest-perf-client
46     ${prefix}=    NexusKeywords.Compose_Full_Java_Command    -Xmx1G -XX:MaxPermSize=256M -jar ${filename}
47     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix}    ${prefix}
48
49 Invoke_Restperfclient
50     [Arguments]    ${timeout}    ${url}    ${testcase}=${EMPTY}    ${ip}=${ODL_SYSTEM_IP}    ${port}=${RESTCONFPORT}    ${count}=${REQUEST_COUNT}
51     ...    ${async}=false    ${user}=${ODL_RESTCONF_USER}    ${password}=${ODL_RESTCONF_PASSWORD}
52     [Documentation]    Invoke RestPerfClient on the specified URL with the specified timeout.
53     ...    Assemble the RestPerfClient invocation commad, setup the specified
54     ...    timeout for the SSH connection, invoke the assembled command and
55     ...    then check that RestPerfClient finished its run correctly.
56     ${logname}=    Utils.Get_Log_File_Name    restperfclient    ${testcase}
57     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${logname}
58     ${options}=    BuiltIn.Set_Variable    --ip ${ip} --port ${port} --edits ${count}
59     ${options}=    BuiltIn.Set_Variable    ${options} --edit-content request1.json --async-requests ${async}
60     ${options}=    BuiltIn.Set_Variable    ${options} --auth ${user} ${password}
61     ${timeout_in_minutes}=    Utils.Convert_To_Minutes    ${timeout}
62     ${options}=    BuiltIn.Set_Variable    ${options} --timeout ${timeout_in_minutes} --destination ${url}
63     ${command}=    BuiltIn.Set_Variable    ${RestPerfClient__restperfclient_invocation_command_prefix} ${options}
64     BuiltIn.Log    Running restperfclient: ${command}
65     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
66     SSHLibrary.Set_Client_Configuration    timeout=${timeout}
67     SetupUtils.Set_Known_Bug_Id    5413
68     Execute_Command_Passes    ${command} >${RestPerfClient__restperfclientlog} 2>&1
69     SetupUtils.Set_Unknown_Bug_Id
70     ${result}=    Grep_Restperfclient_Log    FINISHED. Execution time:
71     BuiltIn.Should_Not_Be_Equal    '${result}'    ''
72
73 Grep_Restperfclient_Log
74     [Arguments]    ${pattern}
75     [Documentation]    Search for the specified string in the log file produced by latest invocation of RestPerfClient
76     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
77     ${result}=    SSHLibrary.Execute_Command    grep '${pattern}' ${RestPerfClient__restperfclientlog}
78     [Return]    ${result}
79
80 Get_Current_Log_Name
81     [Return]    ${RestPerfClient__restperfclientlog}
82
83 Collect_From_Restperfclient
84     [Documentation]    Collect useful data produced by restperfclient
85     BuiltIn.Should_Not_Be_Equal    '${RestPerfClient__restperfclientlog}'    ''
86     SSHLibrary.Get_File    ${RestPerfClient__restperfclientlog}
87     BuiltIn.Set_Suite_Variable    ${RestPerfClient__restperfclientlog}    ${EMPTY}
88
89 Teardown_Restperfclient
90     [Documentation]    Free resources allocated during the RestPerfClient setup
91     SSHLibrary.Switch_Connection    ${RestPerfClient__restperfclient}
92     SSHLibrary.Close_Connection