Test related to release lock and conflicts
Signed-off-by: Vijay <vikantan@in.ibm.com>
Change-Id: I7d2142754855a7db4bb66537b97565fc119babd7
diff --git a/openpower/ext_interfaces/test_lock_management.robot b/openpower/ext_interfaces/test_lock_management.robot
index 1b62d09..cbef02f 100644
--- a/openpower/ext_interfaces/test_lock_management.robot
+++ b/openpower/ext_interfaces/test_lock_management.robot
@@ -224,6 +224,94 @@
Write ${TWO_SEG_FLAG_2} ${234}
+Verify Valid Lock Transactions Release
+ [Documentation] Verify valid lock transactions release.
+ [Tags] Verify_Valid_Lock_Transactions_Release
+
+ ${transaction_id1}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_2} ${234}
+ ${locks_before}= Get Locks List ${SESSION_ID}
+
+ ${transaction_id2}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_3} ${234}
+ ${transaction_id3}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_2} ${234}
+ ${transaction_id4}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_3} ${234}
+
+ ${transaction_ids}= Create List ${transaction_id2} ${transaction_id3} ${transaction_id4}
+ Release Locks ${transaction_ids}
+ ${locks_after}= Get Locks List ${SESSION_ID}
+ Should Be Equal ${locks_before} ${locks_after}
+
+
+Verify Invalid Lock Transactions Release
+ [Documentation] Verify invalid lock transactions release.
+ [Tags] Verify_Invalid_Lock_Transactions_Release
+
+ ${transaction_id1}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_2} ${234}
+ ${locks_before}= Get Locks List ${SESSION_ID}
+
+ ${transaction_id2}= Evaluate ${transaction_id1} + 1
+ ${transaction_id3}= Evaluate ${transaction_id1} - 1
+ ${transaction_ids}= Create List ${transaction_id2} ${transaction_id1} ${transaction_id3}
+
+ # If any transaction/s in the list does not belong to current session then it will be a bad request.
+ Release Locks ${transaction_ids} exp_status_code=${HTTP_BAD_REQUEST}
+ ${locks_after}= Get Locks List ${SESSION_ID}
+ Should Be Equal ${locks_before} ${locks_after}
+
+
+Verify Locks Release By Session
+ [Documentation] Verify locks release by session.
+ [Tags] Verify_Locks_Release_By_Session
+
+ ${locks_before}= Get Locks List ${SESSION_ID}
+ ${transaction_id1}= Acquire Lock On A Given Resource
+ ... Write ${TWO_SEG_FLAG_2} ${234}
+
+ # Release Lock by Session without mentioning transaction_ids.
+ Release Locks release_type=Session
+ ${locks_after}= Get Locks List ${SESSION_ID}
+ Should Be Equal ${locks_before} ${locks_after}
+
+ ${transaction_id1}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_2} ${234}
+ ${transaction_id2}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_3} ${234}
+ ${transaction_ids}= Create List ${transaction_id1} ${transaction_id2}
+
+ # Release Lock by Session by mentioning transaction_ids also in the request.
+ Release Locks ${transaction_ids} release_type=Session
+
+
+Verify Locks Created By One Session Cannot Be Deleted By Another Session
+ [Documentation] Verify locks created by one session cannot be deleted by another session.
+ [Tags] Verify_Locks_Created_By_One_Session_Cannot_Be_Deleted_By_Another_Session
+
+ ${transaction_id1}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_2} ${234}
+ ${locks_tran1}= Get Locks List ${SESSION_ID}
+
+ Redfish.Login
+ ${session_id} ${session_key}= Return Session Id And Session Key
+
+ ${transaction_id2}= Acquire Lock On A Given Resource
+ ... Read ${TWO_SEG_FLAG_3} ${234}
+ ${locks_before}= Get Locks List ${SESSION_ID}
+
+ ${transaction_ids}= Create List ${transaction_id1} ${transaction_id2}
+ Release Locks ${transaction_ids} exp_status_code=${HTTP_UNAUTHORIZED} conflict_record=${locks_tran1}
+ ${locks_after}= Get Locks List ${SESSION_ID}
+ Should Be Equal ${locks_before} ${locks_after}
+
+ # When release_type=Session, transaction_ids should be ignored.
+ Release Locks ${transaction_ids} release_type=Session
+ ${locks_after}= Get Locks List ${SESSION_ID}
+ Should Be Equal ${EMPTY_LIST} ${locks_after}
+
+
*** Keywords ***
Locks Persistency Check After BMC Reboot
@@ -245,7 +333,8 @@
${locks_curr}= Run Keyword Get Locks List ${SESSION_ID}
Should Be Equal ${locks_prev} ${locks_curr}
- Release Lock ${transaction_id}
+ ${transaction_ids}= Create List ${transaction_id}
+ Release Locks ${transaction_ids}
Return Data Dictionary For Single Request
@@ -378,20 +467,50 @@
[Return] ${locks["Records"]}
-Release Lock
- [Documentation] Release lock.
- [Arguments] @{transaction_ids} ${release_type}=Transaction ${exp_status_code}=${HTTP_OK}
+Release Locks
+ [Documentation] Release locks.
+ [Arguments] ${transaction_ids}=${EMPTY_LIST} ${release_type}=Transaction ${exp_status_code}=${HTTP_OK}
+ ... ${conflict_record}=${EMPTY_LIST}
# Description of argument(s):
- # transaction_ids List of transaction ids. Ex: [15, 18]
+ # transaction_ids List of transaction ids or session ids. Ex: [15, 18] or ["euHoAQpvNe", "ecTjANqwFr"]
# release_type Release all locks acquired using current session or only given transaction numbers.
# Ex: Session, Transaction. Default will be Transaction.
# exp_status_code expected status code from the ReleaseLock request for given inputs.
+ # conflict_record Expected conflict record.
+ # When release_type=Session then TransactionIDs list will be ignored.
${data}= Set Variable {"Type": "${release_type}", "TransactionIDs": ${transaction_ids}}
${data}= Evaluate json.dumps(${data}) json
- Redfish.Post /ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock
+ ${resp}= Redfish.Post /ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock
... body=${data} valid_status_codes=[${exp_status_code}]
+ Should Be True ${resp.status} ${exp_status_code}
+ Return From Keyword If ${conflict_record} == ${EMPTY_LIST}
+
+ ${conflict}= Evaluate json.loads('''${resp.text}''') json
+
+ # Example of conflict
+ # {
+ # "Record":{
+ # "HMCID":"hmc-id",
+ # "LockType":"Read",
+ # "ResourceID":234,
+ # "SegmentFlags":[
+ # {
+ # "LockFlag":"DontLock",
+ # "SegmentLength":3
+ # },
+ # {
+ # "LockFlag":"LockAll",
+ # "SegmentLength":1
+ # }
+ # ],
+ # "SessionID":"OorUVwrXuT",
+ # "TransactionID":47
+ # }
+ # }
+
+ Should Be Equal ${conflict_record[0]} ${conflict["Record"]}
Verify Lock Record
@@ -478,8 +597,8 @@
Verify Lock Record ${lock_found} &{inputs}
Return From Keyword If '${exp_status_code}' != '${HTTP_OK}' or ${err_msgs} == ['NA']
-
- Release Lock ${transaction_id}
+ ${transaction_ids}= Create List ${transaction_id}
+ Release Locks ${transaction_ids}
Verify Lock Record ${False} &{inputs}
# Delete the session.