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

Fix fan speed read #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix fan speed read #30

wants to merge 1 commit into from

Conversation

dprital
Copy link
Owner

@dprital dprital commented Aug 7, 2024

Why I did it

Reading fan speed can lead to the following Error:

ERR pmon#thermalctld: Failed to read from file /var/run/hw-management/thermal/fan1_speed_get - ValueError("invalid literal for int() with base 10: ''")

The error message means that the string provided to int could not be parsed as an integer.

In order to avoid from it, "float" need to be used according to the following example:

int(float('55063.000000'))

    def get_speed(self, idx):
        # 1 based fan index 
        if idx < 1 or idx > self.num_fans: 
            print("Invalid fan index %d\n" % idx)
            return 0

        attr = "fan" + str(idx) + "_input"
        output = pddf_obj.get_attr_name_output("FAN-CTRL", attr)
        if not output:
            return 0

        #mode = output['mode']
        val = output['status'].rstrip()

        if val.isalpha():
            return 0
        else:
            rpm_speed = int(float(val))

        return rpm_speed

    def get_speeds(self):
        num_fan = self.get_num_fan()
        ret = "FAN_INDEX\t\tRPM\n"

        for i in range(1, num_fan+1):
            attr1 = "fan" + str(i) + "_input"
            output = pddf_obj.get_attr_name_output("FAN-CTRL", attr1)
            if not output:
                return ""

            #mode = output['mode']
            val = output['status'].rstrip()

            if val.isalpha():
                frpm = 0
            else:
                frpm = int(val)

            ret += "FAN-%d\t\t\t%d\n" % (i, frpm)

        return ret

While the code at def get_speed(self, idx): is protected, the code in def get_speeds(self): is not.
So the fix should be to change frpm = int(val) into frpm = int(float(val)) in this API

Work item tracking
  • Microsoft ADO (number only):

How I did it

Add float(val)

How to verify it

Run sonic-mgmt tests

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205
  • 202211
  • 202305

Tested branch (Please provide the tested image version)

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant