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