Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / libraries / CarPeople.robot
1 *** Settings ***
2 Documentation     Resource housing Keywords common to tests which interact with car/people models.
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 resource is tightly coupled with "crud" cluster suite,
12 ...               as it is not straightforward to allow ${VAR_DIR} customization.
13 Resource          ${CURDIR}/TemplatedRequests.robot
14
15 *** Variables ***
16 ${VAR_DIR}        ${CURDIR}/../../../variables/carpeople/crud
17
18 *** Keywords ***
19 Add_Several_People
20     [Arguments]    ${session}    ${iterations}    ${iter_start}=1
21     [Documentation]    Simple loop for issuing add-person RPCs to session, one by one.
22     ...    People need to be added via RPC, otherwise buy-car routed RPC will not find registered path.
23     ...    See javadocs in RpcProviderRegistry.java
24     FOR    ${i}    IN RANGE    ${iter_start}    ${iter_start}+${iterations}
25         TemplatedRequests.Post_As_Json_Templated    folder=${VAR_DIR}/add-person    mapping={"i": "${i}"}    session=${session}
26     END
27
28 Buy_Several_Cars
29     [Arguments]    ${session}    ${iterations}    ${iter_start}=1    ${registration_delay}=20s
30     [Documentation]    Simple loop for issuing buy-car RPCs to session, one by one.
31     ...    This needs to be a separate Keyword mostly just because nested FOR loops are not allowed.
32     ...    Actual fact of buying one car is done by inner Keyword.
33     FOR    ${iter}    IN RANGE    ${iter_start}    ${iter_start}+${iterations}
34         Buy_Single_Car    session=${session}    iteration=${iter}    registration_delay=${registration_delay}
35     END
36
37 Buy_Single_Car
38     [Arguments]    ${session}    ${iteration}=1    ${registration_delay}=20s
39     [Documentation]    Each buy-car RPC is routed, which means there is a delay between
40     ...    the time add-car RPC is executed and the time member in question registers the route.
41     ...    To distinguish functional bugs from performance ones, this Keyword waits up to 20 seconds
42     ...    while retrying buy-car requests.
43     BuiltIn.Wait_Until_Keyword_Succeeds    ${registration_delay}    1s    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_DIR}/buy-car    mapping={"i": "${iteration}"}    session=${session}
44
45 Set_Variables_For_Shard
46     [Arguments]    ${shard_name}    ${shard_type}=config
47     [Documentation]    Get leader and followers for given shard name and
48     ...    set several suite variables related to member indices and sessions.
49     ...    ClusterManagement Resource is assumed to be initialized.
50     ...    TODO: car-people shard name causes dash in variable names. Should we convert to underscores?
51     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}
52     BuiltIn.Set_Suite_Variable    \${${shard_name}_leader_index}    ${leader}
53     BuiltIn.Set_Suite_Variable    \${${shard_name}_follower_indices}    ${follower_list}
54     ${first_follower_index} =    Collections.Get_From_List    ${follower_list}    0
55     BuiltIn.Set_Suite_Variable    \${${shard_name}_first_follower_index}    ${first_follower_index}
56     ${leader_session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${leader}
57     BuiltIn.Set_Suite_Variable    \${${shard_name}_leader_session}    ${leader_session}
58     ${sessions} =    BuiltIn.Create_List
59     FOR    ${follower_index}    IN    @{follower_list}
60         ${follower_session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${follower_index}
61         Collections.Append_To_List    ${sessions}    ${follower_session}
62     END
63     BuiltIn.Set_Suite_Variable    \${${shard_name}_follower_sessions}    ${sessions}
64     ${first_follower_session} =    Collections.Get_From_List    ${sessions}    0
65     BuiltIn.Set_Suite_Variable    \${${shard_name}_first_follower_session}    ${first_follower_session}
66
67 Set_Tmp_Variables_For_Shard_For_Nodes
68     [Arguments]    ${member_index_list}    ${shard_name}=car    ${shard_type}=config
69     [Documentation]    Get current leader and followers for given shard. Can be used for less nodes than full odl configuration.
70     ...    Variable names do not contain neither node nor shard names, so the variables are only suitable for temporary use, as indicated by Tmp in the keyword name.
71     ...    This keyword sets the following suite variables:
72     ...    ${new_leader_session} - http session for the leader node
73     ...    ${new_follower_sessions} - list of http sessions for the follower nodes
74     ...    ${new_first_follower_session} - http session for the first follower node
75     ...    ${new_leader_index} - index of the shard leader
76     ...    ${new_followers_list} - list of followers indexes
77     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${member_index_list}
78     BuiltIn.Set_Suite_Variable    \${new_leader_index}    ${leader}
79     BuiltIn.Set_Suite_Variable    \${new_followers_list}    ${follower_list}
80     ${leader_session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${leader}
81     BuiltIn.Set_Suite_Variable    \${new_leader_session}    ${leader_session}
82     ${sessions} =    BuiltIn.Create_List
83     FOR    ${follower_index}    IN    @{follower_list}
84         ${follower_session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${follower_index}
85         Collections.Append_To_List    ${sessions}    ${follower_session}
86     END
87     BuiltIn.Set_Suite_Variable    \${new_follower_sessions}    ${sessions}
88     ${first_follower_session} =    Collections.Get_From_List    ${sessions}    0
89     BuiltIn.Set_Suite_Variable    \${new_first_follower_session}    ${first_follower_session}
90     BuiltIn.Return_From_Keyword    ${leader}    ${follower_list}