Add redfishtool utility library file and related changes

Change-Id: Ida402a7c8d188603f085f5a3740bdb3e0efea3a4
Signed-off-by: manashsarma <manashsarma@in.ibm.com>
diff --git a/lib/dmtf_redfishtool_utils.robot b/lib/dmtf_redfishtool_utils.robot
new file mode 100644
index 0000000..936e3d1
--- /dev/null
+++ b/lib/dmtf_redfishtool_utils.robot
@@ -0,0 +1,105 @@
+*** Settings ***
+
+
+Documentation   Utilities for Redfishtool testing.
+
+Resource        resource.robot
+Resource        bmc_redfish_resource.robot
+Library         OperatingSystem
+Library         String
+Library         Collections
+
+
+*** Keywords ***
+
+Redfishtool Get
+    [Documentation]  Execute redfishtool for GET operation.
+    [Arguments]  ${uri}  ${cmd_args}=${root_cmd_args}  ${expected_error}=200
+
+    # 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
+    ...    Should Be True  ${expected_error} == 200
+    ...  ELSE
+    ...    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}=200
+
+    # 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
+    ...    Should Be True  ${expected_error} == 200
+    ...  ELSE
+    ...    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}=200
+
+    # 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
+    ...    Should Be True  ${expected_error} == 200
+    ...  ELSE
+    ...    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}=200
+
+    # 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
+    ...    Should Be True  ${expected_error} == 200
+    ...  ELSE
+    ...    Is HTTP error Expected  ${cmd_output}  ${expected_error}
+
+    [Return]  ${cmd_output}
+
+
+Is HTTP error Expected
+    [Documentation]  Check if the HTTP error is expected.
+    [Arguments]  ${cmd_output}  ${error_expected}
+
+    # Description of argument(s):
+    # cmd_output      Output of an HTTP operation.
+    # error_expected  Expected error.
+
+    Should Be True  ${error_expected} != 200
+    @{words} =  Split String  ${error_expected}  ,
+    @{errorString}=  Split String  ${cmd_output}  ${SPACE}
+    Should Contain Any  ${errorString}  @{words}
diff --git a/redfish/dmtf_tools/test_redfishtool_certificate.robot b/redfish/dmtf_tools/test_redfishtool_certificate.robot
index e1c4dc1..5ec8437 100644
--- a/redfish/dmtf_tools/test_redfishtool_certificate.robot
+++ b/redfish/dmtf_tools/test_redfishtool_certificate.robot
@@ -11,7 +11,7 @@
 Resource          ../../lib/bmc_redfish_resource.robot
 Resource          ../../lib/openbmc_ffdc.robot
 Resource          ../../lib/certificate_utils.robot
-
+Resource          ../../lib/dmtf_redfishtool_utils.robot
 
 Suite Setup       Suite Setup Execution
 
@@ -101,19 +101,6 @@
 *** Keywords ***
 
 
-Is HTTP error Expected
-    [Documentation]  Check if the HTTP error is expected.
-    [Arguments]  ${cmd_output}  ${error_expected}
-
-    # Description of argument(s):
-    # cmd_output      Output of an HTTP operation.
-    # error_expected  Expected error.
-
-    @{words} =  Split String  ${error_expected}  ,
-    @{errorString}=  Split String  ${cmd_output}  ${SPACE}
-    Should Contain Any  ${errorString}  @{words}
-
-
 Verify Redfishtool Install Certificate
     [Documentation]  Install and verify certificate using Redfishtool.
     [Arguments]  ${cert_type}  ${cert_format}  ${expected_status}  ${delete_cert}=${True}
@@ -162,7 +149,7 @@
     ${json_object}=  To JSON  ${cmd_output}
     ${cert_list}=  Set Variable  ${json_object["Members"]}
     FOR  ${cert}  IN  @{cert_list}
-      Redfishtool Delete  ${cert["@odata.id"]}  ${root_cmd_args}  ${HTTP_NO_CONTENT}
+      Redfishtool Delete  ${cert["@odata.id"]}  ${root_cmd_args}
     END
 
 
@@ -270,22 +257,6 @@
     ...    Should Not Contain  ${cert_file_content}  ${bmc_cert_content}
 
 
-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 GetAttribute
     [Documentation]  Execute redfishtool for GET operation.
     [Arguments]  ${uri}  ${Attribute}  ${cmd_args}=${root_cmd_args}  ${expected_error}=""
