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