1*** 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
10
11*** Keywords ***
12
13DCMI Power Get Limits
14    [Documentation]  Run dcmi power get_limit and return values as a
15    ...  dictionary.
16
17    # This keyword packages the five lines returned by dcmi power get_limit
18    # command into a dictionary.  For example, the dcmi command may return:
19    #  Current Limit State: No Active Power Limit
20    #  Exception actions:   Hard Power Off & Log Event to SEL
21    #  Power Limit:         500   Watts
22    #  Correction time:     0 milliseconds
23    #  Sampling period:     0 seconds
24    # The power limit setting can be obtained with the following:
25    # &{limits}=  DCMI Power Get Limits
26    # ${power_setting}=  Set Variable  ${limits['power_limit']}
27
28    ${output}=  Run External IPMI Standard Command  dcmi power get_limit
29    ${output}=  Remove String  ${output}  Watts
30    ${output}=  Remove String  ${output}  milliseconds
31    ${output}=  Remove String  ${output}  seconds
32    &{limits}=  Key Value Outbuf To Dict  ${output}
33    [Return]  &{limits}
34
35
36Get DCMI Power Limit
37    [Documentation]  Return the system's current DCMI power_limit
38    ...  watts setting.
39
40    &{limits}=  DCMI Power Get Limits
41    ${power_setting}=  Get From Dictionary  ${limits}  power_limit
42    [Return]  ${power_setting}
43
44
45Set DCMI Power Limit And Verify
46    [Documentation]  Set system power limit via IPMI DCMI command.
47    [Arguments]  ${power_limit}
48
49    # Description of argument(s):
50    # limit      The power limit in watts
51
52    ${cmd}=  Catenate  dcmi power set_limit limit ${power_limit}
53    Run External IPMI Standard Command  ${cmd}
54    ${power}=  Get DCMI Power Limit
55    Should Be True  ${power} == ${power_limit}
56    ...  msg=Failed setting dcmi power limit to ${power_limit} watts.
57
58
59Activate DCMI Power And Verify
60    [Documentation]  Activate DCMI power limiting.
61
62    ${resp}=  Run External IPMI Standard Command  dcmi power activate
63    Should Contain  ${resp}  successfully activated
64    ...  msg=Command failed: dcmi power activate.
65
66
67Fail If DCMI Power Is Not Activated
68    [Documentation]  Fail if DCMI power limiting is not activated.
69
70    ${cmd}=  Catenate  dcmi power get_limit | grep State:
71    ${resp}=  Run External IPMI Standard Command  ${cmd}
72    Should Contain  ${resp}  Power Limit Active  msg=DCMI power is not active.
73
74
75Deactivate DCMI Power And Verify
76    [Documentation]  Deactivate DCMI power power limiting.
77
78    ${cmd}=  Catenate  dcmi power deactivate | grep deactivated
79    ${resp}=  Run External IPMI Standard Command  ${cmd}
80    Should Contain  ${resp}  successfully deactivated
81    ...  msg=Command failed: dcmi power deactivater.
82
83
84Fail If DCMI Power Is Not Deactivated
85    [Documentation]  Fail if DCMI power limiting is not deactivated.
86
87    ${cmd}=  Catenate  dcmi power get_limit | grep State:
88    ${resp}=  Run External IPMI Standard Command  ${cmd}
89    Should Contain  ${resp}  No Active Power Limit
90    ...  msg=DCMI power is not deactivated.
91
92
93Get DCMI Power Limit Via REST
94    [Documentation]  Return the system's current DCMI power_limit
95    ...  watts setting using REST interface.
96
97    ${power_limit}=  Read Attribute  ${CONTROL_HOST_URI}power_cap  PowerCap
98    [Return]  ${power_limit}
99
100
101Set DCMI Power Limit Via REST
102    [Documentation]  Set system power limit via REST command.
103    [Arguments]  ${power_limit}  ${verify}=${True}
104
105    # Description of argument(s):
106    # power_limit  The power limit in watts.
107    # verify       If True, read the power setting to confirm.
108
109    ${data}=  Create Dictionary  data=${power_limit}
110    Write Attribute   ${CONTROL_HOST_URI}power_cap  PowerCap  data=${data}
111    Return From Keyword If  ${verify} == ${False}
112    ${power}=  Read Attribute  ${CONTROL_HOST_URI}power_cap  PowerCap
113    Should Be True  ${power} == ${power_limit}
114    ...  msg=Failed setting power limit to ${power_limit} watts via REST.
115
116
117Activate DCMI Power Via REST
118    [Documentation]  Activate DCMI power limiting via REST.
119    [Arguments]  ${verify}=${True}
120
121    # Description of argument(s):
122    # verify       If True, read the setting to confirm.
123
124    ${data}=  Create Dictionary  data=${True}
125    Write Attribute   ${CONTROL_HOST_URI}power_cap  PowerCapEnable
126    ...  data=${data}
127    Return From Keyword If  ${verify} == ${False}
128    ${setting}=  Get DCMI Power Acivation Via REST
129    Should Be True  ${setting} == ${1}
130    ...  msg=Failed to activate power limiting via REST.
131
132
133Deactivate DCMI Power Via REST
134    [Documentation]  Deactivate DCMI power limiting via REST.
135    [Arguments]  ${verify}=${True}
136
137    # Description of argument(s):
138    # verify       If True, read the setting to confirm.
139
140    ${data}=  Create Dictionary  data=${False}
141    Write Attribute   ${CONTROL_HOST_URI}power_cap  PowerCapEnable
142    ...  data=${data}
143    Return From Keyword If  ${verify} == ${False}
144    ${setting}=  Get DCMI Power Acivation Via REST
145    Should Be True  ${setting} == ${0}
146    ...  msg=Failed to deactivate power limiting via REST.
147
148
149Get DCMI Power Acivation Via REST
150    [Documentation]  Return the system's current DCMI power activation
151    ...  state setting using REST interface.
152
153    ${power_activation_setting}=  Read Attribute
154    ...  ${CONTROL_HOST_URI}power_cap  PowerCapEnable
155    [Return]  ${power_activation_setting}
156
157
158OCC Tool Upload Setup
159    [Documentation]  Upload occtoolp9 to /tmp on the OS.
160
161    ${cmd}=  Catenate  wget --no-check-certificate
162    ...  -O/tmp/occtoolp9 --content-disposition
163    ...  https://github.com/open-power/occ/raw/master/src/tools/occtoolp9
164    ...  && chmod 777 /tmp/occtoolp9
165    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
166