ganesanb | c288aff | 2022-05-19 19:55:47 +0530 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Implemented keywords to execute DBUS related commands on BMC. |
| 3 | |
| 4 | Resource resource.robot |
| 5 | Library OperatingSystem |
| 6 | Library Collections |
| 7 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 8 | *** Variables *** |
ganesanb | c288aff | 2022-05-19 19:55:47 +0530 | [diff] [blame] | 9 | |
| 10 | ${BUSCTL_TREE_COMMAND} busctl tree | less |
| 11 | ${BUSCTL_INTROSPECT_COMMAND} busctl introspect |
| 12 | @{dbus_uri_list} |
| 13 | |
| 14 | *** Keywords *** |
| 15 | |
| 16 | Get DBUS URI List From BMC |
| 17 | [Documentation] Get the available DBUS URIs from device tree on BMC. |
| 18 | [Arguments] ${service_name} ${dbus_url} |
| 19 | |
| 20 | # Return the dbus uris corresponding to the service name provided. |
| 21 | # Description of argument(s): |
| 22 | # service_name Any service uri of the dbus. |
| 23 | # Eg : xyz.openbmc_project.FruDevice |
| 24 | # dbus_url Any dbus url of the dbus. |
| 25 | # Eg : /xyz/openbmc_project/FruDevice |
| 26 | |
| 27 | # Execute dbus tree command |
| 28 | ${bmc_response}= BMC Execute Command ${BUSCTL_TREE_COMMAND} |
| 29 | ${bmc_response}= Convert To List ${bmc_response} |
| 30 | ${bmc_response_output}= Get From List ${bmc_response} 0 |
| 31 | ${bmc_response_output_list}= Split String ${bmc_response_output} \n\n |
| 32 | # Identify the offset of the service name in the response. |
| 33 | ${service_name_index_value}= get_subsequent_value_from_list ${bmc_response_output_list} ${service_name} |
| 34 | ${service_name_index_value}= Get From List ${service_name_index_value} 0 |
| 35 | |
| 36 | # Get the service name and its corresponding URI's. |
| 37 | ${service_name_with_uri_list}= Get From List ${bmc_response_output_list} ${service_name_index_value} |
| 38 | ${service_name_with_uri_list}= Split String ${service_name_with_uri_list} \n |
| 39 | |
| 40 | # Find index of all the uris where the dbus URI matched. |
| 41 | ${uri_list_index}= get_subsequent_value_from_list ${service_name_with_uri_list} ${dbus_url} |
| 42 | FOR ${list_index} IN @{uri_list_index} |
| 43 | # For each index, get the URI and append to list |
| 44 | ${dbus_uri}= Get From List ${service_name_with_uri_list} ${list_index} |
| 45 | Append To List ${dbus_uri_list} ${dbus_uri} |
| 46 | END |
| 47 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 48 | RETURN ${dbus_uri_list[1:]} |
ganesanb | c288aff | 2022-05-19 19:55:47 +0530 | [diff] [blame] | 49 | |
| 50 | |
| 51 | Fetch DBUS URI List Without Unicode |
| 52 | [Documentation] Gets the list of DBUS URI for the service and returns only sub URIs. |
| 53 | [Arguments] ${dbus_uri_list} |
| 54 | |
| 55 | # Return the dbus uris list without the unicodes. |
| 56 | # Description of argument(s): |
| 57 | # dbus_uri_list List of all the uris for the corresponding service name. |
| 58 | # Example: Converts " ├─/xyz/openbmc_project/FruDevice/device_0", |
| 59 | # ... to '/xyz/openbmc_project/FruDevice/device_0' |
| 60 | |
| 61 | @{dbus_list}= Create List |
| 62 | FOR ${item} IN @{dbus_uri_list} |
| 63 | ${item}= Set Variable ${item.strip()} |
ganesanb | 07958e1 | 2023-04-26 05:38:22 -0700 | [diff] [blame] | 64 | ${item}= Remove Unicode From Uri ${item} |
ganesanb | c288aff | 2022-05-19 19:55:47 +0530 | [diff] [blame] | 65 | Append To List ${dbus_list} ${item} |
| 66 | END |
| 67 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 68 | RETURN ${dbus_list} |
ganesanb | c288aff | 2022-05-19 19:55:47 +0530 | [diff] [blame] | 69 | |
| 70 | |
| 71 | Execute DBUS Introspect Command |
| 72 | [Documentation] Execute the DBUS introspect command and return response. |
| 73 | [Arguments] ${dbus_command} |
| 74 | |
| 75 | # Execute the busctl instrospect command for the service name and dbus uri. |
| 76 | # Description of argument(s): |
| 77 | # dbus_command Command with service name and dbus uri for the fru device. |
| 78 | # Example : xyz.openbmc_project.FruDevice xyz/openbmc_project/FruDevice/device_0 |
| 79 | |
| 80 | ${cmd}= Catenate ${BUSCTL_INTROSPECT_COMMAND} ${dbus_command} |
| 81 | ${resp}= BMC Execute Command ${cmd} |
| 82 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 83 | RETURN ${resp[0]} |