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