blob: 668adc3545becfb1d1ea9fd04792c3cebcc1874e [file] [log] [blame]
Steven Sombarebfb6622017-09-19 08:51:24 -05001*** Settings ***
2Documentation Utilities for power management tests.
3
4Resource ../lib/rest_client.robot
5Resource ../lib/openbmc_ffdc.robot
6Resource ../lib/boot_utils.robot
7Resource ../lib/ipmi_client.robot
8Library ../lib/var_funcs.py
9
George Keishinga670bf32022-07-18 13:30:11 -050010*** Variables ***
11
12${power_cap_uri} /redfish/v1/Chassis/${CHASSIS_ID}/EnvironmentMetrics
Steven Sombarebfb6622017-09-19 08:51:24 -050013
14*** Keywords ***
15
George Keishinga670bf32022-07-18 13:30:11 -050016Get System Power Cap Limit
17 [Documentation] Get the allowed MAX and MIN power limit of the chassis.
18
19 # GET request of /redfish/v1/Chassis/chassis/EnvironmentMetrics | grep -A5 Power
20 # "PowerLimitWatts": {
21 # "AllowableMax": 2488,
22 # "AllowableMin": 1778,
23 # "ControlMode": "Disabled",
24 # "SetPoint": 2488
25 # }
26
27 ${power_limit_watts}= Redfish.Get Attribute ${power_cap_uri} PowerLimitWatts
28
George Keishing409df052024-01-17 22:36:14 +053029 RETURN ${power_limit_watts}
George Keishinga670bf32022-07-18 13:30:11 -050030
31
Steven Sombarebfb6622017-09-19 08:51:24 -050032DCMI Power Get Limits
33 [Documentation] Run dcmi power get_limit and return values as a
34 ... dictionary.
35
36 # This keyword packages the five lines returned by dcmi power get_limit
37 # command into a dictionary. For example, the dcmi command may return:
38 # Current Limit State: No Active Power Limit
39 # Exception actions: Hard Power Off & Log Event to SEL
40 # Power Limit: 500 Watts
41 # Correction time: 0 milliseconds
42 # Sampling period: 0 seconds
43 # The power limit setting can be obtained with the following:
44 # &{limits}= DCMI Power Get Limits
45 # ${power_setting}= Set Variable ${limits['power_limit']}
46
47 ${output}= Run External IPMI Standard Command dcmi power get_limit
48 ${output}= Remove String ${output} Watts
49 ${output}= Remove String ${output} milliseconds
50 ${output}= Remove String ${output} seconds
51 &{limits}= Key Value Outbuf To Dict ${output}
George Keishing409df052024-01-17 22:36:14 +053052 RETURN &{limits}
Steven Sombarebfb6622017-09-19 08:51:24 -050053
54
55Get DCMI Power Limit
56 [Documentation] Return the system's current DCMI power_limit
57 ... watts setting.
58
59 &{limits}= DCMI Power Get Limits
60 ${power_setting}= Get From Dictionary ${limits} power_limit
George Keishing409df052024-01-17 22:36:14 +053061 RETURN ${power_setting}
Steven Sombarebfb6622017-09-19 08:51:24 -050062
63
64Set DCMI Power Limit And Verify
65 [Documentation] Set system power limit via IPMI DCMI command.
66 [Arguments] ${power_limit}
67
68 # Description of argument(s):
69 # limit The power limit in watts
70
71 ${cmd}= Catenate dcmi power set_limit limit ${power_limit}
72 Run External IPMI Standard Command ${cmd}
73 ${power}= Get DCMI Power Limit
74 Should Be True ${power} == ${power_limit}
Steven Sombarfc4d5752017-11-28 11:56:35 -060075 ... msg=Failed setting dcmi power limit to ${power_limit} watts.
Steven Sombarebfb6622017-09-19 08:51:24 -050076
77
78Activate DCMI Power And Verify
79 [Documentation] Activate DCMI power limiting.
80
81 ${resp}= Run External IPMI Standard Command dcmi power activate
82 Should Contain ${resp} successfully activated
83 ... msg=Command failed: dcmi power activate.
84
85
86Fail If DCMI Power Is Not Activated
87 [Documentation] Fail if DCMI power limiting is not activated.
88
89 ${cmd}= Catenate dcmi power get_limit | grep State:
90 ${resp}= Run External IPMI Standard Command ${cmd}
91 Should Contain ${resp} Power Limit Active msg=DCMI power is not active.
92
93
94Deactivate DCMI Power And Verify
95 [Documentation] Deactivate DCMI power power limiting.
96
97 ${cmd}= Catenate dcmi power deactivate | grep deactivated
98 ${resp}= Run External IPMI Standard Command ${cmd}
99 Should Contain ${resp} successfully deactivated
100 ... msg=Command failed: dcmi power deactivater.
101
102
103Fail If DCMI Power Is Not Deactivated
104 [Documentation] Fail if DCMI power limiting is not deactivated.
105
106 ${cmd}= Catenate dcmi power get_limit | grep State:
107 ${resp}= Run External IPMI Standard Command ${cmd}
108 Should Contain ${resp} No Active Power Limit
109 ... msg=DCMI power is not deactivated.
110
111
Steven Sombarc4351022018-01-15 13:47:38 -0600112Get DCMI Power Limit Via REST
113 [Documentation] Return the system's current DCMI power_limit
114 ... watts setting using REST interface.
115
116 ${power_limit}= Read Attribute ${CONTROL_HOST_URI}power_cap PowerCap
George Keishing409df052024-01-17 22:36:14 +0530117 RETURN ${power_limit}
Steven Sombarc4351022018-01-15 13:47:38 -0600118
119
120Set DCMI Power Limit Via REST
121 [Documentation] Set system power limit via REST command.
122 [Arguments] ${power_limit} ${verify}=${True}
123
124 # Description of argument(s):
125 # power_limit The power limit in watts.
126 # verify If True, read the power setting to confirm.
127
Steven Sombar90b76102019-01-11 11:04:38 -0600128 ${int_power_limit}= Convert To Integer ${power_limit}
129 ${data}= Create Dictionary data=${int_power_limit}
Steven Sombarc4351022018-01-15 13:47:38 -0600130 Write Attribute ${CONTROL_HOST_URI}power_cap PowerCap data=${data}
131 Return From Keyword If ${verify} == ${False}
132 ${power}= Read Attribute ${CONTROL_HOST_URI}power_cap PowerCap
133 Should Be True ${power} == ${power_limit}
134 ... msg=Failed setting power limit to ${power_limit} watts via REST.
135
136
137Activate DCMI Power Via REST
138 [Documentation] Activate DCMI power limiting via REST.
139 [Arguments] ${verify}=${True}
140
141 # Description of argument(s):
142 # verify If True, read the setting to confirm.
143
144 ${data}= Create Dictionary data=${True}
145 Write Attribute ${CONTROL_HOST_URI}power_cap PowerCapEnable
146 ... data=${data}
147 Return From Keyword If ${verify} == ${False}
George Keishing9bfdf8a2024-04-19 11:09:07 +0530148 ${setting}= Get DCMI Power Activation Via REST
Steven Sombarc4351022018-01-15 13:47:38 -0600149 Should Be True ${setting} == ${1}
150 ... msg=Failed to activate power limiting via REST.
151
152
153Deactivate DCMI Power Via REST
154 [Documentation] Deactivate DCMI power limiting via REST.
155 [Arguments] ${verify}=${True}
156
157 # Description of argument(s):
158 # verify If True, read the setting to confirm.
159
160 ${data}= Create Dictionary data=${False}
161 Write Attribute ${CONTROL_HOST_URI}power_cap PowerCapEnable
162 ... data=${data}
163 Return From Keyword If ${verify} == ${False}
George Keishing9bfdf8a2024-04-19 11:09:07 +0530164 ${setting}= Get DCMI Power Activation Via REST
Steven Sombarc4351022018-01-15 13:47:38 -0600165 Should Be True ${setting} == ${0}
166 ... msg=Failed to deactivate power limiting via REST.
167
168
George Keishing9bfdf8a2024-04-19 11:09:07 +0530169Get DCMI Power Activation Via REST
Steven Sombarc4351022018-01-15 13:47:38 -0600170 [Documentation] Return the system's current DCMI power activation
171 ... state setting using REST interface.
172
173 ${power_activation_setting}= Read Attribute
174 ... ${CONTROL_HOST_URI}power_cap PowerCapEnable
George Keishing409df052024-01-17 22:36:14 +0530175 RETURN ${power_activation_setting}
Steven Sombarc4351022018-01-15 13:47:38 -0600176
177
Steven Sombarebfb6622017-09-19 08:51:24 -0500178OCC Tool Upload Setup
179 [Documentation] Upload occtoolp9 to /tmp on the OS.
180
181 ${cmd}= Catenate wget --no-check-certificate
182 ... -O/tmp/occtoolp9 --content-disposition
183 ... https://github.com/open-power/occ/raw/master/src/tools/occtoolp9
184 ... && chmod 777 /tmp/occtoolp9
185 ${output} ${stderr} ${rc}= OS Execute Command ${cmd}