xref: /openbmc/openbmc-test-automation/openpower/ext_interfaces/test_lock_management.robot (revision afdd2a1df81c626a95fa83d2d4d1322e2f96665b)
1bc331e22SVijay*** Settings ***
2bc331e22SVijay
3bc331e22SVijayDocumentation    Test Lock Management feature of Management Console on BMC.
4bc331e22SVijay
5bc331e22SVijayResource         ../../lib/resource.robot
6bc331e22SVijayResource         ../../lib/bmc_redfish_resource.robot
7bc331e22SVijayResource         ../../lib/openbmc_ffdc.robot
8bc331e22SVijay
9355daac7SVijayTest Setup       Test Setup Execution
10bc331e22SVijayTest Teardown    Test Teardown Execution
11bc331e22SVijay
12bc331e22SVijay*** Variables ***
13bc331e22SVijay
14bc331e22SVijay# Data-sets for testing different test cases.
15bc331e22SVijay&{LOCKALL_LEN1}                   LockFlag=LockAll                SegmentLength=${1}
16bc331e22SVijay&{LOCKALL_LEN2}                   LockFlag=LockAll                SegmentLength=${2}
17bc331e22SVijay&{LOCKALL_LEN3}                   LockFlag=LockAll                SegmentLength=${3}
18bc331e22SVijay&{LOCKALL_LEN4}                   LockFlag=LockAll                SegmentLength=${4}
19bc331e22SVijay&{LOCKALL_LEN5}                   LockFlag=LockAll                SegmentLength=${5}
20bc331e22SVijay
21bc331e22SVijay&{LOCKALL_INVALID_LOCKFLAG1}      LockFlag=LocAll                 SegmentLength=${2}
22bc331e22SVijay&{LOCKALL_INVALID_LOCKFLAG2}      LockFlag=LOCKALL                SegmentLength=${3}
23bc331e22SVijay&{LOCKALL_INVALID_LOCKFLAG3}      LOCKFLAG=LockAll                SegmentLength=${4}
24bc331e22SVijay&{LOCKSAME_INVALID_LOCKFLAG3}     Lock=LockSame                   SegmentLength=${1}
25bc331e22SVijay&{LOCKSAME_INVALID_LOCKFLAG4}     Lock=LockSame                   SegmentLength=${True}
26bc331e22SVijay
27bc331e22SVijay&{LOCKSAME_LEN1}                  LockFlag=LockSame               SegmentLength=${1}
28bc331e22SVijay&{LOCKSAME_LEN2}                  LockFlag=LockSame               SegmentLength=${2}
29bc331e22SVijay&{LOCKSAME_LEN3}                  LockFlag=LockSame               SegmentLength=${3}
30bc331e22SVijay&{LOCKSAME_LEN4}                  LockFlag=LockSame               SegmentLength=${4}
31bc331e22SVijay&{LOCKSAME_INVALID_LEN1}          LockFlag=LockSame               SegmentLength=${0}
32bc331e22SVijay&{LOCKSAME_INVALID_LEN2}          LockFlag=LockSame               SegmentLength=${5}
33bc331e22SVijay&{LOCKSAME_INVALID_LEN_STR}       LockFlag=LockSame               SegmentLength=2
34bc331e22SVijay&{LOCKSAME_INVALID_LEN_NEG}       LockFlag=LockSame               SegmentLength=${-3}
35bc331e22SVijay&{LOCKSAME_INVALID_LEN_BOOL}      Lock=LockSame                   SegmentLength=${True}
36bc331e22SVijay
37bc331e22SVijay&{DONTLOCK_LEN1}                  LockFlag=DontLock               SegmentLength=${1}
38bc331e22SVijay&{DONTLOCK_LEN2}                  LockFlag=DontLock               SegmentLength=${2}
39bc331e22SVijay&{DONTLOCK_LEN3}                  LockFlag=DontLock               SegmentLength=${3}
40bc331e22SVijay&{DONTLOCK_LEN4}                  LockFlag=DontLock               SegmentLength=${4}
41bc331e22SVijay&{DONTLOCK_INVALID_LEN}           LockFlag=DontLock               SegmentLength=${5}
42bc331e22SVijay&{DONTLOCK_INVALID_LEN_BOOL}      LockFlag=DONTLOCK               SegmentLength=${False}
43bc331e22SVijay&{DONTLOCK_INVALID_LOCKFLAG}      LOCKFLAG=LockAll                SegmentLength=${4}
44bc331e22SVijay
45bc331e22SVijay@{ONE_SEG_FLAG_ALL}               ${LOCKALL_LEN1}
46bc331e22SVijay@{ONE_SEG_FLAG_SAME}              ${LOCKSAME_LEN3}
47bc331e22SVijay@{ONE_SEG_FLAG_DONT}              ${DONTLOCK_LEN4}
48bc331e22SVijay
49bc331e22SVijay@{TWO_SEG_FLAG_1}                 ${LOCKALL_LEN1}                 ${LOCKSAME_LEN2}
50bc331e22SVijay@{TWO_SEG_FLAG_2}                 ${DONTLOCK_LEN3}                ${LOCKALL_LEN1}
51bc331e22SVijay@{TWO_SEG_FLAG_3}                 ${DONTLOCK_LEN4}                ${LOCKSAME_LEN3}
52bc331e22SVijay@{TWO_SEG_FLAG_4}                 ${DONTLOCK_INVALID_LEN}         ${LOCKSAME_LEN3}
53bc331e22SVijay@{TWO_SEG_FLAG_5}                 ${DONTLOCK_LEN2}                ${LOCKSAME_INVALID_LEN1}
54bc331e22SVijay
55bc331e22SVijay@{TWO_SEG_FLAG_INVALID1}          ${DONTLOCK_LEN4}                ${LOCKSAME_INVALID_LEN1}
56bc331e22SVijay@{TWO_SEG_FLAG_INVALID2}          ${LOCKALL_LEN5}                 ${DONTLOCK_LEN1}
57bc331e22SVijay@{TWO_SEG_FLAG_INVALID3}          ${DONTLOCK_LEN1}                ${LOCKALL_INVALID_LOCKFLAG1}
58bc331e22SVijay@{TWO_SEG_FLAG_INVALID4}          ${DONTLOCK_LEN2}                ${LOCKALL_INVALID_LOCKFLAG2}
59bc331e22SVijay@{TWO_SEG_FLAG_INVALID5}          ${DONTLOCK_LEN2}                ${LOCKALL_INVALID_LOCKFLAG3}
60bc331e22SVijay@{TWO_SEG_FLAG_INVALID6}          ${LOCKALL_LEN3}                 ${LOCKSAME_INVALID_LOCKFLAG3}
61bc331e22SVijay@{TWO_SEG_FLAG_INVALID7}          ${DONTLOCK_LEN2}                ${LOCKSAME_INVALID_LOCKFLAG4}
62bc331e22SVijay@{TWO_SEG_FLAG_INVALID8}          ${DONTLOCK_INVALID_LOCKFLAG}    ${LOCKSAME_INVALID_LEN_BOOL}
63bc331e22SVijay@{TWO_SEG_FLAG_INVALID9}          ${DONTLOCK_LEN2}                ${LOCKSAME_INVALID_LOCKFLAG4}
64bc331e22SVijay
65bc331e22SVijay@{THREE_SEG_FLAG_1}               ${LOCKALL_LEN1}                 @{TWO_SEG_FLAG_3}
66bc331e22SVijay@{THREE_SEG_FLAG_2}               ${LOCKSAME_LEN4}                @{TWO_SEG_FLAG_2}
67bc331e22SVijay@{THREE_SEG_FLAG_3}               ${DONTLOCK_LEN3}                @{TWO_SEG_FLAG_1}
68bc331e22SVijay
69bc331e22SVijay@{FOUR_SEG_FLAG_1}                ${LOCKALL_LEN1}                 @{THREE_SEG_FLAG_2}
70bc331e22SVijay@{FOUR_SEG_FLAG_2}                ${LOCKSAME_LEN4}                @{THREE_SEG_FLAG_3}
71bc331e22SVijay@{FOUR_SEG_FLAG_3}                ${DONTLOCK_LEN3}                @{THREE_SEG_FLAG_1}
72bc331e22SVijay
73bc331e22SVijay@{FIVE_SEG_FLAG_1}                ${LOCKALL_LEN1}                 @{FOUR_SEG_FLAG_2}
74bc331e22SVijay@{FIVE_SEG_FLAG_2}                ${LOCKSAME_LEN4}                @{FOUR_SEG_FLAG_3}
75bc331e22SVijay@{FIVE_SEG_FLAG_3}                ${DONTLOCK_LEN3}                @{FOUR_SEG_FLAG_1}
76bc331e22SVijay
77bc331e22SVijay@{SIX_SEG_FLAG_1}                 ${LOCKALL_LEN1}                 @{FIVE_SEG_FLAG_2}
78bc331e22SVijay@{SIX_SEG_FLAG_2}                 ${LOCKSAME_LEN4}                @{FIVE_SEG_FLAG_3}
79bc331e22SVijay@{SIX_SEG_FLAG_3}                 ${DONTLOCK_LEN3}                @{FIVE_SEG_FLAG_1}
80bc331e22SVijay
81bc331e22SVijay@{SEVEN_SEG_FLAG_1}               ${LOCKALL_LEN1}                 @{SIX_SEG_FLAG_2}
82bc331e22SVijay@{SEVEN_SEG_FLAG_2}               ${LOCKSAME_LEN4}                @{SIX_SEG_FLAG_3}
83bc331e22SVijay@{SEVEN_SEG_FLAG_3}               ${DONTLOCK_LEN3}                @{SIX_SEG_FLAG_1}
84bc331e22SVijay
85bc331e22SVijay# Different messages to be verified.
86bc331e22SVijay${PROP_REQ_ERR}         is a required property and must be included in the request.
87bc331e22SVijay${PROP_ERR}             is not in the list of valid properties for the resource.
88bc331e22SVijay${PROP_TYPE_ERR}        is of a different type than the property can accept.
89bc331e22SVijay
90bc331e22SVijay# Build error patterns list.
91355daac7SVijay@{EMPTY_LIST}
92bc331e22SVijay@{ERR_PATTERN1}                   ${PROP_REQ_ERR}                ${PROP_ERR}
93bc331e22SVijay@{ERR_PATTERN2}                   ${PROP_TYPE_ERR}
94bc331e22SVijay@{ERR_PATTERN3}                   ${PROP_REQ_ERR}                ${PROP_ERR}                 ${PROP_TYPE_ERR}
95bc331e22SVijay
96bc331e22SVijay# Dictionary of Locks with Transaction ID as key and Session ID as a value.
97bc331e22SVijay&{LOCKS}
98bc331e22SVijay
99bc331e22SVijay
100bc331e22SVijay*** Test Cases ***
101bc331e22SVijay
102bc331e22SVijayAcquire And Release Different Read Locks
103bc331e22SVijay    [Documentation]  Acquire and release different read locks.
104bc331e22SVijay    [Tags]  Acquire_And_Release_Different_Read_Locks
105bc331e22SVijay    [Template]  Acquire And Release Lock
106bc331e22SVijay
107bc331e22SVijay    # lock  seg_flags                     resource_id  hmc_id  exp_status_code      err_msgs         new_sess
108bc331e22SVijay    # type                                                                                            req
109355daac7SVijay    Read    ${ONE_SEG_FLAG_ALL}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
110355daac7SVijay    Read    ${ONE_SEG_FLAG_SAME}          ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
111355daac7SVijay    Read    ${ONE_SEG_FLAG_DONT}          ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
112149ba768SVijay    Read    ${TWO_SEG_FLAG_1}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
113355daac7SVijay    Read    ${TWO_SEG_FLAG_2}             ${234}       hmc-id  ${HTTP_OK}           ${EMPTY_LIST}    ${True}
114355daac7SVijay    Read    ${TWO_SEG_FLAG_3}             ${234}       hmc-id  ${HTTP_OK}           ${EMPTY_LIST}    ${True}
115355daac7SVijay    Read    ${TWO_SEG_FLAG_4}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
116355daac7SVijay    Read    ${TWO_SEG_FLAG_5}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
117149ba768SVijay    Read    ${THREE_SEG_FLAG_1}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
118149ba768SVijay    Read    ${THREE_SEG_FLAG_2}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
119149ba768SVijay    Read    ${THREE_SEG_FLAG_3}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
120149ba768SVijay    Read    ${FOUR_SEG_FLAG_1}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
121149ba768SVijay    Read    ${FOUR_SEG_FLAG_2}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
122149ba768SVijay    Read    ${FOUR_SEG_FLAG_3}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
123149ba768SVijay    Read    ${FIVE_SEG_FLAG_1}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
124149ba768SVijay    Read    ${FIVE_SEG_FLAG_2}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
125149ba768SVijay    Read    ${FIVE_SEG_FLAG_3}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
126149ba768SVijay    Read    ${SIX_SEG_FLAG_1}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
127149ba768SVijay    Read    ${SIX_SEG_FLAG_2}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
128149ba768SVijay    Read    ${SIX_SEG_FLAG_3}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
129355daac7SVijay    Read    ${SEVEN_SEG_FLAG_1}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
130355daac7SVijay    Read    ${SEVEN_SEG_FLAG_2}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
131355daac7SVijay    Read    ${SEVEN_SEG_FLAG_3}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
132355daac7SVijay    Read    ${LOCKSAME_INVALID_LEN1}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
133bc331e22SVijay    Read    ${LOCKSAME_INVALID_LEN_STR}   ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN2}  ${True}
134bc331e22SVijay    Read    ${LOCKSAME_INVALID_LEN_NEG}   ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN2}  ${True}
135bc331e22SVijay    Read    ${LOCKSAME_INVALID_LEN_BOOL}  ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN2}  ${True}
136bc331e22SVijay    Read    ${DONTLOCK_INVALID_LEN_BOOL}  ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN2}  ${True}
137355daac7SVijay    Read    ${TWO_SEG_FLAG_INVALID1}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
138355daac7SVijay    Read    ${TWO_SEG_FLAG_INVALID2}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
139355daac7SVijay    Read    ${TWO_SEG_FLAG_INVALID3}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
140355daac7SVijay    Read    ${TWO_SEG_FLAG_INVALID4}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${EMPTY_LIST}    ${True}
141bc331e22SVijay    Read    ${TWO_SEG_FLAG_INVALID5}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN1}  ${True}
142bc331e22SVijay    Read    ${TWO_SEG_FLAG_INVALID6}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN1}  ${True}
143bc331e22SVijay    Read    ${TWO_SEG_FLAG_INVALID7}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN3}  ${True}
144bc331e22SVijay    Read    ${TWO_SEG_FLAG_INVALID8}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN1}  ${True}
145bc331e22SVijay    Read    ${TWO_SEG_FLAG_INVALID9}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN2}  ${True}
146bc331e22SVijay    Read    ${TWO_SEG_FLAG_3}             234          hmc-id  ${HTTP_BAD_REQUEST}  ${ERR_PATTERN2}  ${True}
147bc331e22SVijay
148bc331e22SVijay
149bc331e22SVijayAcquire And Release Different Write Locks
150bc331e22SVijay    [Documentation]  Acquire and release different write locks.
151bc331e22SVijay    [Tags]  Acquire_And_Release_Different_Write_Locks
152bc331e22SVijay    [Template]  Acquire And Release Lock
153bc331e22SVijay
154bc331e22SVijay    # lock  seg_flags                    resource_id  hmc_id  exp_status_code       err_msgs         new_sess
155bc331e22SVijay    # type                                                                                            req
156355daac7SVijay    Write  ${ONE_SEG_FLAG_ALL}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
157355daac7SVijay    Write  ${ONE_SEG_FLAG_SAME}          ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
158355daac7SVijay    Write  ${ONE_SEG_FLAG_DONT}          ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
15960f01e48SVijay    Write  ${TWO_SEG_FLAG_1}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
160355daac7SVijay    Write  ${TWO_SEG_FLAG_2}             ${234}       hmc-id  ${HTTP_OK}            ${EMPTY_LIST}    ${True}
161355daac7SVijay    Write  ${TWO_SEG_FLAG_3}             ${234}       hmc-id  ${HTTP_OK}            ${EMPTY_LIST}    ${True}
162355daac7SVijay    Write  ${TWO_SEG_FLAG_INVALID4}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
16360f01e48SVijay    Write  ${THREE_SEG_FLAG_1}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
16460f01e48SVijay    Write  ${THREE_SEG_FLAG_2}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
16560f01e48SVijay    Write  ${THREE_SEG_FLAG_3}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
16660f01e48SVijay    Write  ${FOUR_SEG_FLAG_1}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
16760f01e48SVijay    Write  ${FOUR_SEG_FLAG_2}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
16860f01e48SVijay    Write  ${FOUR_SEG_FLAG_3}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
16960f01e48SVijay    Write  ${FIVE_SEG_FLAG_1}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
17060f01e48SVijay    Write  ${FIVE_SEG_FLAG_2}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
17160f01e48SVijay    Write  ${FIVE_SEG_FLAG_3}            ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
17260f01e48SVijay    Write  ${SIX_SEG_FLAG_1}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
17360f01e48SVijay    Write  ${SIX_SEG_FLAG_2}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
17460f01e48SVijay    Write  ${SIX_SEG_FLAG_3}             ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
175355daac7SVijay    Write  ${SEVEN_SEG_FLAG_1}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
176355daac7SVijay    Write  ${SEVEN_SEG_FLAG_2}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
177355daac7SVijay    Write  ${SEVEN_SEG_FLAG_3}           ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
178355daac7SVijay    Write  ${LOCKSAME_INVALID_LEN1}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
179355daac7SVijay    Write  ${LOCKSAME_INVALID_LEN_STR}   ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
180355daac7SVijay    Write  ${LOCKSAME_INVALID_LEN_NEG}   ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
181355daac7SVijay    Write  ${LOCKSAME_INVALID_LEN_BOOL}  ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
182355daac7SVijay    Write  ${DONTLOCK_INVALID_LEN_BOOL}  ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
183355daac7SVijay    Write  ${TWO_SEG_FLAG_INVALID1}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
184355daac7SVijay    Write  ${TWO_SEG_FLAG_INVALID2}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${EMPTY_LIST}    ${True}
185bc331e22SVijay    Write  ${TWO_SEG_FLAG_INVALID8}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${ERR_PATTERN1}  ${True}
186bc331e22SVijay    Write  ${TWO_SEG_FLAG_INVALID5}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${ERR_PATTERN1}  ${True}
187bc331e22SVijay    Write  ${TWO_SEG_FLAG_INVALID9}      ${234}       hmc-id  ${HTTP_BAD_REQUEST}   ${ERR_PATTERN2}  ${True}
188bc331e22SVijay    Write  ${TWO_SEG_FLAG_3}             234          hmc-id  ${HTTP_BAD_REQUEST}   ${ERR_PATTERN2}  ${True}
189bc331e22SVijay
190bc331e22SVijay
191bc331e22SVijayVerify GetLockList Returns An Empty Record For An Invalid Session Id
192bc331e22SVijay    [Documentation]  Verify GetLockList returns an empty record for an invalid session id.
193bc331e22SVijay    [Tags]  Verify_GetLockList_Returns_An_Empty_Record_For_An_Invalid_Session_Id
194bc331e22SVijay
195bc331e22SVijay    ${session_location}=  Redfish.Get Session Location
196bc331e22SVijay    ${session_id}=  Evaluate  os.path.basename($session_location)  modules=os
197bc331e22SVijay
198bc331e22SVijay    ${records}=  Run Keyword  Get Locks List  ${session_id}
199bc331e22SVijay    ${records}=  Run Keyword  Get Locks List  ZZzZZz9zzZ
200bc331e22SVijay    ${length}=  Get Length  ${records}
201bc331e22SVijay    Should Be Equal  ${length}  ${0}
202bc331e22SVijay
203bc331e22SVijay
204355daac7SVijayVerify Lock Conflicts
205355daac7SVijay    [Documentation]  Verify lock conflicts.
206355daac7SVijay    [Tags]  Verify_Lock_Conflicts
207355daac7SVijay    [Template]  Acquire And Release Lock
208355daac7SVijay
209355daac7SVijay    Write  ${TWO_SEG_FLAG_2}  ${234}  hmc-id  ${HTTP_OK}        ['NA']  ${True}
210355daac7SVijay    Read   ${TWO_SEG_FLAG_2}  ${234}  hmc-id  ${HTTP_CONFLICT}  ['NA']  ${False}
211355daac7SVijay    Read   ${TWO_SEG_FLAG_2}  ${234}  hmc-id  ${HTTP_OK}        ['NA']  ${True}
212355daac7SVijay    Write  ${TWO_SEG_FLAG_2}  ${234}  hmc-id  ${HTTP_CONFLICT}  ['NA']  ${False}
213355daac7SVijay    Write  ${TWO_SEG_FLAG_2}  ${234}  hmc-id  ${HTTP_OK}        ['NA']  ${True}
214355daac7SVijay    Write  ${TWO_SEG_FLAG_2}  ${234}  hmc-id  ${HTTP_CONFLICT}  ['NA']  ${False}
215355daac7SVijay
216355daac7SVijay
21785610eeeSVijayVerify Persistency Of Locks After BMC Reboot
21885610eeeSVijay    [Documentation]  Verify persistency of locks after BMC reboot.
21985610eeeSVijay    [Tags]  Verify_Persistency_Of_Locks_After_BMC_Reboot
22085610eeeSVijay    [Template]  Locks Persistency Check After BMC Reboot
22185610eeeSVijay
22285610eeeSVijay    # lock_type  seg_flags          resource_id
22385610eeeSVijay    Read         ${TWO_SEG_FLAG_2}  ${234}
22485610eeeSVijay    Write        ${TWO_SEG_FLAG_2}  ${234}
22585610eeeSVijay
22685610eeeSVijay
227*afdd2a1dSVijayVerify Valid Lock Transactions Release
228*afdd2a1dSVijay    [Documentation]  Verify valid lock transactions release.
229*afdd2a1dSVijay    [Tags]  Verify_Valid_Lock_Transactions_Release
230*afdd2a1dSVijay
231*afdd2a1dSVijay    ${transaction_id1}=  Acquire Lock On A Given Resource
232*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_2}  ${234}
233*afdd2a1dSVijay    ${locks_before}=  Get Locks List  ${SESSION_ID}
234*afdd2a1dSVijay
235*afdd2a1dSVijay    ${transaction_id2}=  Acquire Lock On A Given Resource
236*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_3}  ${234}
237*afdd2a1dSVijay    ${transaction_id3}=  Acquire Lock On A Given Resource
238*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_2}  ${234}
239*afdd2a1dSVijay    ${transaction_id4}=  Acquire Lock On A Given Resource
240*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_3}  ${234}
241*afdd2a1dSVijay
242*afdd2a1dSVijay    ${transaction_ids}=  Create List  ${transaction_id2}  ${transaction_id3}  ${transaction_id4}
243*afdd2a1dSVijay    Release Locks  ${transaction_ids}
244*afdd2a1dSVijay    ${locks_after}=  Get Locks List  ${SESSION_ID}
245*afdd2a1dSVijay    Should Be Equal  ${locks_before}  ${locks_after}
246*afdd2a1dSVijay
247*afdd2a1dSVijay
248*afdd2a1dSVijayVerify Invalid Lock Transactions Release
249*afdd2a1dSVijay    [Documentation]  Verify invalid lock transactions release.
250*afdd2a1dSVijay    [Tags]  Verify_Invalid_Lock_Transactions_Release
251*afdd2a1dSVijay
252*afdd2a1dSVijay    ${transaction_id1}=  Acquire Lock On A Given Resource
253*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_2}  ${234}
254*afdd2a1dSVijay    ${locks_before}=  Get Locks List  ${SESSION_ID}
255*afdd2a1dSVijay
256*afdd2a1dSVijay    ${transaction_id2}=  Evaluate  ${transaction_id1} + 1
257*afdd2a1dSVijay    ${transaction_id3}=  Evaluate  ${transaction_id1} - 1
258*afdd2a1dSVijay    ${transaction_ids}=  Create List  ${transaction_id2}  ${transaction_id1}  ${transaction_id3}
259*afdd2a1dSVijay
260*afdd2a1dSVijay    # If any transaction/s in the list does not belong to current session then it will be a bad request.
261*afdd2a1dSVijay    Release Locks  ${transaction_ids}  exp_status_code=${HTTP_BAD_REQUEST}
262*afdd2a1dSVijay    ${locks_after}=  Get Locks List  ${SESSION_ID}
263*afdd2a1dSVijay    Should Be Equal  ${locks_before}  ${locks_after}
264*afdd2a1dSVijay
265*afdd2a1dSVijay
266*afdd2a1dSVijayVerify Locks Release By Session
267*afdd2a1dSVijay    [Documentation]  Verify locks release by session.
268*afdd2a1dSVijay    [Tags]  Verify_Locks_Release_By_Session
269*afdd2a1dSVijay
270*afdd2a1dSVijay    ${locks_before}=  Get Locks List  ${SESSION_ID}
271*afdd2a1dSVijay    ${transaction_id1}=  Acquire Lock On A Given Resource
272*afdd2a1dSVijay    ...  Write  ${TWO_SEG_FLAG_2}  ${234}
273*afdd2a1dSVijay
274*afdd2a1dSVijay    # Release Lock by Session without mentioning transaction_ids.
275*afdd2a1dSVijay    Release Locks  release_type=Session
276*afdd2a1dSVijay    ${locks_after}=  Get Locks List  ${SESSION_ID}
277*afdd2a1dSVijay    Should Be Equal  ${locks_before}  ${locks_after}
278*afdd2a1dSVijay
279*afdd2a1dSVijay    ${transaction_id1}=  Acquire Lock On A Given Resource
280*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_2}  ${234}
281*afdd2a1dSVijay    ${transaction_id2}=  Acquire Lock On A Given Resource
282*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_3}  ${234}
283*afdd2a1dSVijay    ${transaction_ids}=  Create List  ${transaction_id1}  ${transaction_id2}
284*afdd2a1dSVijay
285*afdd2a1dSVijay    # Release Lock by Session by mentioning transaction_ids also in the request.
286*afdd2a1dSVijay    Release Locks  ${transaction_ids}  release_type=Session
287*afdd2a1dSVijay
288*afdd2a1dSVijay
289*afdd2a1dSVijayVerify Locks Created By One Session Cannot Be Deleted By Another Session
290*afdd2a1dSVijay    [Documentation]  Verify locks created by one session cannot be deleted by another session.
291*afdd2a1dSVijay    [Tags]  Verify_Locks_Created_By_One_Session_Cannot_Be_Deleted_By_Another_Session
292*afdd2a1dSVijay
293*afdd2a1dSVijay    ${transaction_id1}=  Acquire Lock On A Given Resource
294*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_2}  ${234}
295*afdd2a1dSVijay    ${locks_tran1}=  Get Locks List  ${SESSION_ID}
296*afdd2a1dSVijay
297*afdd2a1dSVijay    Redfish.Login
298*afdd2a1dSVijay    ${session_id}  ${session_key}=  Return Session Id And Session Key
299*afdd2a1dSVijay
300*afdd2a1dSVijay    ${transaction_id2}=  Acquire Lock On A Given Resource
301*afdd2a1dSVijay    ...  Read  ${TWO_SEG_FLAG_3}  ${234}
302*afdd2a1dSVijay    ${locks_before}=  Get Locks List  ${SESSION_ID}
303*afdd2a1dSVijay
304*afdd2a1dSVijay    ${transaction_ids}=  Create List  ${transaction_id1}  ${transaction_id2}
305*afdd2a1dSVijay    Release Locks  ${transaction_ids}  exp_status_code=${HTTP_UNAUTHORIZED}  conflict_record=${locks_tran1}
306*afdd2a1dSVijay    ${locks_after}=  Get Locks List  ${SESSION_ID}
307*afdd2a1dSVijay    Should Be Equal  ${locks_before}  ${locks_after}
308*afdd2a1dSVijay
309*afdd2a1dSVijay    # When release_type=Session, transaction_ids should be ignored.
310*afdd2a1dSVijay    Release Locks  ${transaction_ids}  release_type=Session
311*afdd2a1dSVijay    ${locks_after}=  Get Locks List  ${SESSION_ID}
312*afdd2a1dSVijay    Should Be Equal  ${EMPTY_LIST}  ${locks_after}
313*afdd2a1dSVijay
314*afdd2a1dSVijay
315bc331e22SVijay*** Keywords ***
316bc331e22SVijay
31785610eeeSVijayLocks Persistency Check After BMC Reboot
31885610eeeSVijay    [Documentation]  Locks persistency check after BMC reboot.
31985610eeeSVijay    [Arguments]  ${lock_type}  ${seg_flags}  ${resource_id}
32085610eeeSVijay
32185610eeeSVijay    # Description of argument(s):
32285610eeeSVijay    # lock_type    Type of lock (Read/Write).
32385610eeeSVijay    # seg_flags    Segmentation Flags to identify lock elements under system level in the hierarchy.
32485610eeeSVijay    # resource_id  Decimal +ve integer value of maximum 8 hex bytes.  Ex: 134, 2048 etc.
32585610eeeSVijay
32685610eeeSVijay    ${transaction_id}=  Run Keyword  Acquire Lock On A Given Resource
32785610eeeSVijay    ...  ${lock_type}  ${seg_flags}  ${resource_id}
32885610eeeSVijay
32985610eeeSVijay    ${locks_prev}=  Run Keyword  Get Locks List  ${SESSION_ID}
33085610eeeSVijay
33185610eeeSVijay    Initialize OpenBMC
33285610eeeSVijay    OBMC Reboot (off)
33385610eeeSVijay
33485610eeeSVijay    ${locks_curr}=  Run Keyword  Get Locks List  ${SESSION_ID}
33585610eeeSVijay    Should Be Equal  ${locks_prev}  ${locks_curr}
336*afdd2a1dSVijay    ${transaction_ids}=  Create List  ${transaction_id}
337*afdd2a1dSVijay    Release Locks  ${transaction_ids}
33885610eeeSVijay
33985610eeeSVijay
340bc331e22SVijayReturn Data Dictionary For Single Request
341bc331e22SVijay    [Documentation]  Return data dictionary for single request.
342bc331e22SVijay    [Arguments]  ${lock_type}  ${seg_flags}  ${resource_id}
343bc331e22SVijay
344bc331e22SVijay    # Description of argument(s):
345bc331e22SVijay    # lock_type    Type of lock (Read/Write).
346bc331e22SVijay    # seg_flags    Segmentation Flags to identify lock elements under system level in the hierarchy.
347bc331e22SVijay    # resource_id  Decimal +ve integer value of maximum 8 hex bytes.  Ex: 134, 2048 etc.
348bc331e22SVijay
349bc331e22SVijay    ${SEG_FLAGS_LOCK}=  Create Dictionary  LockType=${lock_type}  SegmentFlags=@{seg_flags}
350bc331e22SVijay    ...  ResourceID=${resource_id}
351bc331e22SVijay    ${SEG_FLAGS_ENTRIES}=  Create List  ${SEG_FLAGS_LOCK}
352bc331e22SVijay    ${LOCK_REQUEST}=  Create Dictionary  Request=${SEG_FLAGS_ENTRIES}
353bc331e22SVijay    Log To Console  ${LOCK_REQUEST}
354bc331e22SVijay
355bc331e22SVijay    [Return]  ${LOCK_REQUEST}
356bc331e22SVijay
357bc331e22SVijay
358bc331e22SVijayAcquire Lock On A Given Resource
359bc331e22SVijay    [Documentation]  Acquire lock on a given resource.
360bc331e22SVijay    [Arguments]  ${lock_type}  ${seg_flags}  ${resource_id}  ${exp_status_code}=${HTTP_OK}
361355daac7SVijay    ...  ${err_msgs}=${EMPTY_LIST}
362bc331e22SVijay
363bc331e22SVijay    # Description of argument(s):
364bc331e22SVijay    # lock_type        Type of lock (Read/Write).
365bc331e22SVijay    # seg_flags        Segmentation Flags to identify lock elements under system level in the hierarchy.
366bc331e22SVijay    #                  Ex:  [{'LockFlag': 'LockAll', 'SegmentLength': 1},
367bc331e22SVijay    #                        {'LockFlag': 'LockSame', 'SegmentLength': 2}]
368bc331e22SVijay    # resource_id      Decimal +ve integer value of maximum 8 hex bytes.  Ex: 134, 2048 etc.
369355daac7SVijay    # exp_status_code  Expected status code from the AcquireLock request for given inputs.
370355daac7SVijay    # err_msgs         List of expected error messages.
371bc331e22SVijay
372bc331e22SVijay    ${data}=  Return Data Dictionary For Single Request  ${lock_type}  ${seg_flags}  ${resource_id}
373bc331e22SVijay    ${resp}=  Redfish.Post  /ibm/v1/HMC/LockService/Actions/LockService.AcquireLock
374bc331e22SVijay    ...  body=${data}  valid_status_codes=[${exp_status_code}]
375bc331e22SVijay
376bc331e22SVijay    ${transaction_id}=  Run Keyword If  ${exp_status_code} != ${HTTP_OK}
377bc331e22SVijay    ...  Set Variable  ${0}
378bc331e22SVijay    ...  ELSE  Load Lock Record And Build Transaction To Session Map  ${resp.text}
379bc331e22SVijay
380355daac7SVijay    Run Keyword If  ${exp_status_code} == ${HTTP_CONFLICT} and ${err_msgs} == ['NA']
381355daac7SVijay    ...  Load Response And Verify Conflict  ${resp.text}  ${SESSION_ID}
382355daac7SVijay    ...  ELSE  Run Keyword If  ${exp_status_code} != ${HTTP_OK} and ${err_msgs} != ${EMPTY_LIST}
383bc331e22SVijay    ...  Load Response And Verify Error  ${resp.text}  err_msgs=${err_msgs}
384355daac7SVijay
385bc331e22SVijay    Append Transaction Id And Session Id To Locks Dictionary  ${transaction_id}
386bc331e22SVijay
387bc331e22SVijay    [Return]  ${transaction_id}
388bc331e22SVijay
389bc331e22SVijay
390bc331e22SVijayLoad Lock Record And Build Transaction To Session Map
391bc331e22SVijay    [Documentation]  Load lock record and build transaction to session map.
392bc331e22SVijay    [Arguments]  ${resp_text}
393bc331e22SVijay
394bc331e22SVijay    # Description of argument(s):
395bc331e22SVijay    # resp_text  Response test from a REST request.
396bc331e22SVijay
397bc331e22SVijay    ${acquire_lock}=  Evaluate  json.loads('''${resp_text}''')  json
398bc331e22SVijay    Append Transaction Id And Session Id To Locks Dictionary  ${acquire_lock["TransactionID"]}
399bc331e22SVijay
400bc331e22SVijay    [Return]  ${acquire_lock["TransactionID"]}
401bc331e22SVijay
402bc331e22SVijay
403bc331e22SVijayLoad Response And Verify Error
404bc331e22SVijay    [Documentation]  Load response and verify error.
405355daac7SVijay    [Arguments]  ${error_resp}  ${err_msgs}=${EMPTY_LIST}
406bc331e22SVijay
407bc331e22SVijay    # Description of argument(s):
408bc331e22SVijay    # error_resp  Error response from a REST request.
409bc331e22SVijay    # err_msgs    List of error msg patterns.
410bc331e22SVijay
411bc331e22SVijay    ${error_resp}=  Replace String  ${error_resp}  \"  \\"
412bc331e22SVijay    ${error_response}=  Evaluate  json.loads('''${error_resp}''')  json
413bc331e22SVijay
414bc331e22SVijay    ${errors}=  Get Dictionary Values  ${error_response}
415bc331e22SVijay    ${extended_errors}=  Create List
416bc331e22SVijay
417bc331e22SVijay    FOR  ${error}  IN  @{errors}
418bc331e22SVijay      Append To List  ${extended_errors}  ${error[0]["Message"]}
419bc331e22SVijay    END
420bc331e22SVijay
421bc331e22SVijay    Log To Console  EXTENDED = ${extended_errors}
422bc331e22SVijay
423bc331e22SVijay    FOR  ${exp_error}  IN  @{err_msgs}
424bc331e22SVijay        Run Keyword  Expect List Of Errors In An Extended Errors  ${exp_error}  ${extended_errors}
425bc331e22SVijay    END
426bc331e22SVijay
427bc331e22SVijay
428bc331e22SVijayExpect List Of Errors In An Extended Errors
429bc331e22SVijay    [Documentation]  Expect list of errors in an extended errors.
430355daac7SVijay    [Arguments]  ${exp_error}  ${extended_errors}=${EMPTY_LIST}
431bc331e22SVijay
432bc331e22SVijay    ${found}=  Set Variable  ${False}
433bc331e22SVijay
434bc331e22SVijay    FOR  ${error_record}  IN  @{extended_errors}
435bc331e22SVijay      ${found}=  Evaluate  '${exp_error}' in '${error_record}'
436bc331e22SVijay      Exit For Loop If  ${found} == ${True}
437bc331e22SVijay    END
438bc331e22SVijay
439bc331e22SVijay    Should Be True  ${found}
440bc331e22SVijay
441bc331e22SVijay
442bc331e22SVijayAppend Transaction Id And Session Id To Locks Dictionary
443bc331e22SVijay    [Documentation]  Append transaction id and session id to locks dictionary.
444bc331e22SVijay    [Arguments]  ${transaction_id}
445bc331e22SVijay
446bc331e22SVijay    # Description of argument(s):
447bc331e22SVijay    # transaction_id  Transaction ID created from acquire lock request. Ex: 8, 9 etc.
448bc331e22SVijay
449bc331e22SVijay    Set To Dictionary  ${LOCKS}  ${${transaction_id}}  ${session_id}
450bc331e22SVijay
451bc331e22SVijay
452bc331e22SVijayGet Locks List
453bc331e22SVijay    [Documentation]  Get locks list.
454bc331e22SVijay    [Arguments]  @{sessions}  ${exp_status_code}=${HTTP_OK}
455bc331e22SVijay
456bc331e22SVijay    # Description of argument(s):
457bc331e22SVijay    # sessions         List of comma separated strings. Ex: ["euHoAQpvNe", "ecTjANqwFr"]
458bc331e22SVijay    # exp_status_code  expected status code from the GetLockList request for given inputs.
459bc331e22SVijay
460bc331e22SVijay    ${sessions}=  Evaluate  json.dumps(${sessions})  json
461bc331e22SVijay    ${data}=  Set Variable  {"SessionIDs": ${sessions}}
462bc331e22SVijay    ${resp}=  Redfish.Post  /ibm/v1/HMC/LockService/Actions/LockService.GetLockList
463bc331e22SVijay    ...  body=${data}  valid_status_codes=[${exp_status_code}]
464bc331e22SVijay
465bc331e22SVijay    ${locks}=  Evaluate  json.loads('''${resp.text}''')  json
466bc331e22SVijay
467bc331e22SVijay    [Return]  ${locks["Records"]}
468bc331e22SVijay
469bc331e22SVijay
470*afdd2a1dSVijayRelease Locks
471*afdd2a1dSVijay    [Documentation]  Release locks.
472*afdd2a1dSVijay    [Arguments]  ${transaction_ids}=${EMPTY_LIST}  ${release_type}=Transaction  ${exp_status_code}=${HTTP_OK}
473*afdd2a1dSVijay    ...  ${conflict_record}=${EMPTY_LIST}
474bc331e22SVijay
475bc331e22SVijay    # Description of argument(s):
476*afdd2a1dSVijay    # transaction_ids  List of transaction ids or session ids. Ex: [15, 18]  or ["euHoAQpvNe", "ecTjANqwFr"]
477bc331e22SVijay    # release_type     Release all locks acquired using current session or only given transaction numbers.
478bc331e22SVijay    #                  Ex:  Session,  Transaction.  Default will be Transaction.
479bc331e22SVijay    # exp_status_code  expected status code from the ReleaseLock request for given inputs.
480*afdd2a1dSVijay    # conflict_record  Expected conflict record.
481bc331e22SVijay
482*afdd2a1dSVijay    # When release_type=Session then TransactionIDs list will be ignored.
483bc331e22SVijay    ${data}=  Set Variable  {"Type": "${release_type}", "TransactionIDs": ${transaction_ids}}
484bc331e22SVijay    ${data}=  Evaluate  json.dumps(${data})  json
485*afdd2a1dSVijay    ${resp}=  Redfish.Post  /ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock
486bc331e22SVijay    ...  body=${data}  valid_status_codes=[${exp_status_code}]
487*afdd2a1dSVijay    Should Be True  ${resp.status}  ${exp_status_code}
488*afdd2a1dSVijay    Return From Keyword If  ${conflict_record} == ${EMPTY_LIST}
489*afdd2a1dSVijay
490*afdd2a1dSVijay    ${conflict}=  Evaluate  json.loads('''${resp.text}''')  json
491*afdd2a1dSVijay
492*afdd2a1dSVijay    # Example of conflict
493*afdd2a1dSVijay    # {
494*afdd2a1dSVijay    #    "Record":{
495*afdd2a1dSVijay    #       "HMCID":"hmc-id",
496*afdd2a1dSVijay    #       "LockType":"Read",
497*afdd2a1dSVijay    #       "ResourceID":234,
498*afdd2a1dSVijay    #       "SegmentFlags":[
499*afdd2a1dSVijay    #          {
500*afdd2a1dSVijay    #             "LockFlag":"DontLock",
501*afdd2a1dSVijay    #             "SegmentLength":3
502*afdd2a1dSVijay    #          },
503*afdd2a1dSVijay    #          {
504*afdd2a1dSVijay    #             "LockFlag":"LockAll",
505*afdd2a1dSVijay    #             "SegmentLength":1
506*afdd2a1dSVijay    #          }
507*afdd2a1dSVijay    #       ],
508*afdd2a1dSVijay    #       "SessionID":"OorUVwrXuT",
509*afdd2a1dSVijay    #       "TransactionID":47
510*afdd2a1dSVijay    #    }
511*afdd2a1dSVijay    # }
512*afdd2a1dSVijay
513*afdd2a1dSVijay    Should Be Equal  ${conflict_record[0]}  ${conflict["Record"]}
514bc331e22SVijay
515bc331e22SVijay
516bc331e22SVijayVerify Lock Record
517bc331e22SVijay    [Documentation]  Verify lock record.
518bc331e22SVijay    [Arguments]  ${lock_found}  &{lock_records}
519bc331e22SVijay
520bc331e22SVijay    # Description of argument(s):
521bc331e22SVijay    # lock_found    True if lock record is expected to be present, else False.
522bc331e22SVijay    # lock_records  A dictionary containing key value pairs of a lock record.
523bc331e22SVijay
524bc331e22SVijay    ${session}=  Get From Dictionary  ${LOCKS}  ${lock_records["TransactionID"]}
525bc331e22SVijay    ${locks}=  Run Keyword  Get Locks List  ${session}
526bc331e22SVijay
527bc331e22SVijay    ${lock_record_found}=  Set Variable  ${False}
528bc331e22SVijay
529bc331e22SVijay    FOR  ${record}  IN  @{locks}
530bc331e22SVijay      ${record}=  Evaluate  json.dumps(${record})  json
531bc331e22SVijay      ${record}=  Evaluate  json.loads('''${record}''')  json
532bc331e22SVijay      ${lock_record_found}=  Set Variable If  ${record["TransactionID"]} == ${lock_records["TransactionID"]}
533bc331e22SVijay      ...  ${True}  ${False}
534bc331e22SVijay
535bc331e22SVijay      Continue For Loop If  ${lock_record_found} == ${False}
536bc331e22SVijay      Dictionaries Should Be Equal  ${record}  ${lock_records}
537bc331e22SVijay      Exit For Loop
538bc331e22SVijay    END
539bc331e22SVijay
540bc331e22SVijay    Should Be Equal  ${lock_record_found}  ${lock_found}
541bc331e22SVijay
542bc331e22SVijay
543355daac7SVijayLoad Response And Verify Conflict
544355daac7SVijay    [Documentation]  Load response and verify conflict.
545355daac7SVijay    [Arguments]  ${conflict_resp}  ${sessions}
546355daac7SVijay
547355daac7SVijay    # Description of argument(s):
548355daac7SVijay    # conflict_resp  Conflict response from a REST request.
549355daac7SVijay    #                Example : { "Record": { "HMCID": "hmc-id", "LockType": "Write", "ResourceID": 234,
550355daac7SVijay    #                            "SegmentFlags": [ { "LockFlag": "DontLock", "SegmentLength": 3},
551355daac7SVijay    #                                              { "LockFlag": "LockAll",  "SegmentLength": 1}],
552355daac7SVijay    #                            "SessionID": "B6geYEdo6T", "TransactionID": 104 } }
553355daac7SVijay    # sessions       Comma separated list of sessions
554355daac7SVijay
555355daac7SVijay    ${curr_locks}=  Run Keyword  Get Locks List  ${sessions}
556355daac7SVijay    ${conflict_resp}=  Replace String  ${conflict_resp}  \"  \\"
557355daac7SVijay    ${conflict_response}=  Evaluate  json.loads('''${conflict_resp}''')  json
558355daac7SVijay
559355daac7SVijay    ${conflicts}=  Get Dictionary Values  ${conflict_response}
560355daac7SVijay    List Should Contain Value  ${conflicts}  ${PREV_INPUTS}
561355daac7SVijay
562355daac7SVijay
563bc331e22SVijayAcquire And Release Lock
564bc331e22SVijay    [Documentation]  Acquire and release lock.
565bc331e22SVijay    [Arguments]  ${lock_type}  ${seg_flags}  ${resource_id}  ${hmc_id}  ${exp_status_code}=${HTTP_OK}
566355daac7SVijay    ...  ${err_msgs}=${EMPTY_LIST}  ${new_sess_req}=${True}
567bc331e22SVijay
568bc331e22SVijay    # Description of argument(s):
569bc331e22SVijay    # lock_type        Type of lock (Read/Write).
570bc331e22SVijay    # seg_flags        Segmentation Flags to identify lock elements under system level in the hierarchy.
571bc331e22SVijay    #                  Ex:  [{'LockFlag': 'LockAll', 'SegmentLength': 1},
572bc331e22SVijay    #                        {'LockFlag': 'LockSame', 'SegmentLength': 2}]
573bc331e22SVijay    # resource_id      Decimal +ve integer value of maximum 8 hex bytes.  Ex: 134, 2048 etc.
574bc331e22SVijay    # hmc_id           Hardware management console id.
575bc331e22SVijay    # exp_status_code  Expected status code from the AcquireLock request for given inputs.
576355daac7SVijay    # err_msgs         List of expected error messages.
577355daac7SVijay    # new_sess_req     Create a new session before acquiring a lock if True.
578bc331e22SVijay
579bc331e22SVijay    # Get REST session to BMC.
580bc331e22SVijay    Run Keyword If  ${new_sess_req} == ${True}  Create New Session
581bc331e22SVijay
582bc331e22SVijay    ${inputs}=  Create Dictionary  LockType=${lock_type}  ResourceID=${resource_id}
583bc331e22SVijay    ...  SegmentFlags=${seg_flags}  HMCID=${hmc_id}
584bc331e22SVijay
585bc331e22SVijay    ${transaction_id}=  Run Keyword  Acquire Lock On A Given Resource  ${inputs["LockType"]}
586bc331e22SVijay    ...  ${inputs["SegmentFlags"]}  ${inputs["ResourceID"]}  ${exp_status_code}  err_msgs=${err_msgs}
587bc331e22SVijay
588355daac7SVijay    # Each lock request from a new session is saved so that for next lock request using same session
589355daac7SVijay    # can refer to previous lock data to verify conflict records if any.
590355daac7SVijay    Run Keyword If  ${new_sess_req} == ${True}  Set Test Variable Dictionary Of Previous Lock Request
591355daac7SVijay    ...  ${lock_type}  ${seg_flags}  ${resource_id}  ${hmc_id}  ${SESSION_ID}  ${transaction_id}
592bc331e22SVijay
593355daac7SVijay    ${session}=  Get From Dictionary  ${LOCKS}  ${transaction_id}
594bc331e22SVijay    Set To Dictionary  ${inputs}  TransactionID=${${transaction_id}}  SessionID=${session}
595355daac7SVijay
596bc331e22SVijay    ${lock_found}=  Set Variable If  ${exp_status_code} == ${HTTP_OK}  ${True}  ${False}
597bc331e22SVijay    Verify Lock Record  ${lock_found}  &{inputs}
598bc331e22SVijay
599355daac7SVijay    Return From Keyword If  '${exp_status_code}' != '${HTTP_OK}' or ${err_msgs} == ['NA']
600*afdd2a1dSVijay    ${transaction_ids}=  Create List  ${transaction_id}
601*afdd2a1dSVijay    Release Locks  ${transaction_ids}
602bc331e22SVijay    Verify Lock Record  ${False}  &{inputs}
603bc331e22SVijay
604bc331e22SVijay    # Delete the session.
605bc331e22SVijay    Redfish.Logout
606bc331e22SVijay
607bc331e22SVijay
608bc331e22SVijayCreate New Session
609bc331e22SVijay    [Documentation]  Create new session.
610bc331e22SVijay
611355daac7SVijay    # Delete current session.
612bc331e22SVijay    Redfish.Logout
613bc331e22SVijay
614bc331e22SVijay    # Get a redfish session to BMC.
615bc331e22SVijay    Redfish.Login
616355daac7SVijay    ${session_id}  ${session_key}=  Return Session Id And Session Key
617355daac7SVijay    Set Test Variable  ${SESSION_ID}  ${session_id}
618355daac7SVijay    Set Test Variable  ${SESSION_KEY}  ${session_key}
619bc331e22SVijay
620bc331e22SVijay
621bc331e22SVijayTest Teardown Execution
622bc331e22SVijay    [Documentation]  Test teardown execution.
623bc331e22SVijay
624bc331e22SVijay    FFDC On Test Case Fail
625bc331e22SVijay    Redfish.Logout
626bc331e22SVijay
627355daac7SVijay
628355daac7SVijayReturn Session Id And Session Key
629355daac7SVijay    [Documentation]  Return session id and sesion key.
630355daac7SVijay
631355daac7SVijay    ${session_location}=  Redfish.Get Session Location
632355daac7SVijay    ${session_id}=  Evaluate  os.path.basename($session_location)  modules=os
633355daac7SVijay    ${session_key}=  Redfish.Get Session Key
634355daac7SVijay
635355daac7SVijay    [Return]  ${session_id}  ${session_key}
636355daac7SVijay
637355daac7SVijay
638355daac7SVijayTest Setup Execution
639355daac7SVijay    [Documentation]  Test setup execution.
640355daac7SVijay
641355daac7SVijay    Create New Session
642355daac7SVijay
643355daac7SVijay    Set Test Variable Dictionary Of Previous Lock Request  ${EMPTY}  ${EMPTY_LIST}  ${EMPTY}  ${EMPTY}
644355daac7SVijay    ...  ${EMPTY}  ${EMPTY}
645355daac7SVijay
646355daac7SVijay
647355daac7SVijaySet Test Variable Dictionary Of Previous Lock Request
648355daac7SVijay    [Documentation]  Set test variable dictionary of previous lock request.
649355daac7SVijay    [Arguments]  ${lock_type}  ${seg_flags}  ${resource_id}  ${hmc_id}  ${session_id}  ${transaction_id}
650355daac7SVijay
651355daac7SVijay    # Description of argument(s):
652355daac7SVijay    # lock_type            Type of lock (Read/Write).
653355daac7SVijay    # seg_flags            Segmentation Flags to identify lock elements under system level in the hierarchy.
654355daac7SVijay    #                      Ex:  [{'LockFlag': 'LockAll', 'SegmentLength': 1},
655355daac7SVijay    #                           {'LockFlag': 'LockSame', 'SegmentLength': 2}]
656355daac7SVijay    # resource_id          Decimal +ve integer value of maximum 8 hex bytes.  Ex: 134, 2048 etc.
657355daac7SVijay    # hmc_id               Hardware management console id.
658355daac7SVijay    # session_id           Session id of the transaction.
659355daac7SVijay    # transaction_id       Transaction_id of the lock request.
660355daac7SVijay
661355daac7SVijay    ${prev_inputs}=  Create Dictionary  LockType=${lock_type}  ResourceID=${resource_id}
662355daac7SVijay    ...  SegmentFlags=${seg_flags}  HMCID=${hmc_id}  SessionID=${session_id}  TransactionID=${transaction_id}
663355daac7SVijay
664355daac7SVijay    Set Test Variable  ${PREV_INPUTS}  ${prev_inputs}
665