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