| Steven Sombar | ebfb662 | 2017-09-19 08:51:24 -0500 | [diff] [blame] | 1 | *** Settings *** | 
 | 2 | Documentation     Utilities for power management tests. | 
 | 3 |  | 
 | 4 | Resource          ../lib/rest_client.robot | 
 | 5 | Resource          ../lib/openbmc_ffdc.robot | 
 | 6 | Resource          ../lib/boot_utils.robot | 
 | 7 | Resource          ../lib/ipmi_client.robot | 
 | 8 | Library           ../lib/var_funcs.py | 
 | 9 |  | 
| George Keishing | a670bf3 | 2022-07-18 13:30:11 -0500 | [diff] [blame] | 10 | *** Variables *** | 
 | 11 |  | 
 | 12 | ${power_cap_uri}    /redfish/v1/Chassis/${CHASSIS_ID}/EnvironmentMetrics | 
| Steven Sombar | ebfb662 | 2017-09-19 08:51:24 -0500 | [diff] [blame] | 13 |  | 
 | 14 | *** Keywords *** | 
 | 15 |  | 
| George Keishing | a670bf3 | 2022-07-18 13:30:11 -0500 | [diff] [blame] | 16 | Get 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 Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 29 |     RETURN  ${power_limit_watts} | 
| George Keishing | a670bf3 | 2022-07-18 13:30:11 -0500 | [diff] [blame] | 30 |  | 
 | 31 |  | 
| Steven Sombar | ebfb662 | 2017-09-19 08:51:24 -0500 | [diff] [blame] | 32 | DCMI 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 Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 52 |     RETURN  &{limits} | 
| Steven Sombar | ebfb662 | 2017-09-19 08:51:24 -0500 | [diff] [blame] | 53 |  | 
 | 54 |  | 
 | 55 | Get 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 Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 61 |     RETURN  ${power_setting} | 
| Steven Sombar | ebfb662 | 2017-09-19 08:51:24 -0500 | [diff] [blame] | 62 |  | 
 | 63 |  | 
 | 64 | Set 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 Sombar | fc4d575 | 2017-11-28 11:56:35 -0600 | [diff] [blame] | 75 |     ...  msg=Failed setting dcmi power limit to ${power_limit} watts. | 
| Steven Sombar | ebfb662 | 2017-09-19 08:51:24 -0500 | [diff] [blame] | 76 |  | 
 | 77 |  | 
 | 78 | Activate 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 |  | 
 | 86 | Fail 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 |  | 
 | 94 | Deactivate 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 |  | 
 | 103 | Fail 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 Sombar | c435102 | 2018-01-15 13:47:38 -0600 | [diff] [blame] | 112 | Get 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 Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 117 |     RETURN  ${power_limit} | 
| Steven Sombar | c435102 | 2018-01-15 13:47:38 -0600 | [diff] [blame] | 118 |  | 
 | 119 |  | 
 | 120 | Set 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 Sombar | 90b7610 | 2019-01-11 11:04:38 -0600 | [diff] [blame] | 128 |     ${int_power_limit}=  Convert To Integer  ${power_limit} | 
 | 129 |     ${data}=  Create Dictionary  data=${int_power_limit} | 
| Steven Sombar | c435102 | 2018-01-15 13:47:38 -0600 | [diff] [blame] | 130 |     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 |  | 
 | 137 | Activate 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 Keishing | 9bfdf8a | 2024-04-19 11:09:07 +0530 | [diff] [blame] | 148 |     ${setting}=  Get DCMI Power Activation Via REST | 
| Steven Sombar | c435102 | 2018-01-15 13:47:38 -0600 | [diff] [blame] | 149 |     Should Be True  ${setting} == ${1} | 
 | 150 |     ...  msg=Failed to activate power limiting via REST. | 
 | 151 |  | 
 | 152 |  | 
 | 153 | Deactivate 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 Keishing | 9bfdf8a | 2024-04-19 11:09:07 +0530 | [diff] [blame] | 164 |     ${setting}=  Get DCMI Power Activation Via REST | 
| Steven Sombar | c435102 | 2018-01-15 13:47:38 -0600 | [diff] [blame] | 165 |     Should Be True  ${setting} == ${0} | 
 | 166 |     ...  msg=Failed to deactivate power limiting via REST. | 
 | 167 |  | 
 | 168 |  | 
| George Keishing | 9bfdf8a | 2024-04-19 11:09:07 +0530 | [diff] [blame] | 169 | Get DCMI Power Activation Via REST | 
| Steven Sombar | c435102 | 2018-01-15 13:47:38 -0600 | [diff] [blame] | 170 |     [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 Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 175 |     RETURN  ${power_activation_setting} | 
| Steven Sombar | c435102 | 2018-01-15 13:47:38 -0600 | [diff] [blame] | 176 |  | 
 | 177 |  | 
| Steven Sombar | ebfb662 | 2017-09-19 08:51:24 -0500 | [diff] [blame] | 178 | OCC 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} |