Skip to content

Commit

Permalink
Merge branch 'master' into credo_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prgeor authored Sep 19, 2023
2 parents 3ffe78a + 0dafb55 commit 300932e
Show file tree
Hide file tree
Showing 34 changed files with 2,396 additions and 364 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Semgrep

on:
pull_request: {}
push:
branches:
- master
- '201[7-9][0-1][0-9]'
- '202[0-9][0-1][0-9]'

jobs:
semgrep:
if: github.repository_owner == 'sonic-net'
name: Semgrep
runs-on: ubuntu-latest
container:
image: returntocorp/semgrep
steps:
- uses: actions/checkout@v3
- run: semgrep ci
env:
SEMGREP_RULES: p/default
3 changes: 1 addition & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ steps:

- script: |
set -xe
sudo apt-get -y purge libhiredis-dev libnl-3-dev libnl-route-3-dev || true
sudo apt-get -y purge libnl-3-dev libnl-route-3-dev || true
sudo dpkg -i libyang_1.0.73_amd64.deb \
libnl-3-200_*.deb \
libnl-genl-3-200_*.deb \
libnl-route-3-200_*.deb \
libnl-nf-3-200_*.deb \
libhiredis0.14_*.deb \
libswsscommon_1.0.0_amd64.deb \
python3-swsscommon_1.0.0_amd64.deb
workingDirectory: $(Build.ArtifactStagingDirectory)/target/debs/bullseye/
Expand Down
1 change: 1 addition & 0 deletions sonic_platform_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
from . import psu_base
from . import sfp_base
from . import thermal_base
from . import sensor_base
from . import watchdog_base
118 changes: 118 additions & 0 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(self):
# List of ThermalBase-derived objects representing all thermals
# available on the chassis
self._thermal_list = []
self._voltage_sensor_list = []
self._current_sensor_list = []

# List of SfpBase-derived objects representing all sfps
# available on the chassis
Expand Down Expand Up @@ -451,6 +453,95 @@ def get_thermal_manager(self):
"""
raise NotImplementedError

##############################################
# Voltage Sensor Methods
##############################################

def get_num_voltage_sensors(self):
"""
Retrieves the number of voltage sensors available on this chassis
Returns:
An integer, the number of voltage sensors available on this chassis
"""
return len(self._voltage_sensor_list)

def get_all_voltage_sensors(self):
"""
Retrieves all voltage sensors available on this chassis
Returns:
A list of objects derived from VoltageSensorBase representing all voltage
sensors available on this chassis
"""
return self._voltage_sensor_list

def get_voltage_sensor(self, index):
"""
Retrieves voltage sensor unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the voltage sensor to
retrieve
Returns:
An object derived from VoltageSensorBase representing the specified voltage sensor
"""
voltage_sensor = None

try:
voltage_sensor = self._voltage_sensor_list[index]
except IndexError:
sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format(
index, len(self._voltage_sensor_list)-1))

return voltage_sensor

##############################################
# Current Sensor Methods
##############################################

def get_num_current_sensors(self):
"""
Retrieves the number of current sensors available on this chassis
Returns:
An integer, the number of current sensors available on this chassis
"""
return len(self._current_sensor_list)

def get_all_current_sensors(self):
"""
Retrieves all current sensors available on this chassis
Returns:
A list of objects derived from CurrentSensorBase representing all current
sensors available on this chassis
"""
return self._current_sensor_list

def get_current_sensor(self, index):
"""
Retrieves current sensor object represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the current sensor to
retrieve
Returns:
An object derived from CurrentSensorBase representing the specified current
sensor
"""
current_sensor = None

try:
current_sensor = self._current_sensor_list[index]
except IndexError:
sys.stderr.write("Current sensor index {} out of range (0-{})\n".format(
index, len(self._current_sensor_list)-1))

return current_sensor

##############################################
# SFP methods
##############################################
Expand Down Expand Up @@ -546,6 +637,33 @@ def get_status_led(self):
"""
raise NotImplementedError

##############################################
# System LED methods
##############################################

def set_uid_led(self, color):
"""
Sets the state of the system UID LED
Args:
color: A string representing the color with which to set the
system UID LED
Returns:
bool: True if system LED state is set successfully, False if not
"""
raise NotImplementedError

def get_uid_led(self):
"""
Gets the state of the system UID LED
Returns:
A string, one of the valid LED color strings which could be vendor
specified.
"""
raise NotImplementedError

