1*** Settings ***
2
3Documentation    Module to test IPMI Get BIOS POST Code Command.
4Resource         ../lib/ipmi_client.robot
5Resource         ../lib/boot_utils.robot
6Library          ../lib/ipmi_utils.py
7Variables        ../data/ipmi_raw_cmd_table.py
8
9Suite Setup  IPMI Power On
10Suite Teardown  IPMI Power On  stack_mode=skip  quiet=1
11
12*** Test Cases ***
13Test Get BIOS POST Code via IPMI Raw Command
14    [Documentation]  Get BIOS POST Code via IPMI raw command.
15    [Tags]  Test_Get_BIOS_POST_Code_via_IPMI_Raw_Command
16
17    Wait Until Keyword Succeeds  10 min  1 sec  Check Host Is Pinging  ${OS_HOST}
18    Wait Until Keyword Succeeds  1 min  1 sec  Check Chassis Power Status  on
19    ${resp}=  Run IPMI Standard Command  raw ${IPMI_RAW_CMD['BIOS_POST_Code']['Get'][0]}
20    Verify POST Code Response Length  ${resp}
21
22Test Get BIOS POST Code via IPMI Raw Command After Power Cycle
23    [Documentation]  Get BIOS POST Code via IPMI raw command after power cycle.
24    [Tags]  Test_Get_BIOS_POST_Code_via_IPMI_Raw_Command_After_Power_Cycle
25
26    ${resp}=  Run IPMI Standard Command  chassis power cycle
27    Wait Until Keyword Succeeds  1 min  1 sec  Check Host Is Not Pinging  ${OS_HOST}
28    Wait Until Keyword Succeeds  10 min  1 sec  Check Host Is Pinging  ${OS_HOST}
29
30    ${resp}=  Run IPMI Standard Command  raw ${IPMI_RAW_CMD['BIOS_POST_Code']['Get'][0]}
31    Verify POST Code Response Length  ${resp}
32
33Test Get BIOS POST Code via IPMI Raw Command With Host Powered Off
34    [Documentation]  Get BIOS POST Code via IPMI raw command after power off.
35    [Tags]  Test_Get_BIOS_POST_Code_via_IPMI_Raw_Command_With_Host_Powered_Off
36
37    ${resp}=  Run IPMI Standard Command  chassis power off
38    Wait Until Keyword Succeeds  1 min  1 sec  Check Host Is Not Pinging  ${OS_HOST}
39    Wait Until Keyword Succeeds  1 min  1 sec  Check Chassis Power Status  off
40
41    ${resp}=  Run IPMI Standard Command  raw ${IPMI_RAW_CMD['BIOS_POST_Code']['Get'][0]}  fail_on_err=0
42    Should Contain  ${resp}  ${IPMI_RAW_CMD['BIOS_POST_Code']['Get'][3]}
43
44*** Keywords ***
45Verify POST Code Response Length
46    [Documentation]  Verify the BIOS POST Code response byte length.
47    [Tags]  Verify_POST_Code_Response_Length
48    [Arguments]  ${resp}
49
50    # Description of argument(s):
51    # resp                          The complete response bytes from
52    #                               Get BIOS POST Code command returned
53    #                               in one string.
54
55    @{resp_bytes}=  Split String  ${resp}
56    ${string_length}=  Get Length  ${resp_bytes}
57
58    # Convert response byte length to integer.
59    ${value}=  Get Slice From List  ${resp_bytes}   2   4
60    Reverse List   ${value}
61    ${byte_length_string}=  Evaluate   "".join(${value})
62    ${byte_length_integer}=  Convert To Integer  ${byte_length_string}  16
63    ${true_length}=  Evaluate  (${string_length} - 4)
64
65    Should Be Equal  ${true_length}  ${byte_length_integer}
66
67Check Chassis Power Status
68    [Documentation]  Validate chassis power status.
69    [Arguments]  ${expected_state}
70
71    # Description of argument(s):
72    # expected_state    on, off
73
74    ${resp}=  Run IPMI Standard Command  chassis power status
75    Should Contain  ${resp}  ${expected_state}
76
77Check Host Is Pinging
78    [Documentation]  Check given ip/hostname is pinging.
79    [Arguments]  ${host_ip}
80
81    # Description of argument(s):
82    # host_ip      The host name or IP of the host to ping.
83
84    ${ping_rsp}=  Host Ping  ${host_ip}
85    # Should Not Contain  ${ping_rsp}  Destination Host Unreachable
86    # ...  msg=${host_ip} is not pinging.
87    Should Not Contain  ${ping_rsp}  100% packet loss
88    ...  msg=${host_ip} is not pinging.
89
90Check Host Is Not Pinging
91    [Documentation]  Check given ip/hostname is not pinging.
92    [Arguments]  ${host_ip}
93
94    # Description of argument(s):
95    # host_ip      The host name or IP of the host to ping.
96
97    ${ping_rsp}=  Host Ping  ${host_ip}
98    Should Contain  ${ping_rsp}  100% packet loss
99    ...  msg=${host_ip} is pinging.
100
101Host Ping
102    [Documentation]  Ping the given host.
103    [Arguments]  ${host_ip}
104
105    # Description of argument(s):
106    # host_ip      The host name or IP of the host to ping.
107
108    ${cmd}=  Catenate  ping -c 4 ${host_ip}
109    ${output}=  Run  ${cmd}
110
111    [Return]  ${output}
112