blob: 089bab3e62797f00496e9329bf0dc90809114ac0 [file] [log] [blame]
manashsarma579d8252020-05-28 08:10:51 -05001*** Settings ***
2
3
4Documentation Utilities for Redfishtool testing.
5
6Resource resource.robot
7Resource bmc_redfish_resource.robot
8Library OperatingSystem
9Library String
10Library Collections
11
12
13*** Keywords ***
14
15Redfishtool 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
ganesanb85c22652023-04-22 16:08:30 +000025 ${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}
manashsarma579d8252020-05-28 08:10:51 -050029
30 [Return] ${cmd_output}
31
32
33Redfishtool 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
ganesanb85c22652023-04-22 16:08:30 +000044 ${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}
manashsarma579d8252020-05-28 08:10:51 -050048
49 [Return] ${cmd_output}
50
51
52Redfishtool 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 Keishinge01ee582023-05-16 10:17:08 +053063
ganesanb85c22652023-04-22 16:08:30 +000064 ${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}
manashsarma579d8252020-05-28 08:10:51 -050068
69 [Return] ${cmd_output}
70
71
72Redfishtool 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
ganesanb85c22652023-04-22 16:08:30 +000082 ${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}
manashsarma579d8252020-05-28 08:10:51 -050086
87 [Return] ${cmd_output}
88
89
90Is 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
ganesanb85c22652023-04-22 16:08:30 +000098 ${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}
manashsarma579d8252020-05-28 08:10:51 -0500105 @{words} = Split String ${error_expected} ,
106 @{errorString}= Split String ${cmd_output} ${SPACE}
ganesanb85c22652023-04-22 16:08:30 +0000107 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