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