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