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