blob: 593657400cb379ac9a1ce5c01e9b9680a0801d17 [file] [log] [blame]
Sridevi Ramesh0047de82019-02-01 06:33:08 -06001*** Settings ***
George Keishingb10eaca2019-02-24 05:07:30 -06002Documentation BMC and host redfish utility keywords.
Sridevi Ramesh0047de82019-02-01 06:33:08 -06003
George Keishing2db7bca2019-02-14 13:03:08 -06004Resource resource.robot
Sridevi Ramesh0047de82019-02-01 06:33:08 -06005Resource bmc_redfish_resource.robot
6
7
8*** Keywords ***
9
10Redfish Power Operation
George Keishingb10eaca2019-02-24 05:07:30 -060011 [Documentation] Do Redfish host power operation.
Sridevi Ramesh0047de82019-02-01 06:33:08 -060012 [Arguments] ${reset_type}
13 # Description of arguments:
14 # reset_type Type of power operation.
15 # (e.g. On/ForceOff/GracefulRestart/GracefulShutdown)
16
17 # Example:
18 # "Actions": {
19 # "#ComputerSystem.Reset": {
20 # "ResetType@Redfish.AllowableValues": [
21 # "On",
22 # "ForceOff",
George Keishingeeb526c2020-03-03 07:39:44 -060023 # "ForceOn",
24 # "ForceRestart",
Sridevi Ramesh0047de82019-02-01 06:33:08 -060025 # "GracefulRestart",
26 # "GracefulShutdown"
George Keishingeeb526c2020-03-03 07:39:44 -060027 # "PowerCycle",
28 # "Nmi"
Sridevi Ramesh0047de82019-02-01 06:33:08 -060029 # ],
George Keishing2deec3c2019-02-26 09:20:10 -060030 # "target": "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"
31 # }
32 # }
Sridevi Ramesh0047de82019-02-01 06:33:08 -060033
George Keishingc2b176e2019-03-02 23:31:30 -060034 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/system/ ComputerSystem.Reset
Sridevi Ramesh0047de82019-02-01 06:33:08 -060035 ${payload}= Create Dictionary ResetType=${reset_type}
Michael Walsh213feb32019-03-08 14:44:31 -060036 ${resp}= Redfish.Post ${target} body=&{payload}
Sridevi Ramesh0047de82019-02-01 06:33:08 -060037
38
George Keishingb10eaca2019-02-24 05:07:30 -060039Redfish BMC Reset Operation
40 [Documentation] Do Redfish BMC reset operation.
Sridevi Ramesh0047de82019-02-01 06:33:08 -060041
George Keishingb10eaca2019-02-24 05:07:30 -060042 # Example:
43 # "Actions": {
44 # "#Manager.Reset": {
45 # "ResetType@Redfish.AllowableValues": [
46 # "GracefulRestart"
47 # ],
48 # "target": "/redfish/v1/Managers/bmc/Actions/Manager.Reset"
49 # }
50
George Keishingc2b176e2019-03-02 23:31:30 -060051 ${target}= redfish_utils.Get Target Actions /redfish/v1/Managers/bmc/ Manager.Reset
George Keishingb10eaca2019-02-24 05:07:30 -060052 ${payload}= Create Dictionary ResetType=GracefulRestart
George Keishing07fb41f2020-06-16 08:09:19 -050053 Redfish.Post ${target} body=&{payload}
George Keishingcaa718b2019-03-10 00:08:33 -060054
55
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -060056Reset BIOS Via Redfish
57 [Documentation] Do BIOS reset through Redfish.
58
59 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/system/Bios/ Bios.ResetBios
60 Redfish.Post ${target} valid_status_codes=[${HTTP_OK}]
61
62
George Keishingcaa718b2019-03-10 00:08:33 -060063Delete All Redfish Sessions
64 [Documentation] Delete all active redfish sessions.
65
66 Redfish.Login
67 ${saved_session_info}= Get Redfish Session Info
68
69 ${resp_list}= Redfish_Utils.Get Member List
70 ... /redfish/v1/SessionService/Sessions
71
72 # Remove the current login session from the list.
73 Remove Values From List ${resp_list} ${saved_session_info["location"]}
74
75 :FOR ${session} IN @{resp_list}
76 \ Redfish.Delete ${session}
77
78 Redfish.Logout
Michael Walshcf163322019-05-22 16:56:17 -050079
80
81Get Valid FRUs
82 [Documentation] Return a dictionary containing all of the valid FRU records for the given fru_type.
83 [Arguments] ${fru_type}
84
85 # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK".
86
87 # Description of argument(s):
88 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
89
90 ${fru_records}= Redfish_Utils.Enumerate Request
91 ... /redfish/v1/Systems/system/${fru_type} return_json=0
Michael Walshe256a4f2019-05-29 10:49:06 -050092 ${fru_records}= Filter Struct ${fru_records} [('State', 'Enabled'), ('Health', 'OK')]
Michael Walshcf163322019-05-22 16:56:17 -050093
94 [Return] ${fru_records}
95
96
97Get Num Valid FRUs
98 [Documentation] Return the number of valid FRU records for the given fru_type.
99 [Arguments] ${fru_type}
100
101 # Description of argument(s):
102 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
103
104 ${fru_records}= Get Valid FRUs ${fru_type}
105 ${num_valid_frus}= Get length ${fru_records}
106
107 [Return] ${num_valid_frus}
Marissa Garzad76b1422019-09-13 16:31:54 -0500108
109
110Verify Valid Records
111 [Documentation] Verify all records retrieved with the given arguments are valid.
112 [Arguments] ${record_type} ${redfish_uri} ${reading_type}
113
114 # Description of Argument(s):
115 # record_type The sensor record type (e.g. "PowerSupplies")
116 # redfish_uri The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power)
117 # reading_type The power watt readings (e.g. "PowerInputWatts")
118
119 # A valid record will have "State" key "Enabled" and "Health" key "OK".
120 ${records}= Redfish.Get Attribute ${redfish_uri} ${record_type}
121
122 Rprint Vars records
123
124 # Example output:
125 # records:
126 # [0]:
127 # [@odata.id]: /redfish/v1/Chassis/chassis/Power#/PowerControl/0
128 # [@odata.type]: #Power.v1_0_0.PowerControl
129 # [MemberId]: 0
130 # [Name]: Chassis Power Control
131 # [PowerConsumedWatts]: 264.0
132 # [PowerLimit]:
133 # [LimitInWatts]: None
134 # [PowerMetrics]:
135 # [AverageConsumedWatts]: 325
136 # [IntervalInMin]: 3
137 # [MaxConsumedWatts]: 538
138 # [Status]:
139 # [Health]: OK
140 # [State]: Enabled
141
142 ${invalid_records}= Filter Struct ${records}
143 ... [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')] regex=1 invert=1
144 Valid Length invalid_records max_length=0
Marissa Garzafdee1b02019-09-20 14:52:12 -0500145
146 [Return] ${records}
Vijayff2c0bc2020-02-03 00:05:45 -0600147
148
149Redfish Create User
150 [Documentation] Redfish create user.
151 [Arguments] ${user_name} ${password} ${role_id} ${enabled} ${force}=${False}
152
153 # Description of argument(s):
154 # user_name The user name to be created.
155 # password The password to be assigned.
156 # role_id The role ID of the user to be created.
157 # (e.g. "Administrator", "Operator", etc.).
158 # enabled Indicates whether the username being created.
159 # should be enabled (${True}, ${False}).
160 # force Delete user account and re-create if force is True.
161
162 ${curr_role}= Run Keyword And Ignore Error Get User Role ${user_name}
163 # Ex: ${curr_role} = ('PASS', 'Administrator')
164
165 ${user_exists}= Run Keyword And Return Status Should Be Equal As Strings ${curr_role}[0] PASS
166
167 # Delete user account when force is True.
168 Run Keyword If ${force} == ${True} Redfish.Delete ${REDFISH_ACCOUNTS_URI}${user_name}
169 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
170
171 # Create specified user when force is True or User does not exist.
172 ${payload}= Create Dictionary
173 ... UserName=${user_name} Password=${password} RoleId=${role_id} Enabled=${enabled}
174
175 Run Keyword If ${force} == ${True} or ${user_exists} == ${False}
176 ... Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
177 ... valid_status_codes=[${HTTP_CREATED}]
178
179
180Get User Role
181 [Documentation] Get User Role.
182 [Arguments] ${user_name}
183
184 # Description of argument(s):
185 # user_name User name to get it's role.
186
187 ${role_config}= Redfish_Utils.Get Attribute
188 ... ${REDFISH_ACCOUNTS_URI}${user_name} RoleId
189
190 [Return] ${role_config}
191
192
193Create Users With Different Roles
194 [Documentation] Create users with different roles.
195 [Arguments] ${users} ${force}=${False}
196
197 # Description of argument(s):
198 # users Dictionary of roles and user credentails to be created.
199 # Ex: {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'}
200 # force Delete given user account if already exists when force is True.
201
202 FOR ${role} IN @{users}
203 Redfish Create User ${users['${role}'][0]} ${users['${role}']}[1] ${role} ${True} ${force}
204 END
205
Vijay39373152020-02-14 08:08:20 -0600206
207Delete BMC Users Via Redfish
208 [Documentation] Delete BMC users via redfish.
209 [Arguments] ${users}
210
211 # Description of argument(s):
212 # users Dictionary of roles and user credentials to be deleted.
213
214 FOR ${role} IN @{users}
215 Redfish.Delete /redfish/v1/AccountService/Accounts/${users['${role}'][0]}
216 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
217 END
218