New keywords added to handle LDAP `NoAccess` user
Changes:
- Added keyword to configure IP address using NoAccess user.
- Added keyword to delete IP address using NoAccess user.
Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
Change-Id: Ic8d5e2d0ded8f66cdfb00865d802c9c31edf6113
diff --git a/redfish/account_service/test_ldap_configuration.robot b/redfish/account_service/test_ldap_configuration.robot
index a83ecc5..94d7af4 100644
--- a/redfish/account_service/test_ldap_configuration.robot
+++ b/redfish/account_service/test_ldap_configuration.robot
@@ -772,7 +772,10 @@
${test_gateway}= Get BMC Default Gateway
- Add IP Address ${test_ip} ${test_mask} ${test_gateway} ${valid_status_code}
+ Run Keyword If '${group_privilege}' == 'NoAccess'
+ ... Add IP Address With NoAccess User ${test_ip} ${test_mask} ${test_gateway} ${valid_status_code}
+ ... ELSE
+ ... Add IP Address ${test_ip} ${test_mask} ${test_gateway} ${valid_status_code}
Update LDAP User Role And Delete IP Address
@@ -798,7 +801,10 @@
Redfish.Login ${LDAP_USER} ${LDAP_USER_PASSWORD}
- Delete IP Address ${test_ip} ${valid_status_code}
+ Run Keyword If '${group_privilege}' == 'NoAccess'
+ ... Delete IP Address With NoAccess User ${test_ip} ${valid_status_code}
+ ... ELSE
+ ... Delete IP Address ${test_ip} ${valid_status_code}
Update LDAP User Role And Read Network Configuration
@@ -820,3 +826,105 @@
Redfish.Login ${LDAP_USER} ${LDAP_USER_PASSWORD}
Redfish.Get ${REDFISH_NW_ETH0_URI} valid_status_codes=[${valid_status_code}]
+
+Add IP Address With NoAccess User
+ [Documentation] Add IP Address To BMC.
+ [Arguments] ${ip} ${subnet_mask} ${gateway}
+ ... ${valid_status_codes}=${HTTP_OK}
+
+ # Description of argument(s):
+ # ip IP address to be added (e.g. "10.7.7.7").
+ # subnet_mask Subnet mask for the IP to be added
+ # (e.g. "255.255.0.0").
+ # gateway Gateway for the IP to be added (e.g. "10.7.7.1").
+ # valid_status_codes Expected return code from patch operation
+ # (e.g. "200"). See prolog of rest_request
+ # method in redfish_plus.py for details.
+
+ # Logout from LDAP user.
+ Redfish.Logout
+
+ # Login with local user.
+ Redfish.Login
+
+ ${empty_dict}= Create Dictionary
+ ${ip_data}= Create Dictionary Address=${ip}
+ ... SubnetMask=${subnet_mask} Gateway=${gateway}
+
+ ${patch_list}= Create List
+ ${network_configurations}= Get Network Configuration
+ ${num_entries}= Get Length ${network_configurations}
+
+ FOR ${INDEX} IN RANGE 0 ${num_entries}
+ Append To List ${patch_list} ${empty_dict}
+ END
+
+ ${valid_status_codes}= Run Keyword If '${valid_status_codes}' == '${HTTP_OK}'
+ ... Set Variable ${HTTP_OK},${HTTP_NO_CONTENT}
+ ... ELSE Set Variable ${valid_status_codes}
+
+ # We need not check for existence of IP on BMC while adding.
+ Append To List ${patch_list} ${ip_data}
+ ${data}= Create Dictionary IPv4StaticAddresses=${patch_list}
+
+ ${active_channel_config}= Get Active Channel Config
+ ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+
+ # Logout from local user.
+ Redfish.Logout
+
+ # Login from LDAP user and check if we can configure IP address.
+ Redfish.Login ${LDAP_USER} ${LDAP_USER_PASSWORD}
+
+ Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
+ ... valid_status_codes=[${valid_status_codes}]
+
+
+Delete IP Address With NoAccess User
+ [Documentation] Delete IP Address Of BMC.
+ [Arguments] ${ip} ${valid_status_codes}=${HTTP_OK}
+
+ # Description of argument(s):
+ # ip IP address to be deleted (e.g. "10.7.7.7").
+ # valid_status_codes Expected return code from patch operation
+ # (e.g. "200"). See prolog of rest_request
+ # method in redfish_plus.py for details.
+
+ # Logout from LDAP user.
+ Redfish.Logout
+
+ # Login with local user.
+ Redfish.Login
+
+ ${empty_dict}= Create Dictionary
+ ${patch_list}= Create List
+
+ @{network_configurations}= Get Network Configuration
+ FOR ${network_configuration} IN @{network_configurations}
+ Run Keyword If '${network_configuration['Address']}' == '${ip}'
+ ... Append To List ${patch_list} ${null}
+ ... ELSE Append To List ${patch_list} ${empty_dict}
+ END
+
+ ${ip_found}= Run Keyword And Return Status List Should Contain Value
+ ... ${patch_list} ${null} msg=${ip} does not exist on BMC
+ Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC
+
+ # Run patch command only if given IP is found on BMC
+ ${data}= Create Dictionary IPv4StaticAddresses=${patch_list}
+
+ ${active_channel_config}= Get Active Channel Config
+ ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+
+ # Logout from local user.
+ Redfish.Logout
+
+ # Login from LDAP user and check if we can delete IP address.
+ Redfish.Login ${LDAP_USER} ${LDAP_USER_PASSWORD}
+
+ Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
+ ... valid_status_codes=[${valid_status_codes}]
+
+ # Note: Network restart takes around 15-18s after patch request processing
+ Sleep ${NETWORK_TIMEOUT}s
+ Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}