xref: /openbmc/openbmc-test-automation/openpower/ext_interfaces/test_lock_management.robot (revision 3b3a7eca4bdc196b7caef7c1f8aacc80cd1f38f2)
1bc331e22SVijay*** Settings ***
2bc331e22SVijay
3d03f2ce1SSushil SinghDocumentation        Test lock management feature of management console on BMC.
4bc331e22SVijay
5bc331e22SVijayResource             ../../lib/resource.robot
6bc331e22SVijayResource             ../../lib/openbmc_ffdc.robot
7566daaf3SGeorge KeishingResource             ../../lib/bmc_redfish_utils.robot
8d03f2ce1SSushil SinghResource             ../../lib/external_intf/management_console_utils.robot
9728ef9c9SSushil SinghLibrary              ../../lib/bmc_network_utils.py
10bc331e22SVijay
1140ef0eb7SSushil SinghSuite Setup          Run Keyword And Ignore Error  Delete All Redfish Sessions
12d03f2ce1SSushil SinghSuite Teardown       Redfish.Logout
13d03f2ce1SSushil SinghTest Setup           Printn
14d03f2ce1SSushil SinghTest Teardown        FFDC On Test Case Fail
15bc331e22SVijay
16bc331e22SVijay*** Variables ***
17bc331e22SVijay
18d03f2ce1SSushil Singh${BAD_REQUEST}       Bad Request
19bc331e22SVijay
20bc331e22SVijay*** Test Cases ***
21bc331e22SVijay
22d03f2ce1SSushil SinghAcquire Read Write Lock
23bc331e22SVijay    [Documentation]  Acquire and release different read locks.
24d03f2ce1SSushil Singh    [Tags]  Acquire_Read_Write_Lock
25d03f2ce1SSushil Singh    [Template]  Acquire Lock On Resource
26bc331e22SVijay
27d03f2ce1SSushil Singh    # client_id    lock_type     reboot_flag
28d03f2ce1SSushil Singh    HMCID-01       ReadCase1     False
29d03f2ce1SSushil Singh    HMCID-01       ReadCase2     False
30d03f2ce1SSushil Singh    HMCID-01       ReadCase3     False
31d03f2ce1SSushil Singh    HMCID-01       WriteCase1    False
32d03f2ce1SSushil Singh    HMCID-01       WriteCase2    False
33d03f2ce1SSushil Singh    HMCID-01       WriteCase3    False
34bc331e22SVijay
35bc331e22SVijay
36d03f2ce1SSushil SinghCheck Lock Persistency On BMC Reboot
37d03f2ce1SSushil Singh    [Documentation]  Acquire lock and check after reboot it remain same.
38d03f2ce1SSushil Singh    [Tags]  Check_Lock_Persistency_On_BMC_Reboot
39d03f2ce1SSushil Singh    [Template]  Acquire Lock On Resource
40bc331e22SVijay
41d03f2ce1SSushil Singh    # client_id    lock_type     reboot_flag
42d03f2ce1SSushil Singh    HMCID-01       ReadCase1     True
43d03f2ce1SSushil Singh    HMCID-01       ReadCase2     True
44d03f2ce1SSushil Singh    HMCID-01       ReadCase3     True
45d03f2ce1SSushil Singh    HMCID-01       WriteCase1    True
46d03f2ce1SSushil Singh    HMCID-01       WriteCase2    True
47d03f2ce1SSushil Singh    HMCID-01       WriteCase3    True
48bc331e22SVijay
49bc331e22SVijay
50d03f2ce1SSushil SinghAcquire Read Lock On Read Lock
51d03f2ce1SSushil Singh    [Documentation]  Acquire read lock on another read lock.
52d03f2ce1SSushil Singh    [Tags]  Acquire_Read_Lock_On_Read_Lock
53d03f2ce1SSushil Singh    [Template]  Acquire Lock On Another Lock
54bc331e22SVijay
55d03f2ce1SSushil Singh    # client_id
56d03f2ce1SSushil Singh    HMCID-01
57bc331e22SVijay
58bc331e22SVijay
59d03f2ce1SSushil SinghGet Lock Records Empty For Invalid Session
60d03f2ce1SSushil Singh    [Documentation]  Record of lock list is empty for invalid session.
61d03f2ce1SSushil Singh    [Tags]  Get_Lock_Records_Empty_For_Invalid_Session
62d03f2ce1SSushil Singh    [Template]  Verify Empty Lock Records For Invalid Session
63355daac7SVijay
64d03f2ce1SSushil Singh    # client_id
65d03f2ce1SSushil Singh    HMCID-01
66355daac7SVijay
67355daac7SVijay
68d03f2ce1SSushil SinghFail To Acquire Lock On Another Lock
69d03f2ce1SSushil Singh    [Documentation]  Fail to acquire another lock.
70d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_On_Another_Lock
71d03f2ce1SSushil Singh    [Template]  Verify Acquire Lock Fails On Another Lock
7285610eeeSVijay
73d03f2ce1SSushil Singh    # client_id    lock_type
74d03f2ce1SSushil Singh    HMCID-01       ReadCase2,WriteCase2
75d03f2ce1SSushil Singh    HMCID-01       WriteCase2,WriteCase2
76d03f2ce1SSushil Singh    HMCID-01       WriteCase2,ReadCase2
77566daaf3SGeorge Keishing
78566daaf3SGeorge Keishing
79e33c6e6aSSushil SinghAcquire Lock After Reboot
80e33c6e6aSSushil Singh    [Documentation]  Acquire and release read and write locks after reboot.
81e33c6e6aSSushil Singh    [Tags]  Acquire_Lock_After_Reboot
82e33c6e6aSSushil Singh    [Template]  Verify Acquire Lock After Reboot
83e33c6e6aSSushil Singh
84e33c6e6aSSushil Singh    # client_id    lock_type
85e33c6e6aSSushil Singh    HMCID-01       ReadCase1
86e33c6e6aSSushil Singh    HMCID-01       ReadCase2
87e33c6e6aSSushil Singh    HMCID-01       ReadCase3
88e33c6e6aSSushil Singh    HMCID-01       WriteCase1
89e33c6e6aSSushil Singh    HMCID-01       WriteCase2
90e33c6e6aSSushil Singh    HMCID-01       WriteCase3
91e33c6e6aSSushil Singh
92e33c6e6aSSushil Singh
93d03f2ce1SSushil SinghAcquire And Release Lock In Loop
94d03f2ce1SSushil Singh    [Documentation]  Acquire and release read, write locks in loop.
95d03f2ce1SSushil Singh    [Tags]  Acquire_And_Release_Lock_In_Loop
96d03f2ce1SSushil Singh    [Template]  Verify Acquire And Release Lock In Loop
97566daaf3SGeorge Keishing
98d03f2ce1SSushil Singh    # client_id    lock_type
99d03f2ce1SSushil Singh    HMCID-01       ReadCase1
100d03f2ce1SSushil Singh    HMCID-01       ReadCase2
101d03f2ce1SSushil Singh    HMCID-01       ReadCase3
102d03f2ce1SSushil Singh    HMCID-01       WriteCase1
103d03f2ce1SSushil Singh    HMCID-01       WriteCase2
104d03f2ce1SSushil Singh    HMCID-01       WriteCase3
10585610eeeSVijay
10685610eeeSVijay
107d03f2ce1SSushil SinghVerify Release Of Valid Locks
108d03f2ce1SSushil Singh    [Documentation]  Release all valid locks.
109d03f2ce1SSushil Singh    [Tags]  Verify_Release_Of_Valid_Locks
110d03f2ce1SSushil Singh    [Template]  Acquire And Release Multiple Locks
111afdd2a1dSVijay
112d03f2ce1SSushil Singh    # client_id    lock_type                        release_lock_type
113d03f2ce1SSushil Singh    HMCID-01       ReadCase1,ReadCase1,ReadCase1    Transaction
114d03f2ce1SSushil Singh    HMCID-02       ReadCase1,ReadCase1,ReadCase1    Session
115afdd2a1dSVijay
116afdd2a1dSVijay
117d03f2ce1SSushil SinghInvalid Locks Fail To Release
118d03f2ce1SSushil Singh    [Documentation]  Release in-valid lock result in fail.
119d03f2ce1SSushil Singh    [Tags]  Invalid_Locks_Fail_To_Release
120d03f2ce1SSushil Singh    [Template]  Verify Invalid Locks Fail To Release
121afdd2a1dSVijay
122d03f2ce1SSushil Singh    # client_id    lock_type                        release_lock_type
123d03f2ce1SSushil Singh    HMCID-01       ReadCase1,ReadCase1,ReadCase1    Transaction
124d03f2ce1SSushil Singh    12345          ReadCase2,ReadCase2,ReadCase2    Transaction
125d03f2ce1SSushil Singh    HMCID          ReadCase3,ReadCase3,ReadCase3    Transaction
126afdd2a1dSVijay
127afdd2a1dSVijay
128d03f2ce1SSushil SinghFail To Release Lock For Another Session
129d03f2ce1SSushil Singh    [Documentation]  Failed to release locks from another session.
130d03f2ce1SSushil Singh    [Tags]  Fail_To_Release_Lock_For_Another_Session
131d03f2ce1SSushil Singh    [Template]  Verify Fail To Release Lock For Another Session
132afdd2a1dSVijay
133d03f2ce1SSushil Singh    # client_id          lock_type
134d03f2ce1SSushil Singh    HMCID-01,HMCID-02    ReadCase1,ReadCase1
135afdd2a1dSVijay
136afdd2a1dSVijay
137e33c6e6aSSushil SinghTest Invalid Resource ID Data Type Locking
138e33c6e6aSSushil Singh    [Documentation]  Failed to acquire lock for invalid resource id data type.
139e33c6e6aSSushil Singh    [Tags]  Test_Invalid_Resource_ID_Data_Type_Locking
140e33c6e6aSSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Resource ID Data Type
141e33c6e6aSSushil Singh
142e33c6e6aSSushil Singh    # client_id    lock_type
143e33c6e6aSSushil Singh    HMCID-01       ReadCase1
144e33c6e6aSSushil Singh    HMCID-01       ReadCase2
145e33c6e6aSSushil Singh    HMCID-01       ReadCase3
146e33c6e6aSSushil Singh    HMCID-01       WriteCase1
147e33c6e6aSSushil Singh    HMCID-01       WriteCase2
148e33c6e6aSSushil Singh    HMCID-01       WriteCase3
149e33c6e6aSSushil Singh
150e33c6e6aSSushil Singh
151d03f2ce1SSushil SinghFail To Acquire Lock For Invalid Lock Type
152d03f2ce1SSushil Singh    [Documentation]  Failed to acquire read, write lock for invalid lock data passed.
153d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Lock_Type
154d03f2ce1SSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
155afdd2a1dSVijay
156d03f2ce1SSushil Singh    # client_id    lock_type      message
157d03f2ce1SSushil Singh    HMCID-01       ReadCase1      ${BAD_REQUEST}
158d03f2ce1SSushil Singh    HMCID-01       ReadCase2      ${BAD_REQUEST}
159d03f2ce1SSushil Singh    HMCID-01       ReadCase3      ${BAD_REQUEST}
160d03f2ce1SSushil Singh    HMCID-01       ReadCase4      ${BAD_REQUEST}
161d03f2ce1SSushil Singh    HMCID-01       ReadCase5      ${BAD_REQUEST}
162d03f2ce1SSushil Singh    HMCID-01       WriteCase1     ${BAD_REQUEST}
163d03f2ce1SSushil Singh    HMCID-01       WriteCase2     ${BAD_REQUEST}
164d03f2ce1SSushil Singh    HMCID-01       WriteCase3     ${BAD_REQUEST}
165d03f2ce1SSushil Singh    HMCID-01       WriteCase4     ${BAD_REQUEST}
166d03f2ce1SSushil Singh    HMCID-01       WriteCase5     ${BAD_REQUEST}
167afdd2a1dSVijay
168afdd2a1dSVijay
169d03f2ce1SSushil SinghFail To Acquire Lock For Invalid Lock Flag
170d03f2ce1SSushil Singh    [Documentation]  Failed to acquire read write lock for invalid lock flag passed.
171d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Lock_Flag
172d03f2ce1SSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
173afdd2a1dSVijay
174d03f2ce1SSushil Singh    # client_id    lock_type       message
175d03f2ce1SSushil Singh    HMCID-01       ReadCase6       ${BAD_REQUEST}
176d03f2ce1SSushil Singh    HMCID-01       ReadCase7       ${BAD_REQUEST}
177d03f2ce1SSushil Singh    HMCID-01       ReadCase8       ${BAD_REQUEST}
178d03f2ce1SSushil Singh    HMCID-01       ReadCase9       ${BAD_REQUEST}
179d03f2ce1SSushil Singh    HMCID-01       ReadCase10      ${BAD_REQUEST}
180d03f2ce1SSushil Singh    HMCID-01       ReadCase11      ${BAD_REQUEST}
181d03f2ce1SSushil Singh    HMCID-01       WriteCase6      ${BAD_REQUEST}
182d03f2ce1SSushil Singh    HMCID-01       WriteCase7      ${BAD_REQUEST}
183d03f2ce1SSushil Singh    HMCID-01       WriteCase8      ${BAD_REQUEST}
184d03f2ce1SSushil Singh    HMCID-01       WriteCase9      ${BAD_REQUEST}
185d03f2ce1SSushil Singh    HMCID-01       WriteCase10     ${BAD_REQUEST}
186d03f2ce1SSushil Singh    HMCID-01       WriteCase11     ${BAD_REQUEST}
187afdd2a1dSVijay
188afdd2a1dSVijay
189d03f2ce1SSushil SinghFail To Acquire Lock For Invalid Segment Flag
190d03f2ce1SSushil Singh    [Documentation]  Failed to acquire read write lock for invalid segment flag passed.
191d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Segment_Flag
192d03f2ce1SSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
193d03f2ce1SSushil Singh
194d03f2ce1SSushil Singh    # client_id    lock_type       message
195d03f2ce1SSushil Singh    HMCID-01       ReadCase12      ${BAD_REQUEST}
196d03f2ce1SSushil Singh    HMCID-01       ReadCase13      ${BAD_REQUEST}
197d03f2ce1SSushil Singh    HMCID-01       ReadCase14      ${BAD_REQUEST}
198d03f2ce1SSushil Singh    HMCID-01       WriteCase12     ${BAD_REQUEST}
199d03f2ce1SSushil Singh    HMCID-01       WriteCase13     ${BAD_REQUEST}
200d03f2ce1SSushil Singh    HMCID-01       WriteCase14     ${BAD_REQUEST}
201afdd2a1dSVijay
202bace3005SSushil Singh
203*3b3a7ecaSSushil SinghFail To Acquire Lock For Invalid Segment Data Type Flag
204*3b3a7ecaSSushil Singh    [Documentation]  Failed to acquire read write lock for invalid segment flag passed.
205*3b3a7ecaSSushil Singh    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Segment_Data_Type_Flag
206*3b3a7ecaSSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
207*3b3a7ecaSSushil Singh
208*3b3a7ecaSSushil Singh    # client_id    lock_type       message
209*3b3a7ecaSSushil Singh    HMCID-01       ReadCase15      ${EMPTY}
210*3b3a7ecaSSushil Singh    HMCID-01       ReadCase16      ${EMPTY}
211*3b3a7ecaSSushil Singh    HMCID-01       ReadCase17      ${EMPTY}
212*3b3a7ecaSSushil Singh    HMCID-01       ReadCase18      ${EMPTY}
213*3b3a7ecaSSushil Singh    HMCID-01       WriteCase15     ${EMPTY}
214*3b3a7ecaSSushil Singh    HMCID-01       WriteCase16     ${EMPTY}
215*3b3a7ecaSSushil Singh    HMCID-01       WriteCase17     ${EMPTY}
216*3b3a7ecaSSushil Singh    HMCID-01       WriteCase18     ${EMPTY}
217*3b3a7ecaSSushil Singh
218*3b3a7ecaSSushil Singh
219bace3005SSushil SinghGet Empty Lock Records For Session Where No Locks Acquired
220bace3005SSushil Singh    [Documentation]  If session does not acquire locks then get lock should return
221bace3005SSushil Singh    ...              empty lock records.
222bace3005SSushil Singh    [Tags]  Get_Empty_Lock_Records_For_Session_Where_No_Locks_Acquired
223bace3005SSushil Singh    [Template]  Verify No Locks Records For Session With No Acquired Lock
224bace3005SSushil Singh
225bace3005SSushil Singh    # client_id
226bace3005SSushil Singh    HMCID-01
227bace3005SSushil Singh
228728ef9c9SSushil Singh
229728ef9c9SSushil SinghGet Lock Records For Multiple Session
230728ef9c9SSushil Singh    [Documentation]  Get lock records of multiple session.
231728ef9c9SSushil Singh    [Tags]  Get_Lock_Records_For_Multiple_Session
232728ef9c9SSushil Singh    [Template]  Verify Lock Records Of Multiple Session
233728ef9c9SSushil Singh
234728ef9c9SSushil Singh    # client_ids         lock_type
235728ef9c9SSushil Singh    HMCID-01,HMCID-02    ReadCase1,ReadCase1
236728ef9c9SSushil Singh
237728ef9c9SSushil Singh
238bc331e22SVijay*** Keywords ***
239bc331e22SVijay
240d03f2ce1SSushil SinghCreate Redfish Session With ClientID
241d03f2ce1SSushil Singh    [Documentation]  Create redifish session with client id.
242d03f2ce1SSushil Singh    [Arguments]  ${client_id}
24385610eeeSVijay
24485610eeeSVijay    # Description of argument(s):
245d03f2ce1SSushil Singh    # client_id    This client id can contain string value
246d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
24785610eeeSVijay
248d03f2ce1SSushil Singh    ${session_info}=  Create Dictionary
249d03f2ce1SSushil Singh    ${session}=  Redfish Login  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client_id}"}}
25085610eeeSVijay
251d03f2ce1SSushil Singh    Set To Dictionary  ${session_info}  SessionIDs  ${session['Id']}
252d03f2ce1SSushil Singh    Set To Dictionary  ${session_info}  ClientID  ${session["Oem"]["OpenBMC"]["ClientID"]}
25385610eeeSVijay
254d03f2ce1SSushil Singh    [Return]  ${session_info}
25585610eeeSVijay
25685610eeeSVijay
257d03f2ce1SSushil SinghRW General Dictionary
258d03f2ce1SSushil Singh    [Documentation]  Create dictionay of lock request.
259d03f2ce1SSushil Singh    [Arguments]  ${read_case}  ${res_id}
260bc331e22SVijay
261bc331e22SVijay    # Description of argument(s):
262d03f2ce1SSushil Singh    # read_case    Read or Write lock type.
263d03f2ce1SSushil Singh    # res_id       Resource id.
264bc331e22SVijay
265d03f2ce1SSushil Singh    ${request_dict}=  Create Dictionary
266566daaf3SGeorge Keishing
267d03f2ce1SSushil Singh    FOR  ${key}  IN  @{read_case.keys()}
268d03f2ce1SSushil Singh      Set To Dictionary  ${request_dict}  LockType  ${key}
269d03f2ce1SSushil Singh      Set To Dictionary  ${request_dict}  SegmentFlags  ${read_case["${key}"]}
270d03f2ce1SSushil Singh    END
271bc331e22SVijay
272d03f2ce1SSushil Singh    Set To Dictionary  ${request_dict}  ResourceID  ${res_id}
273d03f2ce1SSushil Singh
274d03f2ce1SSushil Singh    [Return]  ${request_dict}
275bc331e22SVijay
276bc331e22SVijay
277d03f2ce1SSushil SinghReturn Description Of Response
278d03f2ce1SSushil Singh    [Documentation]  Return description of REST response.
279bc331e22SVijay    [Arguments]  ${resp_text}
280bc331e22SVijay
281bc331e22SVijay    # Description of argument(s):
282d03f2ce1SSushil Singh    # resp_text    REST response body.
283bc331e22SVijay
284d03f2ce1SSushil Singh    # resp_text after successful partition file upload looks like:
285d03f2ce1SSushil Singh    # {
286d03f2ce1SSushil Singh    #    "Description": "File Created"
287d03f2ce1SSushil Singh    # }
288bc331e22SVijay
289d03f2ce1SSushil Singh    ${message}=  Evaluate  json.loads('''${resp_text}''')  json
290d03f2ce1SSushil Singh
291d03f2ce1SSushil Singh    [Return]  ${message}
292bc331e22SVijay
293bc331e22SVijay
294a7d71f02SSushil SinghVerify Redfish Session Deleted
295a7d71f02SSushil Singh    [Documentation]  Verify the redfish session is deleted.
296a7d71f02SSushil Singh    [Arguments]  ${session_info}
297a7d71f02SSushil Singh
298a7d71f02SSushil Singh    # Description of argument(s):
299a7d71f02SSushil Singh    # session_info    Session information are stored in dictionary.
300a7d71f02SSushil Singh
301a7d71f02SSushil Singh    # ${session_info} = {
302a7d71f02SSushil Singh    #     'SessionIDs': 'XXXXXXXXX',
303a7d71f02SSushil Singh    #     'ClientID': 'XXXXXX',
304a7d71f02SSushil Singh    #     'SessionToken': 'XXXXXXXXX',
305a7d71f02SSushil Singh    #     'SessionResp': session response from redfish login
306a7d71f02SSushil Singh    # }
307a7d71f02SSushil Singh
308a7d71f02SSushil Singh    # SessionIDs   : Session IDs
309a7d71f02SSushil Singh    # ClientID     : Client ID
310a7d71f02SSushil Singh    # SessionToken : Session token
311a7d71f02SSushil Singh    # SessionResp  : Response of creating an redfish login session
312a7d71f02SSushil Singh
313a7d71f02SSushil Singh    ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions
314a7d71f02SSushil Singh
315a7d71f02SSushil Singh    FOR  ${session}  IN  @{sessions['Members']}
316a7d71f02SSushil Singh      Should Not Be Equal As Strings  session  ['/redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}']
317a7d71f02SSushil Singh    END
318a7d71f02SSushil Singh
319a7d71f02SSushil Singh
320a7d71f02SSushil SinghVerify Redfish List Of Session Deleted
321a7d71f02SSushil Singh    [Documentation]  Verify all the list of redfish session is deleted.
322a7d71f02SSushil Singh    [Arguments]  ${session_info_list}
323a7d71f02SSushil Singh
324a7d71f02SSushil Singh    # Description of argument(s):
325a7d71f02SSushil Singh    # session_info_list    List contains individual session record are stored in dictionary.
326a7d71f02SSushil Singh
327a7d71f02SSushil Singh    # ${session_info_list} = [{
328a7d71f02SSushil Singh    #     'SessionIDs': 'XXXXXXXXX',
329a7d71f02SSushil Singh    #     'ClientID': 'XXXXXX',
330a7d71f02SSushil Singh    #     'SessionToken': 'XXXXXXXXX',
331a7d71f02SSushil Singh    #     'SessionResp': session response from redfish login
332a7d71f02SSushil Singh    # }]
333a7d71f02SSushil Singh
334a7d71f02SSushil Singh    # SessionIDs   : Session IDs
335a7d71f02SSushil Singh    # ClientID     : Client ID
336a7d71f02SSushil Singh    # SessionToken : Session token
337a7d71f02SSushil Singh    # SessionResp  : Response of creating an redfish login session
338a7d71f02SSushil Singh
339a7d71f02SSushil Singh    FOR  ${session_record}  IN  @{session_info_list}
340a7d71f02SSushil Singh      Verify Redfish Session Deleted  ${session_record}
341a7d71f02SSushil Singh    END
342a7d71f02SSushil Singh
343a7d71f02SSushil Singh
344d03f2ce1SSushil SinghRedfish Post Acquire Lock
345d03f2ce1SSushil Singh    [Documentation]  Acquire and release lock.
346d03f2ce1SSushil Singh    [Arguments]  ${lock_type}  ${status_code}=${HTTP_OK}
347bc331e22SVijay
348bc331e22SVijay    # Description of argument(s):
349d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
350d03f2ce1SSushil Singh    # status_code    HTTP status code.
351bc331e22SVijay
352e33c6e6aSSushil Singh    ${lock_dict_param}=  Form Data To Acquire Lock  ${lock_type}
353e33c6e6aSSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${lock_dict_param}
354d03f2ce1SSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
355d03f2ce1SSushil Singh    ${resp}=  Return Description Of Response  ${resp.content}
356bc331e22SVijay
357d03f2ce1SSushil Singh    [Return]  ${resp}
358bc331e22SVijay
359bc331e22SVijay
360d03f2ce1SSushil SinghRedfish Post Acquire Invalid Lock
361d03f2ce1SSushil Singh    [Documentation]  Redfish to post request to acquire in-valid lock.
362d03f2ce1SSushil Singh    [Arguments]  ${lock_type}  ${message}  ${status_code}=${HTTP_OK}
363bc331e22SVijay
364bc331e22SVijay    # Description of argument(s):
365d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
366d03f2ce1SSushil Singh    # message        Return message from URI.
367d03f2ce1SSushil Singh    # status_code    HTTP status code.
368bc331e22SVijay
369e33c6e6aSSushil Singh    ${lock_dict_param}=  Form Data To Acquire Invalid Lock  ${lock_type}
370e33c6e6aSSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${lock_dict_param}
371d03f2ce1SSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
372*3b3a7ecaSSushil Singh    Run Keyword If  '${message}' != '${EMPTY}'
373*3b3a7ecaSSushil Singh    ...  Valid Value  message  ['${resp.content}']
374d03f2ce1SSushil Singh
375d03f2ce1SSushil Singh    [Return]  ${resp}
376bc331e22SVijay
377bc331e22SVijay
378e33c6e6aSSushil SinghRedfish Post Acquire Invalid Lock With Invalid Data Type Of Resource ID
379e33c6e6aSSushil Singh    [Documentation]  Redfish to post request to acquire in-valid lock with invalid data type of resource id.
380e33c6e6aSSushil Singh    [Arguments]  ${lock_type}  ${status_code}=${HTTP_OK}
381e33c6e6aSSushil Singh
382e33c6e6aSSushil Singh    # Description of argument(s):
383e33c6e6aSSushil Singh    # lock_type      Read lock or Write lock.
384e33c6e6aSSushil Singh    # status_code    HTTP status code.
385e33c6e6aSSushil Singh
386e33c6e6aSSushil Singh    ${lock_dict_param}=  Form Data To Acquire Invalid Lock With Invalid Data Type Of Resource ID  ${lock_type}
387e33c6e6aSSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${lock_dict_param}
388e33c6e6aSSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
389e33c6e6aSSushil Singh
390e33c6e6aSSushil Singh    [Return]  ${resp}
391e33c6e6aSSushil Singh
392e33c6e6aSSushil Singh
393d03f2ce1SSushil SinghForm Data To Acquire Lock
394d03f2ce1SSushil Singh    [Documentation]  Create a dictionay for lock request.
395d03f2ce1SSushil Singh    [Arguments]  ${lock_type}
396d03f2ce1SSushil Singh
397d03f2ce1SSushil Singh    # Description of argument(s):
398d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
399d03f2ce1SSushil Singh
400d03f2ce1SSushil Singh    ${lock_res_info}=  Get Lock Resource Information
401d03f2ce1SSushil Singh    ${resp}=  RW General Dictionary
402d03f2ce1SSushil Singh    ...    ${lock_res_info["Valid Case"]["${lock_type}"]}
403d03f2ce1SSushil Singh    ...    ${lock_res_info["Valid Case"]["ResourceID"]}
404d03f2ce1SSushil Singh    ${temp_list}=  Create List  ${resp}
405e33c6e6aSSushil Singh    ${lock_request_dict}=  Create Dictionary  Request=${temp_list}
406d03f2ce1SSushil Singh
407e33c6e6aSSushil Singh    [Return]  ${lock_request_dict}
408e33c6e6aSSushil Singh
409e33c6e6aSSushil Singh
410e33c6e6aSSushil SinghForm Data To Acquire Invalid Lock With Invalid Data Type Of Resource ID
411e33c6e6aSSushil Singh    [Documentation]  Create a dictionay for in-valid lock request.
412e33c6e6aSSushil Singh    [Arguments]  ${lock_type}
413e33c6e6aSSushil Singh
414e33c6e6aSSushil Singh    # Description of argument(s):
415e33c6e6aSSushil Singh    # lock_type      Read lock or Write lock.
416e33c6e6aSSushil Singh
417e33c6e6aSSushil Singh    ${lock_res_info}=  Get Lock Resource Information
418e33c6e6aSSushil Singh    ${resp}=  RW General Dictionary
419e33c6e6aSSushil Singh    ...    ${lock_res_info["Valid Case"]["${lock_type}"]}
420e33c6e6aSSushil Singh    ...    ${lock_res_info["Invalid Case"]["ResourceIDInvalidDataType"]}
421e33c6e6aSSushil Singh    ${temp_list}=  Create List  ${resp}
422e33c6e6aSSushil Singh    ${lock_request_dict}=  Create Dictionary  Request=${temp_list}
423e33c6e6aSSushil Singh
424e33c6e6aSSushil Singh    [Return]  ${lock_request_dict}
425d03f2ce1SSushil Singh
426d03f2ce1SSushil Singh
427d03f2ce1SSushil SinghForm Data To Acquire Invalid Lock
428d03f2ce1SSushil Singh    [Documentation]  Create a dictionay for in-valid lock request.
429d03f2ce1SSushil Singh    [Arguments]  ${lock_type}
430d03f2ce1SSushil Singh
431d03f2ce1SSushil Singh    # Description of argument(s):
432d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
433d03f2ce1SSushil Singh
434d03f2ce1SSushil Singh    ${lock_res_info}=  Get Lock Resource Information
435d03f2ce1SSushil Singh    ${resp}=  RW General Dictionary
436d03f2ce1SSushil Singh    ...    ${lock_res_info["Invalid Case"]["${lock_type}"]}
437d03f2ce1SSushil Singh    ...    ${lock_res_info["Valid Case"]["ResourceID"]}
438d03f2ce1SSushil Singh    ${temp_list}=  Create List  ${resp}
439e33c6e6aSSushil Singh    ${lock_request_dict}=  Create Dictionary  Request=${temp_list}
440d03f2ce1SSushil Singh
441e33c6e6aSSushil Singh    [Return]  ${lock_request_dict}
442d03f2ce1SSushil Singh
443d03f2ce1SSushil Singh
444d03f2ce1SSushil SinghGet Locks List On Resource
445bc331e22SVijay    [Documentation]  Get locks list.
446d03f2ce1SSushil Singh    [Arguments]  ${session_info}  ${exp_status_code}=${HTTP_OK}
447bc331e22SVijay
448bc331e22SVijay    # Description of argument(s):
449d03f2ce1SSushil Singh    # session_info       Session information in dict.
450d03f2ce1SSushil Singh    # exp_status_code    Expected HTTP status code.
451bc331e22SVijay
452d03f2ce1SSushil Singh    ${data}=  Set Variable  {"SessionIDs": ["${session_info['SessionIDs']}"]}
453566daaf3SGeorge Keishing    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.GetLockList
454566daaf3SGeorge Keishing    ...  data=${data}
455bc331e22SVijay    ${locks}=  Evaluate  json.loads('''${resp.text}''')  json
456bc331e22SVijay
457bc331e22SVijay    [Return]  ${locks["Records"]}
458bc331e22SVijay
459bc331e22SVijay
460d03f2ce1SSushil SinghVerify Lock On Resource
461d03f2ce1SSushil Singh    [Documentation]  Verify lock on resource.
462d03f2ce1SSushil Singh    [Arguments]  ${session_info}  ${transaction_id}
463bc331e22SVijay
464bc331e22SVijay    # Description of argument(s):
465d03f2ce1SSushil Singh    # session_info      Session information in dict.
466d03f2ce1SSushil Singh    # transaction_id    Transaction id in list stored in dict.
467bc331e22SVijay
468d03f2ce1SSushil Singh    ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_info['SessionIDs']}
469d03f2ce1SSushil Singh    Rprint Vars  sessions
470d03f2ce1SSushil Singh    ${lock_list}=  Get Locks List On Resource  ${session_info}
471d03f2ce1SSushil Singh    ${lock_length}=  Get Length  ${lock_list}
472d03f2ce1SSushil Singh    ${tran_id_length}=  Get Length  ${transaction_id}
473d03f2ce1SSushil Singh    Should Be Equal As Integers  ${tran_id_length}  ${lock_length}
474afdd2a1dSVijay
475d03f2ce1SSushil Singh    FOR  ${tran_id}  ${lock}  IN ZIP  ${transaction_id}  ${lock_list}
476d03f2ce1SSushil Singh      Valid Value  session_info['ClientID']  ['${lock['HMCID']}']
477d03f2ce1SSushil Singh      Valid Value  session_info['SessionIDs']  ['${lock['SessionID']}']
478d03f2ce1SSushil Singh      Should Be Equal As Integers  ${tran_id['TransactionID']}  ${lock['TransactionID']}
479bc331e22SVijay    END
480bc331e22SVijay
481bc331e22SVijay
482d03f2ce1SSushil SinghAcquire Lock On Resource
483d03f2ce1SSushil Singh    [Documentation]  Acquire lock on resource.
484d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${reboot_flag}=False
485bc331e22SVijay
486bc331e22SVijay    # Description of argument(s):
487d03f2ce1SSushil Singh    # client_id    This client id can contain string value
488d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
489d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
490d03f2ce1SSushil Singh    # reboot_flag  Flag is used to run reboot the BMC code.
491d03f2ce1SSushil Singh    #               (e.g. True or False).
492bc331e22SVijay
493d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
494d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
495d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
496d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
497d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
498566daaf3SGeorge Keishing
499e33c6e6aSSushil Singh    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
500bc331e22SVijay
501d03f2ce1SSushil Singh    Run Keyword If  '${reboot_flag}' == 'True'
502d03f2ce1SSushil Singh    ...  Run Keywords  Redfish OBMC Reboot (off)  AND
503d03f2ce1SSushil Singh    ...  Redfish Login  AND
504e33c6e6aSSushil Singh    ...  Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}  AND
505d03f2ce1SSushil Singh    ...  Verify Lock On Resource  ${session_info}  ${trans_id_list}  AND
506d03f2ce1SSushil Singh    ...  Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
507bc331e22SVijay
508d03f2ce1SSushil Singh    Run Keyword If  '${reboot_flag}' == 'False'
509d03f2ce1SSushil Singh    ...  Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
510bc331e22SVijay
511d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
512d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
513d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
514bc331e22SVijay
515bc331e22SVijay
516d03f2ce1SSushil SinghForm Data To Release Lock
517d03f2ce1SSushil Singh    [Documentation]  Create a dictonay to release lock.
518d03f2ce1SSushil Singh    [Arguments]  ${trans_id_list}
519355daac7SVijay
520355daac7SVijay    # Description of argument(s):
521d03f2ce1SSushil Singh    # trans_id_list
522355daac7SVijay
523d03f2ce1SSushil Singh    @{tran_ids}=  Create List
524355daac7SVijay
525d03f2ce1SSushil Singh    FOR  ${item}  IN  @{trans_id_list}
526d03f2ce1SSushil Singh      Append To List  ${tran_ids}  ${item['TransactionID']}
527d03f2ce1SSushil Singh    END
528d03f2ce1SSushil Singh
529d03f2ce1SSushil Singh    [Return]  ${tran_ids}
530d03f2ce1SSushil Singh
531d03f2ce1SSushil Singh
532d03f2ce1SSushil SinghRelease Locks On Resource
533d03f2ce1SSushil Singh    [Documentation]  Redfish request to release a lock.
534d03f2ce1SSushil Singh    [Arguments]  ${session_info}  ${trans_id_list}  ${release_lock_type}=Transaction  ${status_code}=${HTTP_OK}
535d03f2ce1SSushil Singh
536d03f2ce1SSushil Singh    # Description of argument(s):
537d03f2ce1SSushil Singh    # session_info        Session information in dict.
538d03f2ce1SSushil Singh    # trans_id_list       Transaction id list.
539d03f2ce1SSushil Singh    # release_lock_type   Release lock by Transaction, Session.
540d03f2ce1SSushil Singh    # status_code         HTTP status code.
541d03f2ce1SSushil Singh
542d03f2ce1SSushil Singh    ${tran_ids}=  Form Data To Release Lock  ${trans_id_list}
543d03f2ce1SSushil Singh    ${data}=  Set Variable  {"Type": "${release_lock_type}", "TransactionIDs":${tran_ids}}
544d03f2ce1SSushil Singh    ${data}=  Evaluate  json.dumps(${data})  json
545d03f2ce1SSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock  data=${data}
546d03f2ce1SSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
547d03f2ce1SSushil Singh
548d03f2ce1SSushil Singh
549d03f2ce1SSushil SinghAcquire Lock On Another Lock
550d03f2ce1SSushil Singh    [Documentation]  Acquire lock on another lock.
551d03f2ce1SSushil Singh    [Arguments]  ${client_id}
552d03f2ce1SSushil Singh
553d03f2ce1SSushil Singh    # Description of argument(s):
554d03f2ce1SSushil Singh    # client_id    This client id can contain string value
555d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
556d03f2ce1SSushil Singh
557d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
558d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
559d03f2ce1SSushil Singh
560d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ReadCase1
561d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
562d03f2ce1SSushil Singh
563d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ReadCase1
564d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
565d03f2ce1SSushil Singh
566d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
567d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}
568d03f2ce1SSushil Singh
569d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
570d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
571d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
572d03f2ce1SSushil Singh
573d03f2ce1SSushil Singh
574d03f2ce1SSushil SinghVerify Empty Lock Records For Invalid Session
575d03f2ce1SSushil Singh    [Documentation]  Verify no lock record found for invalid session.
576d03f2ce1SSushil Singh    [Arguments]  ${client_id}
577d03f2ce1SSushil Singh
578d03f2ce1SSushil Singh    # Description of argument(s):
579d03f2ce1SSushil Singh    # client_id    This client id can contain string value
580d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
581d03f2ce1SSushil Singh
582d03f2ce1SSushil Singh    ${session_info1}=  Create Redfish Session With ClientID  ${client_id}
583d03f2ce1SSushil Singh
584d03f2ce1SSushil Singh    ${lock_list1}=  Get Locks List On Resource  ${session_info1}
585d03f2ce1SSushil Singh    ${lock_length1}=  Get Length  ${lock_list1}
586d03f2ce1SSushil Singh
587d03f2ce1SSushil Singh    ${session_info2}=  Copy Dictionary  ${session_info1}  deepcopy=True
588d03f2ce1SSushil Singh    set to dictionary  ${session_info2}  SessionIDs  xxyXyyYZZz
589d03f2ce1SSushil Singh
590d03f2ce1SSushil Singh    ${lock_list2}=  Get Locks List On Resource  ${session_info2}
591d03f2ce1SSushil Singh    ${lock_length2}=  Get Length  ${lock_list1}
592d03f2ce1SSushil Singh
593d03f2ce1SSushil Singh    Valid Value  lock_length1  ${lock_list2}
594d03f2ce1SSushil Singh
595d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info1}
596d03f2ce1SSushil Singh
597d03f2ce1SSushil Singh
598d03f2ce1SSushil SinghVerify Acquire Lock Fails On Another Lock
599d03f2ce1SSushil Singh    [Documentation]  Verify acquire lock on another lock fails.
600d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}
601d03f2ce1SSushil Singh
602d03f2ce1SSushil Singh    # Description of argument(s):
603d03f2ce1SSushil Singh    # client_id    This client id can contain string value
604d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
605d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
606d03f2ce1SSushil Singh
607d03f2ce1SSushil Singh    @{lock_type_list}=  Split String  ${lock_type}  ,
608d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
609d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
610d03f2ce1SSushil Singh
611d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
612d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
613d03f2ce1SSushil Singh
614d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
615d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]  status_code=${HTTP_CONFLICT}
616d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}
617d03f2ce1SSushil Singh
618d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
619d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
620d03f2ce1SSushil Singh
621d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
622d03f2ce1SSushil Singh
623d03f2ce1SSushil Singh
624e33c6e6aSSushil SinghVerify Acquire Lock After Reboot
625e33c6e6aSSushil Singh    [Documentation]  Acquire read and write lock after the reboot and release lock.
626e33c6e6aSSushil Singh    [Arguments]  ${client_id}  ${lock_type}
627e33c6e6aSSushil Singh
628e33c6e6aSSushil Singh    # Description of argument(s):
629e33c6e6aSSushil Singh    # client_id    This client id can contain string value
630e33c6e6aSSushil Singh    #              (e.g. 12345, "HMCID").
631e33c6e6aSSushil Singh    # lock_type    Read lock or Write lock.
632e33c6e6aSSushil Singh
633e33c6e6aSSushil Singh    ${trans_id_list}=  Create List
634e33c6e6aSSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
635e33c6e6aSSushil Singh    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
636e33c6e6aSSushil Singh    Redfish OBMC Reboot (off)
637e33c6e6aSSushil Singh    Redfish Login
638e33c6e6aSSushil Singh    Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}
639e33c6e6aSSushil Singh
640e33c6e6aSSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
641e33c6e6aSSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
642e33c6e6aSSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
643e33c6e6aSSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
644e33c6e6aSSushil Singh
645e33c6e6aSSushil Singh    ${trans_id_emptylist}=  Create List
646e33c6e6aSSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
647e33c6e6aSSushil Singh    Redfish Delete Session  ${session_info}
648e33c6e6aSSushil Singh
649e33c6e6aSSushil Singh
650d03f2ce1SSushil SinghVerify Acquire And Release Lock In Loop
651d03f2ce1SSushil Singh    [Documentation]  Acquire lock in loop.
652d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}
653d03f2ce1SSushil Singh
654d03f2ce1SSushil Singh    # Description of argument(s):
655d03f2ce1SSushil Singh    # client_id    This client id can contain string value
656d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
657d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
658d03f2ce1SSushil Singh
659d03f2ce1SSushil Singh    FOR  ${count}  IN RANGE  1  11
660d03f2ce1SSushil Singh      ${trans_id_list}=  Create List
661d03f2ce1SSushil Singh      ${session_info}=  Create Redfish Session With ClientID  ${client_id}
662d03f2ce1SSushil Singh      ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
663d03f2ce1SSushil Singh      Append To List  ${trans_id_list}  ${trans_id}
664d03f2ce1SSushil Singh      Verify Lock On Resource  ${session_info}  ${trans_id_list}
665d03f2ce1SSushil Singh      Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
666d03f2ce1SSushil Singh      ${trans_id_emptylist}=  Create List
667d03f2ce1SSushil Singh      Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
668d03f2ce1SSushil Singh    END
669d03f2ce1SSushil Singh
670d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
671d03f2ce1SSushil Singh
672d03f2ce1SSushil Singh
673d03f2ce1SSushil SinghAcquire And Release Multiple Locks
674d03f2ce1SSushil Singh    [Documentation]  Acquire mutilple locks on resource.
675d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
676d03f2ce1SSushil Singh
677d03f2ce1SSushil Singh    # Description of argument(s):
678d03f2ce1SSushil Singh    # client_id          This client id can contain string value
679d03f2ce1SSushil Singh    #                    (e.g. 12345, "HMCID").
680d03f2ce1SSushil Singh    # lock_type          Read lock or Write lock.
681d03f2ce1SSushil Singh    # release_lock_type  The value can be Transaction or Session.
682d03f2ce1SSushil Singh
683d03f2ce1SSushil Singh    @{lock_type_list}=  Split String  ${lock_type}  ,
684d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
685d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
686d03f2ce1SSushil Singh
687d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
688d03f2ce1SSushil Singh
689d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
690d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
691d03f2ce1SSushil Singh
692d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
693d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[2]
694d03f2ce1SSushil Singh
695d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
696d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
697d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=${release_lock_type}
698d03f2ce1SSushil Singh
699d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
700d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
701d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
702d03f2ce1SSushil Singh
703d03f2ce1SSushil Singh
704d03f2ce1SSushil SinghVerify Invalid Locks Fail To Release
705d03f2ce1SSushil Singh    [Documentation]  Verify invalid locks fails to be released.
706d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
707d03f2ce1SSushil Singh
708d03f2ce1SSushil Singh    # Description of argument(s):
709d03f2ce1SSushil Singh    # client_id          This client id can contain string value
710d03f2ce1SSushil Singh    #                    (e.g. 12345, "HMCID").
711d03f2ce1SSushil Singh    # lock_type          Read lock or Write lock.
712d03f2ce1SSushil Singh    # release_lock_type  The value can be Transaction or Session.
713d03f2ce1SSushil Singh
714d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
715d03f2ce1SSushil Singh    @{lock_type_list}=  Split String  ${lock_type}  ,
716d03f2ce1SSushil Singh
717d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
718d03f2ce1SSushil Singh
719d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
720d03f2ce1SSushil Singh    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
721d03f2ce1SSushil Singh    ${value}=  Evaluate  ${value} + 10
722d03f2ce1SSushil Singh    Set To Dictionary  ${trans_id}  TransactionID  ${value}
723d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
724d03f2ce1SSushil Singh
725d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
726d03f2ce1SSushil Singh    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
727d03f2ce1SSushil Singh    ${value}=  Evaluate  ${value} + 10
728d03f2ce1SSushil Singh    Set To Dictionary  ${trans_id}  TransactionID  ${value}
729d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
730d03f2ce1SSushil Singh
731d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[2]
732d03f2ce1SSushil Singh    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
733d03f2ce1SSushil Singh    ${value}=  Evaluate  ${value} + 10
734d03f2ce1SSushil Singh    Set To Dictionary  ${trans_id}  TransactionID  ${value}
735d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
736d03f2ce1SSushil Singh
737d03f2ce1SSushil Singh    Release Locks On Resource
738d03f2ce1SSushil Singh    ...  ${session_info}  ${trans_id_list}
739d03f2ce1SSushil Singh    ...  release_lock_type=${release_lock_type}  status_code=${HTTP_BAD_REQUEST}
740d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=Session
741d03f2ce1SSushil Singh
742d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
743d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
744d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
745d03f2ce1SSushil Singh
746d03f2ce1SSushil Singh
747d03f2ce1SSushil SinghVerify Fail To Release Lock For Another Session
748d03f2ce1SSushil Singh    [Documentation]  Verify failed to release the lock form another session.
749d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}
750d03f2ce1SSushil Singh
751d03f2ce1SSushil Singh    # Description of argument(s):
752d03f2ce1SSushil Singh    # client_id    This client id can contain string value
753d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
754d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
755d03f2ce1SSushil Singh
756d03f2ce1SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
757d03f2ce1SSushil Singh    ${lock_type_list}=  Split String  ${lock_type}  ,
758d03f2ce1SSushil Singh    ${trans_id_list1}=  Create List
759d03f2ce1SSushil Singh    ${trans_id_list2}=  Create List
760d03f2ce1SSushil Singh
761d03f2ce1SSushil Singh    ${session_info1}=  Create Redfish Session With ClientID  ${client_ids}[0]
762d03f2ce1SSushil Singh
763d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
764d03f2ce1SSushil Singh    Append To List  ${trans_id_list1}  ${trans_id}
765d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info1}  ${trans_id_list1}
766d03f2ce1SSushil Singh
767d03f2ce1SSushil Singh    ${session_info2}=  Create Redfish Session With ClientID  ${client_ids}[1]
768d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
769d03f2ce1SSushil Singh    Append To List  ${trans_id_list2}  ${trans_id}
770d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info2}  ${trans_id_list2}
771d03f2ce1SSushil Singh
772d03f2ce1SSushil Singh    Release Locks On Resource
773d03f2ce1SSushil Singh    ...  ${session_info1}  ${trans_id_list1}  Transaction  status_code=${HTTP_UNAUTHORIZED}
774d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info1}  ${trans_id_list1}
775d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info1}  ${trans_id_list1}  release_lock_type=Session
776d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info2}  ${trans_id_list2}  release_lock_type=Session
777d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info1}
778d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info2}
779d03f2ce1SSushil Singh
780d03f2ce1SSushil Singh
781e33c6e6aSSushil SinghVerify Fail To Acquire Lock For Invalid Resource ID Data Type
782e33c6e6aSSushil Singh    [Documentation]  Verify fail to acquire the lock with invalid resource id data type.
783e33c6e6aSSushil Singh    [Arguments]  ${client_id}  ${lock_type}
784e33c6e6aSSushil Singh
785e33c6e6aSSushil Singh    # Description of argument(s):
786e33c6e6aSSushil Singh    # client_id    This client id can contain string value
787e33c6e6aSSushil Singh    #              (e.g. 12345, "HMCID").
788e33c6e6aSSushil Singh    # lock_type    Read lock or Write lock.
789e33c6e6aSSushil Singh
790e33c6e6aSSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
791e33c6e6aSSushil Singh    Redfish Post Acquire Invalid Lock With Invalid Data Type Of Resource ID
792e33c6e6aSSushil Singh    ...  ${lock_type}  status_code=${HTTP_BAD_REQUEST}
793e33c6e6aSSushil Singh    Redfish Delete Session  ${session_info}
794e33c6e6aSSushil Singh
795e33c6e6aSSushil Singh
796d03f2ce1SSushil SinghVerify Fail To Acquire Lock For Invalid Lock Data
797e33c6e6aSSushil Singh    [Documentation]  Verify fail to acquired lock with invalid lock types, lock flags, segement flags.
798d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${message}
799d03f2ce1SSushil Singh
800d03f2ce1SSushil Singh    # Description of argument(s):
801d03f2ce1SSushil Singh    # client_id    This client id can contain string value
802d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
803d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
804d03f2ce1SSushil Singh    # message      Return message from URI.
805d03f2ce1SSushil Singh
806d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
807d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Invalid Lock  ${lock_type}  message=${message}  status_code=${HTTP_BAD_REQUEST}
808d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
809bace3005SSushil Singh
810bace3005SSushil Singh
811bace3005SSushil SinghVerify No Locks Records For Session With No Acquired Lock
812bace3005SSushil Singh    [Documentation]  Verify no records found for a session where no lock is acquired.
813bace3005SSushil Singh    [Arguments]  ${client_id}
814bace3005SSushil Singh
815bace3005SSushil Singh    # Description of argument(s):
816bace3005SSushil Singh    # client_id    This client id can contain string value
817bace3005SSushil Singh    #              (e.g. 12345, "HMCID").
818bace3005SSushil Singh
819bace3005SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
820bace3005SSushil Singh    ${trans_id_emptylist}=  Create List
821bace3005SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
822bace3005SSushil Singh    Redfish Delete Session  ${session_info}
823728ef9c9SSushil Singh
824728ef9c9SSushil Singh
825728ef9c9SSushil SinghCreate List Of Session ID
826728ef9c9SSushil Singh    [Documentation]  Create session id list from session dict info.
827728ef9c9SSushil Singh    [Arguments]  ${session_dict_info}
828728ef9c9SSushil Singh
829728ef9c9SSushil Singh    # Description of argument(s):
830728ef9c9SSushil Singh    # session_dict_info      Session information in dict.
831728ef9c9SSushil Singh
832728ef9c9SSushil Singh    @{session_id_list}=  Create List
833728ef9c9SSushil Singh
834728ef9c9SSushil Singh    FOR  ${session}  IN  @{session_dict_info}
835728ef9c9SSushil Singh      Append To List  ${session_id_list}  ${session["SessionIDs"]}
836728ef9c9SSushil Singh    END
837728ef9c9SSushil Singh
838728ef9c9SSushil Singh    ${num_id}=  Get Length  ${session_id_list}
839728ef9c9SSushil Singh    Should Not Be Equal As Integers  ${num_id}  ${0}
840728ef9c9SSushil Singh
841728ef9c9SSushil Singh    ${session_id_list}=  Evaluate  json.dumps(${session_id_list})  json
842728ef9c9SSushil Singh
843728ef9c9SSushil Singh    [Return]  ${session_id_list}
844728ef9c9SSushil Singh
845728ef9c9SSushil Singh
846728ef9c9SSushil SinghGet Locks List On Resource With Session List
847728ef9c9SSushil Singh    [Documentation]  Get locks list from session of list.
848728ef9c9SSushil Singh    [Arguments]  ${session_id_list}  ${exp_status_code}=${HTTP_OK}
849728ef9c9SSushil Singh
850728ef9c9SSushil Singh    # Description of argument(s):
851728ef9c9SSushil Singh    # session_id_list    Session ids list.
852728ef9c9SSushil Singh    # exp_status_code    Expected HTTP status code.
853728ef9c9SSushil Singh
854728ef9c9SSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.GetLockList
855728ef9c9SSushil Singh    ...  data={"SessionIDs": ${session_id_list}}
856728ef9c9SSushil Singh    ${locks}=  Evaluate  json.loads('''${resp.text}''')  json
857728ef9c9SSushil Singh
858728ef9c9SSushil Singh    [Return]  ${locks}
859728ef9c9SSushil Singh
860728ef9c9SSushil Singh
861728ef9c9SSushil SinghVerify List Of Session Lock On Resource
862728ef9c9SSushil Singh    [Documentation]  Verify list of lock record from list of sessions.
863728ef9c9SSushil Singh    [Arguments]  ${session_dict_info}  ${transaction_id_list}
864728ef9c9SSushil Singh
865728ef9c9SSushil Singh    # Description of argument(s):
866728ef9c9SSushil Singh    # session_dict_info      Session information in dict.
867728ef9c9SSushil Singh    # transaction_id_list    Transaction id in list stored in dict.
868728ef9c9SSushil Singh
869728ef9c9SSushil Singh    ${session_id_list}=  Create List Of Session ID  ${session_dict_info}
870728ef9c9SSushil Singh    ${lock_list_resp}=  Get Locks List On Resource With Session List  ${session_id_list}
871728ef9c9SSushil Singh    ${lock_list}=  Set Variable  ${lock_list_resp['Records']}
872728ef9c9SSushil Singh
873728ef9c9SSushil Singh    FOR  ${session_id}  ${tran_id}  ${lock_record}  IN ZIP  ${session_dict_info}  ${transaction_id_list}  ${lock_list}
874728ef9c9SSushil Singh      Valid Value  session_id['SessionIDs']  ['${lock_record['SessionID']}']
875728ef9c9SSushil Singh      Should Be Equal As Integers  ${tran_id['TransactionID']}  ${lock_record['TransactionID']}
876728ef9c9SSushil Singh    END
877728ef9c9SSushil Singh
878728ef9c9SSushil Singh
879728ef9c9SSushil SinghVerify Lock Records Of Multiple Session
880728ef9c9SSushil Singh    [Documentation]  Verify all records found for a multiple sessions.
881728ef9c9SSushil Singh    [Arguments]  ${client_ids}  ${lock_type}
882728ef9c9SSushil Singh
883728ef9c9SSushil Singh    # Description of argument(s):
884728ef9c9SSushil Singh    # client_ids    This client id can contain string value
885728ef9c9SSushil Singh    #               (e.g. 12345, "HMCID").
886728ef9c9SSushil Singh    # lock_type     Read lock or Write lock.
887728ef9c9SSushil Singh
888728ef9c9SSushil Singh    ${client_id_list}=  Split String  ${client_ids}  ,
889728ef9c9SSushil Singh    ${lock_type_list}=  Split String  ${lock_type}  ,
890728ef9c9SSushil Singh    ${trans_id_list1}=  Create List
891728ef9c9SSushil Singh    ${trans_id_list2}=  Create List
892728ef9c9SSushil Singh
893728ef9c9SSushil Singh    ${session_dict_list}=  Create List
894728ef9c9SSushil Singh    ${lock_list}=  Create List
895728ef9c9SSushil Singh
896728ef9c9SSushil Singh    ${client_id1}=  Create List
897728ef9c9SSushil Singh    Append To List  ${client_id1}  ${client_id_list}[0]
898728ef9c9SSushil Singh    ${session_info1}=  Create Session With List Of ClientID  ${client_id1}
899728ef9c9SSushil Singh    Append To List  ${session_dict_list}  ${session_info1}[0]
900728ef9c9SSushil Singh    Verify A Session Created With ClientID  ${client_id1}  ${session_info1}
901728ef9c9SSushil Singh
902728ef9c9SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
903728ef9c9SSushil Singh    Append To List  ${trans_id_list1}  ${trans_id}
904728ef9c9SSushil Singh    Append To List  ${lock_list}  ${trans_id}
905728ef9c9SSushil Singh    Verify Lock On Resource  ${session_info1}[0]  ${trans_id_list1}
906728ef9c9SSushil Singh
907728ef9c9SSushil Singh
908728ef9c9SSushil Singh    ${client_id2}=  Create List
909728ef9c9SSushil Singh    Append To List  ${client_id2}  ${client_id_list}[1]
910728ef9c9SSushil Singh    ${session_info2}=  Create Session With List Of ClientID  ${client_id2}
911728ef9c9SSushil Singh    Append To List  ${session_dict_list}  ${session_info2}[0]
912728ef9c9SSushil Singh    Verify A Session Created With ClientID  ${client_id2}  ${session_info2}
913728ef9c9SSushil Singh
914728ef9c9SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
915728ef9c9SSushil Singh    Append To List  ${trans_id_list2}  ${trans_id}
916728ef9c9SSushil Singh    Append To List  ${lock_list}  ${trans_id}
917728ef9c9SSushil Singh    Verify Lock On Resource  ${session_info2}[0]  ${trans_id_list2}
918728ef9c9SSushil Singh
919728ef9c9SSushil Singh    Verify List Of Session Lock On Resource  ${session_dict_list}  ${lock_list}
920728ef9c9SSushil Singh
921728ef9c9SSushil Singh    ${session_token}=  Get From Dictionary  ${session_info1}[0]  SessionToken
922728ef9c9SSushil Singh    Set Global Variable  ${XAUTH_TOKEN}  ${session_token}
923728ef9c9SSushil Singh
924728ef9c9SSushil Singh    Release Locks On Resource  ${session_info1}  ${trans_id_list1}  release_lock_type=Transaction
925728ef9c9SSushil Singh
926728ef9c9SSushil Singh    ${session_token}=  Get From Dictionary  ${session_info2}[0]  SessionToken
927728ef9c9SSushil Singh    Set Global Variable  ${XAUTH_TOKEN}  ${session_token}
928728ef9c9SSushil Singh
929728ef9c9SSushil Singh    Release Locks On Resource  ${session_info2}  ${trans_id_list2}  release_lock_type=Transaction
930728ef9c9SSushil Singh
931728ef9c9SSushil Singh    ${trans_id_emptylist}=  Create List
932728ef9c9SSushil Singh    Verify Lock On Resource  ${session_info1}[0]  ${trans_id_emptylist}
933728ef9c9SSushil Singh    Verify Lock On Resource  ${session_info2}[0]  ${trans_id_emptylist}
934728ef9c9SSushil Singh
935728ef9c9SSushil Singh    Redfish Delete List Of Session  ${session_dict_list}
936