From bfe8894c25ae464f774b4f3e899e727270baafa4 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 15 Dec 2016 14:35:56 -0800 Subject: [PATCH] Use the new common ONIE syseeprom and machine.conf infrastructure. The ONL platform base class supports extracting, parsing, and caching the contents of the ONIE machine.conf file and the TLVs in the ONIE system eeprom. The mellanox platforms that rely on this information now request it from the common baseclass and use the common ONIE JSON parsing infrastructure to populate the onie_info structure in the SYSI implementation. --- .../src/python/mellanox/__init__.py | 12 ++ .../onlp/builds/src/module/src/sysi.c | 147 +---------------- .../python/x86_64_mlnx_msn2100_r0/__init__.py | 4 +- .../onlp/builds/src/module/src/sysi.c | 147 +---------------- .../python/x86_64_mlnx_msn2410_r0/__init__.py | 4 +- .../onlp/builds/src/module/src/sysi.c | 150 ------------------ .../python/x86_64_mlnx_msn2700_r0/__init__.py | 4 +- 7 files changed, 23 insertions(+), 445 deletions(-) diff --git a/packages/platforms/mellanox/vendor-config/src/python/mellanox/__init__.py b/packages/platforms/mellanox/vendor-config/src/python/mellanox/__init__.py index 2d089e30..56cd4d71 100644 --- a/packages/platforms/mellanox/vendor-config/src/python/mellanox/__init__.py +++ b/packages/platforms/mellanox/vendor-config/src/python/mellanox/__init__.py @@ -5,3 +5,15 @@ from onl.platform.base import * class OnlPlatformMellanox(OnlPlatformBase): MANUFACTURER='Mellanox' PRIVATE_ENTERPRISE_NUMBER=33049 + + # + # Some platforms rely on the output of the onie-syseeprom tool + # and the machine.conf file to implement parts of ONLP. + # + def syseeprom_export(self): + print "Caching ONIE System EEPROM..." + onie = self.onie_syseeprom_get() + mc = self.onie_machine_get() + if 'onie_version' in mc: + onie['0x29'] = mc['onie_version'] + self.onie_syseeprom_set(onie) diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c index 74b17de7..e104052c 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c @@ -48,30 +48,6 @@ static char arr_cplddev_name[NUM_OF_CPLD][30] = "cpld_mgmt_version" }; -static void -_onlp_sysi_execute_command(char *command, char buffer[COMMAND_OUTPUT_BUFFER]) -{ - FILE *fp = NULL; - - /* Open the command for reading. */ - fp = popen(command, "r"); - if (NULL == fp) { - AIM_LOG_WARN("Failed to run command '%s'\n", command); - } - - /* Read the output */ - if (fgets(buffer, COMMAND_OUTPUT_BUFFER-1, fp) == NULL) { - AIM_LOG_WARN("Failed to read output of command '%s'\n", command); - pclose(fp); - } - - /* The last symbol is '\n', so remote it */ - buffer[strnlen(buffer, COMMAND_OUTPUT_BUFFER) - 1] = '\0'; - - /* close */ - pclose(fp); -} - const char* onlp_sysi_platform_get(void) { @@ -131,128 +107,11 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max) return 0; } -static int -_onlp_sysi_grep_output(char value[256], const char *attr, const char *tmp_file) -{ - int value_offset = 30; /* value offset in onie-syseeprom */ - char command[256] = {0}; - char buffer[COMMAND_OUTPUT_BUFFER] = {0}; - int v = 0; - - snprintf(command, sizeof(command), "cat '%s' | grep '%s'", tmp_file, attr); - _onlp_sysi_execute_command(command, buffer); - - /* Reading value from buffer with command output */ - while (buffer[value_offset] != '\n' && - buffer[value_offset] != '\r' && - buffer[value_offset] != '\0') { - value[v] = buffer[value_offset]; - v++; - value_offset++; - } - value[v] = '\0'; - - AIM_LOG_VERBOSE("Value for sytem attribute '%s' is '%s' \n", attr, value); - - return ONLP_STATUS_OK; -} +#include int onlp_sysi_onie_info_get(onlp_onie_info_t* onie) { - - const char onie_version_file[] = "/bsp/onie-version"; - const char onie_version_command[] = "onie-shell -c 'onie-sysinfo -v' > /bsp/onie-version"; - const char onie_syseeprom_file[] = "/bsp/onie-syseeprom"; - const char onie_syseeprom_command[] = "onie-shell -c onie-syseeprom > /bsp/onie-syseeprom"; - struct stat stat_buf; - char value[256] = {0}; - char command[256] = {0}; - int rc = 0; - int exit_status; - - /* We must initialize this otherwise crash occurs while free memory */ - list_init(&onie->vx_list); - - /* Check if cache file exist */ - rc = stat(onie_syseeprom_file, &stat_buf); - if (-1 == rc) { - rc = system(onie_syseeprom_command); - if (-1 == rc) { - return rc; - } - exit_status = WEXITSTATUS(rc); - if (EXIT_SUCCESS != exit_status) { - return ONLP_STATUS_E_GENERIC; - } - } - - rc = _onlp_sysi_grep_output(value, "Product Name", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->product_name = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Part Number", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->part_number = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Serial Number", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->serial_number = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Base MAC Address", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - strncpy((char*)onie->mac, value, sizeof(onie->mac)); - rc = _onlp_sysi_grep_output(value, "Manufacture Date", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacture_date = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Device Version", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->device_version = atoi(value); - rc = _onlp_sysi_grep_output(value, "Manufacturer", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacturer = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Manufacturer", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacturer = aim_strdup(value); - onie->vendor = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "MAC Addresses", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->mac_range = atoi(value); - /* Check if onie version first run and cache file exist */ - rc = stat(onie_version_file, &stat_buf); - if (-1 == rc) - { - rc = system(onie_version_command); - if (-1 == rc) { - return rc; - } - exit_status = WEXITSTATUS(rc); - if (EXIT_SUCCESS != exit_status) { - return ONLP_STATUS_E_GENERIC; - }} - snprintf(command, sizeof(command), "cat '%s'", onie_version_file); - _onlp_sysi_execute_command(command, value); - /* ONIE version */ - onie->onie_version = aim_strdup(value); - - /* Platform name */ - onie->platform_name = aim_strdup("x86_64-mlnx_msn2100-r0"); - - return ONLP_STATUS_OK; + return onlp_onie_read_json(onie, + "/lib/platform-config/current/onl/etc/onie/eeprom.json"); } - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/platform-config/r0/src/python/x86_64_mlnx_msn2100_r0/__init__.py b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/platform-config/r0/src/python/x86_64_mlnx_msn2100_r0/__init__.py index 07c284ea..f7e82a25 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/platform-config/r0/src/python/x86_64_mlnx_msn2100_r0/__init__.py +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/platform-config/r0/src/python/x86_64_mlnx_msn2100_r0/__init__.py @@ -10,8 +10,8 @@ class OnlPlatform_x86_64_mlnx_msn2100_r0(OnlPlatformMellanox, def baseconfig(self): # load modules import os - # necessary if there are issues with the install + # necessary if there are issues with the install # os.system("/usr/bin/apt-get install") os.system("/etc/mlnx/mlnx-hw-management start") - + self.syseeprom_export(); return True diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c index 5ad5efd1..157396a6 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c @@ -52,30 +52,6 @@ static char arr_cplddev_name[NUM_OF_CPLD][30] = "cpld_port_version" }; -static void -_onlp_sysi_execute_command(char *command, char buffer[COMMAND_OUTPUT_BUFFER]) -{ - FILE *fp = NULL; - - /* Open the command for reading. */ - fp = popen(command, "r"); - if (NULL == fp) { - AIM_LOG_WARN("Failed to run command '%s'\n", command); - } - - /* Read the output */ - if (fgets(buffer, COMMAND_OUTPUT_BUFFER-1, fp) == NULL) { - AIM_LOG_WARN("Failed to read output of command '%s'\n", command); - pclose(fp); - } - - /* The last symbol is '\n', so remote it */ - buffer[strnlen(buffer, COMMAND_OUTPUT_BUFFER) - 1] = '\0'; - - /* close */ - pclose(fp); -} - const char* onlp_sysi_platform_get(void) { @@ -139,128 +115,9 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max) return 0; } -static int -_onlp_sysi_grep_output(char value[256], const char *attr, const char *tmp_file) -{ - int value_offset = 30; /* value offset in onie-syseeprom */ - char command[256] = {0}; - char buffer[COMMAND_OUTPUT_BUFFER] = {0}; - int v = 0; - - snprintf(command, sizeof(command), "cat '%s' | grep '%s'", tmp_file, attr); - _onlp_sysi_execute_command(command, buffer); - - /* Reading value from buffer with command output */ - while (buffer[value_offset] != '\n' && - buffer[value_offset] != '\r' && - buffer[value_offset] != '\0') { - value[v] = buffer[value_offset]; - v++; - value_offset++; - } - value[v] = '\0'; - - AIM_LOG_VERBOSE("Value for sytem attribute '%s' is '%s' \n", attr, value); - - return ONLP_STATUS_OK; -} - int onlp_sysi_onie_info_get(onlp_onie_info_t* onie) { - - const char onie_version_file[] = "/bsp/onie-version"; - const char onie_version_command[] = "onie-shell -c 'onie-sysinfo -v' > /bsp/onie-version"; - const char onie_syseeprom_file[] = "/bsp/onie-syseeprom"; - const char onie_syseeprom_command[] = "onie-shell -c onie-syseeprom > /bsp/onie-syseeprom"; - struct stat stat_buf; - char value[256] = {0}; - char command[256] = {0}; - int rc = 0; - int exit_status; - - /* We must initialize this otherwise crash occurs while free memory */ - list_init(&onie->vx_list); - - /* Check if cache file exist */ - rc = stat(onie_syseeprom_file, &stat_buf); - if (-1 == rc) { - rc = system(onie_syseeprom_command); - if (-1 == rc) { - return rc; - } - exit_status = WEXITSTATUS(rc); - if (EXIT_SUCCESS != exit_status) { - return ONLP_STATUS_E_GENERIC; - } - } - - rc = _onlp_sysi_grep_output(value, "Product Name", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->product_name = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Part Number", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->part_number = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Serial Number", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->serial_number = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Base MAC Address", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - strncpy((char*)onie->mac, value, sizeof(onie->mac)); - rc = _onlp_sysi_grep_output(value, "Manufacture Date", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacture_date = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Device Version", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->device_version = atoi(value); - rc = _onlp_sysi_grep_output(value, "Manufacturer", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacturer = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Manufacturer", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacturer = aim_strdup(value); - onie->vendor = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "MAC Addresses", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->mac_range = atoi(value); - /* Check if onie version first run and cache file exist */ - rc = stat(onie_version_file, &stat_buf); - if (-1 == rc) - { - rc = system(onie_version_command); - if (-1 == rc) { - return rc; - } - exit_status = WEXITSTATUS(rc); - if (EXIT_SUCCESS != exit_status) { - return ONLP_STATUS_E_GENERIC; - }} - snprintf(command, sizeof(command), "cat '%s'", onie_version_file); - _onlp_sysi_execute_command(command, value); - /* ONIE version */ - onie->onie_version = aim_strdup(value); - - /* Platform name */ - onie->platform_name = aim_strdup("x86_64-mlnx_msn2410-r0"); - - return ONLP_STATUS_OK; + return onlp_onie_read_json(onie, + "/lib/platform-config/current/onl/etc/onie/eeprom.json"); } - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/platform-config/r0/src/python/x86_64_mlnx_msn2410_r0/__init__.py b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/platform-config/r0/src/python/x86_64_mlnx_msn2410_r0/__init__.py index 5fea9592..88e38724 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/platform-config/r0/src/python/x86_64_mlnx_msn2410_r0/__init__.py +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/platform-config/r0/src/python/x86_64_mlnx_msn2410_r0/__init__.py @@ -10,8 +10,8 @@ class OnlPlatform_x86_64_mlnx_msn2410_r0(OnlPlatformMellanox, def baseconfig(self): # load modules import os - # necessary if there are issues with the install + # necessary if there are issues with the install # os.system("/usr/bin/apt-get install") os.system("/etc/mlnx/mlnx-hw-management start") - + self.syseeprom_export(); return True diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c index 89b806be..b9b22ede 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c @@ -52,30 +52,6 @@ static char arr_cplddev_name[NUM_OF_CPLD][30] = "cpld_port_version" }; -static void -_onlp_sysi_execute_command(char *command, char buffer[COMMAND_OUTPUT_BUFFER]) -{ - FILE *fp = NULL; - - /* Open the command for reading. */ - fp = popen(command, "r"); - if (NULL == fp) { - AIM_LOG_WARN("Failed to run command '%s'\n", command); - } - - /* Read the output */ - if (fgets(buffer, COMMAND_OUTPUT_BUFFER-1, fp) == NULL) { - AIM_LOG_WARN("Failed to read output of command '%s'\n", command); - pclose(fp); - } - - /* The last symbol is '\n', so remote it */ - buffer[strnlen(buffer, COMMAND_OUTPUT_BUFFER) - 1] = '\0'; - - /* close */ - pclose(fp); -} - const char* onlp_sysi_platform_get(void) { @@ -138,129 +114,3 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max) return 0; } - -static int -_onlp_sysi_grep_output(char value[256], const char *attr, const char *tmp_file) -{ - int value_offset = 30; /* value offset in onie-syseeprom */ - char command[256] = {0}; - char buffer[COMMAND_OUTPUT_BUFFER] = {0}; - int v = 0; - - snprintf(command, sizeof(command), "cat '%s' | grep '%s'", tmp_file, attr); - _onlp_sysi_execute_command(command, buffer); - - /* Reading value from buffer with command output */ - while (buffer[value_offset] != '\n' && - buffer[value_offset] != '\r' && - buffer[value_offset] != '\0') { - value[v] = buffer[value_offset]; - v++; - value_offset++; - } - value[v] = '\0'; - - AIM_LOG_VERBOSE("Value for sytem attribute '%s' is '%s' \n", attr, value); - - return ONLP_STATUS_OK; -} - -int -onlp_sysi_onie_info_get(onlp_onie_info_t* onie) -{ - - const char onie_version_file[] = "/bsp/onie-version"; - const char onie_version_command[] = "onie-shell -c 'onie-sysinfo -v' > /bsp/onie-version"; - const char onie_syseeprom_file[] = "/bsp/onie-syseeprom"; - const char onie_syseeprom_command[] = "onie-shell -c onie-syseeprom > /bsp/onie-syseeprom"; - struct stat stat_buf; - char value[256] = {0}; - char command[256] = {0}; - int rc = 0; - int exit_status; - - /* We must initialize this otherwise crash occurs while free memory */ - list_init(&onie->vx_list); - - /* Check if cache file exist */ - rc = stat(onie_syseeprom_file, &stat_buf); - if (-1 == rc) { - rc = system(onie_syseeprom_command); - if (-1 == rc) { - return rc; - } - exit_status = WEXITSTATUS(rc); - if (EXIT_SUCCESS != exit_status) { - return ONLP_STATUS_E_GENERIC; - } - } - - rc = _onlp_sysi_grep_output(value, "Product Name", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->product_name = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Part Number", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->part_number = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Serial Number", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->serial_number = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Base MAC Address", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - strncpy((char*)onie->mac, value, sizeof(onie->mac)); - rc = _onlp_sysi_grep_output(value, "Manufacture Date", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacture_date = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Device Version", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->device_version = atoi(value); - rc = _onlp_sysi_grep_output(value, "Manufacturer", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacturer = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "Manufacturer", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->manufacturer = aim_strdup(value); - onie->vendor = aim_strdup(value); - rc = _onlp_sysi_grep_output(value, "MAC Addresses", onie_syseeprom_file); - if (ONLP_STATUS_OK != rc) { - return rc; - } - onie->mac_range = atoi(value); - /* Check if onie version first run and cache file exist */ - rc = stat(onie_version_file, &stat_buf); - if (-1 == rc) - { - rc = system(onie_version_command); - if (-1 == rc) { - return rc; - } - exit_status = WEXITSTATUS(rc); - if (EXIT_SUCCESS != exit_status) { - return ONLP_STATUS_E_GENERIC; - }} - snprintf(command, sizeof(command), "cat '%s'", onie_version_file); - _onlp_sysi_execute_command(command, value); - /* ONIE version */ - onie->onie_version = aim_strdup(value); - - /* Platform name */ - onie->platform_name = aim_strdup("x86_64-mlnx_msn2700-r0"); - - return ONLP_STATUS_OK; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/platform-config/r0/src/python/x86_64_mlnx_msn2700_r0/__init__.py b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/platform-config/r0/src/python/x86_64_mlnx_msn2700_r0/__init__.py index 4e52aa01..c12120d1 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/platform-config/r0/src/python/x86_64_mlnx_msn2700_r0/__init__.py +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/platform-config/r0/src/python/x86_64_mlnx_msn2700_r0/__init__.py @@ -10,8 +10,8 @@ class OnlPlatform_x86_64_mlnx_msn2700_r0(OnlPlatformMellanox, def baseconfig(self): # load modules import os - # necessary if there are issues with the install + # necessary if there are issues with the install # os.system("/usr/bin/apt-get install") os.system("/etc/mlnx/mlnx-hw-management start") - + self.syseeprom_export(); return True