From 1da68a14070bf2718739841898ac5d18fe3430e8 Mon Sep 17 00:00:00 2001 From: andrii savka Date: Tue, 17 Oct 2017 14:40:21 +0300 Subject: [PATCH 1/7] Added PSU util for Mellanox platforms --- .../x86_64-mlnx_msn2100-r0/plugins/psuutil.py | 68 +++++++++++++++++++ .../x86_64-mlnx_msn2410-r0/plugins/psuutil.py | 68 +++++++++++++++++++ .../x86_64-mlnx_msn2700-r0/plugins/psuutil.py | 68 +++++++++++++++++++ .../x86_64-mlnx_msn2740-r0/plugins/psuutil.py | 68 +++++++++++++++++++ dockers/docker-snmp-sv2/Dockerfile.j2 | 9 ++- rules/docker-snmp-sv2.mk | 2 +- 6 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py create mode 100644 device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py create mode 100644 device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py create mode 100644 device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py new file mode 100644 index 000000000000..e195fa13d0bd --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +############################################################################# +# Mellanox +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError, e: + raise ImportError (str(e) + "- required module not found") + +class PSUutil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_path = "/sys/bus/i2c/devices/2-0060/" + self.psu_presence = "psu{}_status" + self.psu_oper_status = "psu{}_pg_status" + + def get_num_psus(self): + """ + Retrieves the number of PSUs available on the device + + :return: An integer, the number of PSUs available on the device + """ + return 2 + + def get_psu_status(self, index): + """ + Retrieves the oprational status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is operating properly, False if PSU is faulty + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + + return status == 1 + + def get_psu_presence(self, index): + """ + Retrieves the presence status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is plugged, False if not + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + + return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py new file mode 100644 index 000000000000..e195fa13d0bd --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +############################################################################# +# Mellanox +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError, e: + raise ImportError (str(e) + "- required module not found") + +class PSUutil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_path = "/sys/bus/i2c/devices/2-0060/" + self.psu_presence = "psu{}_status" + self.psu_oper_status = "psu{}_pg_status" + + def get_num_psus(self): + """ + Retrieves the number of PSUs available on the device + + :return: An integer, the number of PSUs available on the device + """ + return 2 + + def get_psu_status(self, index): + """ + Retrieves the oprational status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is operating properly, False if PSU is faulty + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + + return status == 1 + + def get_psu_presence(self, index): + """ + Retrieves the presence status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is plugged, False if not + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + + return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py new file mode 100644 index 000000000000..e195fa13d0bd --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +############################################################################# +# Mellanox +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError, e: + raise ImportError (str(e) + "- required module not found") + +class PSUutil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_path = "/sys/bus/i2c/devices/2-0060/" + self.psu_presence = "psu{}_status" + self.psu_oper_status = "psu{}_pg_status" + + def get_num_psus(self): + """ + Retrieves the number of PSUs available on the device + + :return: An integer, the number of PSUs available on the device + """ + return 2 + + def get_psu_status(self, index): + """ + Retrieves the oprational status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is operating properly, False if PSU is faulty + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + + return status == 1 + + def get_psu_presence(self, index): + """ + Retrieves the presence status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is plugged, False if not + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + + return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py new file mode 100644 index 000000000000..e195fa13d0bd --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +############################################################################# +# Mellanox +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError, e: + raise ImportError (str(e) + "- required module not found") + +class PSUutil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_path = "/sys/bus/i2c/devices/2-0060/" + self.psu_presence = "psu{}_status" + self.psu_oper_status = "psu{}_pg_status" + + def get_num_psus(self): + """ + Retrieves the number of PSUs available on the device + + :return: An integer, the number of PSUs available on the device + """ + return 2 + + def get_psu_status(self, index): + """ + Retrieves the oprational status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is operating properly, False if PSU is faulty + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + + return status == 1 + + def get_psu_presence(self, index): + """ + Retrieves the presence status of power supply unit (PSU) defined + by index + + :param index: An integer, index of the PSU of which to query status + :return: Boolean, True if PSU is plugged, False if not + """ + if index is None: + return False + + status = 0 + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + + return status == 1 diff --git a/dockers/docker-snmp-sv2/Dockerfile.j2 b/dockers/docker-snmp-sv2/Dockerfile.j2 index 2ab867031874..a9814bc198ff 100644 --- a/dockers/docker-snmp-sv2/Dockerfile.j2 +++ b/dockers/docker-snmp-sv2/Dockerfile.j2 @@ -1,5 +1,8 @@ FROM docker-config-engine +RUN echo 'deb http://debian-archive.trafficmanager.net/debian jessie-backports main' >> /etc/apt/sources.list && \ + echo 'deb [arch=amd64] http://packages.microsoft.com/repos/sonic-dev/ jessie main' >> /etc/apt/sources.list + COPY [ \ {% for deb in docker_snmp_sv2_debs.split(' ') -%} "debs/{{ deb }}", @@ -22,9 +25,9 @@ ENV DEBIAN_FRONTEND=noninteractive # TODO: remove libpython3.6-dev, its and pip's dependencies if we can get pip3 directly # install subagent # clean up -RUN apt-get update && apt-get install -y libperl5.20 libpci3 libwrap0 \ - libexpat1-dev \ - curl gcc && \ +RUN apt-get update && apt-get install -y --force-yes libperl5.20 libpci3 libwrap0 \ + libexpat1-dev grub2-common bash-completion curl gcc \ + python-pip python-click-default-group python-click python-natsort python-tabulate && \ dpkg -i \ {% for deb in docker_snmp_sv2_debs.split(' ') -%} debs/{{ deb }}{{' '}} diff --git a/rules/docker-snmp-sv2.mk b/rules/docker-snmp-sv2.mk index 95fdcc25775c..65eceadd0524 100644 --- a/rules/docker-snmp-sv2.mk +++ b/rules/docker-snmp-sv2.mk @@ -3,7 +3,7 @@ DOCKER_SNMP_SV2 = docker-snmp-sv2.gz $(DOCKER_SNMP_SV2)_PATH = $(DOCKERS_PATH)/docker-snmp-sv2 ## TODO: remove LIBPY3_DEV if we can get pip3 directly -$(DOCKER_SNMP_SV2)_DEPENDS += $(SNMP) $(SNMPD) $(PY3) $(LIBPY3_DEV) +$(DOCKER_SNMP_SV2)_DEPENDS += $(SNMP) $(SNMPD) $(PY3) $(LIBPY3_DEV) $(SONIC_UTILS) $(DOCKER_SNMP_SV2)_PYTHON_WHEELS += $(ASYNCSNMP_PY3) $(DOCKER_SNMP_SV2)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE) SONIC_DOCKER_IMAGES += $(DOCKER_SNMP_SV2) From 62a0d93bb0e1d2db7557540beb840f489295e38d Mon Sep 17 00:00:00 2001 From: andrii savka Date: Wed, 22 Nov 2017 16:40:53 +0200 Subject: [PATCH 2/7] Rename PsuUtil, removed unused deb repo from snmp docker --- device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py | 2 +- device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py | 2 +- device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py | 2 +- device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py | 2 +- dockers/docker-snmp-sv2/Dockerfile.j2 | 3 +-- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py index e195fa13d0bd..faa702b0a55d 100644 --- a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -15,7 +15,7 @@ except ImportError, e: raise ImportError (str(e) + "- required module not found") -class PSUutil(PsuBase): +class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py index e195fa13d0bd..faa702b0a55d 100644 --- a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py @@ -15,7 +15,7 @@ except ImportError, e: raise ImportError (str(e) + "- required module not found") -class PSUutil(PsuBase): +class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py index e195fa13d0bd..faa702b0a55d 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -15,7 +15,7 @@ except ImportError, e: raise ImportError (str(e) + "- required module not found") -class PSUutil(PsuBase): +class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py index e195fa13d0bd..faa702b0a55d 100644 --- a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py @@ -15,7 +15,7 @@ except ImportError, e: raise ImportError (str(e) + "- required module not found") -class PSUutil(PsuBase): +class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): diff --git a/dockers/docker-snmp-sv2/Dockerfile.j2 b/dockers/docker-snmp-sv2/Dockerfile.j2 index a9814bc198ff..3d274fb7ac73 100644 --- a/dockers/docker-snmp-sv2/Dockerfile.j2 +++ b/dockers/docker-snmp-sv2/Dockerfile.j2 @@ -1,7 +1,6 @@ FROM docker-config-engine -RUN echo 'deb http://debian-archive.trafficmanager.net/debian jessie-backports main' >> /etc/apt/sources.list && \ - echo 'deb [arch=amd64] http://packages.microsoft.com/repos/sonic-dev/ jessie main' >> /etc/apt/sources.list +RUN echo 'deb [arch=amd64] http://packages.microsoft.com/repos/sonic-dev/ jessie main' >> /etc/apt/sources.list COPY [ \ {% for deb in docker_snmp_sv2_debs.split(' ') -%} From f1419653ade0d55117b4695718f15c8983c25a79 Mon Sep 17 00:00:00 2001 From: andrii savka Date: Tue, 28 Nov 2017 14:21:47 +0200 Subject: [PATCH 3/7] PSU plugin fixes for MLNX Bulldog platform --- .../x86_64-mlnx_msn2100-r0/plugins/psuutil.py | 17 ++++++++--------- .../x86_64-mlnx_msn2410-r0/plugins/psuutil.py | 14 ++++++++++---- .../x86_64-mlnx_msn2700-r0/plugins/psuutil.py | 14 ++++++++++---- .../x86_64-mlnx_msn2740-r0/plugins/psuutil.py | 14 ++++++++++---- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py index faa702b0a55d..7a0f079ac03a 100644 --- a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -45,8 +45,11 @@ def get_psu_status(self, index): return False status = 0 - with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: - status = int(power_status.read()) + try: + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + except IOError: + return False return status == 1 @@ -58,11 +61,7 @@ def get_psu_presence(self, index): :param index: An integer, index of the PSU of which to query status :return: Boolean, True if PSU is plugged, False if not """ - if index is None: - return False + if index and index > 0 and index <= self.get_num_psus(): + return True - status = 0 - with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: - status = int(presence_status.read()) - - return status == 1 + return False diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py index faa702b0a55d..646d5a66fc0f 100644 --- a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py @@ -45,8 +45,11 @@ def get_psu_status(self, index): return False status = 0 - with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: - status = int(power_status.read()) + try: + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + except IOError: + return False return status == 1 @@ -62,7 +65,10 @@ def get_psu_presence(self, index): return False status = 0 - with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: - status = int(presence_status.read()) + try: + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + except IOError: + return False return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py index faa702b0a55d..646d5a66fc0f 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -45,8 +45,11 @@ def get_psu_status(self, index): return False status = 0 - with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: - status = int(power_status.read()) + try: + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + except IOError: + return False return status == 1 @@ -62,7 +65,10 @@ def get_psu_presence(self, index): return False status = 0 - with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: - status = int(presence_status.read()) + try: + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + except IOError: + return False return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py index faa702b0a55d..646d5a66fc0f 100644 --- a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py @@ -45,8 +45,11 @@ def get_psu_status(self, index): return False status = 0 - with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: - status = int(power_status.read()) + try: + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + except IOError: + return False return status == 1 @@ -62,7 +65,10 @@ def get_psu_presence(self, index): return False status = 0 - with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: - status = int(presence_status.read()) + try: + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + except IOError: + return False return status == 1 From c76d7e0694dbfb9472916adae3b0a419c5154bfd Mon Sep 17 00:00:00 2001 From: andrii savka Date: Wed, 29 Nov 2017 18:15:17 +0200 Subject: [PATCH 4/7] [PSU] Fixes of review remarks --- .../x86_64-mlnx_msn2100-r0/plugins/psuutil.py | 15 ++-- .../x86_64-mlnx_msn2410-r0/plugins/psuutil.py | 75 +------------------ .../x86_64-mlnx_msn2700-r0/plugins/psuutil.py | 10 +-- .../x86_64-mlnx_msn2740-r0/plugins/psuutil.py | 75 +------------------ dockers/docker-snmp-sv2/Dockerfile.j2 | 1 + rules/docker-snmp-sv2.mk | 1 + 6 files changed, 15 insertions(+), 162 deletions(-) mode change 100644 => 120000 device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py mode change 100644 => 120000 device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py index 7a0f079ac03a..88bdd51e9b67 100644 --- a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -12,7 +12,7 @@ try: from sonic_psu.psu_base import PsuBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class PsuUtil(PsuBase): @@ -36,9 +36,9 @@ def get_num_psus(self): def get_psu_status(self, index): """ Retrieves the oprational status of power supply unit (PSU) defined - by index + by 1-based index - :param index: An integer, index of the PSU of which to query status + :param index: An integer, 1-based index of the PSU of which to query status :return: Boolean, True if PSU is operating properly, False if PSU is faulty """ if index is None: @@ -56,12 +56,9 @@ def get_psu_status(self, index): def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined - by index + by 1-based index - :param index: An integer, index of the PSU of which to query status + :param index: An integer, 1-based index of the PSU of which to query status :return: Boolean, True if PSU is plugged, False if not """ - if index and index > 0 and index <= self.get_num_psus(): - return True - - return False + return isinstance(index, int) and index > 0 and index <= self.get_num_psus() diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py deleted file mode 100644 index 646d5a66fc0f..000000000000 --- a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python - -############################################################################# -# Mellanox -# -# Module contains an implementation of SONiC PSU Base API and -# provides the PSUs status which are available in the platform -# -############################################################################# - -import os.path - -try: - from sonic_psu.psu_base import PsuBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") - -class PsuUtil(PsuBase): - """Platform-specific PSUutil class""" - - def __init__(self): - PsuBase.__init__(self) - - self.psu_path = "/sys/bus/i2c/devices/2-0060/" - self.psu_presence = "psu{}_status" - self.psu_oper_status = "psu{}_pg_status" - - def get_num_psus(self): - """ - Retrieves the number of PSUs available on the device - - :return: An integer, the number of PSUs available on the device - """ - return 2 - - def get_psu_status(self, index): - """ - Retrieves the oprational status of power supply unit (PSU) defined - by index - - :param index: An integer, index of the PSU of which to query status - :return: Boolean, True if PSU is operating properly, False if PSU is faulty - """ - if index is None: - return False - - status = 0 - try: - with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: - status = int(power_status.read()) - except IOError: - return False - - return status == 1 - - def get_psu_presence(self, index): - """ - Retrieves the presence status of power supply unit (PSU) defined - by index - - :param index: An integer, index of the PSU of which to query status - :return: Boolean, True if PSU is plugged, False if not - """ - if index is None: - return False - - status = 0 - try: - with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: - status = int(presence_status.read()) - except IOError: - return False - - return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py new file mode 120000 index 000000000000..9f724238a8d5 --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py @@ -0,0 +1 @@ +../../x86_64-mlnx_msn2700-r0/plugins/psuutil.py \ No newline at end of file diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py index 646d5a66fc0f..301569c13a94 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -12,7 +12,7 @@ try: from sonic_psu.psu_base import PsuBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class PsuUtil(PsuBase): @@ -36,9 +36,9 @@ def get_num_psus(self): def get_psu_status(self, index): """ Retrieves the oprational status of power supply unit (PSU) defined - by index + by 1-based index - :param index: An integer, index of the PSU of which to query status + :param index: An integer, 1-based index of the PSU of which to query status :return: Boolean, True if PSU is operating properly, False if PSU is faulty """ if index is None: @@ -56,9 +56,9 @@ def get_psu_status(self, index): def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined - by index + by 1-based index - :param index: An integer, index of the PSU of which to query status + :param index: An integer, 1-based index of the PSU of which to query status :return: Boolean, True if PSU is plugged, False if not """ if index is None: diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py deleted file mode 100644 index 646d5a66fc0f..000000000000 --- a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python - -############################################################################# -# Mellanox -# -# Module contains an implementation of SONiC PSU Base API and -# provides the PSUs status which are available in the platform -# -############################################################################# - -import os.path - -try: - from sonic_psu.psu_base import PsuBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") - -class PsuUtil(PsuBase): - """Platform-specific PSUutil class""" - - def __init__(self): - PsuBase.__init__(self) - - self.psu_path = "/sys/bus/i2c/devices/2-0060/" - self.psu_presence = "psu{}_status" - self.psu_oper_status = "psu{}_pg_status" - - def get_num_psus(self): - """ - Retrieves the number of PSUs available on the device - - :return: An integer, the number of PSUs available on the device - """ - return 2 - - def get_psu_status(self, index): - """ - Retrieves the oprational status of power supply unit (PSU) defined - by index - - :param index: An integer, index of the PSU of which to query status - :return: Boolean, True if PSU is operating properly, False if PSU is faulty - """ - if index is None: - return False - - status = 0 - try: - with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: - status = int(power_status.read()) - except IOError: - return False - - return status == 1 - - def get_psu_presence(self, index): - """ - Retrieves the presence status of power supply unit (PSU) defined - by index - - :param index: An integer, index of the PSU of which to query status - :return: Boolean, True if PSU is plugged, False if not - """ - if index is None: - return False - - status = 0 - try: - with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: - status = int(presence_status.read()) - except IOError: - return False - - return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py new file mode 120000 index 000000000000..9f724238a8d5 --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py @@ -0,0 +1 @@ +../../x86_64-mlnx_msn2700-r0/plugins/psuutil.py \ No newline at end of file diff --git a/dockers/docker-snmp-sv2/Dockerfile.j2 b/dockers/docker-snmp-sv2/Dockerfile.j2 index 3d274fb7ac73..a06ed26faaba 100644 --- a/dockers/docker-snmp-sv2/Dockerfile.j2 +++ b/dockers/docker-snmp-sv2/Dockerfile.j2 @@ -24,6 +24,7 @@ ENV DEBIAN_FRONTEND=noninteractive # TODO: remove libpython3.6-dev, its and pip's dependencies if we can get pip3 directly # install subagent # clean up +## TODO: remove click modules and grub2-common bash-completion if we can use PSU util directly RUN apt-get update && apt-get install -y --force-yes libperl5.20 libpci3 libwrap0 \ libexpat1-dev grub2-common bash-completion curl gcc \ python-pip python-click-default-group python-click python-natsort python-tabulate && \ diff --git a/rules/docker-snmp-sv2.mk b/rules/docker-snmp-sv2.mk index 65eceadd0524..5a61a444d95b 100644 --- a/rules/docker-snmp-sv2.mk +++ b/rules/docker-snmp-sv2.mk @@ -3,6 +3,7 @@ DOCKER_SNMP_SV2 = docker-snmp-sv2.gz $(DOCKER_SNMP_SV2)_PATH = $(DOCKERS_PATH)/docker-snmp-sv2 ## TODO: remove LIBPY3_DEV if we can get pip3 directly +## TODO: replace SONIC_UTILS if we can use PSU util directly $(DOCKER_SNMP_SV2)_DEPENDS += $(SNMP) $(SNMPD) $(PY3) $(LIBPY3_DEV) $(SONIC_UTILS) $(DOCKER_SNMP_SV2)_PYTHON_WHEELS += $(ASYNCSNMP_PY3) $(DOCKER_SNMP_SV2)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE) From 114346b895a8425db11f5ac87ef552c093cbe3a5 Mon Sep 17 00:00:00 2001 From: andrii savka Date: Fri, 1 Dec 2017 12:39:16 +0200 Subject: [PATCH 5/7] [PSU] Changed TODO descriptions for dependenciesw --- dockers/docker-snmp-sv2/Dockerfile.j2 | 4 +++- rules/docker-snmp-sv2.mk | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dockers/docker-snmp-sv2/Dockerfile.j2 b/dockers/docker-snmp-sv2/Dockerfile.j2 index a06ed26faaba..6a5bdba1924f 100644 --- a/dockers/docker-snmp-sv2/Dockerfile.j2 +++ b/dockers/docker-snmp-sv2/Dockerfile.j2 @@ -24,7 +24,9 @@ ENV DEBIAN_FRONTEND=noninteractive # TODO: remove libpython3.6-dev, its and pip's dependencies if we can get pip3 directly # install subagent # clean up -## TODO: remove click modules and grub2-common bash-completion if we can use PSU util directly +## TODO: remove grub2-common, bash-completion, python-pip, python-click-default-group, +# python-click, python-natsort and python-tabulate once we no longer need to install +# sonic-utilities for PSU plugin support RUN apt-get update && apt-get install -y --force-yes libperl5.20 libpci3 libwrap0 \ libexpat1-dev grub2-common bash-completion curl gcc \ python-pip python-click-default-group python-click python-natsort python-tabulate && \ diff --git a/rules/docker-snmp-sv2.mk b/rules/docker-snmp-sv2.mk index 5a61a444d95b..142b0f7523c4 100644 --- a/rules/docker-snmp-sv2.mk +++ b/rules/docker-snmp-sv2.mk @@ -3,7 +3,8 @@ DOCKER_SNMP_SV2 = docker-snmp-sv2.gz $(DOCKER_SNMP_SV2)_PATH = $(DOCKERS_PATH)/docker-snmp-sv2 ## TODO: remove LIBPY3_DEV if we can get pip3 directly -## TODO: replace SONIC_UTILS if we can use PSU util directly +## TODO: replace SONIC_UTILS with appropriate target once +# SONiC Python modules are moved to their own package $(DOCKER_SNMP_SV2)_DEPENDS += $(SNMP) $(SNMPD) $(PY3) $(LIBPY3_DEV) $(SONIC_UTILS) $(DOCKER_SNMP_SV2)_PYTHON_WHEELS += $(ASYNCSNMP_PY3) $(DOCKER_SNMP_SV2)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE) From bc2945d3e92bc5136b8d9b09e559c9f56fa39330 Mon Sep 17 00:00:00 2001 From: andrii savka Date: Fri, 1 Dec 2017 13:02:05 +0200 Subject: [PATCH 6/7] [PSU] Revert usage psuutil.py link instead of file because it should be copied in SNMP as a file --- .../x86_64-mlnx_msn2410-r0/plugins/psuutil.py | 75 ++++++++++++++++++- .../x86_64-mlnx_msn2740-r0/plugins/psuutil.py | 75 ++++++++++++++++++- 2 files changed, 148 insertions(+), 2 deletions(-) mode change 120000 => 100644 device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py mode change 120000 => 100644 device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py deleted file mode 120000 index 9f724238a8d5..000000000000 --- a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py +++ /dev/null @@ -1 +0,0 @@ -../../x86_64-mlnx_msn2700-r0/plugins/psuutil.py \ No newline at end of file diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py new file mode 100644 index 000000000000..301569c13a94 --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +############################################################################# +# Mellanox +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError as e: + raise ImportError (str(e) + "- required module not found") + +class PsuUtil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_path = "/sys/bus/i2c/devices/2-0060/" + self.psu_presence = "psu{}_status" + self.psu_oper_status = "psu{}_pg_status" + + def get_num_psus(self): + """ + Retrieves the number of PSUs available on the device + + :return: An integer, the number of PSUs available on the device + """ + return 2 + + def get_psu_status(self, index): + """ + Retrieves the oprational status of power supply unit (PSU) defined + by 1-based index + + :param index: An integer, 1-based index of the PSU of which to query status + :return: Boolean, True if PSU is operating properly, False if PSU is faulty + """ + if index is None: + return False + + status = 0 + try: + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + except IOError: + return False + + return status == 1 + + def get_psu_presence(self, index): + """ + Retrieves the presence status of power supply unit (PSU) defined + by 1-based index + + :param index: An integer, 1-based index of the PSU of which to query status + :return: Boolean, True if PSU is plugged, False if not + """ + if index is None: + return False + + status = 0 + try: + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + except IOError: + return False + + return status == 1 diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py deleted file mode 120000 index 9f724238a8d5..000000000000 --- a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py +++ /dev/null @@ -1 +0,0 @@ -../../x86_64-mlnx_msn2700-r0/plugins/psuutil.py \ No newline at end of file diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py new file mode 100644 index 000000000000..301569c13a94 --- /dev/null +++ b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +############################################################################# +# Mellanox +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError as e: + raise ImportError (str(e) + "- required module not found") + +class PsuUtil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_path = "/sys/bus/i2c/devices/2-0060/" + self.psu_presence = "psu{}_status" + self.psu_oper_status = "psu{}_pg_status" + + def get_num_psus(self): + """ + Retrieves the number of PSUs available on the device + + :return: An integer, the number of PSUs available on the device + """ + return 2 + + def get_psu_status(self, index): + """ + Retrieves the oprational status of power supply unit (PSU) defined + by 1-based index + + :param index: An integer, 1-based index of the PSU of which to query status + :return: Boolean, True if PSU is operating properly, False if PSU is faulty + """ + if index is None: + return False + + status = 0 + try: + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read()) + except IOError: + return False + + return status == 1 + + def get_psu_presence(self, index): + """ + Retrieves the presence status of power supply unit (PSU) defined + by 1-based index + + :param index: An integer, 1-based index of the PSU of which to query status + :return: Boolean, True if PSU is plugged, False if not + """ + if index is None: + return False + + status = 0 + try: + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read()) + except IOError: + return False + + return status == 1 From 3751083110ef31405a4de09750f75d130081f63f Mon Sep 17 00:00:00 2001 From: andrii savka Date: Fri, 8 Dec 2017 02:41:33 +0200 Subject: [PATCH 7/7] [PSU] Updated sonic-utilities submodule --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index e87bb97760a4..cc147b9d0f0a 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit e87bb97760a4cf069da51b2a0da732f7a40f3215 +Subproject commit cc147b9d0f0a2edd1e89019052755a92840dd5f9