From 8c4fd2b73bef726a99107cd495725dcbb0c2e28a Mon Sep 17 00:00:00 2001 From: Volodymyr Boiko <66446128+vboykox@users.noreply.github.com> Date: Wed, 24 Feb 2021 19:42:18 +0200 Subject: [PATCH] [barefoot][platform] Refactor legacy scripts (#6871) Removed or adapted obsolete code Signed-off-by: Volodymyr Boyko --- .../scripts/bf-fancontrol | 3 + .../scripts/bf-sfputil | 10 ---- .../scripts/eeprom | 10 ---- .../scripts/fancontrol | 11 ---- .../scripts/ps_info | 10 ---- .../scripts/sensors | 5 +- .../scripts/test | 1 - .../setup.py | 3 +- .../sonic_platform/bfn_extensions/__init__.py | 4 ++ .../bfn_extensions/platform_fancontrol.py | 59 +++++++++++++++++++ .../bfn_extensions/platform_sensors.py | 26 ++++++++ .../scripts | 1 + .../scripts/bf-sfputil | 10 ---- .../scripts/eeprom | 10 ---- .../scripts/fancontrol | 11 ---- .../scripts/ps_info | 10 ---- .../scripts/sensors | 12 ---- .../scripts/test | 1 - .../sonic-platform-modules-bfn/scripts | 1 + .../scripts/bf-sfputil | 10 ---- .../sonic-platform-modules-bfn/scripts/eeprom | 10 ---- .../scripts/fancontrol | 11 ---- .../scripts/ps_info | 10 ---- .../scripts/sensors | 12 ---- .../sonic-platform-modules-bfn/scripts/test | 1 - 25 files changed, 98 insertions(+), 154 deletions(-) create mode 100755 platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-fancontrol delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-sfputil delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-montara/scripts/eeprom delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-montara/scripts/fancontrol delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-montara/scripts/ps_info delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-montara/scripts/test create mode 100644 platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/__init__.py create mode 100644 platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_fancontrol.py create mode 100644 platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_sensors.py create mode 120000 platform/barefoot/sonic-platform-modules-bfn-newport/scripts delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-newport/scripts/bf-sfputil delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-newport/scripts/eeprom delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-newport/scripts/fancontrol delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-newport/scripts/ps_info delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-newport/scripts/sensors delete mode 100755 platform/barefoot/sonic-platform-modules-bfn-newport/scripts/test create mode 120000 platform/barefoot/sonic-platform-modules-bfn/scripts delete mode 100755 platform/barefoot/sonic-platform-modules-bfn/scripts/bf-sfputil delete mode 100755 platform/barefoot/sonic-platform-modules-bfn/scripts/eeprom delete mode 100755 platform/barefoot/sonic-platform-modules-bfn/scripts/fancontrol delete mode 100755 platform/barefoot/sonic-platform-modules-bfn/scripts/ps_info delete mode 100755 platform/barefoot/sonic-platform-modules-bfn/scripts/sensors delete mode 100755 platform/barefoot/sonic-platform-modules-bfn/scripts/test diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-fancontrol b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-fancontrol new file mode 100755 index 0000000000..7407c2d724 --- /dev/null +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-fancontrol @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 -m sonic_platform.bfn_extensions.platform_fancontrol "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-sfputil b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-sfputil deleted file mode 100755 index 3df67614e4..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/bf-sfputil +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd sfputil "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/eeprom b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/eeprom deleted file mode 100755 index 07d98556cb..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/eeprom +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd eeprom "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/fancontrol b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/fancontrol deleted file mode 100755 index 515fcbdd69..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/fancontrol +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd fancontrol "$@" - diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/ps_info b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/ps_info deleted file mode 100755 index 38c9d33304..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/ps_info +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd ps_info "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/sensors b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/sensors index 07af695532..5f06a9c99b 100755 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/sensors +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/sensors @@ -7,6 +7,5 @@ if [ -t 1 ] ; then DOCKER_EXEC_FLAGS+="t" fi -docker exec -$DOCKER_EXEC_FLAGS syncd sensors "$@" - - +python3 -m sonic_platform.bfn_extensions.platform_sensors "$@" +docker exec -$DOCKER_EXEC_FLAGS pmon sensors "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/test b/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/test deleted file mode 100755 index 38327722c9..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/scripts/test +++ /dev/null @@ -1 +0,0 @@ -echo "test" diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/setup.py b/platform/barefoot/sonic-platform-modules-bfn-montara/setup.py index fc14c94ac4..14e1bb6b6c 100755 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/setup.py +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/setup.py @@ -12,7 +12,8 @@ setup( maintainer_email='', packages=[ 'sonic_platform', - 'sonic_platform/pltfm_mgr_rpc' + 'sonic_platform/pltfm_mgr_rpc', + 'sonic_platform/bfn_extensions', ], package_data = {'sonic_platform':['logging.conf']}, classifiers=[ diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/__init__.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/__init__.py new file mode 100644 index 0000000000..67517a64e8 --- /dev/null +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/__init__.py @@ -0,0 +1,4 @@ +__all__ = [ + 'platform_sensors', + 'platform_fancontrol', +] diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_fancontrol.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_fancontrol.py new file mode 100644 index 0000000000..43a700c21d --- /dev/null +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_fancontrol.py @@ -0,0 +1,59 @@ +import sys + +from sonic_platform.platform_thrift_client import thrift_try + +_MAX_FAN = 10 + +def fan_speed_set(fan, percent): + def set_fan_speed(client): + return client.pltfm_mgr.pltfm_mgr_fan_speed_set(fan, percent) + return thrift_try(set_fan_speed) + +def fan_speed_info_get(): + for fan_num in range(1, _MAX_FAN + 1): + def get_data(client, fan_num=fan_num): + return client.pltfm_mgr.pltfm_mgr_fan_info_get(fan_num) + fan_info = thrift_try(get_data) + if fan_info.fan_num == fan_num: + yield fan_info + +if __name__ == '__main__': + def print_usage(): + print("Usage: platform_fancontrol.py ", file=sys.stderr) + print(" function: fan_speed_set ", file=sys.stderr) + print(" fan_speed_info_get ", file=sys.stderr) + + argc = len(sys.argv) + if argc == 1: + print_usage() + exit(0) + + if sys.argv[1] == "fan_speed_set": + if argc != 4: + print_usage() + exit(0) + + fan = int(sys.argv[2]) + percent = int(sys.argv[3]) + + if (fan > _MAX_FAN) | (fan < 0): + print("Invalid value for fan #.\n", file=sys.stderr) + print_usage() + exit(0) + + if (percent > 100) | (percent < 0): + print("Invalid value for precent\n", file=sys.stderr) + print_usage() + exit(0) + + fan_speed_set(fan, percent) + exit(0) + + if sys.argv[1] == "fan_speed_info_get": + for fan_info in fan_speed_info_get(): + print("fan number: %d front rpm: %d rear rpm: %d percent: %d%% " % + (fan_info.fan_num, fan_info.front_rpm, fan_info.rear_rpm, fan_info.percent)) + + exit(0) + + print_usage() diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_sensors.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_sensors.py new file mode 100644 index 0000000000..330884ca73 --- /dev/null +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/bfn_extensions/platform_sensors.py @@ -0,0 +1,26 @@ +import sys +import codecs +import urllib + +from sonic_platform.platform_thrift_client import thrift_try + +def platform_sensors_get(args): + options = "" + if len(args)!=0: + options = urllib.quote(" ".join(args)) + def get_data(client): + return client.pltfm_mgr.pltfm_mgr_sensor_info_get(options) + raw_out = thrift_try(get_data) + raw_list = raw_out.split('\"') + if len(raw_list) >= 2: + sensors_out = raw_list[1] + sensors_out = codecs.decode(sensors_out, "unicode_escape") + return sensors_out + return None + +if __name__ == '__main__': + data = platform_sensors_get(sys.argv[1:]) + if data: + print(data) + else: + print("No sensors info available", file=sys.stderr) diff --git a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts new file mode 120000 index 0000000000..14008f0618 --- /dev/null +++ b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts @@ -0,0 +1 @@ +../sonic-platform-modules-bfn-montara/scripts \ No newline at end of file diff --git a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/bf-sfputil b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/bf-sfputil deleted file mode 100755 index 3df67614e4..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/bf-sfputil +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd sfputil "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/eeprom b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/eeprom deleted file mode 100755 index 07d98556cb..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/eeprom +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd eeprom "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/fancontrol b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/fancontrol deleted file mode 100755 index 515fcbdd69..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/fancontrol +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd fancontrol "$@" - diff --git a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/ps_info b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/ps_info deleted file mode 100755 index 38c9d33304..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/ps_info +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd ps_info "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/sensors b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/sensors deleted file mode 100755 index 07af695532..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/sensors +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd sensors "$@" - - diff --git a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/test b/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/test deleted file mode 100755 index 38327722c9..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-newport/scripts/test +++ /dev/null @@ -1 +0,0 @@ -echo "test" diff --git a/platform/barefoot/sonic-platform-modules-bfn/scripts b/platform/barefoot/sonic-platform-modules-bfn/scripts new file mode 120000 index 0000000000..14008f0618 --- /dev/null +++ b/platform/barefoot/sonic-platform-modules-bfn/scripts @@ -0,0 +1 @@ +../sonic-platform-modules-bfn-montara/scripts \ No newline at end of file diff --git a/platform/barefoot/sonic-platform-modules-bfn/scripts/bf-sfputil b/platform/barefoot/sonic-platform-modules-bfn/scripts/bf-sfputil deleted file mode 100755 index 3df67614e4..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn/scripts/bf-sfputil +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd sfputil "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn/scripts/eeprom b/platform/barefoot/sonic-platform-modules-bfn/scripts/eeprom deleted file mode 100755 index 07d98556cb..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn/scripts/eeprom +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd eeprom "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn/scripts/fancontrol b/platform/barefoot/sonic-platform-modules-bfn/scripts/fancontrol deleted file mode 100755 index 515fcbdd69..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn/scripts/fancontrol +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd fancontrol "$@" - diff --git a/platform/barefoot/sonic-platform-modules-bfn/scripts/ps_info b/platform/barefoot/sonic-platform-modules-bfn/scripts/ps_info deleted file mode 100755 index 38c9d33304..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn/scripts/ps_info +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd ps_info "$@" diff --git a/platform/barefoot/sonic-platform-modules-bfn/scripts/sensors b/platform/barefoot/sonic-platform-modules-bfn/scripts/sensors deleted file mode 100755 index 07af695532..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn/scripts/sensors +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - -docker exec -$DOCKER_EXEC_FLAGS syncd sensors "$@" - - diff --git a/platform/barefoot/sonic-platform-modules-bfn/scripts/test b/platform/barefoot/sonic-platform-modules-bfn/scripts/test deleted file mode 100755 index 38327722c9..0000000000 --- a/platform/barefoot/sonic-platform-modules-bfn/scripts/test +++ /dev/null @@ -1 +0,0 @@ -echo "test"