1*** Settings ***
2
3Documentation           Test lock management feature of management console on BMC.
4
5Resource                ../../lib/resource.robot
6Resource                ../../lib/openbmc_ffdc.robot
7Resource                ../../lib/bmc_redfish_utils.robot
8Resource                ../../lib/external_intf/management_console_utils.robot
9Resource                ../../lib/rest_response_code.robot
10Library                 ../../lib/bmc_network_utils.py
11Library                 JSONLibrary
12
13Suite Setup              Run Keyword And Ignore Error  Delete All Redfish Sessions
14Suite Teardown           Run Keyword And Ignore Error  Delete All Redfish Sessions
15Test Setup               Printn
16Test Teardown            FFDC On Test Case Fail
17
18*** Variables ***
19
20${CONFLICT_RQUEST}       Conflict
21${BAD_REQUEST}           Bad Request
22&{default_trans_id}      TransactionID=${1}
23
24*** Test Cases ***
25
26Acquire Read Write Lock
27    [Documentation]  Acquire and release different read locks.
28    [Tags]  Acquire_Read_Write_Lock
29    [Template]  Acquire Lock On Resource
30
31    # client_id    lock_type     reboot_flag
32    HMCID-01       ReadCase1     False
33    HMCID-01       ReadCase2     False
34    HMCID-01       ReadCase3     False
35    HMCID-01       WriteCase1    False
36    HMCID-01       WriteCase2    False
37    HMCID-01       WriteCase3    False
38
39
40Verify Lock Is Not Persistent On BMC Reboot
41    [Documentation]  Acquire lock and after reboot the locks are removed as no persistency
42    ...  maintained.
43    [Tags]  Verify_Lock_Is_Not_Persistent_On_BMC_Reboot
44    [Template]  Acquire Lock On Resource
45
46    # client_id    lock_type     reboot_flag
47    HMCID-01       ReadCase1     True
48    HMCID-01       ReadCase2     True
49    HMCID-01       ReadCase3     True
50    HMCID-01       WriteCase1    True
51    HMCID-01       WriteCase2    True
52    HMCID-01       WriteCase3    True
53
54
55Check After Reboot Transaction ID Set To Default
56    [Documentation]  After reboot, the transaction id starts with default i.e. 1,
57    ...  if any lock is acquired.
58    [Tags]  Check_After_Reboot_Transaction_ID_Set_To_Default
59    [Template]  Verify Acquire And Release Lock In Loop
60
61    # client_id    lock_type     reboot_flag
62    HMCID-01       ReadCase1     True
63    HMCID-01       WriteCase1    True
64
65
66Acquire Read Lock On Read Lock
67    [Documentation]  Acquire read lock on another read lock.
68    [Tags]  Acquire_Read_Lock_On_Read_Lock
69    [Template]  Acquire Lock On Another Lock
70
71    # client_id
72    HMCID-01
73
74
75Fail To Acquire Lock On Another Lock
76    [Documentation]  Fail to acquire another lock.
77    [Tags]  Fail_To_Acquire_Lock_On_Another_Lock
78    [Template]  Verify Acquire Lock Fails On Another Lock
79
80    # client_id    lock_type
81    HMCID-01       ReadCase7,WriteCase6
82    HMCID-01       WriteCase6,WriteCase6
83    HMCID-01       WriteCase6,ReadCase7
84
85
86Acquire Lock After Reboot
87    [Documentation]  Acquire and release read and write locks after reboot.
88    [Tags]  Acquire_Lock_After_Reboot
89    [Template]  Verify Acquire Lock After Reboot
90
91    # client_id    lock_type
92    HMCID-01       ReadCase1
93    HMCID-01       ReadCase2
94    HMCID-01       ReadCase3
95    HMCID-01       WriteCase1
96    HMCID-01       WriteCase2
97    HMCID-01       WriteCase3
98
99
100Acquire And Release Lock In Loop
101    [Documentation]  Acquire and release read, write locks in loop.
102    [Tags]  Acquire_And_Release_Lock_In_Loop
103    [Template]  Verify Acquire And Release Lock In Loop
104
105    # client_id    lock_type
106    HMCID-01       ReadCase1
107    HMCID-01       ReadCase2
108    HMCID-01       ReadCase3
109    HMCID-01       WriteCase1
110    HMCID-01       WriteCase2
111    HMCID-01       WriteCase3
112
113
114Fail To Acquire Read And Write In Single Request
115    [Documentation]  Fail to acquire read and write lock in single request.
116    [Tags]  Fail_To_Acquire_Read_And_Write_In_Single_Request
117    [Template]  Verify Fail To Acquire Read And Write In Single Request
118
119    # client_id    lock_type               status_code
120    HMCID-01       ReadCase1,WriteCase1    ${HTTP_CONFLICT}
121    HMCID-01       WriteCase1,ReadCase1    ${HTTP_CONFLICT}
122    HMCID-01       WriteCase1,WriteCase1   ${HTTP_CONFLICT}
123
124
125Acquire Read In Single Request
126    [Documentation]  Acquire read in single request.
127    [Tags]  Acquire_Read_In_Single_Request
128    [Template]  Verify Acquire Read In Single Request
129
130    # client_id    lock_type
131    HMCID-01       ReadCase1,ReadCase1
132
133
134Acquire Multiple Lock Request At CEC Level
135    [Documentation]  Acquire write lock on read lock under CEC level.
136    [Tags]  Acquire_Multiple_Lock_Request_At_CEC_Level
137    [Template]  Verify Acquire Multiple Lock Request At CEC Level
138
139    # client_id    lock_type
140    HMCID-01       ReadCase4,WriteCase4
141    HMCID-01       WriteCase5,ReadCase5
142    HMCID-01       ReadCase6,WriteCase6
143    HMCID-01       WriteCase7,ReadCase7
144
145
146Verify Release Of Valid Locks
147    [Documentation]  Release all valid locks.
148    [Tags]  Verify_Release_Of_Valid_Locks
149    [Template]  Acquire And Release Multiple Locks
150
151    # client_id    lock_type                        release_lock_type
152    HMCID-01       ReadCase1,ReadCase1,ReadCase1    Transaction
153    HMCID-02       ReadCase1,ReadCase1,ReadCase1    Session
154
155
156Release Lock When Session Deleted
157    [Documentation]  Release lock when session gets deleted.
158    [Tags]  Release_Lock_When_Session_Deleted
159    [Template]  Verify Release Lock When Session Deleted
160
161    # client_id    lock_type
162    HMCID-01       ReadCase1
163    HMCID-01       WriteCase1
164
165
166Fail To Release Lock With Invalid TransactionID
167    [Documentation]  Fail to release lock with invalid transaction id.
168    [Tags]  Fail_To_Release_Lock_With_Invalid_TransactionID
169    [Template]  Verify Fail To Release Lock With Invalid TransactionID
170
171    # client_id    lock_type     release_lock_type
172    HMCID-01       ReadCase1     Transaction
173    HMCID-01       WriteCase1    Transaction
174
175
176Fail To Release Multiple Lock With Invalid TransactionID
177    [Documentation]  Release in-valid lock result in fail.
178    [Tags]  Fail_To_Release_Multiple_Lock_With_Invalid_TransactionID
179    [Template]  Verify Fail To Release Multiple Lock With Invalid TransactionID
180
181    # client_id    lock_type                        release_lock_type
182    HMCID-01       ReadCase1,ReadCase1,ReadCase1    Transaction
183    12345          ReadCase2,ReadCase2,ReadCase2    Transaction
184    HMCID          ReadCase3,ReadCase3,ReadCase3    Transaction
185
186
187Fail To Release Multiple Lock With Valid And Invalid TransactionID
188    [Documentation]  Release multiple lock with valid and invalid transaction.
189    [Tags]  Fail_To_Release_Multiple_Lock_With_Valid_And_Invalid_TransactionID
190    [Template]  Verify Fail To Release Multiple Lock With Valid And Invalid TransactionID
191
192    # client_id    lock_type              release_lock_type
193    HMCID-01       ReadCase1,ReadCase1    Transaction
194
195
196Fail To Release Lock With String As TransactionID Data Type
197    [Documentation]  Fail to release lock with string as transaction id data type.
198    [Tags]  Fail_To_Release_Lock_With_String_As_TransactionID_Data_Type
199    [Template]  Verify Fail To Release Lock With TransactionID As String Type
200
201    # client_id    lock_type     release_lock_type
202    HMCID-01       ReadCase1     Transaction
203    HMCID-01       WriteCase1    Transaction
204
205
206Fail To Release Lock For Another Session
207    [Documentation]  Failed to release locks from another session.
208    [Tags]  Fail_To_Release_Lock_For_Another_Session
209    [Template]  Verify Fail To Release Lock For Another Session
210
211    # client_id          lock_type
212    HMCID-01,HMCID-02    ReadCase1,ReadCase1
213
214
215Test Invalid Resource ID Data Type Locking
216    [Documentation]  Failed to acquire lock for invalid resource id data type.
217    [Tags]  Test_Invalid_Resource_ID_Data_Type_Locking
218    [Template]  Verify Fail To Acquire Lock For Invalid Resource ID Data Type
219
220    # client_id    lock_type
221    HMCID-01       ReadCase1
222    HMCID-01       ReadCase2
223    HMCID-01       ReadCase3
224    HMCID-01       WriteCase1
225    HMCID-01       WriteCase2
226    HMCID-01       WriteCase3
227
228
229Fail To Acquire Lock For Invalid Lock Type
230    [Documentation]  Failed to acquire read, write lock for invalid lock data passed.
231    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Lock_Type
232    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
233
234    # client_id    lock_type      message
235    HMCID-01       ReadCase1      ${BAD_REQUEST}
236    HMCID-01       ReadCase2      ${BAD_REQUEST}
237    HMCID-01       ReadCase3      ${BAD_REQUEST}
238    HMCID-01       ReadCase4      ${BAD_REQUEST}
239    HMCID-01       ReadCase5      ${BAD_REQUEST}
240    HMCID-01       WriteCase1     ${BAD_REQUEST}
241    HMCID-01       WriteCase2     ${BAD_REQUEST}
242    HMCID-01       WriteCase3     ${BAD_REQUEST}
243    HMCID-01       WriteCase4     ${BAD_REQUEST}
244    HMCID-01       WriteCase5     ${BAD_REQUEST}
245
246
247Fail To Acquire Lock For Invalid Lock Flag
248    [Documentation]  Failed to acquire read write lock for invalid lock flag passed.
249    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Lock_Flag
250    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
251
252    # client_id    lock_type       message
253    HMCID-01       ReadCase6       ${BAD_REQUEST}
254    HMCID-01       ReadCase7       ${BAD_REQUEST}
255    HMCID-01       ReadCase8       ${BAD_REQUEST}
256    HMCID-01       ReadCase9       ${BAD_REQUEST}
257    HMCID-01       ReadCase10      ${BAD_REQUEST}
258    HMCID-01       ReadCase11      ${BAD_REQUEST}
259    HMCID-01       WriteCase6      ${BAD_REQUEST}
260    HMCID-01       WriteCase7      ${BAD_REQUEST}
261    HMCID-01       WriteCase8      ${BAD_REQUEST}
262    HMCID-01       WriteCase9      ${BAD_REQUEST}
263    HMCID-01       WriteCase10     ${BAD_REQUEST}
264    HMCID-01       WriteCase11     ${BAD_REQUEST}
265
266
267Fail To Acquire Lock For Invalid Segment Flag
268    [Documentation]  Failed to acquire read write lock for invalid segment flag passed.
269    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Segment_Flag
270    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
271
272    # client_id    lock_type       message
273    HMCID-01       ReadCase12      ${BAD_REQUEST}
274    HMCID-01       ReadCase13      ${BAD_REQUEST}
275    HMCID-01       ReadCase14      ${BAD_REQUEST}
276    HMCID-01       WriteCase12     ${BAD_REQUEST}
277    HMCID-01       WriteCase13     ${BAD_REQUEST}
278    HMCID-01       WriteCase14     ${BAD_REQUEST}
279
280
281Fail To Acquire Lock For Invalid Segment Data Type Flag
282    [Documentation]  Failed to acquire read write lock for invalid segment flag passed.
283    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Segment_Data_Type_Flag
284    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
285
286    # client_id    lock_type       message
287    HMCID-01       ReadCase15      ${EMPTY}
288    HMCID-01       ReadCase16      ${EMPTY}
289    HMCID-01       ReadCase17      ${EMPTY}
290    HMCID-01       ReadCase18      ${EMPTY}
291    HMCID-01       WriteCase15     ${EMPTY}
292    HMCID-01       WriteCase16     ${EMPTY}
293    HMCID-01       WriteCase17     ${EMPTY}
294    HMCID-01       WriteCase18     ${EMPTY}
295
296
297Get Empty Lock Records For Session Where No Locks Acquired
298    [Documentation]  If session does not acquire locks then get lock should return
299    ...              empty lock records.
300    [Tags]  Get_Empty_Lock_Records_For_Session_Where_No_Locks_Acquired
301    [Template]  Verify No Locks Records For Session With No Acquired Lock
302
303    # client_id
304    HMCID-01
305
306
307Get Lock Records Empty For Invalid Session
308    [Documentation]  Record of lock list is empty for invalid session.
309    [Tags]  Get_Lock_Records_Empty_For_Invalid_Session
310    [Template]  Verify Empty Lock Records For Invalid Session
311
312    # client_id
313    HMCID-01
314
315
316Get Lock Records For Multiple Session
317    [Documentation]  Get lock records of multiple session.
318    [Tags]  Get_Lock_Records_For_Multiple_Session
319    [Template]  Verify Lock Records Of Multiple Session
320
321    # client_ids         lock_type
322    HMCID-01,HMCID-02    ReadCase1,ReadCase1
323
324
325Get Lock Records For Multiple Invalid Session
326    [Documentation]  Record of lock list is empty for list of invalid session.
327    [Tags]  Get_Lock_Records_For_Multiple_Invalid_Session
328    [Template]  Verify Lock Records For Multiple Invalid Session
329
330    # client_id
331    HMCID-01
332
333
334Get Lock Records For Multiple Invalid And Valid Session
335    [Documentation]  Get record of lock from invalid and valid session.
336    [Tags]  Get_Lock_Records_For_Multiple_Invalid_And_Valid_Session
337    [Template]  Verify Lock Records For Multiple Invalid And Valid Session
338
339    # client_id          lock_type
340    HMCID-01,HMCID-02    ReadCase1
341
342*** Keywords ***
343
344Create Redfish Session With ClientID
345    [Documentation]  Create redifish session with client id.
346    [Arguments]  ${client_id}
347
348    # Description of argument(s):
349    # client_id    This client id can contain string value
350    #              (e.g. 12345, "HMCID").
351
352    ${session_info}=  Create Dictionary
353    ${session}=  Redfish Login  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client_id}"}}
354
355    Set To Dictionary  ${session_info}  SessionIDs  ${session['Id']}
356    Set To Dictionary  ${session_info}  ClientID  ${session["Oem"]["OpenBMC"]["ClientID"]}
357
358    [Return]  ${session_info}
359
360
361RW General Dictionary
362    [Documentation]  Create dictionary of lock request.
363    [Arguments]  ${read_case}  ${res_id}
364
365    # Description of argument(s):
366    # read_case    Read or Write lock type.
367    # res_id       Resource id.
368
369    ${request_dict}=  Create Dictionary
370
371    FOR  ${key}  IN  @{read_case.keys()}
372      Set To Dictionary  ${request_dict}  LockType  ${key}
373      Set To Dictionary  ${request_dict}  SegmentFlags  ${read_case["${key}"]}
374    END
375
376    Set To Dictionary  ${request_dict}  ResourceID  ${res_id}
377
378    [Return]  ${request_dict}
379
380
381Return Description Of Response
382    [Documentation]  Return description of REST response.
383    [Arguments]  ${resp_text}
384
385    # Description of argument(s):
386    # resp_text    REST response body.
387
388    # resp_text after successful partition file upload looks like:
389    # {
390    #    "Description": "File Created"
391    # }
392
393    ${message}=  Evaluate  json.loads('''${resp_text}''')  json
394
395    [Return]  ${message}
396
397
398Verify Redfish Session Deleted
399    [Documentation]  Verify the redfish session is deleted.
400    [Arguments]  ${session_info}
401
402    # Description of argument(s):
403    # session_info    Session information are stored in dictionary.
404
405    # ${session_info} = {
406    #     'SessionIDs': 'XXXXXXXXX',
407    #     'ClientID': 'XXXXXX',
408    #     'SessionToken': 'XXXXXXXXX',
409    #     'SessionResp': session response from redfish login
410    # }
411
412    # SessionIDs   : Session IDs
413    # ClientID     : Client ID
414    # SessionToken : Session token
415    # SessionResp  : Response of creating an redfish login session
416
417    ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions
418
419    FOR  ${session}  IN  @{sessions['Members']}
420      Should Not Be Equal As Strings
421      ...  session  ['/redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}']
422    END
423
424
425Verify Redfish List Of Session Deleted
426    [Documentation]  Verify all the list of redfish session is deleted.
427    [Arguments]  ${session_info_list}
428
429    # Description of argument(s):
430    # session_info_list    List contains individual session record are stored in dictionary.
431
432    # ${session_info_list} = [{
433    #     'SessionIDs': 'XXXXXXXXX',
434    #     'ClientID': 'XXXXXX',
435    #     'SessionToken': 'XXXXXXXXX',
436    #     'SessionResp': session response from redfish login
437    # }]
438
439    # SessionIDs   : Session IDs
440    # ClientID     : Client ID
441    # SessionToken : Session token
442    # SessionResp  : Response of creating an redfish login session
443
444    FOR  ${session_record}  IN  @{session_info_list}
445      Verify Redfish Session Deleted  ${session_record}
446    END
447
448
449Redfish Post Acquire Lock
450    [Documentation]  Acquire and release lock.
451    [Arguments]  ${lock_type}  ${status_code}=${HTTP_OK}
452
453    # Description of argument(s):
454    # lock_type      Read lock or Write lock.
455    # status_code    HTTP status code.
456
457    ${lock_dict_param}=  Form Data To Acquire Lock  ${lock_type}
458    ${lock_dict_param}=  Convert JSON To String  ${lock_dict_param}
459    ${resp}=  Redfish Post Request
460    ...  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${lock_dict_param}
461    ...  expected_status=any
462    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
463
464    Run Keyword If  ${status_code} == ${HTTP_BAD_REQUEST}
465    ...    Valid Value  ${BAD_REQUEST}  ['${resp.content}']
466    ...  ELSE
467    ...    Run Keyword And Return  Return Description Of Response  ${resp.content}
468
469    [Return]  ${resp}
470
471
472Redfish Post Acquire List Lock
473    [Documentation]  Acquire and release lock.
474    [Arguments]  ${lock_type}  ${status_code}=${HTTP_OK}
475
476    # Description of argument(s):
477    # lock_type      Read lock or Write lock.
478    # status_code    HTTP status code.
479
480    ${lock_dict_param}=  Create Data To Acquire List Of Lock  ${lock_type}
481    ${lock_dict_param}=  Convert JSON To String  ${lock_dict_param}
482    ${resp}=  Redfish Post Request
483    ...  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${lock_dict_param}
484    ...   expected_status=any
485    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
486
487    Run Keyword If  ${status_code} == ${HTTP_CONFLICT}
488    ...    Should Be Equal As Strings  ${CONFLICT_RQUEST}  ${resp.content}
489    ...  ELSE
490    ...    Run Keyword And Return  Return Description Of Response  ${resp.content}
491
492    [Return]  ${resp}
493
494
495Redfish Post Acquire Invalid Lock
496    [Documentation]  Redfish to post request to acquire in-valid lock.
497    [Arguments]  ${lock_type}  ${message}  ${status_code}=${HTTP_OK}
498
499    # Description of argument(s):
500    # lock_type      Read lock or Write lock.
501    # message        Return message from URI.
502    # status_code    HTTP status code.
503
504    ${lock_dict_param}=  Form Data To Acquire Invalid Lock  ${lock_type}
505    ${lock_dict_param}=  Convert JSON To String  ${lock_dict_param}
506    ${resp}=  Redfish Post Request
507    ...  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${lock_dict_param}
508    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
509    Run Keyword If  '${message}' != '${EMPTY}'
510    ...  Valid Value  message  ['${resp.content}']
511
512    [Return]  ${resp}
513
514
515Redfish Post Acquire Invalid Lock With Invalid Data Type Of Resource ID
516    [Documentation]  Redfish to post request to acquire in-valid lock with invalid data type of resource id.
517    [Arguments]  ${lock_type}  ${status_code}=${HTTP_OK}
518
519    # Description of argument(s):
520    # lock_type      Read lock or Write lock.
521    # status_code    HTTP status code.
522
523    ${lock_dict_param}=
524    ...  Form Data To Acquire Invalid Lock With Invalid Data Type Of Resource ID  ${lock_type}
525    ${lock_dict_param}=  Convert JSON To String  ${lock_dict_param}
526    ${resp}=  Redfish Post Request
527    ...  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${lock_dict_param}
528    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
529
530    [Return]  ${resp}
531
532
533Form Data To Acquire Lock
534    [Documentation]  Create a dictionary for lock request.
535    [Arguments]  ${lock_type}
536
537    # Description of argument(s):
538    # lock_type      Read lock or Write lock.
539
540    ${lock_res_info}=  Get Lock Resource Information
541    ${resp}=  RW General Dictionary
542    ...    ${lock_res_info["Valid Case"]["${lock_type}"]}
543    ...    ${lock_res_info["Valid Case"]["ResourceID"]}
544    ${temp_list}=  Create List  ${resp}
545    ${lock_request_dict}=  Create Dictionary  Request=${temp_list}
546
547    [Return]  ${lock_request_dict}
548
549
550Create Data To Acquire List Of Lock
551    [Documentation]  Create a dictionary for list of lock request.
552    [Arguments]  ${lock_type_list}
553
554    # Description of argument(s):
555    # lock_type      Read lock or Write lock.
556
557    ${temp_list}=  Create List
558    ${lock_res_info}=  Get Lock Resource Information
559
560    FOR  ${lock_type}  IN  @{lock_type_list}
561      ${resp}=  RW General Dictionary
562      ...    ${lock_res_info["Valid Case"]["${lock_type}"]}
563      ...    ${lock_res_info["Valid Case"]["ResourceID"]}
564      Append To List  ${temp_list}  ${resp}
565    END
566
567    ${lock_request_dict}=  Create Dictionary  Request=${temp_list}
568
569    [Return]  ${lock_request_dict}
570
571
572Form Data To Acquire Invalid Lock With Invalid Data Type Of Resource ID
573    [Documentation]  Create a dictionary for in-valid lock request.
574    [Arguments]  ${lock_type}
575
576    # Description of argument(s):
577    # lock_type      Read lock or Write lock.
578
579    ${lock_res_info}=  Get Lock Resource Information
580    ${resp}=  RW General Dictionary
581    ...    ${lock_res_info["Valid Case"]["${lock_type}"]}
582    ...    ${lock_res_info["Invalid Case"]["ResourceIDInvalidDataType"]}
583    ${temp_list}=  Create List  ${resp}
584    ${lock_request_dict}=  Create Dictionary  Request=${temp_list}
585
586    [Return]  ${lock_request_dict}
587
588
589Form Data To Acquire Invalid Lock
590    [Documentation]  Create a dictionary for in-valid lock request.
591    [Arguments]  ${lock_type}
592
593    # Description of argument(s):
594    # lock_type      Read lock or Write lock.
595
596    ${lock_res_info}=  Get Lock Resource Information
597    ${resp}=  RW General Dictionary
598    ...    ${lock_res_info["Invalid Case"]["${lock_type}"]}
599    ...    ${lock_res_info["Valid Case"]["ResourceID"]}
600    ${temp_list}=  Create List  ${resp}
601    ${lock_request_dict}=  Create Dictionary  Request=${temp_list}
602
603    [Return]  ${lock_request_dict}
604
605
606Get Locks List On Resource
607    [Documentation]  Get locks list.
608    [Arguments]  ${session_info}  ${exp_status_code}=${HTTP_OK}
609
610    # Description of argument(s):
611    # session_info       Session information in dict.
612    # exp_status_code    Expected HTTP status code.
613
614    ${data}=  Set Variable  {"SessionIDs": ["${session_info['SessionIDs']}"]}
615    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.GetLockList
616    ...  data=${data}
617    ${locks}=  Evaluate  json.loads('''${resp.text}''')  json
618
619    [Return]  ${locks["Records"]}
620
621
622Verify Lock On Resource
623    [Documentation]  Verify lock on resource.
624    [Arguments]  ${session_info}  ${transaction_id}
625
626    # Description of argument(s):
627    # session_info      Session information in dict.
628    # transaction_id    Transaction id in list stored in dict.
629
630    ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_info['SessionIDs']}
631    Rprint Vars  sessions
632    ${lock_list}=  Get Locks List On Resource  ${session_info}
633    ${lock_length}=  Get Length  ${lock_list}
634    ${tran_id_length}=  Get Length  ${transaction_id}
635    Should Be Equal As Integers  ${tran_id_length}  ${lock_length}
636
637    FOR  ${tran_id}  ${lock}  IN ZIP  ${transaction_id}  ${lock_list}
638      Valid Value  session_info['ClientID']  ['${lock['HMCID']}']
639      Valid Value  session_info['SessionIDs']  ['${lock['SessionID']}']
640      Should Be Equal As Integers  ${tran_id['TransactionID']}  ${lock['TransactionID']}
641    END
642
643
644Acquire Lock On Resource
645    [Documentation]  Acquire lock on resource.
646    [Arguments]  ${client_id}  ${lock_type}  ${reboot_flag}=False
647
648    # Description of argument(s):
649    # client_id    This client id can contain string value
650    #              (e.g. 12345, "HMCID").
651    # lock_type    Read lock or Write lock.
652    # reboot_flag  Flag is used to run reboot the BMC code.
653    #               (e.g. True or False).
654
655    ${trans_id_emptylist}=  Create List
656    ${trans_id_list}=  Create List
657
658    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
659    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
660    Append To List  ${trans_id_list}  ${trans_id}
661
662    Verify Lock On Resource  ${session_info}  ${trans_id_list}
663
664    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
665
666    Run Keyword If  '${reboot_flag}' == 'True'
667    ...  Run Keywords  Redfish BMC Reset Operation  AND
668    ...  Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}  AND
669    ...  Is BMC Standby  AND
670    ...  Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
671
672    Run Keyword If  '${reboot_flag}' == 'False'
673    ...  Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
674
675    ${trans_id_emptylist}=  Create List
676    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
677    Redfish Delete Session  ${session_info}
678
679
680Form Data To Release Lock
681    [Documentation]  Create a dictonay to release lock.
682    [Arguments]  ${trans_id_list}
683
684    # Description of argument(s):
685    # trans_id_list
686
687    @{tran_ids}=  Create List
688
689    FOR  ${item}  IN  @{trans_id_list}
690      Append To List  ${tran_ids}  ${item['TransactionID']}
691    END
692
693    [Return]  ${tran_ids}
694
695
696Release Locks On Resource
697    [Documentation]  Redfish request to release a lock.
698    [Arguments]  ${session_info}  ${trans_id_list}  ${release_lock_type}=Transaction
699    ...  ${status_code}=${HTTP_OK}
700
701    # Description of argument(s):
702    # session_info        Session information in dict.
703    # trans_id_list       Transaction id list.
704    # release_lock_type   Release lock by Transaction, Session.
705    # status_code         HTTP status code.
706
707    ${tran_ids}=  Form Data To Release Lock  ${trans_id_list}
708    ${data}=  Set Variable  {"Type": "${release_lock_type}", "TransactionIDs":${tran_ids}}
709    ${data}=  Evaluate  json.dumps(${data})  json
710    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock  data=${data}
711    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
712
713
714Release locks And Delete Session
715    [Documentation]  Release locks and delete redfish session.
716    [Arguments]  ${session_info}  ${trans_id_list}
717
718    Release Locks On Resource  ${session_info}  ${trans_id_list}
719
720    ${trans_id_emptylist}=  Create List
721    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
722
723    Redfish Delete Session  ${session_info}
724
725
726Acquire Lock On Another Lock
727    [Documentation]  Acquire lock on another lock.
728    [Arguments]  ${client_id}
729
730    # Description of argument(s):
731    # client_id    This client id can contain string value
732    #              (e.g. 12345, "HMCID").
733
734    ${trans_id_list}=  Create List
735    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
736
737    ${trans_id}=  Redfish Post Acquire Lock  ReadCase1
738    Append To List  ${trans_id_list}  ${trans_id}
739
740    ${trans_id}=  Redfish Post Acquire Lock  ReadCase1
741    Append To List  ${trans_id_list}  ${trans_id}
742
743    Verify Lock On Resource  ${session_info}  ${trans_id_list}
744
745    Release locks And Delete Session  ${session_info}  ${trans_id_list}
746
747
748Verify Fail To Acquire Read And Write In Single Request
749    [Documentation]  Verify fail to acquire read and write lock passed in single request.
750    [Arguments]  ${client_id}  ${lock_type}  ${status_code}
751
752    # Description of argument(s):
753    # client_id     This client id can contain string value
754    #               (e.g. 12345, "HMCID").
755    # lock_type     Read lock or Write lock.
756    # status_code   HTTP status code
757
758    ${lock_type_list}=  Split String  ${lock_type}  ,
759
760    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
761    ${trans_id}=  Redfish Post Acquire List Lock  ${lock_type_list}  status_code=${status_code}
762    Redfish Delete Session  ${session_info}
763
764
765Verify Acquire Read In Single Request
766    [Documentation]  Verify acquire read in single request.
767    [Arguments]  ${client_id}  ${lock_type}
768
769    # Description of argument(s):
770    # client_id    This client id can contain string value
771    #              (e.g. 12345, "HMCID").
772    # lock_type    Read lock or Write lock.
773
774    ${trans_id_list}=  Create List
775    ${lock_type_list}=  Split String  ${lock_type}  ,
776
777    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
778    ${trans_id}=  Redfish Post Acquire List Lock  ${lock_type_list}
779    Append To List  ${trans_id_list}  ${trans_id}
780    Append To List  ${trans_id_list}  ${trans_id}
781
782    Verify Lock On Resource  ${session_info}  ${trans_id_list}
783    Remove From List  ${trans_id_list}  1
784    Release Locks On Resource  ${session_info}  ${trans_id_list}
785
786    Redfish Delete Session  ${session_info}
787
788
789Verify Empty Lock Records For Invalid Session
790    [Documentation]  Verify no lock record found for invalid session.
791    [Arguments]  ${client_id}
792
793    # Description of argument(s):
794    # client_id    This client id can contain string value
795    #              (e.g. 12345, "HMCID").
796
797    ${session_info1}=  Create Redfish Session With ClientID  ${client_id}
798
799    ${lock_list1}=  Get Locks List On Resource  ${session_info1}
800    ${lock_length1}=  Get Length  ${lock_list1}
801
802    ${session_info2}=  Copy Dictionary  ${session_info1}  deepcopy=True
803    set to dictionary  ${session_info2}  SessionIDs  xxyXyyYZZz
804
805    ${lock_list2}=  Get Locks List On Resource  ${session_info2}
806    ${lock_length2}=  Get Length  ${lock_list2}
807
808    Should Be Equal As Integers  ${lock_length1}  ${lock_length2}
809
810    Redfish Delete Session  ${session_info1}
811
812
813Verify Acquire Lock Fails On Another Lock
814    [Documentation]  Verify acquire lock on another lock fails.
815    [Arguments]  ${client_id}  ${lock_type}
816
817    # Description of argument(s):
818    # client_id    This client id can contain string value
819    #              (e.g. 12345, "HMCID").
820    # lock_type    Read lock or Write lock.
821
822    @{lock_type_list}=  Split String  ${lock_type}  ,
823    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
824    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
825
826    ${trans_id_list}=  Create List
827    Append To List  ${trans_id_list}  ${trans_id}
828
829    Verify Lock On Resource  ${session_info}  ${trans_id_list}
830    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]  status_code=${HTTP_CONFLICT}
831
832    Release locks And Delete Session  ${session_info}  ${trans_id_list}
833
834
835Verify Acquire Lock After Reboot
836    [Documentation]  Acquire read and write lock after the reboot and release lock.
837    [Arguments]  ${client_id}  ${lock_type}
838
839    # Description of argument(s):
840    # client_id    This client id can contain string value
841    #              (e.g. 12345, "HMCID").
842    # lock_type    Read lock or Write lock.
843
844    ${trans_id_list}=  Create List
845    ${session_info}=  Create Session With ClientID  ${client_id}
846
847    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
848    Redfish BMC Reset Operation
849    Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}
850    Is BMC Standby
851
852    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
853    Append To List  ${trans_id_list}  ${trans_id}
854    Verify Lock On Resource  ${session_info}  ${trans_id_list}
855
856    Release locks And Delete Session  ${session_info}  ${trans_id_list}
857
858
859Verify Acquire Multiple Lock Request At CEC Level
860    [Documentation]  Acquire lock in loop.
861    [Arguments]  ${client_id}  ${lock_type}
862
863    # Description of argument(s):
864    # client_id    This client id can contain string value
865    #              (e.g. 12345, "HMCID").
866    # lock_type    Read lock or Write lock.
867
868    ${trans_id_list}=  Create List
869    @{lock_type_list}=  Split String  ${lock_type}  ,
870    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
871
872    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
873    Append To List  ${trans_id_list}  ${trans_id}
874
875    Verify Lock On Resource  ${session_info}  ${trans_id_list}
876
877    Redfish Post Acquire Lock  ${lock_type_list}[1]  status_code=${HTTP_CONFLICT}
878
879    Release locks And Delete Session  ${session_info}  ${trans_id_list}
880
881
882Post Reboot Acquire Lock
883    [Documentation]  Post reboot acquire lock and verify the transaction id is 1.
884    [Arguments]  ${session_info}  ${lock_type}
885
886    # Description of argument(s):
887    # session_info     Session information.
888    # lock_type        Read lock or Write lock.
889
890    ${trans_id_list}=  Create List
891    ${trans_id_list_var}=  Create List
892    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
893    Append To List  ${trans_id_list}  ${trans_id}
894    Append To List  ${trans_id_list_var}  ${default_trans_id}
895    Verify Lock On Resource  ${session_info}  ${trans_id_list}
896    Verify Lock On Resource  ${session_info}  ${trans_id_list_var}
897    Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
898    ${trans_id_emptylist}=  Create List
899    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
900
901
902Verify Acquire And Release Lock In Loop
903    [Documentation]  Acquire lock in loop.
904    [Arguments]  ${client_id}  ${lock_type}  ${reboot_flag}=False
905
906    # Description of argument(s):
907    # client_id    This client id can contain string value
908    #              (e.g. 12345, "HMCID").
909    # lock_type    Read lock or Write lock.
910    # reboot_flag  Flag is used to run reboot the BMC code.
911    #               (e.g. True or False).
912
913    FOR  ${count}  IN RANGE  1  11
914      ${trans_id_list}=  Create List
915      ${session_info}=  Create Redfish Session With ClientID  ${client_id}
916      ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
917      Append To List  ${trans_id_list}  ${trans_id}
918      Verify Lock On Resource  ${session_info}  ${trans_id_list}
919      Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
920      ${trans_id_emptylist}=  Create List
921      Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
922      Redfish Delete Session  ${session_info}
923    END
924
925    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
926    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
927
928    Run Keyword If  '${reboot_flag}' == 'True'
929    ...  Run Keywords  Redfish BMC Reset Operation  AND
930    ...  Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}  AND
931    ...  Is BMC Standby  AND
932    ...  Post Reboot Acquire Lock  ${session_info}  ${lock_type}
933    Redfish Delete Session  ${session_info}
934
935
936Acquire And Release Multiple Locks
937    [Documentation]  Acquire mutilple locks on resource.
938    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
939
940    # Description of argument(s):
941    # client_id          This client id can contain string value
942    #                    (e.g. 12345, "HMCID").
943    # lock_type          Read lock or Write lock.
944    # release_lock_type  The value can be Transaction or Session.
945
946    @{lock_type_list}=  Split String  ${lock_type}  ,
947    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
948    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
949
950    ${trans_id_list}=  Create List
951
952    Append To List  ${trans_id_list}  ${trans_id}
953    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
954
955    Append To List  ${trans_id_list}  ${trans_id}
956    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[2]
957
958    Append To List  ${trans_id_list}  ${trans_id}
959    Verify Lock On Resource  ${session_info}  ${trans_id_list}
960    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=${release_lock_type}
961
962    ${trans_id_emptylist}=  Create List
963    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
964    Redfish Delete Session  ${session_info}
965
966
967Verify Release Lock When Session Deleted
968    [Documentation]  Verify lock get released when session are deleted.
969    [Arguments]  ${client_id}  ${lock_type}
970
971    # Description of argument(s):
972    # client_ids    This client id can contain string value
973    #               (e.g. 12345, "HMCID").
974    # lock_type     Read lock or Write lock.
975
976    ${trans_id_list}=  Create List
977    @{lock_type_list}=  Split String  ${lock_type}  ,
978
979    ${pre_session_info}=  Create Redfish Session With ClientID  ${client_id}
980
981    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
982    Append To List  ${trans_id_list}  ${trans_id}
983    Verify Lock On Resource  ${pre_session_info}  ${trans_id_list}
984
985    Redfish Delete Session  ${pre_session_info}
986    ${post_session_info}=  Create Redfish Session With ClientID  ${client_id}
987    ${resp}=  Get Locks List On Resource With Session List  ${pre_session_info}  ${HTTP_BAD_REQUEST}
988
989    Redfish Delete Session  ${post_session_info}
990
991
992
993Verify Fail To Release Lock With Invalid TransactionID
994    [Documentation]  Verify fail to be release lock with invalid transaction ID.
995    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
996
997    # Description of argument(s):
998    # client_id          This client id can contain string value
999    #                    (e.g. 12345, "HMCID").
1000    # lock_type          Read lock or Write lock.
1001    # release_lock_type  The value can be Transaction or Session.
1002
1003    ${trans_id_list}=  Create List
1004    @{lock_type_list}=  Split String  ${lock_type}  ,
1005
1006    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
1007
1008    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
1009    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
1010    ${value}=  Evaluate  ${value} + 10
1011    Set To Dictionary  ${trans_id}  TransactionID  ${value}
1012    Append To List  ${trans_id_list}  ${trans_id}
1013
1014    Release Locks On Resource
1015    ...  ${session_info}  ${trans_id_list}
1016    ...  release_lock_type=${release_lock_type}  status_code=${HTTP_BAD_REQUEST}
1017    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=Session
1018
1019    ${trans_id_emptylist}=  Create List
1020    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
1021    Redfish Delete Session  ${session_info}
1022
1023
1024Verify Fail To Release Multiple Lock With Invalid TransactionID
1025    [Documentation]  Verify release multiple locks with invalid transaction ID fails.
1026    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
1027
1028    # Description of argument(s):
1029    # client_id          This client id can contain string value
1030    #                    (e.g. 12345, "HMCID").
1031    # lock_type          Read lock or Write lock.
1032    # release_lock_type  The value can be Transaction or Session.
1033
1034    ${trans_id_list}=  Create List
1035    @{lock_type_list}=  Split String  ${lock_type}  ,
1036
1037    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
1038
1039    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
1040    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
1041    ${value}=  Evaluate  ${value} + 10
1042    Set To Dictionary  ${trans_id}  TransactionID  ${value}
1043    Append To List  ${trans_id_list}  ${trans_id}
1044
1045    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
1046    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
1047    ${value}=  Evaluate  ${value} + 10
1048    Set To Dictionary  ${trans_id}  TransactionID  ${value}
1049    Append To List  ${trans_id_list}  ${trans_id}
1050
1051    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[2]
1052    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
1053    ${value}=  Evaluate  ${value} + 10
1054    Set To Dictionary  ${trans_id}  TransactionID  ${value}
1055    Append To List  ${trans_id_list}  ${trans_id}
1056
1057    Release Locks On Resource
1058    ...  ${session_info}  ${trans_id_list}
1059    ...  release_lock_type=${release_lock_type}  status_code=${HTTP_BAD_REQUEST}
1060    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=Session
1061
1062    ${trans_id_emptylist}=  Create List
1063    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
1064    Redfish Delete Session  ${session_info}
1065
1066
1067Verify Fail To Release Multiple Lock With Valid And Invalid TransactionID
1068    [Documentation]  Verify fail to be release multiple lock with valid and invalid transaction ID.
1069    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
1070
1071    # Description of argument(s):
1072    # client_id          This client id can contain string value
1073    #                    (e.g. 12345, "HMCID").
1074    # lock_type          Read lock or Write lock.
1075    # release_lock_type  The value can be Transaction or Session.
1076
1077    ${trans_id_list}=  Create List
1078    @{lock_type_list}=  Split String  ${lock_type}  ,
1079
1080    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
1081
1082    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
1083    Append To List  ${trans_id_list}  ${trans_id}
1084
1085    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
1086    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
1087    ${value}=  Evaluate  ${value} + 10
1088    Set To Dictionary  ${trans_id}  TransactionID  ${value}
1089    Append To List  ${trans_id_list}  ${trans_id}
1090
1091    Release Locks On Resource
1092    ...  ${session_info}  ${trans_id_list}
1093    ...  release_lock_type=${release_lock_type}  status_code=${HTTP_BAD_REQUEST}
1094    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=Session
1095
1096    ${trans_id_emptylist}=  Create List
1097    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
1098    Redfish Delete Session  ${session_info}
1099
1100
1101Verify Fail To Release Lock With TransactionID As String Type
1102    [Documentation]  Verify fail to be release lock with transaction ID as string data type.
1103    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
1104
1105    # Description of argument(s):
1106    # client_id          This client id can contain string value
1107    #                    (e.g. 12345, "HMCID").
1108    # lock_type          Read lock or Write lock.
1109    # release_lock_type  The value can be Transaction or Session.
1110
1111    ${trans_id_list}=  Create List
1112    @{lock_type_list}=  Split String  ${lock_type}  ,
1113
1114    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
1115
1116    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
1117
1118    Append To List  ${trans_id_list}  ${trans_id}
1119
1120    ${temp_trans_id_list}=  Copy Dictionary  ${trans_id_list}  deepcopy=True
1121
1122    ${value}=  Get From Dictionary  ${trans_id_list}[0]  TransactionID
1123    ${value}=  Set Variable  \'${value}\'
1124    Set To Dictionary  ${temp_trans_id_list}[0]  TransactionID  ${value}
1125
1126    Release Locks On Resource
1127    ...  ${session_info}  ${temp_trans_id_list}
1128    ...  release_lock_type=${release_lock_type}  status_code=${HTTP_BAD_REQUEST}
1129
1130    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=${release_lock_type}
1131
1132    ${trans_id_emptylist}=  Create List
1133    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
1134    Redfish Delete Session  ${session_info}
1135
1136
1137Verify Fail To Release Lock For Another Session
1138    [Documentation]  Verify failed to release the lock form another session.
1139    [Arguments]  ${client_id}  ${lock_type}
1140
1141    # Description of argument(s):
1142    # client_id    This client id can contain string value
1143    #              (e.g. 12345, "HMCID").
1144    # lock_type    Read lock or Write lock.
1145
1146    ${client_ids}=  Split String  ${client_id}  ,
1147    ${lock_type_list}=  Split String  ${lock_type}  ,
1148    ${trans_id_list1}=  Create List
1149    ${trans_id_list2}=  Create List
1150
1151    ${session_info1}=  Create Redfish Session With ClientID  ${client_ids}[0]
1152
1153    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
1154    Append To List  ${trans_id_list1}  ${trans_id}
1155    Verify Lock On Resource  ${session_info1}  ${trans_id_list1}
1156
1157    ${session_info2}=  Create Redfish Session With ClientID  ${client_ids}[1]
1158    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
1159    Append To List  ${trans_id_list2}  ${trans_id}
1160    Verify Lock On Resource  ${session_info2}  ${trans_id_list2}
1161
1162    Release Locks On Resource
1163    ...  ${session_info1}  ${trans_id_list1}  Transaction  status_code=${HTTP_BAD_REQUEST}
1164    Verify Lock On Resource  ${session_info1}  ${trans_id_list1}
1165    Release Locks On Resource  ${session_info1}  ${trans_id_list1}  release_lock_type=Session
1166    Release Locks On Resource  ${session_info2}  ${trans_id_list2}  release_lock_type=Session
1167    Redfish Delete Session  ${session_info1}
1168    Redfish Delete Session  ${session_info2}
1169
1170
1171Verify Fail To Acquire Lock For Invalid Resource ID Data Type
1172    [Documentation]  Verify fail to acquire the lock with invalid resource id data type.
1173    [Arguments]  ${client_id}  ${lock_type}
1174
1175    # Description of argument(s):
1176    # client_id    This client id can contain string value
1177    #              (e.g. 12345, "HMCID").
1178    # lock_type    Read lock or Write lock.
1179
1180    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
1181    Redfish Post Acquire Invalid Lock With Invalid Data Type Of Resource ID
1182    ...  ${lock_type}  status_code=${HTTP_BAD_REQUEST}
1183    Redfish Delete Session  ${session_info}
1184
1185
1186Verify Fail To Acquire Lock For Invalid Lock Data
1187    [Documentation]  Verify fail to acquired lock with invalid lock types, lock flags, segment flags.
1188    [Arguments]  ${client_id}  ${lock_type}  ${message}
1189
1190    # Description of argument(s):
1191    # client_id    This client id can contain string value
1192    #              (e.g. 12345, "HMCID").
1193    # lock_type    Read lock or Write lock.
1194    # message      Return message from URI.
1195
1196    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
1197    ${trans_id}=  Redfish Post Acquire Invalid Lock
1198    ...  ${lock_type}  message=${message}  status_code=${HTTP_BAD_REQUEST}
1199    Redfish Delete Session  ${session_info}
1200
1201
1202Verify No Locks Records For Session With No Acquired Lock
1203    [Documentation]  Verify no records found for a session where no lock is acquired.
1204    [Arguments]  ${client_id}
1205
1206    # Description of argument(s):
1207    # client_id    This client id can contain string value
1208    #              (e.g. 12345, "HMCID").
1209
1210    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
1211    ${trans_id_emptylist}=  Create List
1212    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
1213    Redfish Delete Session  ${session_info}
1214
1215
1216Create List Of Session ID
1217    [Documentation]  Create session id list from session dict info.
1218    [Arguments]  ${session_dict_info}
1219
1220    # Description of argument(s):
1221    # session_dict_info      Session information in dict.
1222
1223    @{session_id_list}=  Create List
1224
1225    FOR  ${session}  IN  @{session_dict_info}
1226      Append To List  ${session_id_list}  ${session["SessionIDs"]}
1227    END
1228
1229    ${num_id}=  Get Length  ${session_id_list}
1230    Should Not Be Equal As Integers  ${num_id}  ${0}
1231
1232    ${session_id_list}=  Evaluate  json.dumps(${session_id_list})  json
1233
1234    [Return]  ${session_id_list}
1235
1236
1237Get Locks List On Resource With Session List
1238    [Documentation]  Get locks list from session of list.
1239    [Arguments]  ${session_id_list}  ${exp_status_code}=${HTTP_OK}
1240
1241    # Description of argument(s):
1242    # session_id_list    Session ids list.
1243    # exp_status_code    Expected HTTP status code.
1244
1245    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.GetLockList
1246    ...  data={"SessionIDs":${session_id_list}}  expected_status=any
1247    Should Be Equal As Strings  ${resp.status_code}  ${exp_status_code}
1248    ${locks}=  Evaluate  json.loads('''${resp.text}''')  json
1249
1250    [Return]  ${locks}
1251
1252
1253Verify List Of Session Lock On Resource
1254    [Documentation]  Verify list of lock record from list of sessions.
1255    [Arguments]  ${session_dict_info}  ${transaction_id_list}
1256
1257    # Description of argument(s):
1258    # session_dict_info      Session information in dict.
1259    # transaction_id_list    Transaction id in list stored in dict.
1260
1261    ${session_id_list}=  Create List Of Session ID  ${session_dict_info}
1262    ${lock_list_resp}=  Get Locks List On Resource With Session List  ${session_id_list}
1263    ${lock_list}=  Set Variable  ${lock_list_resp['Records']}
1264
1265    FOR  ${session_id}  ${tran_id}  ${lock_record}  IN ZIP
1266    ...  ${session_dict_info}  ${transaction_id_list}  ${lock_list}
1267      Valid Value  session_id['SessionIDs']  ['${lock_record['SessionID']}']
1268      Should Be Equal As Integers  ${tran_id['TransactionID']}  ${lock_record['TransactionID']}
1269    END
1270
1271
1272Verify Lock Records Of Multiple Session
1273    [Documentation]  Verify all records found for a multiple sessions.
1274    [Arguments]  ${client_ids}  ${lock_type}
1275
1276    # Description of argument(s):
1277    # client_ids    This client id can contain string value
1278    #               (e.g. 12345, "HMCID").
1279    # lock_type     Read lock or Write lock.
1280
1281    ${client_id_list}=  Split String  ${client_ids}  ,
1282    ${lock_type_list}=  Split String  ${lock_type}  ,
1283    ${trans_id_list1}=  Create List
1284    ${trans_id_list2}=  Create List
1285
1286    ${session_dict_list}=  Create List
1287    ${lock_list}=  Create List
1288
1289    ${client_id1}=  Create List
1290    Append To List  ${client_id1}  ${client_id_list}[0]
1291    ${session_info1}=  Create Session With List Of ClientID  ${client_id1}
1292    Append To List  ${session_dict_list}  ${session_info1}[0]
1293    Verify A Session Created With ClientID  ${client_id1}  ${session_info1}
1294
1295    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
1296    Append To List  ${trans_id_list1}  ${trans_id}
1297    Append To List  ${lock_list}  ${trans_id}
1298    Verify Lock On Resource  ${session_info1}[0]  ${trans_id_list1}
1299
1300
1301    ${client_id2}=  Create List
1302    Append To List  ${client_id2}  ${client_id_list}[1]
1303    ${session_info2}=  Create Session With List Of ClientID  ${client_id2}
1304    Append To List  ${session_dict_list}  ${session_info2}[0]
1305    Verify A Session Created With ClientID  ${client_id2}  ${session_info2}
1306
1307    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
1308    Append To List  ${trans_id_list2}  ${trans_id}
1309    Append To List  ${lock_list}  ${trans_id}
1310    Verify Lock On Resource  ${session_info2}[0]  ${trans_id_list2}
1311
1312    Verify List Of Session Lock On Resource  ${session_dict_list}  ${lock_list}
1313
1314    ${session_token}=  Get From Dictionary  ${session_info1}[0]  SessionToken
1315    Set Global Variable  ${XAUTH_TOKEN}  ${session_token}
1316
1317    Release Locks On Resource  ${session_info1}  ${trans_id_list1}  release_lock_type=Transaction
1318
1319    ${session_token}=  Get From Dictionary  ${session_info2}[0]  SessionToken
1320    Set Global Variable  ${XAUTH_TOKEN}  ${session_token}
1321
1322    Release Locks On Resource  ${session_info2}  ${trans_id_list2}  release_lock_type=Transaction
1323
1324    ${trans_id_emptylist}=  Create List
1325    Verify Lock On Resource  ${session_info1}[0]  ${trans_id_emptylist}
1326    Verify Lock On Resource  ${session_info2}[0]  ${trans_id_emptylist}
1327
1328    Redfish Delete List Of Session  ${session_dict_list}
1329
1330
1331Verify Lock Records For Multiple Invalid Session
1332    [Documentation]  Verify no lock record found for multiple invalid session.
1333    [Arguments]  ${client_id}
1334
1335    # Description of argument(s):
1336    # client_id    This client id can contain string value
1337    #              (e.g. 12345, "HMCID").
1338
1339    ${session_dict_list}=  Create List
1340    ${invalid_session_ids}=  Create List  xxyXyyYZZz  xXyXYyYZzz
1341
1342    ${session_info1}=  Create Session With ClientID  ${client_id}
1343
1344    ${session_info2}=  Copy Dictionary  ${session_info1}  deepcopy=True
1345    set to dictionary  ${session_info2}  SessionIDs  ${invalid_session_ids}[0]
1346    Append To List  ${session_dict_list}  ${session_info2}
1347
1348    ${session_info3}=  Copy Dictionary  ${session_info1}  deepcopy=True
1349    set to dictionary  ${session_info3}  SessionIDs  ${invalid_session_ids}[0]
1350    Append To List  ${session_dict_list}  ${session_info3}
1351
1352    ${lock_list1}=  Get Locks List On Resource  ${session_info1}
1353    ${lock_length1}=  Get Length  ${lock_list1}
1354
1355    ${session_id_list}=  Create List Of Session ID  ${session_dict_list}
1356    ${lock_list_resp}=  Get Locks List On Resource With Session List  ${session_id_list}
1357    ${lock_length2}=  Get Length  ${lock_list_resp['Records']}
1358
1359    Should Be Equal As Integers  ${lock_length1}  ${lock_length2}
1360
1361    Redfish Delete Session  ${session_info1}
1362
1363
1364Verify Lock Records For Multiple Invalid And Valid Session
1365    [Documentation]  Verify all records found for a valid and invalid sessions.
1366    [Arguments]  ${client_ids}  ${lock_type}
1367
1368    # Description of argument(s):
1369    # client_ids    This client id can contain string value
1370    #               (e.g. 12345, "HMCID").
1371    # lock_type     Read lock or Write lock.
1372
1373    ${client_id_list}=  Split String  ${client_ids}  ,
1374    ${lock_type_list}=  Split String  ${lock_type}  ,
1375    ${trans_id_list1}=  Create List
1376    ${invalid_session_ids}=  Create List  xxyXyyYZZz
1377
1378    ${session_dict_list}=  Create List
1379    ${lock_list}=  Create List
1380
1381    ${client_id1}=  Create List
1382    Append To List  ${client_id1}  ${client_id_list}[0]
1383    ${session_info1}=  Create Session With List Of ClientID  ${client_id1}
1384    Append To List  ${session_dict_list}  ${session_info1}[0]
1385    Verify A Session Created With ClientID  ${client_id1}  ${session_info1}
1386
1387    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
1388    Append To List  ${trans_id_list1}  ${trans_id}
1389    Append To List  ${lock_list}  ${trans_id}
1390    Verify Lock On Resource  ${session_info1}[0]  ${trans_id_list1}
1391
1392    ${session_info2}=  Copy Dictionary  ${session_info1}  deepcopy=True
1393    set to dictionary  ${session_info2}[0]  SessionIDs  ${invalid_session_ids}[0]
1394    Append To List  ${session_dict_list}  ${session_info2}[0]
1395
1396    Verify List Of Session Lock On Resource  ${session_dict_list}  ${lock_list}
1397
1398    ${session_token}=  Get From Dictionary  ${session_info1}[0]  SessionToken
1399    Set Global Variable  ${XAUTH_TOKEN}  ${session_token}
1400
1401    Release Locks On Resource  ${session_info1}  ${trans_id_list1}  release_lock_type=Transaction
1402
1403    ${trans_id_emptylist}=  Create List
1404    Verify Lock On Resource  ${session_info1}[0]  ${trans_id_emptylist}
1405
1406    Redfish Delete Session  ${session_info1}[0]
1407