Add shutdown(-prefix)-shard_replica rpc into lib
[integration/test.git] / csit / libraries / MdsalLowlevel.robot
1 *** Settings ***
2 Documentation     Keywords wrapping controller's odl-mdsal-lowlevel yang model rpcs.
3 ...
4 ...               Copyright (c) 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 Library           XML
10 Resource          ${CURDIR}/ClusterManagement.robot
11 Resource          ${CURDIR}/TemplatedRequests.robot
12
13 *** Variables ***
14 ${LOWLEVEL_RPC_DIR}    ${CURDIR}/../variables/mdsal/lowlevelrpc
15 ${BECOME_PREFIX_LEADER_DIR}    ${LOWLEVEL_RPC_DIR}/become_prefix_leader
16 ${CHECK_PUBLISH_NOTIFICATIONS_DIR}    ${LOWLEVEL_RPC_DIR}/check_publish_notifications
17 ${CREATE_PREFIX_SHARD_DIR}    ${LOWLEVEL_RPC_DIR}/create_prefix_shard
18 ${GET_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/get_constant
19 ${GET_CONTEXTED_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/get_contexted_constant
20 ${GET_SINGLETON_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/get_singleton_constant
21 ${PRODUCE_TRANSACTIONS_DIR}    ${LOWLEVEL_RPC_DIR}/produce_transactions
22 ${REGISTER_BOUND_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/register_bound_constant
23 ${REGISTER_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/register_constant
24 ${REGISTER_FLAPPING_SINGLETON_DIR}    ${LOWLEVEL_RPC_DIR}/register_flapping_singleton
25 ${REGISTER_SINGLETON_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/register_singleton_constant
26 ${REMOVE_PREFIX_SHARD_DIR}    ${LOWLEVEL_RPC_DIR}/remove_prefix_shard
27 ${SHUTDOWN_SHARD_REPLICA_DIR}    ${LOWLEVEL_RPC_DIR}/shutdown_shard_replica
28 ${SHUTDOWN_PREFIX_SHARD_REPLICA_DIR}    ${LOWLEVEL_RPC_DIR}/shutdown_prefix_shard_replica
29 ${START_PUBLISH_NOTIFICATIONS_DIR}    ${LOWLEVEL_RPC_DIR}/start_publish_notifications
30 ${SUBSCRIBE_DDTL_DIR}    ${LOWLEVEL_RPC_DIR}/subscribe_ddtl
31 ${SUBSCRIBE_DTCL_DIR}    ${LOWLEVEL_RPC_DIR}/subscribe_dtcl
32 ${SUBSCRIBE_YNL_DIR}    ${LOWLEVEL_RPC_DIR}/subscribe_ynl
33 ${UNREGISTER_BOUND_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/unregister_bound_constant
34 ${UNREGISTER_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/unregister_constant
35 ${UNREGISTER_FLAPPING_SINGLETON_DIR}    ${LOWLEVEL_RPC_DIR}/unregister_flapping_singleton
36 ${UNREGISTER_SINGLETON_CONSTANT_DIR}    ${LOWLEVEL_RPC_DIR}/unregister_singleton_constant
37 ${UNSUBSCRIBE_DDTL_DIR}    ${LOWLEVEL_RPC_DIR}/unsubscribe_ddtl
38 ${UNSUBSCRIBE_DTCL_DIR}    ${LOWLEVEL_RPC_DIR}/unsubscribe_dtcl
39 ${UNSUBSCRIBE_YNL_DIR}    ${LOWLEVEL_RPC_DIR}/unsubscribe_ynl
40 ${WRITE_TRANSACTIONS_DIR}    ${LOWLEVEL_RPC_DIR}/write_transactions
41
42 *** Keywords ***
43 Get_Constant
44     [Arguments]    ${member_index}    ${explicit_status_codes}=${NO_STATUS_CODES}
45     [Documentation]    Invoke get-constant rpc on the requested member and return the registered constant unless explicit status code is expected.
46     ...    The ${explicit_status_codes} is a list of http status codes for which the rpc call is considered as passed and is used for calls with
47     ...    expected failures on odl's side, such as calling the rpc on isolated node etc.
48     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
49     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${GET_CONSTANT_DIR}    session=${session}    explicit_status_codes=${explicit_status_codes}
50     BuiltIn.Return_From_Keyword_If    """${explicit_status_codes}""" != """${NO_STATUS_CODES}"""
51     ${xml} =    XML.Parse_Xml    ${text}
52     ${constant} =    XML.Get_Element_Text    ${xml}    xpath=constant
53     BuiltIn.Return_From_Keyword    ${constant}
54
55 Get_Contexted_Constant
56     [Arguments]    ${member_index}    ${context}
57     [Documentation]    Invoke get-contexted-constant rpc on the requested member and return the registered constant. The argument ${context} is only the string part
58     ...    of the whole instance identifier. The ${explicit_status_codes} is a list of http status codes for which the rpc call is considered as passed and is used for
59     ...    calls with expected failures on odl's side, such as calling the rpc on isolated node etc.
60     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
61     &{mapping}    BuiltIn.Create_Dictionary    CONTEXT=${context}
62     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${GET_CONTEXTED_CONSTANT_DIR}    mapping=${mapping}    session=${session}
63     ${xml} =    XML.Parse_Xml    ${text}
64     ${constant} =    XML.Get_Element_Text    ${xml}    xpath=constant
65     BuiltIn.Return_From_Keyword    ${constant}
66
67 Get_Singleton_Constant
68     [Arguments]    ${member_index}    ${explicit_status_codes}=${NO_STATUS_CODES}
69     [Documentation]    Invoke get-singleton-constant rpc on the requested member and return the registered constant unless explicit status code is
70     ...    expected. The ${explicit_status_codes} is a list of http status codes for which the rpc call is considered as passed and is used for calls
71     ...    with expected failures on odl's side, such as calling the rpc on isolated node etc.
72     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
73     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${GET_SINGLETON_CONSTANT_DIR}    session=${session}    explicit_status_codes=${explicit_status_codes}
74     BuiltIn.Return_From_Keyword_If    """${explicit_status_codes}""" != """${NO_STATUS_CODES}"""
75     ${xml} =    XML.Parse_Xml    ${text}
76     ${constant} =    XML.Get_Element_Text    ${xml}    xpath=constant
77     BuiltIn.Return_From_Keyword    ${constant}
78
79 Register_Constant
80     [Arguments]    ${member_index}    ${constant}
81     [Documentation]    Register the get-constant rpc on the requested node with given constant.
82     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
83     &{mapping}    BuiltIn.Create_Dictionary    CONSTANT=${constant}
84     TemplatedRequests.Post_As_Xml_Templated    ${REGISTER_CONSTANT_DIR}    mapping=${mapping}    session=${session}
85
86 Unregister_Constant
87     [Arguments]    ${member_index}
88     [Documentation]    Unregister the get-constant rpc on the given node.
89     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
90     TemplatedRequests.Post_As_Xml_Templated    ${UNREGISTER_CONSTANT_DIR}    session=${session}
91
92 Register_Singleton_Constant
93     [Arguments]    ${member_index}    ${constant}
94     [Documentation]    Register singleton application on given node by invoking register-singleton-constant rpc.
95     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
96     &{mapping}    BuiltIn.Create_Dictionary    CONSTANT=${constant}
97     TemplatedRequests.Post_As_Xml_Templated    ${REGISTER_SINGLETON_CONSTANT_DIR}    mapping=${mapping}    session=${session}
98
99 Unregister_Singleton_Constant
100     [Arguments]    ${member_index}
101     [Documentation]    Unregister singleton application on given node by invoking unregister-singleton-constant rpc.
102     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
103     TemplatedRequests.Post_As_Xml_Templated    ${UNREGISTER_SINGLETON_CONSTANT_DIR}    session=${session}
104
105 Register_Flapping_Singleton
106     [Arguments]    ${member_index}
107     [Documentation]    Activate flapping application on given node by invoking register-flapping-singleton rpc.
108     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
109     TemplatedRequests.Post_As_Xml_Templated    ${REGISTER_FLAPPING_SINGLETON_DIR}    session=${session}
110
111 Unregister_Flapping_Singleton
112     [Arguments]    ${member_index}
113     [Documentation]    Deactivate flapping singleton application by invoking unregister-flapping-singleton rpc.
114     ...    Return the successful re-registrations count.
115     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
116     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNREGISTER_FLAPPING_SINGLETON_DIR}    session=${session}
117     ${xml} =    XML.Parse_Xml    ${text}
118     ${count} =    XML.Get_Element_Text    ${xml}    xpath=flap-count
119     BuiltIn.Return_From_Keyword    ${count}
120
121 Write_Transactions
122     [Arguments]    ${member_index}    ${identifier}    ${seconds}    ${trans_per_sec}    ${chained_trans}=${True}
123     [Documentation]    Create transactions with given rate for given time for module-based shards.
124     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
125     &{mapping}    BuiltIn.Create_Dictionary    ID=${identifier}    DURATION=${seconds}    RATE=${trans_per_sec}    CHAINED_FLAG=${chained_trans}
126     TemplatedRequests.Post_As_Xml_Templated    ${WRITE_TRANSACTIONS_DIR}    mapping=${mapping}    session=${session}
127
128 Produce_Transactions
129     [Arguments]    ${member_index}    ${seconds}    ${trans_per_sec}    ${isolated_trans}=${True}
130     [Documentation]    Create transactions with given rate for given time for prefix-based shards.
131     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
132     &{mapping}    BuiltIn.Create_Dictionary    SECONDS=${seconds}    TPS=${trans_per_sec}    ISOLATED_TRANSACTIONS=${chained_trans}
133     TemplatedRequests.Post_As_Xml_Templated    ${PRODUCE_TRANSACTIONS_DIR}    mapping=${mapping}    session=${session}
134
135 Create_Prefix_Shard
136     [Arguments]    ${member_index}    ${prefix}    ${replicas}
137     [Documentation]    Create prefix based shard. ${replicas} is a list of cluster node indexes, taken e.g. from ClusterManagement.List_Indices_Or_All.
138     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
139     ${replicas_str}    BuiltIn.Set_Variable    ${EMPTY}
140     : FOR    ${replica}    IN    @{replicas}
141     \    ${replicas_str}    BuiltIn.Set_Variable    ${replicas_str}<replicas>member-${replica}</replicas>
142     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    REPLICAS=${replicas_str}
143     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${CREATE_PREFIX_SHARD_DIR}    mapping=${mapping}    session=${session}
144
145 Remove_Prefix_Shard
146     [Arguments]    ${member_index}    ${prefix}
147     [Documentation]    Remove prefix based shard.
148     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
149     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}
150     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${REMOVE_PREFIX_SHARD_DIR}    mapping=${mapping}    session=${session}
151
152 Become_Prefix_Leader
153     [Arguments]    ${member_index}    ${shard_name}
154     [Documentation]    Given node ask to become a shard leader.
155     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
156     &{mapping}    BuiltIn.Create_Dictionary    SHARD_NAME=${shard_name}    ID=prefix-0
157     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${BECOME_PREFIX_LEADER_DIR}    mapping=${mapping}    session=${session}
158
159 Subscribe_Dtcl
160     [Arguments]    ${member_index}
161     [Documentation]    Subscribe a listener for data changes. Invoke subscribe-dtcl rpc.
162     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
163     TemplatedRequests.Post_As_Xml_Templated    ${SUBSCRIBE_DTCL_DIR}    session=${session}
164
165 Unsubscribe_Dtcl
166     [Arguments]    ${member_index}
167     [Documentation]    Unsubscribe a listener from the data changes. Invoke unsubscribe-dtcl rpc.
168     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
169     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_DTCL_DIR}    session=${session}
170     ${xml} =    XML.Parse_Xml    ${text}
171     ${matches} =    XML.Get_Element_Text    ${xml}    xpath=copy-matches
172     ${matches} =    BuiltIn.Convert_To_Boolean    ${matches}
173     BuiltIn.Return_From_Keyword    ${matches}
174
175 Subscribe_Ddtl
176     [Arguments]    ${member_index}
177     [Documentation]    Subscribe DOMDataTreeListener to listen for the data changes.
178     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
179     TemplatedRequests.Post_As_Xml_Templated    ${SUBSCRIBE_DDTL_DIR}    session=${session}
180
181 Unsubscribe_Ddtl
182     [Arguments]    ${member_index}
183     [Documentation]    Unsubscribe DOMDataTreeListener from listening to the data changes.
184     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
185     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_DDTL_DIR}    session=${session}
186     ${xml} =    XML.Parse_Xml    ${text}
187     ${matches} =    XML.Get_Element_Text    ${xml}    xpath=copy-matches
188     ${matches} =    BuiltIn.Convert_To_Boolean    ${matches}
189     BuiltIn.Return_From_Keyword    ${matches}
190
191 Start_Publish_Notifications
192     [Arguments]    ${member_index}    ${gid}    ${seconds}    ${notif_per_sec}
193     [Documentation]    Start publishing notifications by invoking publish-notifications rpc.
194     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
195     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}    DURATION=${seconds}    RATE=${notif_per_sec}
196     TemplatedRequests.Post_As_Xml_Templated    ${START_PUBLISH_NOTIFICATIONS_DIR}    mapping=${mapping}    session=${session}
197
198 Check_Publish_Notifications
199     [Arguments]    ${member_index}    ${gid}
200     [Documentation]    Publishing notifications check by invoking check-publish-notifications rpc. Return publising process state details.
201     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
202     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}
203     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${CHECK_PUBLISH_NOTIFICATIONS_DIR}    mapping=${mapping}    session=${session}
204     ${xml} =    XML.Parse_Xml    ${text}
205     ${active} =    XML.Get_Element_Text    ${xml}    xpath=active
206     ${active} =    BuiltIn.Convert_To_Boolean    ${active}
207     ${status}    ${publish_count}=    BuiltIn.Run_Keyword_And_Ignore_Error    XML.Get_Element_Text    ${xml}    xpath=publish-count
208     BuiltIn.Run_Keyword_If    """${status}""" == """FAIL""" and """${publish_count}""" != """No element matching 'publish-count' found."""    BuiltIn.Fail    ${publish_count}
209     ${publish_count}    BuiltIn.Set_Variable_If    """${status}""" == """FAIL"""    ${EMPTY}    ${publish_count}
210     ${status}    ${last_error}=    BuiltIn.Run_Keyword_And_Ignore_Error    XML.Get_Element_Text    ${xml}    xpath=last-error
211     BuiltIn.Run_Keyword_If    """${status}""" == """FAIL""" and """${last_error}""" != """No element matching 'last-error' found."""    BuiltIn.Fail    ${last_error}
212     ${last_error}    BuiltIn.Set_Variable_If    """${status}""" == """FAIL"""    ${EMPTY}    ${last_error}
213     BuiltIn.Return_From_Keyword    ${active}    ${publish_count}    ${last_error}
214
215 Subscribe_Ynl
216     [Arguments]    ${member_index}    ${gid}
217     [Documentation]    Subscribe listener for the notifications with identifier ${gid}.
218     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
219     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}
220     TemplatedRequests.Post_As_Xml_Templated    ${SUBSCRIBE_YNL_DIR}    mapping=${mapping}    session=${session}
221
222 Unsubscribe_Ynl
223     [Arguments]    ${member_index}    ${gid}
224     [Documentation]    Unsubscribe listener for the ${gid} identifier. Return statistics of the publishing process.
225     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
226     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}
227     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_YNL_DIR}    mapping=${mapping}    session=${session}
228     ${xml} =    XML.Parse_Xml    ${text}
229     ${all_not} =    XML.Get_Element_Text    ${xml}    xpath=all-not
230     ${id_not} =    XML.Get_Element_Text    ${xml}    xpath=id-not
231     ${err_not} =    XML.Get_Element_Text    ${xml}    xpath=err-not
232     ${local_number} =    XML.Get_Element_Text    ${xml}    xpath=local-number
233     BuiltIn.Return_From_Keyword    ${all_not}    ${id_not}    ${err_not}    ${local_number}
234
235 Register_Bound_Constant
236     [Arguments]    ${member_index}    ${context}    ${constant}
237     [Documentation]    Invoke register-bound-constant rpc and register get-contexted-constant rpc. The argument ${context} is only the string part
238     ...    of the whole instance identifier.
239     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
240     &{mapping}    BuiltIn.Create_Dictionary    CONTEXT=${context}    CONSTANT=${constant}
241     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${REGISTER_BOUND_CONSTANT_DIR}    mapping=${mapping}    session=${session}
242
243 Unregister_Bound_Constant
244     [Arguments]    ${member_index}    ${context}
245     [Documentation]    Invoke unregister-bound-constant rpc and unregister get-contexted-constant rpc. The argument ${context} is only the string part
246     ...    of the whole instance identifier.
247     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
248     &{mapping}    BuiltIn.Create_Dictionary    CONTEXT=${context}
249     TemplatedRequests.Post_As_Xml_Templated    ${UNREGISTER_BOUND_CONSTANT_DIR}    mapping=${mapping}    session=${session}
250
251 Shutdown_Shard_Replica
252     [Arguments]    ${member_index}    ${shard_name}
253     [Documentation]    Invoke shutdown-shard-replica rpc.
254     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
255     &{mapping}    BuiltIn.Create_Dictionary    SHARD_NAME=${shard_name}
256     TemplatedRequests.Post_As_Xml_Templated    ${SHUTDOWN_SHARD_REPLICA_DIR}    mapping=${mapping}    session=${session}
257
258 Shutdown_Prefix_Shard_Replica
259     [Arguments]    ${member_index}    ${shard_prefix}
260     [Documentation]    Invoke shutdown-prefix-shard-replica rpc.
261     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
262     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${shard_prefix}
263     TemplatedRequests.Post_As_Xml_Templated    ${SHUTDOWN_PREFIX_SHARD_REPLICA_DIR}    mapping=${mapping}    session=${session}