xref: /openbmc/openbmc-test-automation/ipmi/dcmi/test_dcmi_management_controller.robot (revision 5502e3ed5da70a29746724d1927131cc8a7f2997)
1*** Settings ***
2Documentation    Module to test dcmi management controller functionality.
3Resource         ../../lib/ipmi_client.robot
4Resource         ../../lib/openbmc_ffdc.robot
5Resource         ../../lib/bmc_network_utils.robot
6Resource         ../../lib/boot_utils.robot
7Resource         ../../lib/bmc_redfish_utils.robot
8Variables        ../../data/ipmi_raw_cmd_table.py
9Variables        ../../data/dcmi_raw_cmd_table.py
10Variables        ../../data/ipmi_variable.py
11Library          ../../lib/ipmi_utils.py
12Library          ../../lib/utilities.py
13Library          ../../lib/utils.py
14Library          JSONLibrary
15
16*** Variables ***
17${hostname_file_path}  /etc/hostname
18
19*** Test Cases ***
20Validate IPMI Response Length
21    [Documentation]  Check ipmi response length.
22    [Tags]  Validate_IPMI_Response_Length
23
24    ${rsp}=  Get DCMI Management Controller Identifier String
25    @{ipmi_cmd_rsp_list}=  Split String  ${rsp}
26    # ipmi_cmd_rsp_list = ["00", "0a", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09"]
27    # rsp_length = 10
28    # string_length = 0a
29    ${rsp_length}=  Get Length  ${ipmi_cmd_rsp_list[2:]}
30    ${string_length}=  Get Response Length In Hex  ${rsp_length}
31
32    # ipmi_cmd_rsp_list[1] = 0a
33    # string_length = 0a
34    # the above condition is equal.
35    # suppose if string_length and ipmi_cmd_rsp_lst[1] not matches then it will fails.
36    Should Be Equal As Strings  ${ipmi_cmd_rsp_list[1]}  ${string_length}
37    ...  msg=Id string length in ipmi response is showing wrongly
38
39Test Hostname is Same With Management Controller Identifier String
40    [Documentation]  Check hostname was verified with get management controller identfier string.
41    [Tags]  Validate_Hostname_With_Get_DCMI_MCID_String
42
43    ${rsp}=  Get DCMI Management Controller Identifier String
44    @{ipmi_cmd_rsp_list}=  Split String  ${rsp}
45    ${bmc_console_hostname_bytes_list}=  Get Hostname From BMC Console
46
47    Lists Should Be Equal  ${ipmi_cmd_rsp_list[2:]}  ${bmc_console_hostname_bytes_list}
48    ...  msg=response get from dcmi get mcid cmd and hostname from "cat /etc/os-release" cmd is not same.
49
50Test Get Management Controller Identifier String
51    [Documentation]  Validate set and get mcid string.
52    [Tags]  Set_And_Get_Management_Controller_Identifier_String
53    [Setup]  Get Default MCID
54    [Teardown]  Set Default MCID
55
56    # Set Hostname via DCMI Management Controller Identifier String Command.
57    ${cmd_rsp}=  Set DCMI Management Controller Identifier String
58    @{cmd_rsp_list}=  Split String  ${cmd_rsp}
59    Run Keyword And Continue On Failure
60    ...  Valid Value  cmd_rsp_list[1]  valid_values=['${number_of_bytes_to_write}']
61
62    ${rsp}=  Get DCMI Management Controller Identifier String
63    @{ipmi_cmd_rsp_list}=  Split String  ${rsp}
64
65    # Verify number of bytes that was set and id string length are same.
66    ${string_length}=  Get Response Length In Hex  ${random_int}
67    Run Keyword And Continue On Failure
68    ...  Should Be Equal As Strings  ${ipmi_cmd_rsp_list[1]}  ${string_length}
69    ...  msg=Number of bytes that was set and id string length are not same.
70
71    # Verify ID String Length and data.
72    # ipmi_cmd_rsp_list = ["00", "0a", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09"]
73    # rsp_length = 10
74    # string_length = 0a
75    # ipmi_cmd_rsp_list[1] = 0a
76    # ipmi_cmd_rsp_list[1] is equal to string_length
77    # the above condition is equal.
78    # suppose if string_length and ipmi_cmd_rsp_lst[1] not matches then it will fails.
79    ${rsp_length}=  Get Length  ${ipmi_cmd_rsp_list[2:]}
80    ${string_length}=  Get Response Length In Hex  ${rsp_length}
81    Run Keyword And Continue On Failure
82    ...  Should Be Equal As Strings  ${ipmi_cmd_rsp_list[1]}  ${string_length}
83    ...  msg=Id string length in ipmi response is showing wrongly
84
85    # Verify get dcmi management controller identifier string command response
86    # and the bytes used for Set DCMI MCID string.
87    ${set_dcmi_mcid_cmd}=
88    ...  convert_prefix_hex_list_to_non_prefix_hex_list  ${string_hex_list}
89    Run Keyword And Continue On Failure
90    ...  Lists Should Be Equal  ${ipmi_cmd_rsp_list[2:]}  ${set_dcmi_mcid_cmd}
91    ...  msg=Bytes given in dcmi set mcid command and string bytes got from dcmi get mcid command are not same
92
93    # Verify Hostname of cat /etc/hostname and get dcmi management controller identifier string command.
94    ${bytes_list}=  Get Hostname From BMC Console
95    Run Keyword And Continue On Failure
96    ...  Lists Should Be Equal  ${ipmi_cmd_rsp_list[2:]}  ${bytes_list}
97    ...  msg=Bytes got from dcmi get mcid command and hostname from "cat /etc/os-release" command is not same.
98
99*** Keywords ***
100Get Default MCID
101    [Documentation]  Get default mcid.
102
103    ${default_mcid}=  Get DCMI Management Controller Identifier String
104    Set Test Variable  ${default_mcid}
105
106Set Default MCID
107    [Documentation]  Set default mcid.
108
109    @{ipmi_cmd_rsp_list}=  Split String  ${default_mcid}
110    ${number_of_bytes_to_write}=  Set Variable  ${ipmi_cmd_rsp_list[1]}
111    ${bytes_in_int}=  Convert To Integer  ${number_of_bytes_to_write}  16
112    ${bytes_to_write}=  Evaluate  ${bytes_in_int} + 1
113    ${no_of_bytes_to_write}=  Get Response Length In Hex  ${bytes_to_write}
114    @{tmp_lst}=  Create List
115    FOR  ${bytes}  IN  @{ipmi_cmd_rsp_list[2:]}
116      Append To List  ${tmp_lst}  0x${bytes}
117    END
118    ${default_hex}=  Catenate  @{tmp_lst}
119
120    ${cmd}=  Catenate  ${DCMI_RAW_CMD['DCMI']['MANAGEMENT_CONTROLLER_IDENTIFIER_STRING']['SET']}
121    ...  0x${no_of_bytes_to_write} ${default_hex}
122    Run External IPMI Raw Command  ${cmd}
123
124Get DCMI Management Controller Identifier String
125    [Documentation]  Get DCMI MCID String.
126
127    ${mcid_get_cmd}=  Catenate  ${DCMI_RAW_CMD['DCMI']['MANAGEMENT_CONTROLLER_IDENTIFIER_STRING']['GET']}
128    ${resp}=  Run External IPMI Raw Command  ${mcid_get_cmd}
129
130    [Return]  ${resp}
131
132Set DCMI Management Controller Identifier String
133    [Documentation]  Set DCMI MCID String.
134
135    # 16 bytes maximum as per dcmi spec
136    ${random_int}=  Evaluate  random.randint(1, 15)  modules=random
137    ${random_string}=  Generate Random String  ${random_int}
138    ${string_hex_list}=  convert_name_into_bytes_with_prefix  ${random_string}
139    ${random_hex}=  Catenate  @{string_hex_list}
140    ${number_of_random_string}=  Evaluate  ${random_int} + 1
141    ${number_of_bytes_to_write}=  Get Response Length In Hex  ${number_of_random_string}
142
143    ${mcid_set_cmd}=  Catenate  ${DCMI_RAW_CMD['DCMI']['MANAGEMENT_CONTROLLER_IDENTIFIER_STRING']['SET']}
144    ...  0x${number_of_bytes_to_write} ${random_hex} 0x00
145    ${resp}=  Run External IPMI Raw Command  ${mcid_set_cmd}
146
147    Set Test Variable  ${string_hex_list}
148    Set Test Variable  ${random_int}
149    Set Test Variable  ${number_of_bytes_to_write}
150
151    [Return]  ${resp}
152
153Get Hostname From BMC Console
154    [Documentation]  Get hostname.
155
156    ${cmd}=  Catenate  cat ${hostname_file_path}
157    ${bmc_hostname}=  BMC Execute Command  ${cmd}
158    ${name}=  Convert To List  ${bmc_hostname}
159    ${hostname_bytes}=  convert_name_into_bytes_without_prefix  ${name[0]}
160
161    [Return]  ${hostname_bytes}
162
163Get Response Length In Hex
164    [Documentation]  Get response length in hex.
165    [Arguments]  ${resp_length}
166
167    ${length}=  Convert To Hex  ${resp_length}
168    ${length_1}=  Get Length  ${length}
169    ${length_2}=  Set Variable IF
170    ...  '${length_1}' == '1'  0${length}
171    ...  '${length_1}' != '1'  ${length}
172    ${resp_length_3}=  Convert To Lower Case  ${length_2}
173
174    [Return]  ${resp_length_3}
175