1*** Settings ***
2Documentation             Test BMC using https://github.com/DMTF/Redfish-Usecase-Checkers
3...                       DMTF tool.
4
5Resource                  ../../lib/resource.robot
6Resource                  ../../lib/dmtf_tools_utils.robot
7Resource                  ../../lib/openbmc_ffdc.robot
8Library                   OperatingSystem
9Library                   ../../lib/state.py
10
11Test Setup                Test Setup Execution
12Test Teardown             Test Teardown Execution
13
14*** Variables ***
15
16${DEFAULT_PYTHON}         python3
17
18${rsv_github_url}         https://github.com/DMTF/Redfish-Usecase-Checkers.git
19${rsv_dir_path}           Redfish-Usecase-Checkers
20
21${command_account}        ${DEFAULT_PYTHON} ${rsv_dir_path}${/}account_management/account_management.py
22...                       -r ${OPENBMC_HOST} -u ${OPENBMC_USERNAME}
23...                       -p ${OPENBMC_PASSWORD} -S Always -d ${EXECDIR}${/}account-logs${/}
24
25${command_power_control}  ${DEFAULT_PYTHON} ${rsv_dir_path}${/}power_control/power_control.py
26...                       -r ${OPENBMC_HOST} -u ${OPENBMC_USERNAME}
27...                       -p ${OPENBMC_PASSWORD} -S Always -d ${EXECDIR}${/}power-logs${/}
28
29${power_on_timeout}       15 mins
30${power_off_timeout}      15 mins
31${state_change_timeout}   3 mins
32
33*** Test Case ***
34
35Test BMC Redfish Account Management
36    [Documentation]  Check Account Management with a Redfish interface.
37    [Tags]  Test_BMC_Redfish_Account_Management
38
39    ${output}=  Run DMTF Tool  ${rsv_dir_path}  ${command_account}  check_error=1
40
41    ${output}=  Shell Cmd  cat ${EXECDIR}${/}account-logs${/}results.json
42    Log  ${output}
43
44    ${json}=  OperatingSystem.Get File    ${EXECDIR}${/}account-logs${/}results.json
45
46    ${object}=  Evaluate  json.loads('''${json}''')  json
47
48    ${result_list}=  Set Variable  ${object["TestResults"]}
49
50    @{failed_tc_list}=    Create List
51
52    FOR  ${result}  IN  @{result_list}
53       ${rc}=    evaluate    'ErrorMessages'=='${result}'
54       ${num}=  Run Keyword If  ${rc} == False  Set Variable  ${result_list["${result}"]["fail"]}
55       Run Keyword If  ${num} != None and ${num} > 0  Append To List  ${failed_tc_list}   ${result}
56    END
57
58    Should Be Empty  ${failed_tc_list}  Failed test cases are ${failed_tc_list}
59
60
61Test BMC Redfish Power Control Usecase
62    [Documentation]  Power Control Usecase Test.
63    [Tags]  Test_BMC_Redfish_Power_Control_Usecase
64
65    DMTF Power
66
67
68*** Keywords ***
69
70Test Setup Execution
71    [Documentation]  Do test case setup tasks.
72
73    Printn
74    Download DMTF Tool  ${rsv_dir_path}  ${rsv_github_url}
75
76
77Test Teardown Execution
78    [Documentation]  Do the post-test teardown.
79
80    Printn
81    FFDC On Test Case Fail
82
83
84DMTF Power
85    [Documentation]  Power the BMC machine on via DMTF tools.
86
87    ${output}=  Run DMTF Tool  ${rsv_dir_path}  ${command_power_control}  check_error=1
88    Log  ${output}
89
90    ${json}=  OperatingSystem.Get File    ${EXECDIR}${/}power-logs${/}results.json
91
92    ${object}=  Evaluate  json.loads('''${json}''')  json
93
94    ${result_list}=  Set Variable  ${object["TestResults"]}
95    Log To Console  result: ${result_list}
96
97    @{failed_tc_list}=    Create List
98    @{error_messages}=    Create List
99
100    FOR  ${result}  IN  @{result_list}
101       ${rc}=    evaluate    'ErrorMessages'=='${result}'
102       ${num}=  Run Keyword If  ${rc} == False  Set Variable  ${result_list["${result}"]["fail"]}
103       Run Keyword If  ${num} != None and ${num} > 0  Append To List  ${failed_tc_list}   ${result}
104       Run Keyword If  ${rc} == True   Set Variable
105       ...  Append To List  ${error_messages}  ${result_list["ErrorMessages"]}
106    END
107
108    Log Many            ErrorMessages:   @{error_messages}
109    Log To Console      ErrorMessages:
110    FOR   ${msg}  IN  @{error_messages}
111       Log To Console   ${msg}
112    END
113
114    Should Be Empty  ${error_messages}   DMTF Power keyword failed.
115