manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | |
| 3 | |
| 4 | Documentation Utilities for Redfishtool testing. |
| 5 | |
| 6 | Resource resource.robot |
| 7 | Resource bmc_redfish_resource.robot |
| 8 | Library OperatingSystem |
| 9 | Library String |
| 10 | Library Collections |
| 11 | |
| 12 | |
| 13 | *** Keywords *** |
| 14 | |
| 15 | Redfishtool Get |
| 16 | [Documentation] Execute redfishtool for GET operation. |
| 17 | [Arguments] ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}=200 |
| 18 | |
| 19 | # Description of argument(s): |
| 20 | # uri URI for GET operation (e.g. /redfish/v1/AccountService/Accounts/). |
| 21 | # cmd_args Commandline arguments. |
| 22 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 23 | # authentication error, etc. ). |
| 24 | |
ganesanb | 85c2265 | 2023-04-22 16:08:30 +0000 | [diff] [blame] | 25 | ${cmd}= Catenate ${cmd_args} GET ${uri} |
| 26 | Log ${cmd} |
| 27 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd} |
| 28 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 29 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 30 | RETURN ${cmd_output} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 31 | |
| 32 | |
| 33 | Redfishtool Patch |
| 34 | [Documentation] Execute redfishtool for Patch operation. |
| 35 | [Arguments] ${payload} ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}=200 |
| 36 | |
| 37 | # Description of argument(s): |
| 38 | # payload Payload with POST operation (e.g. data for user name, role, etc. ). |
| 39 | # uri URI for PATCH operation (e.g. /redfish/v1/AccountService/Accounts/ ). |
| 40 | # cmd_args Commandline arguments. |
| 41 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 42 | # authentication error, etc. ). |
| 43 | |
ganesanb | 85c2265 | 2023-04-22 16:08:30 +0000 | [diff] [blame] | 44 | ${cmd}= Catenate ${cmd_args} PATCH ${uri} --data=${payload} |
| 45 | Log ${cmd} |
| 46 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd} |
| 47 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 48 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 49 | RETURN ${cmd_output} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 50 | |
| 51 | |
| 52 | Redfishtool Post |
| 53 | [Documentation] Execute redfishtool for Post operation. |
| 54 | [Arguments] ${payload} ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}=200 |
| 55 | |
| 56 | # Description of argument(s): |
| 57 | # payload Payload with POST operation (e.g. data for user name, password, role, |
| 58 | # enabled attribute) |
| 59 | # uri URI for POST operation (e.g. /redfish/v1/AccountService/Accounts/). |
| 60 | # cmd_args Commandline arguments. |
| 61 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 62 | # authentication error, etc. ). |
George Keishing | e01ee58 | 2023-05-16 10:17:08 +0530 | [diff] [blame] | 63 | |
ganesanb | 85c2265 | 2023-04-22 16:08:30 +0000 | [diff] [blame] | 64 | ${cmd}= Catenate ${cmd_args} POST ${uri} --data=${payload} |
| 65 | Log ${cmd} |
| 66 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd} |
| 67 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 68 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 69 | RETURN ${cmd_output} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 70 | |
| 71 | |
| 72 | Redfishtool Delete |
| 73 | [Documentation] Execute redfishtool for Post operation. |
| 74 | [Arguments] ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}=200 |
| 75 | |
| 76 | # Description of argument(s): |
| 77 | # uri URI for DELETE operation. |
| 78 | # cmd_args Commandline arguments. |
| 79 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 80 | # authentication error, etc. ). |
| 81 | |
ganesanb | 85c2265 | 2023-04-22 16:08:30 +0000 | [diff] [blame] | 82 | ${cmd}= Catenate ${cmd_args} DELETE ${uri} |
| 83 | Log ${cmd} |
| 84 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd} |
| 85 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 86 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 87 | RETURN ${cmd_output} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 88 | |
| 89 | |
| 90 | Is HTTP error Expected |
| 91 | [Documentation] Check if the HTTP error is expected. |
| 92 | [Arguments] ${cmd_output} ${error_expected} |
| 93 | |
| 94 | # Description of argument(s): |
| 95 | # cmd_output Output of an HTTP operation. |
| 96 | # error_expected Expected error. |
| 97 | |
ganesanb | 85c2265 | 2023-04-22 16:08:30 +0000 | [diff] [blame] | 98 | ${cmd_rsp}= Get Regexp Matches ${cmd_output} 200|204 |
| 99 | ${cmd_rsp_status}= Run Keyword And Return Status Should Not Be Empty ${cmd_rsp} |
| 100 | Return From Keyword IF ${cmd_rsp_status} == True |
| 101 | ${matches}= Get Regexp Matches ${error_expected} 200|204 |
| 102 | ${rsp_status}= Run Keyword And Return Status Should Be Empty ${matches} |
| 103 | Run Keyword If ${rsp_status} == False |
| 104 | ... Fail msg=${cmd_output} |
manashsarma | 579d825 | 2020-05-28 08:10:51 -0500 | [diff] [blame] | 105 | @{words} = Split String ${error_expected} , |
| 106 | @{errorString}= Split String ${cmd_output} ${SPACE} |
ganesanb | 85c2265 | 2023-04-22 16:08:30 +0000 | [diff] [blame] | 107 | FOR ${error} IN @{words} |
| 108 | ${status}= Run Keyword And Return Status Should Contain Any ${errorString} ${error} |
| 109 | Return From Keyword If ${status} == True |
| 110 | END |
| 111 | ${rsp_code}= Run Keyword If ${status} == False Get Regexp Matches ${cmd_output} [0-9][0-9][0-9] |
| 112 | ${rsp_code_status}= Run Keyword And Return Status Should Not Be Empty ${rsp_code} |
| 113 | Run Keyword If ${rsp_code_status} == True |
| 114 | ... Fail msg=Getting status code as ${rsp_code[0]} instead of ${error_expected}, status code mismatch. |
| 115 | ... ELSE |
| 116 | ... Fail msg=${cmd_output} |
| 117 | |