Skip to content

Commit d169853

Browse files
committed
Address some review comments; Add watchdog_base
1 parent bfce7ad commit d169853

File tree

6 files changed

+146
-21
lines changed

6 files changed

+146
-21
lines changed

sonic_platform_base/chassis_base.py

+78-10
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,30 @@
1313
raise ImportError(str(e) + " - required module not found")
1414

1515

16+
# NOTE: This class inherits the metaclass 'abc.ABCMeta' from DeviceBase
1617
class ChassisBase(device_base.DeviceBase):
1718
"""
1819
Abstract base class for interfacing with a platform chassis
1920
"""
2021

21-
__metaclass__ = abc.ABCMeta
22-
2322
# Possible reboot causes
24-
REBOOT_CAUSE_POWER_LOSS = "power_loss"
23+
REBOOT_CAUSE_POWER_LOSS = "power_loss"
2524
REBOOT_CAUSE_THERMAL_OVERLOAD = "thermal_overload"
2625
REBOOT_CAUSE_INSUFFICIENT_FAN = "insufficient_fan"
2726
REBOOT_CAUSE_WATCHDOG = "watchdog"
2827
REBOOT_CAUSE_SOFTWARE = "software"
2928

30-
# List of all fans available on the chassis
31-
fan_list = []
29+
30+
# List of FanBase-derived objects representing all fans
31+
# available on the chassis
32+
_fan_list = []
33+
34+
# List of PsuBase-derived objects representing all power supply units
35+
# available on the chassis
36+
_psu_list = []
37+
38+
# Object derived from WatchdogBase for interacting with hardware watchdog
39+
_watchdog = None
3240

3341
@abc.abstractmethod
3442
def get_base_mac(self):
@@ -39,7 +47,7 @@ def get_base_mac(self):
3947
A string containing the MAC address in the format
4048
'XX:XX:XX:XX:XX:XX'
4149
"""
42-
return None
50+
return None
4351

4452
@abc.abstractmethod
4553
def get_reboot_cause(self):
@@ -52,14 +60,18 @@ def get_reboot_cause(self):
5260
"""
5361
return REBOOT_CAUSE_SOFTWARE
5462

63+
##############################################
64+
# Fan module methods
65+
##############################################
66+
5567
def get_num_fans(self):
5668
"""
5769
Retrieves the number of fan modules available on this chassis
5870
5971
Returns:
6072
An integer, the number of fan modules available on this chassis
6173
"""
62-
return len(self.fan_list)
74+
return len(self._fan_list)
6375

6476
def get_all_fans(self):
6577
"""
@@ -69,7 +81,7 @@ def get_all_fans(self):
6981
A list of objects derived from FanBase representing all fan
7082
modules available on this chassis
7183
"""
72-
return self.fan_list
84+
return self._fan_list
7385

7486
def get_fan(self, index):
7587
"""
@@ -86,9 +98,65 @@ def get_fan(self, index):
8698
fan = None
8799

88100
try:
89-
fan = self.fan_list[index]
101+
fan = self._fan_list[index]
90102
except IndexError:
91103
sys.stderr.write("Fan index {} out of range (0-{})\n".format(
92-
index, len(self.fan_list)-1))
104+
index, len(self._fan_list)-1))
93105

94106
return fan
107+
108+
##############################################
109+
# PSU module methods
110+
##############################################
111+
112+
def get_num_psus(self):
113+
"""
114+
Retrieves the number of power supply units available on this chassis
115+
116+
Returns:
117+
An integer, the number of power supply units available on this
118+
chassis
119+
"""
120+
return len(self._psu_list)
121+
122+
def get_all_psus(self):
123+
"""
124+
Retrieves all power supply units available on this chassis
125+
126+
Returns:
127+
A list of objects derived from PsuBase representing all power
128+
supply units available on this chassis
129+
"""
130+
return self._psu_list
131+
132+
def get_fan(self, index):
133+
"""
134+
Retrieves power supply unit represented by (1-based) index <index>
135+
136+
Args:
137+
index: An integer, the index (1-based) of the power supply unit to
138+
retrieve
139+
140+
Returns:
141+
An object dervied from PsuBase representing the specified power
142+
supply unit
143+
"""
144+
psu = None
145+
146+
try:
147+
psu = self._psu_list[index]
148+
except IndexError:
149+
sys.stderr.write("PSU index {} out of range (0-{})\n".format(
150+
index, len(self._psu_list)-1))
151+
152+
return psu
153+
154+
def get_watchdog(self):
155+
"""
156+
Retreives hardware watchdog module on this chassis
157+
158+
Returns:
159+
An object derived from WatchdogBase representing the hardware
160+
watchdog module
161+
"""
162+
return _watchdog

sonic_platform_base/device_base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77

88
try:
99
import abc
10+
import six
1011
except ImportError as e:
1112
raise ImportError(str(e) + " - required module not found")
1213

1314

15+
# NOTE: Using 'six' module here to ensure consistent abc metaclass behavior
16+
# with both Python 2.x and Python 3.x
17+
@six.add_metaclass(abc.ABCMeta)
1418
class DeviceBase(object):
1519
"""
1620
Abstract base class for interfacing with a generic type of platform
1721
peripheral device
1822
"""
1923

20-
__metaclass__ = abc.ABCMeta
21-
2224
@abc.abstractmethod
2325
def get_presence(self):
2426
"""
@@ -48,7 +50,7 @@ def get_serial(self):
4850
string: Serial number of device
4951
"""
5052
return None
51-
53+
5254
@abc.abstractmethod
5355
def get_status(self):
5456
"""

