1*** Settings ***
2
3Documentation    Module to test dcmi get temperature reading functionality.
4Resource         ../../lib/ipmi_client.robot
5Resource         ../../lib/openbmc_ffdc.robot
6Resource         ../../lib/bmc_network_utils.robot
7Resource         ../../lib/boot_utils.robot
8Variables        ../../data/ipmi_raw_cmd_table.py
9Variables        ../../data/dcmi_raw_cmd_table.py
10Variables        ../../data/ipmi_variable.py
11Library          ../../lib/bmc_network_utils.py
12Library          ../../lib/ipmi_utils.py
13Library          ../../lib/utilities.py
14Library          JSONLibrary
15
16Suite Setup  Suite Setup Execution
17
18Force Tags       DCMI_Get_Temperature_Reading
19
20*** Variables ***
21
22${config_file_name}             dcmi_sensors.json
23${dcmi_sensors_info_json_file}  /usr/share/ipmi-providers/${config_file_name}
24${client_config_file_path}      ${EXEC_DIR}/${config_file_name}
25&{dcmi_sensor_uri}
26
27*** Test Cases ***
28Verify Get Temperature Reading Command For Inlet Temperature Sensor
29    [Documentation]  Verify IPMI Get Temperature Reading command for inlet temperature sensor.
30    [Tags]  Verify_Get_Temperature_Reading_Command_For_Inlet_Temperature_Sensor
31
32    ${cmd}=  Catenate  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][0]}
33    ...  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][1]} 0x00 0x00
34    ${ipmi_resp}=  Run IPMI Command  ${cmd}
35    Verify Reading With IPMI  ${ipmi_resp}  ${1}  inlet
36    # Verify Temperature Reading With Dbus URI  ${ipmi_resp}  inlet  ${1}
37
38Verify Get Temperature Reading Command For CPU 0 Temperature Sensor
39    [Documentation]  Verify IPMI Get Temperature Reading command for cpu0 temperature sensor.
40    [Tags]  Verify_Get_Temperature_Reading_Command_For_CPU_0_Temperature_Sensor
41
42    ${cmd}=  Catenate  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][0]}
43    ...  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][2]} 0x00 0x00
44    ${ipmi_resp}=  Run IPMI Command  ${cmd}
45    Verify Reading With IPMI  ${ipmi_resp}  ${1}  cpu
46    # Verify Temperature Reading With Dbus URI  ${ipmi_resp}  cpu  ${1}
47
48Verify Get Temperature Reading Command For CPU 1 Temperature Sensor
49    [Documentation]  Verify IPMI Get Temperature Reading command for cpu1 temperature sensor.
50    [Tags]  Verify_Get_Temperature_Reading_Command_For_CPU_1_Temperature_Sensor
51
52    ${cmd}=  Catenate  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][0]}
53    ...  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][2]} 0x00 0x00
54    ${ipmi_resp}=  Run IPMI Command  ${cmd}
55    Verify Reading With IPMI  ${ipmi_resp}  ${2}  cpu
56    # Verify Temperature Reading With Dbus URI  ${ipmi_resp}  cpu  ${2}
57
58Verify Get Temperature Reading Command For Baseboard Temperature Sensor
59    [Documentation]  Verify IPMI Get Temperature Reading command for baseboard temperature sensor.
60    [Tags]  Verify_Get_Temperature_Reading_Command_For_Baseboard_Temperature_Sensor
61
62    ${cmd}=  Catenate  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][0]}
63    ...  ${DCMI_RAW_CMD['DCMI']['GET_TEMPERATURE_READING'][3]} 0x00 0x00
64    ${ipmi_resp}=  Run IPMI Command  ${cmd}
65    Verify Reading With IPMI  ${ipmi_resp}  ${1}  baseboard
66    # Verify Temperature Reading With Dbus URI  ${ipmi_resp}  baseboard  ${1}
67
68*** Keywords ***
69Suite Setup Execution
70    [Documentation]  Get dcmi sensors uri from config file.
71
72    IPMI Power On  stack_mode=skip  quiet=1
73
74    # Get this file to client machine /usr/share/ipmi-providers/dcmi_sensors.json
75    scp.Open Connection
76    ...  ${OPENBMC_HOST}  username=${OPENBMC_USERNAME}  password=${OPENBMC_PASSWORD}  port=${SSH_PORT}
77    scp.Get File  ${dcmi_sensors_info_json_file}  ${EXEC_DIR}
78    scp.Close Connection
79
80    ${config_file}=  OperatingSystem.Get File  ${client_config_file_path}
81    ${config_file_response}=  Evaluate  json.loads('''${config_file}''')  json
82
83    ${remove_configuration_file}=  Catenate  rm -rf ${client_config_file_path}
84    ${rc}  ${output}=  Shell Cmd  ${remove_configuration_file}
85
86    FOR  ${key}  ${value}  IN  &{config_file_response}
87      &{tmp}=  Create Dictionary
88      FOR  ${response}  IN  @{value}
89        ${sensor_dbus}=  Get From Dictionary  ${response}  dbus
90        ${instance}=  Get From Dictionary  ${response}  instance
91        Set To Dictionary  ${tmp}  ${instance}  ${sensor_dbus}
92      END
93      Set To Dictionary  ${dcmi_sensor_uri}  ${key}  ${tmp}
94    END
95
96Verify Temperature Reading With Dbus URI
97    [Documentation]  Verify temperature from ipmi response and json file.
98    [Arguments]  ${ipmi_resp}  ${key}  ${instance}
99
100    # Description of argument(s):
101    # ipmi_resp         IPMI command response.
102    # key               Entity ID description i.e inlet, cpu, baseboard.
103    # instance          instance number 1, 2, ..
104
105    ${dbus_uris}=  Get From Dictionary  ${dcmi_sensor_uri}  ${key}
106    ${dbus_uri}=  Get From Dictionary  ${dbus_uris}  ${instance}
107
108    ${get_reading_value}=  Set Variable If
109    ...  '${instance}' == '1'  ${3}
110    ...  '${instance}' == '2'  ${5}
111
112    ${ipmi_resp_list}=  Split String  ${ipmi_resp}
113    ${temperature_reading}=  Get From List  ${ipmi_resp_list}  ${get_reading_value}
114    ${temp_reading}=  Convert To Integer  ${temperature_reading}  16
115    ${busctl_cmd}=  Catenate  busctl introspect xyz.openbmc_project.HwmonTempSensor ${dbus_uri}
116    ${busctl_cmd_resp}=  BMC Execute Command  ${busctl_cmd}
117    ${current_temp_value_from_dbus}=  Get Regexp Matches  ${busctl_cmd_resp[0]}
118    ...  \\.Value\\s+property\\s+d\\s+(\\S+)\\s  1
119
120    ${min_value}=  Evaluate  ${temp_reading} - 1
121    ${max_value}=  Evaluate  ${temp_reading} + 1
122
123Check Reading Value In D-Bus
124    [Documentation]  Verify temperature from ipmi response and json file.
125    [Arguments]  ${key}  ${instance}  ${dcmi_reading_value}
126
127    # Description of argument(s):
128    # key               Entity ID description i.e inlet, cpu, baseboard.
129    # instance          instance number 1, 2, ..
130
131    ${dbus_uris}=  Get From Dictionary  ${dcmi_sensor_uri}  ${key}
132    ${dbus_uri}=  Get From Dictionary  ${dbus_uris}  ${instance}
133
134    ${busctl_cmd}=  Catenate  busctl introspect xyz.openbmc_project.HwmonTempSensor ${dbus_uri}
135    ${busctl_cmd_resp}=  BMC Execute Command  ${busctl_cmd}
136    ${current_temp_value_from_dbus}=  Get Regexp Matches  ${busctl_cmd_resp[0]}
137    ...  \\.Value\\s+property\\s+d\\s+(\\S+)\\s  1
138    Run Keyword If  '${current_temp_value_from_dbus[0]}' == 'nan' and '${dcmi_reading_value}' == '0'
139    ...  Fail  msg=sensor reading value is not present.
140    Run Keyword If  '${current_temp_value_from_dbus[0]}' != 'nan' and '${dcmi_reading_value}' == '0'
141    ...  Fail  msg=sensor reading value is showing as 0 in dcmi get temperature raw command.
142    ${dbus_reading_value}=  Set Variable  .${current_temp_value_from_dbus[0].split(".")[1].strip()}
143    ${status}=  Run Keyword And Return Status  Should Be True  ${dbus_reading_value} > .499
144    Run Keyword If  ${status} == False
145    ...  Fail  msg=sensor reading value is showing wrongly in dcmi get temperature raw command.
146    ${dbus_reading_value}=  Set Variable  ${current_temp_value_from_dbus[0].split(".")[0].strip()}
147    Should Be Equal  ${dcmi_reading_value}  ${dbus_reading_value}
148    ...  msg=sensor reading value is showing wrongly in dcmi get temperature raw command.
149
150Verify Reading With IPMI
151    [Documentation]  Verify temperature reading with ipmi command.
152    [Arguments]  ${ipmi_resp}  ${instance}  ${key}
153
154    # Description of argument(s):
155    # ipmi_resp         IPMI command response.
156    # instance          instance number 1, 2, ..
157    # key               Entity ID description i.e inlet, cpu, baseboard.
158
159    ${get_reading_value}=  Set Variable If
160    ...  '${instance}' == '1'  ${3}
161    ...  '${instance}' == '2'  ${5}
162
163    ${ipmi_resp_list}=  Split String  ${ipmi_resp}
164    ${temperature_reading}=  Get From List  ${ipmi_resp_list}  ${get_reading_value}
165    ${dcmi_reading}=  Convert To Integer  ${temperature_reading}  16
166    Run Keyword If  '${dcmi_reading}' == '0'
167    ...  Check Reading Value In D-Bus  ${key}  ${instance}  ${dcmi_reading}
168    ${dcmi_temp_reading}=  Convert To String  ${dcmi_reading}
169    ${ipmi_sensor_cmd_resp}=  Get IPMI Sensor Reading  ${key}  ${instance}
170    ${ipmi_sensor_cmd_resp_list}=  Split String  ${ipmi_sensor_cmd_resp}  |
171    ${ipmi_temp_reading}=  Set Variable  ${ipmi_sensor_cmd_resp_list[1].strip().split(".")[0]}
172    ${reading_status}=  Run Keyword And Return Status  Should Be Equal
173    ...  ${dcmi_temp_reading}  ${ipmi_temp_reading}
174    Run Keyword If  ${reading_status} == False
175    ...  Check Reading Value In D-Bus  ${key}  ${instance}  ${dcmi_temp_reading}
176
177Get IPMI Sensor Reading
178    [Documentation]  Return ipmi sensor reading.
179    [Arguments]  ${key}  ${instance}
180
181    # Description of argument(s):
182    # instance          Entity ID description i.e inlet, cpu, baseboard.
183    # index             Selecting the corresponding sensor dbus uri from list.
184
185    ${dbus_uris}=  Get From Dictionary  ${dcmi_sensor_uri}  ${key}
186    ${dbus_uri}=  Get From Dictionary  ${dbus_uris}  ${instance}
187    ${sensor_name}=  Set Variable  ${dbus_uri.split('/')[-1]}
188
189    ${sensor_format}=  Run IPMI Standard Command  sensor
190    ${sensor_name_status}=  Run Keyword And Return Status  Should Contain
191    ...  ${sensor_format}  _
192
193    ${sensor_name}=  Run Keyword If  ${sensor_name_status} == True
194    ...    Set Variable  ${sensor_name_dbus}
195    ...  ELSE
196    ...    Replace String  ${sensor_name}  _  ${SPACE}
197
198    ${ret}=  Run External IPMI Standard Command  sensor | grep -i "${sensor_name}"
199
200    [Return]  ${ret}
201