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