xref: /openbmc/openbmc-test-automation/openpower/ext_interfaces/test_lock_management.robot (revision d03f2ce140f5fca0d95672e56a6e6ed8c3c40c18)
1bc331e22SVijay*** Settings ***
2bc331e22SVijay
3*d03f2ce1SSushil SinghDocumentation        Test lock management feature of management console on BMC.
4bc331e22SVijay
5bc331e22SVijayResource             ../../lib/resource.robot
6bc331e22SVijayResource             ../../lib/openbmc_ffdc.robot
7566daaf3SGeorge KeishingResource             ../../lib/bmc_redfish_utils.robot
8*d03f2ce1SSushil SinghResource             ../../lib/external_intf/management_console_utils.robot
9bc331e22SVijay
1040ef0eb7SSushil SinghSuite Setup          Run Keyword And Ignore Error  Delete All Redfish Sessions
11*d03f2ce1SSushil SinghSuite Teardown       Redfish.Logout
12*d03f2ce1SSushil SinghTest Setup           Printn
13*d03f2ce1SSushil SinghTest Teardown        FFDC On Test Case Fail
14bc331e22SVijay
15bc331e22SVijay*** Variables ***
16bc331e22SVijay
17*d03f2ce1SSushil Singh${BAD_REQUEST}       Bad Request
18bc331e22SVijay
19bc331e22SVijay*** Test Cases ***
20bc331e22SVijay
21*d03f2ce1SSushil SinghAcquire Read Write Lock
22bc331e22SVijay    [Documentation]  Acquire and release different read locks.
23*d03f2ce1SSushil Singh    [Tags]  Acquire_Read_Write_Lock
24*d03f2ce1SSushil Singh    [Template]  Acquire Lock On Resource
25bc331e22SVijay
26*d03f2ce1SSushil Singh    # client_id    lock_type     reboot_flag
27*d03f2ce1SSushil Singh    HMCID-01       ReadCase1     False
28*d03f2ce1SSushil Singh    HMCID-01       ReadCase2     False
29*d03f2ce1SSushil Singh    HMCID-01       ReadCase3     False
30*d03f2ce1SSushil Singh    HMCID-01       WriteCase1    False
31*d03f2ce1SSushil Singh    HMCID-01       WriteCase2    False
32*d03f2ce1SSushil Singh    HMCID-01       WriteCase3    False
33bc331e22SVijay
34bc331e22SVijay
35*d03f2ce1SSushil SinghCheck Lock Persistency On BMC Reboot
36*d03f2ce1SSushil Singh    [Documentation]  Acquire lock and check after reboot it remain same.
37*d03f2ce1SSushil Singh    [Tags]  Check_Lock_Persistency_On_BMC_Reboot
38*d03f2ce1SSushil Singh    [Template]  Acquire Lock On Resource
39bc331e22SVijay
40*d03f2ce1SSushil Singh    # client_id    lock_type     reboot_flag
41*d03f2ce1SSushil Singh    HMCID-01       ReadCase1     True
42*d03f2ce1SSushil Singh    HMCID-01       ReadCase2     True
43*d03f2ce1SSushil Singh    HMCID-01       ReadCase3     True
44*d03f2ce1SSushil Singh    HMCID-01       WriteCase1    True
45*d03f2ce1SSushil Singh    HMCID-01       WriteCase2    True
46*d03f2ce1SSushil Singh    HMCID-01       WriteCase3    True
47bc331e22SVijay
48bc331e22SVijay
49*d03f2ce1SSushil SinghAcquire Read Lock On Read Lock
50*d03f2ce1SSushil Singh    [Documentation]  Acquire read lock on another read lock.
51*d03f2ce1SSushil Singh    [Tags]  Acquire_Read_Lock_On_Read_Lock
52*d03f2ce1SSushil Singh    [Template]  Acquire Lock On Another Lock
53bc331e22SVijay
54*d03f2ce1SSushil Singh    # client_id
55*d03f2ce1SSushil Singh    HMCID-01
56bc331e22SVijay
57bc331e22SVijay
58*d03f2ce1SSushil SinghGet Lock Records Empty For Invalid Session
59*d03f2ce1SSushil Singh    [Documentation]  Record of lock list is empty for invalid session.
60*d03f2ce1SSushil Singh    [Tags]  Get_Lock_Records_Empty_For_Invalid_Session
61*d03f2ce1SSushil Singh    [Template]  Verify Empty Lock Records For Invalid Session
62355daac7SVijay
63*d03f2ce1SSushil Singh    # client_id
64*d03f2ce1SSushil Singh    HMCID-01
65355daac7SVijay
66355daac7SVijay
67*d03f2ce1SSushil SinghFail To Acquire Lock On Another Lock
68*d03f2ce1SSushil Singh    [Documentation]  Fail to acquire another lock.
69*d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_On_Another_Lock
70*d03f2ce1SSushil Singh    [Template]  Verify Acquire Lock Fails On Another Lock
7185610eeeSVijay
72*d03f2ce1SSushil Singh    # client_id    lock_type
73*d03f2ce1SSushil Singh    HMCID-01       ReadCase2,WriteCase2
74*d03f2ce1SSushil Singh    HMCID-01       WriteCase2,WriteCase2
75*d03f2ce1SSushil Singh    HMCID-01       WriteCase2,ReadCase2
76566daaf3SGeorge Keishing
77566daaf3SGeorge Keishing
78*d03f2ce1SSushil SinghAcquire And Release Lock In Loop
79*d03f2ce1SSushil Singh    [Documentation]  Acquire and release read, write locks in loop.
80*d03f2ce1SSushil Singh    [Tags]  Acquire_And_Release_Lock_In_Loop
81*d03f2ce1SSushil Singh    [Template]  Verify Acquire And Release Lock In Loop
82566daaf3SGeorge Keishing
83*d03f2ce1SSushil Singh    # client_id    lock_type
84*d03f2ce1SSushil Singh    HMCID-01       ReadCase1
85*d03f2ce1SSushil Singh    HMCID-01       ReadCase2
86*d03f2ce1SSushil Singh    HMCID-01       ReadCase3
87*d03f2ce1SSushil Singh    HMCID-01       WriteCase1
88*d03f2ce1SSushil Singh    HMCID-01       WriteCase2
89*d03f2ce1SSushil Singh    HMCID-01       WriteCase3
9085610eeeSVijay
9185610eeeSVijay
92*d03f2ce1SSushil SinghVerify Release Of Valid Locks
93*d03f2ce1SSushil Singh    [Documentation]  Release all valid locks.
94*d03f2ce1SSushil Singh    [Tags]  Verify_Release_Of_Valid_Locks
95*d03f2ce1SSushil Singh    [Template]  Acquire And Release Multiple Locks
96afdd2a1dSVijay
97*d03f2ce1SSushil Singh    # client_id    lock_type                        release_lock_type
98*d03f2ce1SSushil Singh    HMCID-01       ReadCase1,ReadCase1,ReadCase1    Transaction
99*d03f2ce1SSushil Singh    HMCID-02       ReadCase1,ReadCase1,ReadCase1    Session
100afdd2a1dSVijay
101afdd2a1dSVijay
102*d03f2ce1SSushil SinghInvalid Locks Fail To Release
103*d03f2ce1SSushil Singh    [Documentation]  Release in-valid lock result in fail.
104*d03f2ce1SSushil Singh    [Tags]  Invalid_Locks_Fail_To_Release
105*d03f2ce1SSushil Singh    [Template]  Verify Invalid Locks Fail To Release
106afdd2a1dSVijay
107*d03f2ce1SSushil Singh    # client_id    lock_type                        release_lock_type
108*d03f2ce1SSushil Singh    HMCID-01       ReadCase1,ReadCase1,ReadCase1    Transaction
109*d03f2ce1SSushil Singh    12345          ReadCase2,ReadCase2,ReadCase2    Transaction
110*d03f2ce1SSushil Singh    HMCID          ReadCase3,ReadCase3,ReadCase3    Transaction
111afdd2a1dSVijay
112afdd2a1dSVijay
113*d03f2ce1SSushil SinghFail To Release Lock For Another Session
114*d03f2ce1SSushil Singh    [Documentation]  Failed to release locks from another session.
115*d03f2ce1SSushil Singh    [Tags]  Fail_To_Release_Lock_For_Another_Session
116*d03f2ce1SSushil Singh    [Template]  Verify Fail To Release Lock For Another Session
117afdd2a1dSVijay
118*d03f2ce1SSushil Singh    # client_id          lock_type
119*d03f2ce1SSushil Singh    HMCID-01,HMCID-02    ReadCase1,ReadCase1
120afdd2a1dSVijay
121afdd2a1dSVijay
122*d03f2ce1SSushil SinghFail To Acquire Lock For Invalid Lock Type
123*d03f2ce1SSushil Singh    [Documentation]  Failed to acquire read, write lock for invalid lock data passed.
124*d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Lock_Type
125*d03f2ce1SSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
126afdd2a1dSVijay
127*d03f2ce1SSushil Singh    # client_id    lock_type      message
128*d03f2ce1SSushil Singh    HMCID-01       ReadCase1      ${BAD_REQUEST}
129*d03f2ce1SSushil Singh    HMCID-01       ReadCase2      ${BAD_REQUEST}
130*d03f2ce1SSushil Singh    HMCID-01       ReadCase3      ${BAD_REQUEST}
131*d03f2ce1SSushil Singh    HMCID-01       ReadCase4      ${BAD_REQUEST}
132*d03f2ce1SSushil Singh    HMCID-01       ReadCase5      ${BAD_REQUEST}
133*d03f2ce1SSushil Singh    HMCID-01       WriteCase1     ${BAD_REQUEST}
134*d03f2ce1SSushil Singh    HMCID-01       WriteCase2     ${BAD_REQUEST}
135*d03f2ce1SSushil Singh    HMCID-01       WriteCase3     ${BAD_REQUEST}
136*d03f2ce1SSushil Singh    HMCID-01       WriteCase4     ${BAD_REQUEST}
137*d03f2ce1SSushil Singh    HMCID-01       WriteCase5     ${BAD_REQUEST}
138afdd2a1dSVijay
139afdd2a1dSVijay
140*d03f2ce1SSushil SinghFail To Acquire Lock For Invalid Lock Flag
141*d03f2ce1SSushil Singh    [Documentation]  Failed to acquire read write lock for invalid lock flag passed.
142*d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Lock_Flag
143*d03f2ce1SSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
144afdd2a1dSVijay
145*d03f2ce1SSushil Singh    # client_id    lock_type       message
146*d03f2ce1SSushil Singh    HMCID-01       ReadCase6       ${BAD_REQUEST}
147*d03f2ce1SSushil Singh    HMCID-01       ReadCase7       ${BAD_REQUEST}
148*d03f2ce1SSushil Singh    HMCID-01       ReadCase8       ${BAD_REQUEST}
149*d03f2ce1SSushil Singh    HMCID-01       ReadCase9       ${BAD_REQUEST}
150*d03f2ce1SSushil Singh    HMCID-01       ReadCase10      ${BAD_REQUEST}
151*d03f2ce1SSushil Singh    HMCID-01       ReadCase11      ${BAD_REQUEST}
152*d03f2ce1SSushil Singh    HMCID-01       WriteCase6      ${BAD_REQUEST}
153*d03f2ce1SSushil Singh    HMCID-01       WriteCase7      ${BAD_REQUEST}
154*d03f2ce1SSushil Singh    HMCID-01       WriteCase8      ${BAD_REQUEST}
155*d03f2ce1SSushil Singh    HMCID-01       WriteCase9      ${BAD_REQUEST}
156*d03f2ce1SSushil Singh    HMCID-01       WriteCase10     ${BAD_REQUEST}
157*d03f2ce1SSushil Singh    HMCID-01       WriteCase11     ${BAD_REQUEST}
158afdd2a1dSVijay
159afdd2a1dSVijay
160*d03f2ce1SSushil SinghFail To Acquire Lock For Invalid Segment Flag
161*d03f2ce1SSushil Singh    [Documentation]  Failed to acquire read write lock for invalid segment flag passed.
162*d03f2ce1SSushil Singh    [Tags]  Fail_To_Acquire_Lock_For_Invalid_Segment_Flag
163*d03f2ce1SSushil Singh    [Template]  Verify Fail To Acquire Lock For Invalid Lock Data
164*d03f2ce1SSushil Singh
165*d03f2ce1SSushil Singh    # client_id    lock_type       message
166*d03f2ce1SSushil Singh    HMCID-01       ReadCase12      ${BAD_REQUEST}
167*d03f2ce1SSushil Singh    HMCID-01       ReadCase13      ${BAD_REQUEST}
168*d03f2ce1SSushil Singh    HMCID-01       ReadCase14      ${BAD_REQUEST}
169*d03f2ce1SSushil Singh    HMCID-01       WriteCase12     ${BAD_REQUEST}
170*d03f2ce1SSushil Singh    HMCID-01       WriteCase13     ${BAD_REQUEST}
171*d03f2ce1SSushil Singh    HMCID-01       WriteCase14     ${BAD_REQUEST}
172afdd2a1dSVijay
173bc331e22SVijay*** Keywords ***
174bc331e22SVijay
175*d03f2ce1SSushil SinghCreate Redfish Session With ClientID
176*d03f2ce1SSushil Singh    [Documentation]  Create redifish session with client id.
177*d03f2ce1SSushil Singh    [Arguments]  ${client_id}
17885610eeeSVijay
17985610eeeSVijay    # Description of argument(s):
180*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
181*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
18285610eeeSVijay
183*d03f2ce1SSushil Singh    ${session_info}=  Create Dictionary
184*d03f2ce1SSushil Singh    ${session}=  Redfish Login  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client_id}"}}
18585610eeeSVijay
186*d03f2ce1SSushil Singh    Set To Dictionary  ${session_info}  SessionIDs  ${session['Id']}
187*d03f2ce1SSushil Singh    Set To Dictionary  ${session_info}  ClientID  ${session["Oem"]["OpenBMC"]["ClientID"]}
18885610eeeSVijay
189*d03f2ce1SSushil Singh    [Return]  ${session_info}
19085610eeeSVijay
19185610eeeSVijay
192*d03f2ce1SSushil SinghRW General Dictionary
193*d03f2ce1SSushil Singh    [Documentation]  Create dictionay of lock request.
194*d03f2ce1SSushil Singh    [Arguments]  ${read_case}  ${res_id}
195bc331e22SVijay
196bc331e22SVijay    # Description of argument(s):
197*d03f2ce1SSushil Singh    # read_case    Read or Write lock type.
198*d03f2ce1SSushil Singh    # res_id       Resource id.
199bc331e22SVijay
200*d03f2ce1SSushil Singh    ${request_dict}=  Create Dictionary
201566daaf3SGeorge Keishing
202*d03f2ce1SSushil Singh    FOR  ${key}  IN  @{read_case.keys()}
203*d03f2ce1SSushil Singh      Set To Dictionary  ${request_dict}  LockType  ${key}
204*d03f2ce1SSushil Singh      Set To Dictionary  ${request_dict}  SegmentFlags  ${read_case["${key}"]}
205*d03f2ce1SSushil Singh    END
206bc331e22SVijay
207*d03f2ce1SSushil Singh    Set To Dictionary  ${request_dict}  ResourceID  ${res_id}
208*d03f2ce1SSushil Singh
209*d03f2ce1SSushil Singh    [Return]  ${request_dict}
210bc331e22SVijay
211bc331e22SVijay
212*d03f2ce1SSushil SinghReturn Description Of Response
213*d03f2ce1SSushil Singh    [Documentation]  Return description of REST response.
214bc331e22SVijay    [Arguments]  ${resp_text}
215bc331e22SVijay
216bc331e22SVijay    # Description of argument(s):
217*d03f2ce1SSushil Singh    # resp_text    REST response body.
218bc331e22SVijay
219*d03f2ce1SSushil Singh    # resp_text after successful partition file upload looks like:
220*d03f2ce1SSushil Singh    # {
221*d03f2ce1SSushil Singh    #    "Description": "File Created"
222*d03f2ce1SSushil Singh    # }
223bc331e22SVijay
224*d03f2ce1SSushil Singh    ${message}=  Evaluate  json.loads('''${resp_text}''')  json
225*d03f2ce1SSushil Singh
226*d03f2ce1SSushil Singh    [Return]  ${message}
227bc331e22SVijay
228bc331e22SVijay
229*d03f2ce1SSushil SinghRedfish Post Acquire Lock
230*d03f2ce1SSushil Singh    [Documentation]  Acquire and release lock.
231*d03f2ce1SSushil Singh    [Arguments]  ${lock_type}  ${status_code}=${HTTP_OK}
232bc331e22SVijay
233bc331e22SVijay    # Description of argument(s):
234*d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
235*d03f2ce1SSushil Singh    # status_code    HTTP status code.
236bc331e22SVijay
237*d03f2ce1SSushil Singh    ${resp}=  Form Data To Acquire Lock  ${lock_type}
238*d03f2ce1SSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${resp}
239*d03f2ce1SSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
240*d03f2ce1SSushil Singh    ${resp}=  Return Description Of Response  ${resp.content}
241bc331e22SVijay
242*d03f2ce1SSushil Singh    [Return]  ${resp}
243bc331e22SVijay
244bc331e22SVijay
245*d03f2ce1SSushil SinghRedfish Post Acquire Invalid Lock
246*d03f2ce1SSushil Singh    [Documentation]  Redfish to post request to acquire in-valid lock.
247*d03f2ce1SSushil Singh    [Arguments]  ${lock_type}  ${message}  ${status_code}=${HTTP_OK}
248bc331e22SVijay
249bc331e22SVijay    # Description of argument(s):
250*d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
251*d03f2ce1SSushil Singh    # message        Return message from URI.
252*d03f2ce1SSushil Singh    # status_code    HTTP status code.
253bc331e22SVijay
254*d03f2ce1SSushil Singh    ${resp}=  Form Data To Acquire Invalid Lock  ${lock_type}
255*d03f2ce1SSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock  data=${resp}
256*d03f2ce1SSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
257*d03f2ce1SSushil Singh    Valid Value  message  ['${resp.content}']
258*d03f2ce1SSushil Singh
259*d03f2ce1SSushil Singh    [Return]  ${resp}
260bc331e22SVijay
261bc331e22SVijay
262*d03f2ce1SSushil SinghForm Data To Acquire Lock
263*d03f2ce1SSushil Singh    [Documentation]  Create a dictionay for lock request.
264*d03f2ce1SSushil Singh    [Arguments]  ${lock_type}
265*d03f2ce1SSushil Singh
266*d03f2ce1SSushil Singh    # Description of argument(s):
267*d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
268*d03f2ce1SSushil Singh
269*d03f2ce1SSushil Singh    ${lock_res_info}=  Get Lock Resource Information
270*d03f2ce1SSushil Singh    ${resp}=  RW General Dictionary
271*d03f2ce1SSushil Singh    ...    ${lock_res_info["Valid Case"]["${lock_type}"]}
272*d03f2ce1SSushil Singh    ...    ${lock_res_info["Valid Case"]["ResourceID"]}
273*d03f2ce1SSushil Singh    ${temp_list}=  Create List  ${resp}
274*d03f2ce1SSushil Singh    ${lock_request}=  Create Dictionary  Request=${temp_list}
275*d03f2ce1SSushil Singh
276*d03f2ce1SSushil Singh    [Return]  ${lock_request}
277*d03f2ce1SSushil Singh
278*d03f2ce1SSushil Singh
279*d03f2ce1SSushil SinghForm Data To Acquire Invalid Lock
280*d03f2ce1SSushil Singh    [Documentation]  Create a dictionay for in-valid lock request.
281*d03f2ce1SSushil Singh    [Arguments]  ${lock_type}
282*d03f2ce1SSushil Singh
283*d03f2ce1SSushil Singh    # Description of argument(s):
284*d03f2ce1SSushil Singh    # lock_type      Read lock or Write lock.
285*d03f2ce1SSushil Singh
286*d03f2ce1SSushil Singh    ${lock_res_info}=  Get Lock Resource Information
287*d03f2ce1SSushil Singh    ${resp}=  RW General Dictionary
288*d03f2ce1SSushil Singh    ...    ${lock_res_info["Invalid Case"]["${lock_type}"]}
289*d03f2ce1SSushil Singh    ...    ${lock_res_info["Valid Case"]["ResourceID"]}
290*d03f2ce1SSushil Singh    ${temp_list}=  Create List  ${resp}
291*d03f2ce1SSushil Singh    ${lock_request}=  Create Dictionary  Request=${temp_list}
292*d03f2ce1SSushil Singh
293*d03f2ce1SSushil Singh    [Return]  ${lock_request}
294*d03f2ce1SSushil Singh
295*d03f2ce1SSushil Singh
296*d03f2ce1SSushil SinghGet Locks List On Resource
297bc331e22SVijay    [Documentation]  Get locks list.
298*d03f2ce1SSushil Singh    [Arguments]  ${session_info}  ${exp_status_code}=${HTTP_OK}
299bc331e22SVijay
300bc331e22SVijay    # Description of argument(s):
301*d03f2ce1SSushil Singh    # session_info       Session information in dict.
302*d03f2ce1SSushil Singh    # exp_status_code    Expected HTTP status code.
303bc331e22SVijay
304*d03f2ce1SSushil Singh    ${data}=  Set Variable  {"SessionIDs": ["${session_info['SessionIDs']}"]}
305566daaf3SGeorge Keishing    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.GetLockList
306566daaf3SGeorge Keishing    ...  data=${data}
307bc331e22SVijay    ${locks}=  Evaluate  json.loads('''${resp.text}''')  json
308bc331e22SVijay
309bc331e22SVijay    [Return]  ${locks["Records"]}
310bc331e22SVijay
311bc331e22SVijay
312*d03f2ce1SSushil SinghVerify Lock On Resource
313*d03f2ce1SSushil Singh    [Documentation]  Verify lock on resource.
314*d03f2ce1SSushil Singh    [Arguments]  ${session_info}  ${transaction_id}
315bc331e22SVijay
316bc331e22SVijay    # Description of argument(s):
317*d03f2ce1SSushil Singh    # session_info      Session information in dict.
318*d03f2ce1SSushil Singh    # transaction_id    Transaction id in list stored in dict.
319bc331e22SVijay
320*d03f2ce1SSushil Singh    ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_info['SessionIDs']}
321*d03f2ce1SSushil Singh    Rprint Vars  sessions
322*d03f2ce1SSushil Singh    ${lock_list}=  Get Locks List On Resource  ${session_info}
323*d03f2ce1SSushil Singh    ${lock_length}=  Get Length  ${lock_list}
324*d03f2ce1SSushil Singh    ${tran_id_length}=  Get Length  ${transaction_id}
325*d03f2ce1SSushil Singh    Should Be Equal As Integers  ${tran_id_length}  ${lock_length}
326afdd2a1dSVijay
327*d03f2ce1SSushil Singh    FOR  ${tran_id}  ${lock}  IN ZIP  ${transaction_id}  ${lock_list}
328*d03f2ce1SSushil Singh      Valid Value  session_info['ClientID']  ['${lock['HMCID']}']
329*d03f2ce1SSushil Singh      Valid Value  session_info['SessionIDs']  ['${lock['SessionID']}']
330*d03f2ce1SSushil Singh      Should Be Equal As Integers  ${tran_id['TransactionID']}  ${lock['TransactionID']}
331bc331e22SVijay    END
332bc331e22SVijay
333bc331e22SVijay
334*d03f2ce1SSushil SinghRedfish Delete Session
335*d03f2ce1SSushil Singh    [Documentation]  Redfish delete session.
336*d03f2ce1SSushil Singh    [Arguments]  ${session_info}
337355daac7SVijay
338355daac7SVijay    # Description of argument(s):
339*d03f2ce1SSushil Singh    # session_info      Session information in dict.
340355daac7SVijay
341*d03f2ce1SSushil Singh    Redfish.Delete  /redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}
342355daac7SVijay
343355daac7SVijay
344*d03f2ce1SSushil SinghAcquire Lock On Resource
345*d03f2ce1SSushil Singh    [Documentation]  Acquire lock on resource.
346*d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${reboot_flag}=False
347bc331e22SVijay
348bc331e22SVijay    # Description of argument(s):
349*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
350*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
351*d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
352*d03f2ce1SSushil Singh    # reboot_flag  Flag is used to run reboot the BMC code.
353*d03f2ce1SSushil Singh    #               (e.g. True or False).
354bc331e22SVijay
355*d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
356*d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
357*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
358*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
359*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
360566daaf3SGeorge Keishing
361*d03f2ce1SSushil Singh    ${BEROFE_REBOOT_XAUTH_TOKEN}=  Set Variable  ${XAUTH_TOKEN}
362bc331e22SVijay
363*d03f2ce1SSushil Singh    Run Keyword If  '${reboot_flag}' == 'True'
364*d03f2ce1SSushil Singh    ...  Run Keywords  Redfish OBMC Reboot (off)  AND
365*d03f2ce1SSushil Singh    ...  Redfish Login  AND
366*d03f2ce1SSushil Singh    ...  Set Global Variable  ${XAUTH_TOKEN}  ${BEROFE_REBOOT_XAUTH_TOKEN}  AND
367*d03f2ce1SSushil Singh    ...  Verify Lock On Resource  ${session_info}  ${trans_id_list}  AND
368*d03f2ce1SSushil Singh    ...  Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
369bc331e22SVijay
370*d03f2ce1SSushil Singh    Run Keyword If  '${reboot_flag}' == 'False'
371*d03f2ce1SSushil Singh    ...  Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
372bc331e22SVijay
373*d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
374*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
375*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
376bc331e22SVijay
377bc331e22SVijay
378*d03f2ce1SSushil SinghForm Data To Release Lock
379*d03f2ce1SSushil Singh    [Documentation]  Create a dictonay to release lock.
380*d03f2ce1SSushil Singh    [Arguments]  ${trans_id_list}
381355daac7SVijay
382355daac7SVijay    # Description of argument(s):
383*d03f2ce1SSushil Singh    # trans_id_list
384355daac7SVijay
385*d03f2ce1SSushil Singh    @{tran_ids}=  Create List
386355daac7SVijay
387*d03f2ce1SSushil Singh    FOR  ${item}  IN  @{trans_id_list}
388*d03f2ce1SSushil Singh      Append To List  ${tran_ids}  ${item['TransactionID']}
389*d03f2ce1SSushil Singh    END
390*d03f2ce1SSushil Singh
391*d03f2ce1SSushil Singh    [Return]  ${tran_ids}
392*d03f2ce1SSushil Singh
393*d03f2ce1SSushil Singh
394*d03f2ce1SSushil SinghRelease Locks On Resource
395*d03f2ce1SSushil Singh    [Documentation]  Redfish request to release a lock.
396*d03f2ce1SSushil Singh    [Arguments]  ${session_info}  ${trans_id_list}  ${release_lock_type}=Transaction  ${status_code}=${HTTP_OK}
397*d03f2ce1SSushil Singh
398*d03f2ce1SSushil Singh    # Description of argument(s):
399*d03f2ce1SSushil Singh    # session_info        Session information in dict.
400*d03f2ce1SSushil Singh    # trans_id_list       Transaction id list.
401*d03f2ce1SSushil Singh    # release_lock_type   Release lock by Transaction, Session.
402*d03f2ce1SSushil Singh    # status_code         HTTP status code.
403*d03f2ce1SSushil Singh
404*d03f2ce1SSushil Singh    ${tran_ids}=  Form Data To Release Lock  ${trans_id_list}
405*d03f2ce1SSushil Singh    ${data}=  Set Variable  {"Type": "${release_lock_type}", "TransactionIDs":${tran_ids}}
406*d03f2ce1SSushil Singh    ${data}=  Evaluate  json.dumps(${data})  json
407*d03f2ce1SSushil Singh    ${resp}=  Redfish Post Request  /ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock  data=${data}
408*d03f2ce1SSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
409*d03f2ce1SSushil Singh
410*d03f2ce1SSushil Singh
411*d03f2ce1SSushil SinghAcquire Lock On Another Lock
412*d03f2ce1SSushil Singh    [Documentation]  Acquire lock on another lock.
413*d03f2ce1SSushil Singh    [Arguments]  ${client_id}
414*d03f2ce1SSushil Singh
415*d03f2ce1SSushil Singh    # Description of argument(s):
416*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
417*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
418*d03f2ce1SSushil Singh
419*d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
420*d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
421*d03f2ce1SSushil Singh
422*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ReadCase1
423*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
424*d03f2ce1SSushil Singh
425*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ReadCase1
426*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
427*d03f2ce1SSushil Singh
428*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
429*d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}
430*d03f2ce1SSushil Singh
431*d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
432*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
433*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
434*d03f2ce1SSushil Singh
435*d03f2ce1SSushil Singh
436*d03f2ce1SSushil SinghVerify Empty Lock Records For Invalid Session
437*d03f2ce1SSushil Singh    [Documentation]  Verify no lock record found for invalid session.
438*d03f2ce1SSushil Singh    [Arguments]  ${client_id}
439*d03f2ce1SSushil Singh
440*d03f2ce1SSushil Singh    # Description of argument(s):
441*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
442*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
443*d03f2ce1SSushil Singh
444*d03f2ce1SSushil Singh    ${session_info1}=  Create Redfish Session With ClientID  ${client_id}
445*d03f2ce1SSushil Singh
446*d03f2ce1SSushil Singh    ${lock_list1}=  Get Locks List On Resource  ${session_info1}
447*d03f2ce1SSushil Singh    ${lock_length1}=  Get Length  ${lock_list1}
448*d03f2ce1SSushil Singh
449*d03f2ce1SSushil Singh    ${session_info2}=  Copy Dictionary  ${session_info1}  deepcopy=True
450*d03f2ce1SSushil Singh    set to dictionary  ${session_info2}  SessionIDs  xxyXyyYZZz
451*d03f2ce1SSushil Singh
452*d03f2ce1SSushil Singh    ${lock_list2}=  Get Locks List On Resource  ${session_info2}
453*d03f2ce1SSushil Singh    ${lock_length2}=  Get Length  ${lock_list1}
454*d03f2ce1SSushil Singh
455*d03f2ce1SSushil Singh    Valid Value  lock_length1  ${lock_list2}
456*d03f2ce1SSushil Singh
457*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info1}
458*d03f2ce1SSushil Singh
459*d03f2ce1SSushil Singh
460*d03f2ce1SSushil SinghVerify Acquire Lock Fails On Another Lock
461*d03f2ce1SSushil Singh    [Documentation]  Verify acquire lock on another lock fails.
462*d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}
463*d03f2ce1SSushil Singh
464*d03f2ce1SSushil Singh    # Description of argument(s):
465*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
466*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
467*d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
468*d03f2ce1SSushil Singh
469*d03f2ce1SSushil Singh    @{lock_type_list}=  Split String  ${lock_type}  ,
470*d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
471*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
472*d03f2ce1SSushil Singh
473*d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
474*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
475*d03f2ce1SSushil Singh
476*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
477*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]  status_code=${HTTP_CONFLICT}
478*d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}
479*d03f2ce1SSushil Singh
480*d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
481*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
482*d03f2ce1SSushil Singh
483*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
484*d03f2ce1SSushil Singh
485*d03f2ce1SSushil Singh
486*d03f2ce1SSushil SinghVerify Acquire And Release Lock In Loop
487*d03f2ce1SSushil Singh    [Documentation]  Acquire lock in loop.
488*d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}
489*d03f2ce1SSushil Singh
490*d03f2ce1SSushil Singh    # Description of argument(s):
491*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
492*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
493*d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
494*d03f2ce1SSushil Singh
495*d03f2ce1SSushil Singh    FOR  ${count}  IN RANGE  1  11
496*d03f2ce1SSushil Singh      ${trans_id_list}=  Create List
497*d03f2ce1SSushil Singh      ${session_info}=  Create Redfish Session With ClientID  ${client_id}
498*d03f2ce1SSushil Singh      ${trans_id}=  Redfish Post Acquire Lock  ${lock_type}
499*d03f2ce1SSushil Singh      Append To List  ${trans_id_list}  ${trans_id}
500*d03f2ce1SSushil Singh      Verify Lock On Resource  ${session_info}  ${trans_id_list}
501*d03f2ce1SSushil Singh      Release Locks On Resource  ${session_info}  ${trans_id_list}  Transaction  ${HTTP_OK}
502*d03f2ce1SSushil Singh      ${trans_id_emptylist}=  Create List
503*d03f2ce1SSushil Singh      Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
504*d03f2ce1SSushil Singh    END
505*d03f2ce1SSushil Singh
506*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
507*d03f2ce1SSushil Singh
508*d03f2ce1SSushil Singh
509*d03f2ce1SSushil SinghAcquire And Release Multiple Locks
510*d03f2ce1SSushil Singh    [Documentation]  Acquire mutilple locks on resource.
511*d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
512*d03f2ce1SSushil Singh
513*d03f2ce1SSushil Singh    # Description of argument(s):
514*d03f2ce1SSushil Singh    # client_id          This client id can contain string value
515*d03f2ce1SSushil Singh    #                    (e.g. 12345, "HMCID").
516*d03f2ce1SSushil Singh    # lock_type          Read lock or Write lock.
517*d03f2ce1SSushil Singh    # release_lock_type  The value can be Transaction or Session.
518*d03f2ce1SSushil Singh
519*d03f2ce1SSushil Singh    @{lock_type_list}=  Split String  ${lock_type}  ,
520*d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
521*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
522*d03f2ce1SSushil Singh
523*d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
524*d03f2ce1SSushil Singh
525*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
526*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
527*d03f2ce1SSushil Singh
528*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
529*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[2]
530*d03f2ce1SSushil Singh
531*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
532*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_list}
533*d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=${release_lock_type}
534*d03f2ce1SSushil Singh
535*d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
536*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
537*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
538*d03f2ce1SSushil Singh
539*d03f2ce1SSushil Singh
540*d03f2ce1SSushil SinghVerify Invalid Locks Fail To Release
541*d03f2ce1SSushil Singh    [Documentation]  Verify invalid locks fails to be released.
542*d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${release_lock_type}
543*d03f2ce1SSushil Singh
544*d03f2ce1SSushil Singh    # Description of argument(s):
545*d03f2ce1SSushil Singh    # client_id          This client id can contain string value
546*d03f2ce1SSushil Singh    #                    (e.g. 12345, "HMCID").
547*d03f2ce1SSushil Singh    # lock_type          Read lock or Write lock.
548*d03f2ce1SSushil Singh    # release_lock_type  The value can be Transaction or Session.
549*d03f2ce1SSushil Singh
550*d03f2ce1SSushil Singh    ${trans_id_list}=  Create List
551*d03f2ce1SSushil Singh    @{lock_type_list}=  Split String  ${lock_type}  ,
552*d03f2ce1SSushil Singh
553*d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
554*d03f2ce1SSushil Singh
555*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
556*d03f2ce1SSushil Singh    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
557*d03f2ce1SSushil Singh    ${value}=  Evaluate  ${value} + 10
558*d03f2ce1SSushil Singh    Set To Dictionary  ${trans_id}  TransactionID  ${value}
559*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
560*d03f2ce1SSushil Singh
561*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
562*d03f2ce1SSushil Singh    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
563*d03f2ce1SSushil Singh    ${value}=  Evaluate  ${value} + 10
564*d03f2ce1SSushil Singh    Set To Dictionary  ${trans_id}  TransactionID  ${value}
565*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
566*d03f2ce1SSushil Singh
567*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[2]
568*d03f2ce1SSushil Singh    ${value}=  Get From Dictionary  ${trans_id}  TransactionID
569*d03f2ce1SSushil Singh    ${value}=  Evaluate  ${value} + 10
570*d03f2ce1SSushil Singh    Set To Dictionary  ${trans_id}  TransactionID  ${value}
571*d03f2ce1SSushil Singh    Append To List  ${trans_id_list}  ${trans_id}
572*d03f2ce1SSushil Singh
573*d03f2ce1SSushil Singh    Release Locks On Resource
574*d03f2ce1SSushil Singh    ...  ${session_info}  ${trans_id_list}
575*d03f2ce1SSushil Singh    ...  release_lock_type=${release_lock_type}  status_code=${HTTP_BAD_REQUEST}
576*d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info}  ${trans_id_list}  release_lock_type=Session
577*d03f2ce1SSushil Singh
578*d03f2ce1SSushil Singh    ${trans_id_emptylist}=  Create List
579*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info}  ${trans_id_emptylist}
580*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
581*d03f2ce1SSushil Singh
582*d03f2ce1SSushil Singh
583*d03f2ce1SSushil SinghVerify Fail To Release Lock For Another Session
584*d03f2ce1SSushil Singh    [Documentation]  Verify failed to release the lock form another session.
585*d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}
586*d03f2ce1SSushil Singh
587*d03f2ce1SSushil Singh    # Description of argument(s):
588*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
589*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
590*d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
591*d03f2ce1SSushil Singh
592*d03f2ce1SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
593*d03f2ce1SSushil Singh    ${lock_type_list}=  Split String  ${lock_type}  ,
594*d03f2ce1SSushil Singh    ${trans_id_list1}=  Create List
595*d03f2ce1SSushil Singh    ${trans_id_list2}=  Create List
596*d03f2ce1SSushil Singh
597*d03f2ce1SSushil Singh    ${session_info1}=  Create Redfish Session With ClientID  ${client_ids}[0]
598*d03f2ce1SSushil Singh
599*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[0]
600*d03f2ce1SSushil Singh    Append To List  ${trans_id_list1}  ${trans_id}
601*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info1}  ${trans_id_list1}
602*d03f2ce1SSushil Singh
603*d03f2ce1SSushil Singh    ${session_info2}=  Create Redfish Session With ClientID  ${client_ids}[1]
604*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Lock  ${lock_type_list}[1]
605*d03f2ce1SSushil Singh    Append To List  ${trans_id_list2}  ${trans_id}
606*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info2}  ${trans_id_list2}
607*d03f2ce1SSushil Singh
608*d03f2ce1SSushil Singh    Release Locks On Resource
609*d03f2ce1SSushil Singh    ...  ${session_info1}  ${trans_id_list1}  Transaction  status_code=${HTTP_UNAUTHORIZED}
610*d03f2ce1SSushil Singh    Verify Lock On Resource  ${session_info1}  ${trans_id_list1}
611*d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info1}  ${trans_id_list1}  release_lock_type=Session
612*d03f2ce1SSushil Singh    Release Locks On Resource  ${session_info2}  ${trans_id_list2}  release_lock_type=Session
613*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info1}
614*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info2}
615*d03f2ce1SSushil Singh
616*d03f2ce1SSushil Singh
617*d03f2ce1SSushil SinghVerify Fail To Acquire Lock For Invalid Lock Data
618*d03f2ce1SSushil Singh    [Documentation]  Verify fail to quired lock with invalid lock types, lock flags, segement flags.
619*d03f2ce1SSushil Singh    [Arguments]  ${client_id}  ${lock_type}  ${message}
620*d03f2ce1SSushil Singh
621*d03f2ce1SSushil Singh    # Description of argument(s):
622*d03f2ce1SSushil Singh    # client_id    This client id can contain string value
623*d03f2ce1SSushil Singh    #              (e.g. 12345, "HMCID").
624*d03f2ce1SSushil Singh    # lock_type    Read lock or Write lock.
625*d03f2ce1SSushil Singh    # message      Return message from URI.
626*d03f2ce1SSushil Singh
627*d03f2ce1SSushil Singh    ${session_info}=  Create Redfish Session With ClientID  ${client_id}
628*d03f2ce1SSushil Singh    ${trans_id}=  Redfish Post Acquire Invalid Lock  ${lock_type}  message=${message}  status_code=${HTTP_BAD_REQUEST}
629*d03f2ce1SSushil Singh    Redfish Delete Session  ${session_info}
630