##############################################
# Other methods
##############################################
Expand Down
46 changes: 46 additions & 0 deletions sonic_platform_base/fan_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,52 @@ def get_speed_tolerance(self):
"""
raise NotImplementedError

def is_under_speed(self):
"""
Calculates if the fan speed is under the tolerated low speed threshold
Default calculation requires get_speed_tolerance to be implemented, and checks
if the current fan speed (expressed as a percentage) is lower than <get_speed_tolerance>
percent below the target fan speed (expressed as a percentage)
Returns:
A boolean, True if fan speed is under the low threshold, False if not
"""
speed = self.get_speed()
target_speed = self.get_target_speed()
tolerance = self.get_speed_tolerance()

for param, value in (('speed', speed), ('target speed', target_speed), ('speed tolerance', tolerance)):
if not isinstance(value, int):
raise TypeError(f'Fan {param} is not an integer value: {param}={value}')
if value < 0 or value > 100:
raise ValueError(f'Fan {param} is not a valid percentage value: {param}={value}')

return speed * 100 < target_speed * (100 - tolerance)

def is_over_speed(self):
"""
Calculates if the fan speed is over the tolerated high speed threshold
Default calculation requires get_speed_tolerance to be implemented, and checks
if the current fan speed (expressed as a percentage) is higher than <get_speed_tolerance>
percent above the target fan speed (expressed as a percentage)
Returns:
A boolean, True if fan speed is over the high threshold, False if not
"""
speed = self.get_speed()
target_speed = self.get_target_speed()
tolerance = self.get_speed_tolerance()

for param, value in (('speed', speed), ('target speed', target_speed), ('speed tolerance', tolerance)):
if not isinstance(value, int):
raise TypeError(f'Fan {param} is not an integer value: {param}={value}')
if value < 0 or value > 100:
raise ValueError(f'Fan {param} is not a valid percentage value: {param}={value}')

return speed * 100 > target_speed * (100 + tolerance)

def set_speed(self, speed):
"""
Sets the fan speed
Expand Down
91 changes: 91 additions & 0 deletions sonic_platform_base/module_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self):
# List of ThermalBase-derived objects representing all thermals
# available on the module
self._thermal_list = []
self._voltage_sensor_list = []
self._current_sensor_list = []

# List of SfpBase-derived objects representing all sfps
# available on the module
Expand Down Expand Up @@ -372,6 +374,95 @@ def get_thermal(self, index):

return thermal

##############################################
# Voltage Sensor methods
##############################################

def get_num_voltage_sensors(self):
"""
Retrieves the number of voltage sensors available on this module
Returns:
An integer, the number of voltage sensors available on this module
"""
return len(self._voltage_sensor_list)

def get_all_voltage_sensors(self):
"""
Retrieves all voltage sensors available on this module
Returns:
A list of objects derived from VoltageSensorBase representing all voltage
sensors available on this module
"""
return self._voltage_sensor_list

def get_voltage_sensor(self, index):
"""
Retrieves voltage sensor unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the voltage sensor to
retrieve
Returns:
An object derived from VoltageSensorBase representing the specified voltage
sensor
"""
voltage_sensor = None

try:
voltage_sensor = self._voltage_sensor_list[index]
except IndexError:
sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format(
index, len(self._voltage_sensor_list)-1))

return voltage_sensor

##############################################
# Current sensor methods
##############################################

def get_num_current_sensors(self):
"""
Retrieves the number of current sensors available on this module
Returns:
An integer, the number of current sensors available on this module
"""
return len(self._current_sensor_list)

def get_all_current_sensors(self):
"""
Retrieves all current sensors available on this module
Returns:
A list of objects derived from CurrentSensorBase representing all current
sensors available on this module
"""
return self._current_sensor_list

def get_current_sensor(self, index):
"""
Retrieves current sensor object represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the current sensor to
retrieve
Returns:
An object derived from CurrentSensorBase representing the specified current_sensor
"""
current_sensor = None

try:
current_sensor = self._current_sensor_list[index]
except IndexError:
sys.stderr.write("Current sensor index {} out of range (0-{})\n".format(
index, len(self._current_sensor_list)-1))

return current_sensor

##############################################
# SFP methods
##############################################
Expand Down
Loading

0 comments on commit 300932e

Please sign in to comment.