Add user test cases for user creation,updation and deletion

Signed-off-by: manashsarma <manashsarma@in.ibm.com>
Change-Id: Ie377ce854fc2fcb406bbcb5f86abf55f3d1c7e04
Signed-off-by: manashsarma <manashsarma@in.ibm.com>
diff --git a/redfish/dmtf_tools/test_redfishtool.robot b/redfish/dmtf_tools/test_redfishtool.robot
index 01354ac..ff05c18 100644
--- a/redfish/dmtf_tools/test_redfishtool.robot
+++ b/redfish/dmtf_tools/test_redfishtool.robot
@@ -1,35 +1,29 @@
 *** Settings ***
+
+
 Documentation    Verify Redfish tool functionality.
 
-# The following tests are performed:
-#
-# sensors list
-# health check
-#
-# directory PATH in $PATH.
-#
-# Test Parameters:
-# OPENBMC_HOST          The BMC host name or IP address.
-# OPENBMC_USERNAME      The username to login to the BMC.
-# OPENBMC_PASSWORD      Password for OPENBMC_USERNAME.
-#
-# We use DMTF redfishtool for writing openbmc automation test cases.
-# DMTF redfishtool is a commandline tool that implements the client
-# side of the Redfish RESTful API for Data Center Hardware Management.
+Library           OperatingSystem
+Library           String
+Library           Collections
 
-Library                 String
-Library                 OperatingSystem
+Resource          ../../lib/resource.robot
+Resource          ../../lib/bmc_redfish_resource.robot
+Resource          ../../lib/openbmc_ffdc.robot
 
-Suite Setup             Suite Setup Execution
+
+Suite Setup       Suite Setup Execution
+
 
 *** Variables ***
 
-${root_cmd_args}        redfishtool raw -r ${OPENBMC_HOST} -u ${OPENBMC_USERNAME} -p ${OPENBMC_PASSWORD} -S Always
-${HTTTP_ERROR}          Error
-${min_number_sensors}   ${15}
+
+${root_cmd_args}       redfishtool raw -r ${OPENBMC_HOST} -u ${OPENBMC_USERNAME} -p ${OPENBMC_PASSWORD} -S Always
+${min_number_sensors}  ${15}
 
 *** Test Cases ***
 
+
 Verify Redfishtool Sensor Commands
     [Documentation]  Verify redfishtool's sensor commands.
     [Tags]  Verify_Redfishtool_Sensor_Commands
@@ -39,6 +33,7 @@
     Should Be True  ${json_object["Members@odata.count"]} > ${min_number_sensors}
     ...  msg=There should be at least ${min_number_sensors} sensors.
 
+
 Verify Redfishtool Health Check Commands
     [Documentation]  Verify redfishtool's health check command.
     [Tags]  Verify_Redfishtool_Health_Check_Commands
@@ -49,19 +44,184 @@
     Should Be Equal  OK  ${status["Health"]}
     ...  msg=Health status should be OK.
 
+
+Verify Redfishtool Create Users
+    [Documentation]  Create user via Redfishtool and verify.
+    [Tags]  Verify_Redfishtool_Create_Users
+    [Teardown]  Redfishtool Delete User  "UserT100"
+
+    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
+    Redfishtool Verify User  "UserT100"  "Operator"
+
+
+Verify Redfishtool Modify Users
+    [Documentation]  Modify user via Redfishtool and verify.
+    [Tags]  Verify_Redfishtool_Modify_Users
+    [Teardown]  Redfishtool Delete User  "UserT100"
+
+    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
+    Redfishtool Update User Role  "UserT100"  "Administrator"
+    Redfishtool Verify User  "UserT100"  "Administrator"
+
+
+Verify Redfishtool Delete Users
+    [Documentation]  Delete user via Redfishtool and verify.
+    [Tags]  Verify_Redfishtool_Delete_Users
+
+    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
+    Redfishtool Delete User  "UserT100"
+    ${status}=  Redfishtool Verify User Name Exists  "UserT100"
+    Should Be True  ${status} == False
+
+
 *** Keywords ***
 
-Redfishtool Get
-    [Documentation]  Return the output of redfishtool for GET operation.
-    [Arguments]  ${uri}  ${cmd_args}=${root_cmd_args}
+
+Is HTTP error Expected
+    [Documentation]  Check if the HTTP error is expected.
+    [Arguments]  ${cmd_output}  ${error_expected}
 
     # Description of argument(s):
-    # uri  URI for GET operation.
-    # cmd_args redfishtool command arguments.
+    # cmd_output      Output of an HTTP operation.
+    # error_expected  Expected error.
 
