Upgrade RF syntax for v3.2 compatibility
[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     END
143     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    REPLICAS=${replicas_str}
144     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${CREATE_PREFIX_SHARD_DIR}    mapping=${mapping}    session=${session}
145
146 Remove_Prefix_Shard
147     [Arguments]    ${member_index}    ${prefix}
148     [Documentation]    Remove prefix based shard.
149     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
150     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}
151     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${REMOVE_PREFIX_SHARD_DIR}    mapping=${mapping}    session=${session}
152
153 Become_Prefix_Leader
154     [Arguments]    ${member_index}    ${shard_name}
155     [Documentation]    Given node ask to become a shard leader.
156     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
157     &{mapping}    BuiltIn.Create_Dictionary    SHARD_NAME=${shard_name}    ID=prefix-0
158     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${BECOME_PREFIX_LEADER_DIR}    mapping=${mapping}    session=${session}
159
160 Subscribe_Dtcl
161     [Arguments]    ${member_index}
162     [Documentation]    Subscribe a listener for data changes. Invoke subscribe-dtcl rpc.
163     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
164     TemplatedRequests.Post_As_Xml_Templated    ${SUBSCRIBE_DTCL_DIR}    session=${session}
165
166 Unsubscribe_Dtcl
167     [Arguments]    ${member_index}
168     [Documentation]    Invoke unsubscribe-dtcl rpc, return copy-matches field as boolean.
169     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
170     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_DTCL_DIR}    session=${session}
171     BuiltIn.Run_Keyword_And_Return    MdsalLowLevel__Parse_Matches    ${text}
172
173 Unsubscribe_Dtcl_No_Tx
174     [Arguments]    ${member_index}
175     [Documentation]    Unsubscribe a listener from the data changes. Expect success no notifications received. Return boolean status.
176     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
177     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_DTCL_DIR}    session=${session}    additional_allowed_status_codes=${INTERNAL_SERVER_ERROR}
178     BuiltIn.Run_Keyword_And_Return    MdsalLowLevel__Parse_Maybe_No_Tx    ${text}
179
180 Subscribe_Ddtl
181     [Arguments]    ${member_index}
182     [Documentation]    Subscribe DOMDataTreeListener to listen for the data changes.
183     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
184     TemplatedRequests.Post_As_Xml_Templated    ${SUBSCRIBE_DDTL_DIR}    session=${session}
185
186 Unsubscribe_Ddtl
187     [Arguments]    ${member_index}
188     [Documentation]    Invoke unsubscribe-ddtl rpc, return copy-matches field as boolean.
189     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
190     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_DDTL_DIR}    session=${session}
191     BuiltIn.Run_Keyword_And_Return    MdsalLowLevel__Parse_Matches    ${text}
192
193 Unsubscribe_Ddtl_No_Tx
194     [Arguments]    ${member_index}
195     [Documentation]    Unsubscribe a listener from the data changes. Expect success no notifications received. Return boolean status.
196     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
197     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_DDTL_DIR}    session=${session}    additional_allowed_status_codes=${INTERNAL_SERVER_ERROR}
198     BuiltIn.Run_Keyword_And_Return    MdsalLowLevel__Parse_Maybe_No_Tx    ${text}
199
200 MdsalLowLevel__Parse_Matches
201     [Arguments]    ${text}
202     [Documentation]    Interpret the \${text} as XML response to an unsubscribe call and return copy-matches as boolean.
203     ${xml} =    XML.Parse_Xml    ${text}
204     ${matches} =    XML.Get_Element_Text    ${xml}    xpath=copy-matches
205     ${matches} =    BuiltIn.Convert_To_Boolean    ${matches}
206     BuiltIn.Return_From_Keyword    ${matches}
207
208 MdsalLowLevel__Parse_Maybe_No_Tx
209     [Arguments]    ${text}
210     [Documentation]    Attempt to parse the \${text} as successful unsubscribe. If that fails, extract the error message and expect no notifications.
211     ${status}    ${message} =    BuiltIn.Run_Keyword_And_Ignore_Error    MdsalLowLevel__Parse_Matches    ${text}
212     BuiltIn.Return_From_Keyword_If    "${status}" == "PASS"    ${message}
213     ${xml} =    XML.Parse_Xml    ${text}
214     ${message} =    XML.Get_Element_Text    ${xml}    xpath=error/error-message
215     ${status}    ${message} =    BuiltIn.Run_Keyword_And_Ignore_Error    BuiltIn.Should_Contain    ${message}    listener has not received
216     BuiltIn.Return_From_Keyword_If    "${status}" == "PASS"    ${TRUE}
217     [Return]    ${FALSE}
218
219 Start_Publish_Notifications
220     [Arguments]    ${member_index}    ${gid}    ${seconds}    ${notif_per_sec}
221     [Documentation]    Start publishing notifications by invoking publish-notifications rpc.
222     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
223     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}    DURATION=${seconds}    RATE=${notif_per_sec}
224     TemplatedRequests.Post_As_Xml_Templated    ${START_PUBLISH_NOTIFICATIONS_DIR}    mapping=${mapping}    session=${session}
225
226 Check_Publish_Notifications
227     [Arguments]    ${member_index}    ${gid}
228     [Documentation]    Publishing notifications check by invoking check-publish-notifications rpc. Return publising process state details.
229     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
230     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}
231     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${CHECK_PUBLISH_NOTIFICATIONS_DIR}    mapping=${mapping}    session=${session}
232     ${xml} =    XML.Parse_Xml    ${text}
233     ${active} =    XML.Get_Element_Text    ${xml}    xpath=active
234     ${active} =    BuiltIn.Convert_To_Boolean    ${active}
235     ${status}    ${publish_count}=    BuiltIn.Run_Keyword_And_Ignore_Error    XML.Get_Element_Text    ${xml}    xpath=publish-count
236     BuiltIn.Run_Keyword_If    """${status}""" == """FAIL""" and """${publish_count}""" != """No element matching 'publish-count' found."""    BuiltIn.Fail    ${publish_count}
237     ${publish_count}    BuiltIn.Set_Variable_If    """${status}""" == """FAIL"""    ${EMPTY}    ${publish_count}
238     ${status}    ${last_error}=    BuiltIn.Run_Keyword_And_Ignore_Error    XML.Get_Element_Text    ${xml}    xpath=last-error
239     BuiltIn.Run_Keyword_If    """${status}""" == """FAIL""" and """${last_error}""" != """No element matching 'last-error' found."""    BuiltIn.Fail    ${last_error}
240     ${last_error}    BuiltIn.Set_Variable_If    """${status}""" == """FAIL"""    ${EMPTY}    ${last_error}
241     BuiltIn.Return_From_Keyword    ${active}    ${publish_count}    ${last_error}
242
243 Subscribe_Ynl
244     [Arguments]    ${member_index}    ${gid}
245     [Documentation]    Subscribe listener for the notifications with identifier ${gid}.
246     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
247     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}
248     TemplatedRequests.Post_As_Xml_Templated    ${SUBSCRIBE_YNL_DIR}    mapping=${mapping}    session=${session}
249
250 Unsubscribe_Ynl
251     [Arguments]    ${member_index}    ${gid}
252     [Documentation]    Unsubscribe listener for the ${gid} identifier. Return statistics of the publishing process.
253     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
254     &{mapping}    BuiltIn.Create_Dictionary    ID=${gid}
255     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${UNSUBSCRIBE_YNL_DIR}    mapping=${mapping}    session=${session}
256     ${xml} =    XML.Parse_Xml    ${text}
257     ${all_not} =    XML.Get_Element_Text    ${xml}    xpath=all-not
258     ${id_not} =    XML.Get_Element_Text    ${xml}    xpath=id-not
259     ${err_not} =    XML.Get_Element_Text    ${xml}    xpath=err-not
260     ${local_number} =    XML.Get_Element_Text    ${xml}    xpath=local-number
261     BuiltIn.Return_From_Keyword    ${all_not}    ${id_not}    ${err_not}    ${local_number}
262
263 Register_Bound_Constant
264     [Arguments]    ${member_index}    ${context}    ${constant}
265     [Documentation]    Invoke register-bound-constant rpc and register get-contexted-constant rpc. The argument ${context} is only the string part
266     ...    of the whole instance identifier.
267     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
268     &{mapping}    BuiltIn.Create_Dictionary    CONTEXT=${context}    CONSTANT=${constant}
269     ${text} =    TemplatedRequests.Post_As_Xml_Templated    ${REGISTER_BOUND_CONSTANT_DIR}    mapping=${mapping}    session=${session}
270
271 Unregister_Bound_Constant
272     [Arguments]    ${member_index}    ${context}
273     [Documentation]    Invoke unregister-bound-constant rpc and unregister get-contexted-constant rpc. The argument ${context} is only the string part
274     ...    of the whole instance identifier.
275     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
276     &{mapping}    BuiltIn.Create_Dictionary    CONTEXT=${context}
277     TemplatedRequests.Post_As_Xml_Templated    ${UNREGISTER_BOUND_CONSTANT_DIR}    mapping=${mapping}    session=${session}
278
279 Shutdown_Shard_Replica
280     [Arguments]    ${member_index}    ${shard_name}
281     [Documentation]    Invoke shutdown-shard-replica rpc.
282     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
283     &{mapping}    BuiltIn.Create_Dictionary    SHARD_NAME=${shard_name}
284     TemplatedRequests.Post_As_Xml_Templated    ${SHUTDOWN_SHARD_REPLICA_DIR}    mapping=${mapping}    session=${session}
285
286 Shutdown_Prefix_Shard_Replica
287     [Arguments]    ${member_index}    ${shard_prefix}
288     [Documentation]    Invoke shutdown-prefix-shard-replica rpc.
289     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${member_index}
290     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${shard_prefix}
291     TemplatedRequests.Post_As_Xml_Templated    ${SHUTDOWN_PREFIX_SHARD_REPLICA_DIR}    mapping=${mapping}    session=${session}