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