Skip to content

Commit 450b7d7

Browse files
authored
Bug fix: the fields that are not supported by vendor should be "N/A" in STATE_DB (#168)
- Initialize fields as "N/A" and set the field to "N/A" for those not supported by vendor API - Update set_voltage, set_temperature, treating "N/A" instead of None as invalid values - Update unit test cases accordingly Signed-off-by: Stephen Sun <[email protected]>
1 parent c5be3ca commit 450b7d7

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

sonic-psud/scripts/psud

+18-18
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class PsuStatus(object):
305305
return True
306306

307307
def set_voltage(self, voltage, high_threshold, low_threshold):
308-
if not voltage or not high_threshold or not low_threshold:
308+
if voltage == NOT_AVAILABLE or high_threshold == NOT_AVAILABLE or low_threshold == NOT_AVAILABLE:
309309
if self.voltage_good is not True:
310310
self.logger.log_warning('PSU voltage or high_threshold or low_threshold become unavailable, '
311311
'voltage={}, high_threshold={}, low_threshold={}'.format(voltage, high_threshold, low_threshold))
@@ -320,7 +320,7 @@ class PsuStatus(object):
320320
return True
321321

322322
def set_temperature(self, temperature, high_threshold):
323-
if not temperature or not high_threshold:
323+
if temperature == NOT_AVAILABLE or high_threshold == NOT_AVAILABLE:
324324
if self.temperature_good is not True:
325325
self.logger.log_warning('PSU temperature or high_threshold become unavailable, '
326326
'temperature={}, high_threshold={}'.format(temperature, high_threshold))
@@ -445,23 +445,23 @@ class DaemonPsud(daemon_base.DaemonBase):
445445
name = get_psu_key(index)
446446
presence = _wrapper_get_psu_presence(index)
447447
power_good = False
448-
voltage = None
449-
voltage_high_threshold = None
450-
voltage_low_threshold = None
451-
temperature = None
452-
temperature_threshold = None
453-
current = None
454-
power = None
448+
voltage = NOT_AVAILABLE
449+
voltage_high_threshold = NOT_AVAILABLE
450+
voltage_low_threshold = NOT_AVAILABLE
451+
temperature = NOT_AVAILABLE
452+
temperature_threshold = NOT_AVAILABLE
453+
current = NOT_AVAILABLE
454+
power = NOT_AVAILABLE
455455
is_replaceable = try_get(psu.is_replaceable, False)
456456
if presence:
457457
power_good = _wrapper_get_psu_status(index)
458-
voltage = try_get(psu.get_voltage)
459-
voltage_high_threshold = try_get(psu.get_voltage_high_threshold)
460-
voltage_low_threshold = try_get(psu.get_voltage_low_threshold)
461-
temperature = try_get(psu.get_temperature)
462-
temperature_threshold = try_get(psu.get_temperature_high_threshold)
463-
current = try_get(psu.get_current)
464-
power = try_get(psu.get_power)
458+
voltage = try_get(psu.get_voltage, NOT_AVAILABLE)
459+
voltage_high_threshold = try_get(psu.get_voltage_high_threshold, NOT_AVAILABLE)
460+
voltage_low_threshold = try_get(psu.get_voltage_low_threshold, NOT_AVAILABLE)
461+
temperature = try_get(psu.get_temperature, NOT_AVAILABLE)
462+
temperature_threshold = try_get(psu.get_temperature_high_threshold, NOT_AVAILABLE)
463+
current = try_get(psu.get_current, NOT_AVAILABLE)
464+
power = try_get(psu.get_power, NOT_AVAILABLE)
465465

466466
if index not in self.psu_status_dict:
467467
self.psu_status_dict[index] = PsuStatus(self, psu)
@@ -508,8 +508,8 @@ class DaemonPsud(daemon_base.DaemonBase):
508508
self._set_psu_led(psu, psu_status)
509509

510510
fvs = swsscommon.FieldValuePairs(
511-
[(PSU_INFO_MODEL_FIELD, str(try_get(psu.get_model))),
512-
(PSU_INFO_SERIAL_FIELD, str(try_get(psu.get_serial))),
511+
[(PSU_INFO_MODEL_FIELD, str(try_get(psu.get_model, NOT_AVAILABLE))),
512+
(PSU_INFO_SERIAL_FIELD, str(try_get(psu.get_serial, NOT_AVAILABLE))),
513513
(PSU_INFO_TEMP_FIELD, str(temperature)),
514514
(PSU_INFO_TEMP_TH_FIELD, str(temperature_threshold)),
515515
(PSU_INFO_VOLTAGE_FIELD, str(voltage)),

sonic-psud/tests/test_PsuStatus.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,27 @@ def test_set_voltage(self):
121121
assert psu_status.voltage_good == True
122122

123123
# Test passing parameters as None when voltage_good == True
124-
ret = psu_status.set_voltage(None, 12.5, 11.5)
124+
ret = psu_status.set_voltage(psud.NOT_AVAILABLE, 12.5, 11.5)
125125
assert ret == False
126126
assert psu_status.voltage_good == True
127-
ret = psu_status.set_voltage(11.5, None, 11.5)
127+
ret = psu_status.set_voltage(11.5, psud.NOT_AVAILABLE, 11.5)
128128
assert ret == False
129129
assert psu_status.voltage_good == True
130-
ret = psu_status.set_voltage(11.5, 12.5, None)
130+
ret = psu_status.set_voltage(11.5, 12.5, psud.NOT_AVAILABLE)
131131
assert ret == False
132132
assert psu_status.voltage_good == True
133133

134134
# Test passing parameters as None when voltage_good == False
135135
psu_status.voltage_good = False
136-
ret = psu_status.set_voltage(None, 12.5, 11.5)
136+
ret = psu_status.set_voltage(psud.NOT_AVAILABLE, 12.5, 11.5)
137137
assert ret == False
138138
assert psu_status.voltage_good == True
139139
psu_status.voltage_good = False
140-
ret = psu_status.set_voltage(11.5, None, 11.5)
140+
ret = psu_status.set_voltage(11.5, psud.NOT_AVAILABLE, 11.5)
141141
assert ret == False
142142
assert psu_status.voltage_good == True
143143
psu_status.voltage_good = False
144-
ret = psu_status.set_voltage(11.5, 12.5, None)
144+
ret = psu_status.set_voltage(11.5, 12.5, psud.NOT_AVAILABLE)
145145
assert ret == False
146146
assert psu_status.voltage_good == True
147147

@@ -178,20 +178,20 @@ def test_set_temperature(self):
178178
assert psu_status.temperature_good == True
179179

180180
# Test passing parameters as None when temperature_good == True
181-
ret = psu_status.set_temperature(None, 50.0)
181+
ret = psu_status.set_temperature(psud.NOT_AVAILABLE, 50.0)
182182
assert ret == False
183183
assert psu_status.temperature_good == True
184-
ret = psu_status.set_temperature(20.123, None)
184+
ret = psu_status.set_temperature(20.123, psud.NOT_AVAILABLE)
185185
assert ret == False
186186
assert psu_status.temperature_good == True
187187

188188
# Test passing parameters as None when temperature_good == False
189189
psu_status.temperature_good = False
190-
ret = psu_status.set_temperature(None, 50.0)
190+
ret = psu_status.set_temperature(psud.NOT_AVAILABLE, 50.0)
191191
assert ret == False
192192
assert psu_status.temperature_good == True
193193
psu_status.temperature_good = False
194-
ret = psu_status.set_temperature(20.123, None)
194+
ret = psu_status.set_temperature(20.123, psud.NOT_AVAILABLE)
195195
assert ret == False
196196
assert psu_status.temperature_good == True
197197

0 commit comments

Comments
 (0)