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=Faied 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
93OCC Tool Upload Setup
94    [Documentation]  Upload occtoolp9 to /tmp on the OS.
95
96    ${cmd}=  Catenate  wget --no-check-certificate
97    ...  -O/tmp/occtoolp9 --content-disposition
98    ...  https://github.com/open-power/occ/raw/master/src/tools/occtoolp9
99    ...  && chmod 777 /tmp/occtoolp9
100    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
101