@@ -304,40 +275,6 @@
     [Return]  ${json_object["CertificateString"]}
 
 
-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 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.
 
diff --git a/redfish/dmtf_tools/test_redfishtool_general.robot b/redfish/dmtf_tools/test_redfishtool_general.robot
index eced05f..0286cd8 100644
--- a/redfish/dmtf_tools/test_redfishtool_general.robot
+++ b/redfish/dmtf_tools/test_redfishtool_general.robot
@@ -10,6 +10,7 @@
 Resource          ../../lib/resource.robot
 Resource          ../../lib/bmc_redfish_resource.robot
 Resource          ../../lib/openbmc_ffdc.robot
+Resource          ../../lib/dmtf_redfishtool_utils.robot
 
 
 Suite Setup       Suite Setup Execution
@@ -49,35 +50,6 @@
 *** Keywords ***
 
 
-Is HTTP error Expected
-    [Documentation]  Check if the HTTP error is expected.
-    [Arguments]  ${cmd_output}  ${error_expected}
-
-    # Description of argument(s):
-    # cmd_output      Output of an HTTP operation.
-    # error_expected  Expected error.
-
-    @{words} =  Split String  ${error_expected}  ,
-    @{errorString}=  Split String  ${cmd_output}  ${SPACE}
-    Should Contain Any  ${errorString}  @{words}
-
-
-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}
-
-
 Suite Setup Execution
     [Documentation]  Do suite setup execution.
 
diff --git a/redfish/dmtf_tools/test_redfishtool_local_user.robot b/redfish/dmtf_tools/test_redfishtool_local_user.robot
index 2785263..ebd11e9 100644
--- a/redfish/dmtf_tools/test_redfishtool_local_user.robot
+++ b/redfish/dmtf_tools/test_redfishtool_local_user.robot
@@ -11,7 +11,7 @@
 Resource          ../../lib/bmc_redfish_resource.robot
 Resource          ../../lib/openbmc_ffdc.robot
 Resource          ../../lib/certificate_utils.robot
-
+Resource          ../../lib/dmtf_redfishtool_utils.robot
 
 Suite Setup       Suite Setup Execution
 
@@ -103,7 +103,7 @@
 
 Redfishtool Access Resource
     [Documentation]  Access resource.
-    [Arguments]  ${uri}   ${login_user}  ${login_pasword}  ${expected_error}=""
+    [Arguments]  ${uri}   ${login_user}  ${login_pasword}  ${expected_error}=200
 
     # Description of argument(s):
     # uri            URI for resource access.
@@ -117,23 +117,10 @@
     Redfishtool Get  ${uri}  ${user_cmd_args}  ${expected_error}
 
 
-Is HTTP error Expected
-    [Documentation]  Check if the HTTP error is expected.
-    [Arguments]  ${cmd_output}  ${error_expected}
-
-    # Description of argument(s):
-    # cmd_output      Output of an HTTP operation.
-    # error_expected  Expected error.
-
-    @{words} =  Split String  ${error_expected}  ,
-    @{errorString}=  Split String  ${cmd_output}  ${SPACE}
-    Should Contain Any  ${errorString}  @{words}
-
-
 Redfishtool Create User
     [Documentation]  Create new user.
     [Arguments]  ${user_name}  ${password}  ${roleID}  ${enable}  ${login_user}=""  ${login_pasword}=""
-    ...  ${expected_error}=""
+    ...  ${expected_error}=200
 
     # Description of argument(s):
     # user_name      The user name (e.g. "test", "robert", etc.).
@@ -156,7 +143,7 @@
 Redfishtool Update User Role
     [Documentation]  Update user role.
     [Arguments]  ${user_name}  ${newRole}  ${login_user}=""  ${login_pasword}=""
-    ...  ${expected_error}=""
+    ...  ${expected_error}=200
 
     # Description of argument(s):
     # user_name      The user name (e.g. "test", "robert", etc.).
@@ -178,7 +165,7 @@
 
 Redfishtool Delete User
     [Documentation]  Delete an user.
-    [Arguments]  ${user_name}  ${expected_error}=""
+    [Arguments]  ${user_name}  ${expected_error}=200
 
     # Description of argument(s):
     # user_name       The user name (e.g. "test", "robert", etc.).
@@ -215,73 +202,6 @@
     [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.