Skip to content

Commit

Permalink
Bug fix: the fields that are not supported by vendor should be "N/A" …
Browse files Browse the repository at this point in the history
…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 <stephens@nvidia.com>
  • Loading branch information
stephenxs committed Mar 30, 2021
1 parent c5be3ca commit 450b7d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
36 changes: 18 additions & 18 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class PsuStatus(object):
return True

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

def set_temperature(self, temperature, high_threshold):
if not temperature or not high_threshold:
if temperature == NOT_AVAILABLE or high_threshold == NOT_AVAILABLE:
if self.temperature_good is not True:
self.logger.log_warning('PSU temperature or high_threshold become unavailable, '
'temperature={}, high_threshold={}'.format(temperature, high_threshold))
Expand Down Expand Up @@ -445,23 +445,23 @@ class DaemonPsud(daemon_base.DaemonBase):
name = get_psu_key(index)
presence = _wrapper_get_psu_presence(index)
power_good = False
voltage = None
voltage_high_threshold = None
voltage_low_threshold = None
temperature = None
temperature_threshold = None
current = None
power = None
voltage = NOT_AVAILABLE
voltage_high_threshold = NOT_AVAILABLE
voltage_low_threshold = NOT_AVAILABLE
temperature = NOT_AVAILABLE
temperature_threshold = NOT_AVAILABLE
current = NOT_AVAILABLE
power = NOT_AVAILABLE
is_replaceable = try_get(psu.is_replaceable, False)
if presence:
power_good = _wrapper_get_psu_status(index)
voltage = try_get(psu.get_voltage)
voltage_high_threshold = try_get(psu.get_voltage_high_threshold)
voltage_low_threshold = try_get(psu.get_voltage_low_threshold)
temperature = try_get(psu.get_temperature)
temperature_threshold = try_get(psu.get_temperature_high_threshold)
current = try_get(psu.get_current)
power = try_get(psu.get_power)
voltage = try_get(psu.get_voltage, NOT_AVAILABLE)
voltage_high_threshold = try_get(psu.get_voltage_high_threshold, NOT_AVAILABLE)
voltage_low_threshold = try_get(psu.get_voltage_low_threshold, NOT_AVAILABLE)
temperature = try_get(psu.get_temperature, NOT_AVAILABLE)
temperature_threshold = try_get(psu.get_temperature_high_threshold, NOT_AVAILABLE)
current = try_get(psu.get_current, NOT_AVAILABLE)
power = try_get(psu.get_power, NOT_AVAILABLE)

if index not in self.psu_status_dict:
self.psu_status_dict[index] = PsuStatus(self, psu)
Expand Down Expand Up @@ -508,8 +508,8 @@ class DaemonPsud(daemon_base.DaemonBase):
self._set_psu_led(psu, psu_status)

fvs = swsscommon.FieldValuePairs(
[(PSU_INFO_MODEL_FIELD, str(try_get(psu.get_model))),
(PSU_INFO_SERIAL_FIELD, str(try_get(psu.get_serial))),
[(PSU_INFO_MODEL_FIELD, str(try_get(psu.get_model, NOT_AVAILABLE))),
(PSU_INFO_SERIAL_FIELD, str(try_get(psu.get_serial, NOT_AVAILABLE))),
(PSU_INFO_TEMP_FIELD, str(temperature)),
(PSU_INFO_TEMP_TH_FIELD, str(temperature_threshold)),
(PSU_INFO_VOLTAGE_FIELD, str(voltage)),
Expand Down
20 changes: 10 additions & 10 deletions sonic-psud/tests/test_PsuStatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,27 @@ def test_set_voltage(self):
assert psu_status.voltage_good == True

# Test passing parameters as None when voltage_good == True
ret = psu_status.set_voltage(None, 12.5, 11.5)
ret = psu_status.set_voltage(psud.NOT_AVAILABLE, 12.5, 11.5)
assert ret == False
assert psu_status.voltage_good == True
ret = psu_status.set_voltage(11.5, None, 11.5)
ret = psu_status.set_voltage(11.5, psud.NOT_AVAILABLE, 11.5)
assert ret == False
assert psu_status.voltage_good == True
ret = psu_status.set_voltage(11.5, 12.5, None)
ret = psu_status.set_voltage(11.5, 12.5, psud.NOT_AVAILABLE)
assert ret == False
assert psu_status.voltage_good == True

# Test passing parameters as None when voltage_good == False
psu_status.voltage_good = False
ret = psu_status.set_voltage(None, 12.5, 11.5)
ret = psu_status.set_voltage(psud.NOT_AVAILABLE, 12.5, 11.5)
assert ret == False
assert psu_status.voltage_good == True
psu_status.voltage_good = False
ret = psu_status.set_voltage(11.5, None, 11.5)
ret = psu_status.set_voltage(11.5, psud.NOT_AVAILABLE, 11.5)
assert ret == False
assert psu_status.voltage_good == True
psu_status.voltage_good = False
ret = psu_status.set_voltage(11.5, 12.5, None)
ret = psu_status.set_voltage(11.5, 12.5, psud.NOT_AVAILABLE)
assert ret == False
assert psu_status.voltage_good == True

Expand Down Expand Up @@ -178,20 +178,20 @@ def test_set_temperature(self):
assert psu_status.temperature_good == True

# Test passing parameters as None when temperature_good == True
ret = psu_status.set_temperature(None, 50.0)
ret = psu_status.set_temperature(psud.NOT_AVAILABLE, 50.0)
assert ret == False
assert psu_status.temperature_good == True
ret = psu_status.set_temperature(20.123, None)
ret = psu_status.set_temperature(20.123, psud.NOT_AVAILABLE)
assert ret == False
assert psu_status.temperature_good == True

# Test passing parameters as None when temperature_good == False
psu_status.temperature_good = False
ret = psu_status.set_temperature(None, 50.0)
ret = psu_status.set_temperature(psud.NOT_AVAILABLE, 50.0)
assert ret == False
assert psu_status.temperature_good == True
psu_status.temperature_good = False
ret = psu_status.set_temperature(20.123, None)
ret = psu_status.set_temperature(20.123, psud.NOT_AVAILABLE)
assert ret == False
assert psu_status.temperature_good == True

Expand Down

0 comments on commit 450b7d7

Please sign in to comment.