-    ${cmd_output}=  Run  ${cmd_args} GET ${uri}
+    ${error_expected}=  Evaluate  "${error_expected}" in """${cmd_output}"""
+    Should Be True  ${error_expected} == True
+
+
+Redfishtool Create User
+    [Documentation]  Create new user.
+    [Arguments]  ${user_name}  ${password}  ${roleID}  ${enable}  ${expected_error}=""
+
+    # Description of argument(s):
+    # user_name      The user name (e.g. "test", "robert", etc.).
+    # password       The user password (e.g. "0penBmc", "0penBmc1", etc.).
+    # roleID         The role of user (e.g. "Administrator", "Operator", etc.).
+    # enable         Enabled attribute of (e.g. true or false).
+    # expected_error Expected error optionally provided in testcase (e.g. 401 /
+    #                authentication error, etc. )
+
+    ${data}=  Set Variable  '{"UserName":${user_name},"Password":${password},"RoleId":${roleId},"Enabled":${enable}}'
+    Redfishtool Post  ${data}  /redfish/v1/AccountService/Accounts  ${root_cmd_args}
+    ...  ${expected_error}
+
+Redfishtool Update User Role
+    [Documentation]  Update user role.
+    [Arguments]  ${user_name}  ${newRole}  ${login_user}=""  ${login_pasword}=""
+    ...  ${expected_error}=""
+
+    # Description of argument(s):
+    # user_name      The user name (e.g. "test", "robert", etc.).
+    # newRole        The new role of user (e.g. "Administrator", "Operator", etc.).
+    # login_user     The login user name used other than default root user.
+    # login_pasword  The login password.
+    # expected_error Expected error optionally provided in testcase (e.g. 401 /
+    #                authentication error, etc. )
+
+    Redfishtool Patch  '{"RoleId":${newRole}}'  /redfish/v1/AccountService/Accounts/${user_name}
+    ...  ${root_cmd_args}  ${expected_error}
+
+Redfishtool Delete User
+    [Documentation]  Delete an user.
+    [Arguments]  ${user_name}  ${expected_error}=""
+
+    # Description of argument(s):
+    # user_name       The user name (e.g. "test", "robert", etc.).
+    # expected_error  Expected error optionally provided in testcase (e.g. 401 /
+    #                 authentication error, etc. ).
+
+    Redfishtool Delete  /redfish/v1/AccountService/Accounts/${user_name}
+    ...  ${root_cmd_args}  ${expected_error}
+
+
+Redfishtool Verify User
+    [Documentation]  Verify role of the user.
+    [Arguments]  ${user_name}  ${role}
+
+    # Description of argument(s):
+    # user_name  The user name (e.g. "test", "robert", etc.).
+    # role       The new role of user (e.g. "Administrator", "Operator", etc.).
+
+    ${user_account}=  Redfishtool Get  /redfish/v1/AccountService/Accounts/${user_name}
+    ${json_obj}=   Evaluate  json.loads('''${user_account}''')  json
+    Should Be equal  "${json_obj["RoleId"]}"  ${role}
+
+
+Redfishtool Verify User Name Exists
+    [Documentation]  Verify user name exists.
+    [Arguments]  ${user_name}
+
+    # Description of argument(s):
+    # user_name  The user name (e.g. "test", "robert", etc.).
+
+    ${status}=  Run Keyword And Return Status  redfishtool Get
+    ...  /redfish/v1/AccountService/Accounts/${user_name}
+    [return]  ${status}
+
+
+Redfishtool Get
+    [Documentation]  Execute redfishtool for GET operation.
+    [Arguments]  ${uri}  ${cmd_args}=${root_cmd_args}  ${expected_error}=""
+
+    # Description of argument(s):
+    # uri             URI for GET operation (e.g. /redfish/v1/AccountService/Accounts/).
+    # cmd_args        Commandline arguments.
+    # expected_error  Expected error optionally provided in testcase (e.g. 401 /
+    #                 authentication error, etc. ).
+
+    ${rc}  ${cmd_output}=  Run and Return RC and Output  ${cmd_args} GET ${uri}
+    Run Keyword If  ${rc} != 0  Is HTTP error Expected  ${cmd_output}  ${expected_error}
     [Return]  ${cmd_output}
 
+
+Redfishtool Post
+    [Documentation]  Execute redfishtool for  Post operation.
+    [Arguments]  ${payload}  ${uri}  ${cmd_args}=${root_cmd_args}  ${expected_error}=""
+
+    # Description of argument(s):
+    # payload         Payload with POST operation (e.g. data for user name, password, role,
+    #                 enabled attribute)
+    # uri             URI for POST operation (e.g. /redfish/v1/AccountService/Accounts/).
+    # cmd_args        Commandline arguments.
+    # expected_error  Expected error optionally provided in testcase (e.g. 401 /
+    #                 authentication error, etc. ).
+
+    ${rc}  ${cmd_output}=  Run and Return RC and Output  ${cmd_args} POST ${uri} --data=${payload}
+    Run Keyword If  ${rc} != 0  Is HTTP error Expected  ${cmd_output}  ${expected_error}
+    [Return]  ${cmd_output}
+
+
+Redfishtool Patch
+    [Documentation]  Execute redfishtool for  Patch operation.
+    [Arguments]  ${payload}  ${uri}  ${cmd_args}=${root_cmd_args}  ${expected_error}=""
+
+    # Description of argument(s):
+    # payload         Payload with POST operation (e.g. data for user name, role, etc. ).
+    # uri             URI for PATCH operation (e.g. /redfish/v1/AccountService/Accounts/ ).
+    # cmd_args        Commandline arguments.
+    # expected_error  Expected error optionally provided in testcase (e.g. 401 /
+    #                 authentication error, etc. ).
+
+    ${rc}  ${cmd_output}=  Run and Return RC and Output  ${cmd_args} PATCH ${uri} --data=${payload}
+    Run Keyword If  ${rc} != 0  Is HTTP error Expected  ${cmd_output}  ${expected_error}
+    [Return]  ${cmd_output}
+
+
+Redfishtool Delete
+    [Documentation]  Execute redfishtool for  Post operation.
+    [Arguments]  ${uri}  ${cmd_args}=${root_cmd_args}  ${expected_error}=""
+
+    # Description of argument(s):
+    # uri             URI for DELETE operation.
+    # cmd_args        Commandline arguments.
+    # expected_error  Expected error optionally provided in testcase (e.g. 401 /
+    #                 authentication error, etc. ).
+
+    ${rc}  ${cmd_output}=  Run and Return RC and Output  ${cmd_args} DELETE ${uri}
+    Run Keyword If  ${rc} != 0  Is HTTP error Expected  ${cmd_output}  ${expected_error}
+    [Return]  ${cmd_output}
+
+
 Suite Setup Execution
     [Documentation]  Do suite setup execution.