Update LDAP code to handle privilege, Authentication and connection logic

Change includes:
1. Restoring old privilege when there is no privilege before running suite
2. System losing connection due to Add IP and Delete IP functions
3. Authentication issue after executing login without password

Change-Id: I4eaba180b65204937059965abcf29c3d471e5a52
Signed-off-by: Anves Kumar rayankula <anvesr77@in.ibm.com>
diff --git a/redfish/account_service/test_ldap_configuration.robot b/redfish/account_service/test_ldap_configuration.robot
index 67ce11c..141d734 100644
--- a/redfish/account_service/test_ldap_configuration.robot
+++ b/redfish/account_service/test_ldap_configuration.robot
@@ -21,7 +21,6 @@
 ${hostname}             ${EMPTY}
 ${test_ip}              10.6.6.6
 ${test_mask}            255.255.255.0
-${test_gw}              10.6.6.1
 
 ** Test Cases **
 
@@ -338,6 +337,7 @@
     [Documentation]  Verify that LDAP user authentication without LDAP
     ...  user password fails.
     [Tags]  Verify_LDAP_Authentication_Without_Password
+    [Teardown]  Run Keywords  Redfish.Logout  AND  Redfish.Login
 
     ${status}=  Run Keyword And Return Status  Redfish.Login  ${LDAP_USER}
     Valid Value  status  [${False}]
@@ -731,7 +731,7 @@
 Restore LDAP Privilege
     [Documentation]  Restore the LDAP privilege to its original value.
 
-    Return From Keyword If  '${old_ldap_privilege}' == '${EMPTY}'
+    Return From Keyword If  '${old_ldap_privilege}' == '${EMPTY}' or '${old_ldap_privilege}' == '[]'
     # Log back in to restore the original privilege.
     Update LDAP Configuration with LDAP User Role And Group  ${LDAP_TYPE}
     ...  ${old_ldap_privilege}  ${GROUP_NAME}
@@ -797,7 +797,9 @@
 
     Redfish.Login  ${LDAP_USER}  ${LDAP_USER_PASSWORD}
 
-    Add IP Address  ${test_ip}  ${test_mask}  ${test_gw}  ${valid_status_code}
+    ${test_gateway}=  Get BMC Default Gateway
+
+    Add IP Address  ${test_ip}  ${test_mask}  ${test_gateway}  ${valid_status_code}
 
 
 Update LDAP User Role And Delete IP Address
@@ -811,8 +813,10 @@
     # group_name         The group name of user.
     # valid_status_code  The expected valid status code.
 
+    ${test_gateway}=  Get BMC Default Gateway
+
     # Configure IP address before deleting via LDAP user roles.
-    Add IP Address  ${test_ip}  ${test_mask}  ${test_gw}
+    Add IP Address  ${test_ip}  ${test_mask}  ${test_gateway}
 
     Update LDAP Configuration with LDAP User Role And Group  ${ldap_type}
     ...  ${group_privilege}  ${group_name}
@@ -842,3 +846,4 @@
 
     Redfish.Login  ${LDAP_USER}  ${LDAP_USER_PASSWORD}
     Redfish.Get  ${REDFISH_NW_ETH0_URI}  valid_status_codes=[${valid_status_code}]
+