Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[psud] Bug fix: the fields that are not supported by vendor should be "N/A" in STATE_DB #168

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,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 @@ -325,7 +325,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 @@ -443,23 +443,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 @@ -506,8 +506,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 @@ -117,27 +117,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 @@ -174,20 +174,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