sonic_platform_base/fan_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
raise ImportError(str(e) + " - required module not found")
1313

1414

15+
# NOTE: This class inherits the metaclass 'abc.ABCMeta' from DeviceBase
1516
class FanBase(device_base.DeviceBase):
1617
"""
1718
Abstract base class for interfacing with a fan module
1819
"""
19-
__metaclass__ = abc.ABCMeta
20-
20+
2121
# Possible fan directions
2222
FAN_DIRECTION_INTAKE = "intake"
2323
FAN_DIRECTION_EXHAUST = "exhaust"

sonic_platform_base/platform_base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
from __future__ import print_function
1111

1212
try:
13-
import abc
1413
import sys
1514
except ImportError as e:
1615
raise ImportError(str(e) + " - required module not found")
1716

1817

1918
class PlatformBase(object):
2019

21-
__metaclass__ = abc.ABCMeta
22-
23-
# List of all chassis available on the platform
20+
# List of ChassisBase-derived objects representing all chassis available
21+
# on the platform
2422
chassis_list = []
2523

2624
def get_num_chassis(self):

sonic_platform_base/psu_base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
except ImportError as e:
1212
raise ImportError(str(e) + " - required module not found")
1313

14-
14+
# NOTE: This class inherits the metaclass 'abc.ABCMeta' from DeviceBase
1515
class PsuBase(device_base.DeviceBase):
1616
"""
1717
Abstract base class for interfacing with a power supply unit
1818
"""
19-
__metaclass__ = abc.ABCMeta
2019

2120
# Possible fan directions
2221
FAN_DIRECTION_INTAKE = "intake"

sonic_platform_base/watchdog_base.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# watchdog_base.py
3+
#
4+
# Abstract base class for implementing a platform-specific class with which
5+
# to interact with a hardware watchdog module in SONiC
6+
#
7+
8+
try:
9+
import abc
10+
from . import device_base
11+
except ImportError as e:
12+
raise ImportError(str(e) + " - required module not found")
13+
14+
15+
# NOTE: This class inherits the metaclass 'abc.ABCMeta' from DeviceBase
16+
class WatchdogBase(device_base.DeviceBase):
17+
"""
18+
Abstract base class for interfacing with a hardware watchdog module
19+
"""
20+
21+
# Possible fan directions
22+
FAN_DIRECTION_INTAKE = "intake"
23+
FAN_DIRECTION_EXHAUST = "exhaust"
24+
25+
@abc.abstractmethod
26+
def arm(self, seconds):
27+
"""
28+
Arm the hardware watchdog with a timeout of <seconds> seconds
29+
30+
Returns:
31+
A boolean, True if watchdog is armed successfully, False if not
32+
"""
33+
return None
34+
35+
@abc.abstractmethod
36+
def disarm(self):
37+
"""
38+
Disarm the hardware watchdog
39+
40+
Returns:
41+
A boolean, True if watchdog is disarmed successfully, False if not
42+
"""
43+
return 0
44+
45+
@abc.abstractmethod
46+
def is_armed(self):
47+
"""
48+
Retrieves the armed state of the hardware watchdog and if armed, the
49+
number of seconds remaining on the watchdog timer
50+
51+
Returns:
52+
A tuple of the form (bool, int). If the watchdog is armed, the
53+
first value will be 'true' and the second value will be the
54+
number of seconds remaining on the watchdog timer. If the watchdog
55+
is disarmed, the first value will be 'false' and the integer
56+
returned as the second value should be ignored.
57+
"""
58+
return (false, 0)

0 commit comments

Comments
 (0)